package com.caimei.www.service.page.impl;

import com.caimei.www.mapper.SinglePageDao;
import com.caimei.www.pojo.JsonModel;
import com.caimei.www.pojo.page.PageContent;
import com.caimei.www.pojo.save.Suggestion;
import com.caimei.www.service.page.HelpService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Description
 *
 * @author : Charles
 * @date : 2020/8/27
 */
@Service
public class HelpServiceImpl implements HelpService {

    @Resource
    private SinglePageDao singlePageDao;
    @Value("${caimei.wwwDomain}")
    private String domain;

    /**
     * 根据ID查找帮助页
     *
     * @param id
     */
    @Override
    public PageContent getHelpPageById(Integer id) {
        return singlePageDao.getHelpPageById(id);
    }

    /**
     * 保存投诉建议
     *
     * @param suggestion
     * @return
     */
    @Override
    public JsonModel suggestionSave(Suggestion suggestion) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new Date());
        Integer maxId = singlePageDao.getMaxSuggestionId();
        suggestion.setAddTime(format);
        suggestion.setSuggestionID(maxId+1);
        singlePageDao.suggestionSave(suggestion);
        return JsonModel.success("投诉建议成功！","");
    }
}
