package com.sunxung.factoring.web.sys.systemMsg;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sunxung.factoring.component.util.DateUtil;
import com.sunxung.factoring.dict.impl.MsgTypeDict;
import com.sunxung.factoring.entity.sys.systemMsg.MsgReadState;
import com.sunxung.factoring.entity.sys.systemMsg.SystemMsg;
import com.sunxung.factoring.entity.sys.systemMsg.vo.SearchSystemMsg;
import com.sunxung.factoring.service.sys.DictionaryService;
import com.sunxung.factoring.service.sys.systemMsg.SystemMsgService;

/**
 * @description:消息Controller
 * @author:吴端丽
 * @e-mail:1912942707@qq.com
 * @date:2018年3月8日 下午8:34:04
 */
@Controller
public class SystemMsgController {

    private static String PREFIX = "sys/systemMsg/";
    @Autowired
    private SystemMsgService systemMsgService;
    @Autowired
    private DictionaryService dicService;

    /**
     * 进入已发送列表页面. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/sentMsgList")
    public String sentList() {
        return PREFIX + "hasBeenSendList";
    }

    /**
     * 分页获取已发送列表数据. <br/>
     * 
     * @param search
     * @return
     */
    @RequestMapping("/systemMsg/do_sentList")
    @ResponseBody
    public Object do_sentList(SearchSystemMsg search) {
        return systemMsgService.findSentList(search);
    }

    /**
     * 进入新建消息页面. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/add")
    public String add() {
        return PREFIX + "msgAdd";
    }

    /**
     * 新建消息. <br/>
     * 
     * @param systemMsg
     * @return
     */
    @RequestMapping("/systemMsg/do_add")
    @ResponseBody
    public Object do_add(SystemMsg systemMsg) {
        return systemMsgService.add(systemMsg);
    }

    /**
     * 进入已发消息查看页面. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/sentMsgView")
    public String sentView() {
        return PREFIX + "sentMsgView";
    }

    /**
     * 获取已发消息查看数据. <br/>
     * 
     * @param systemMsg
     * @return
     */
    @RequestMapping("/systemMsg/do_sentView")
    @ResponseBody
    public Object do_sentView(Long id) {
        return systemMsgService.getSentMsgView(id);
    }

    /**
     * 进入查看消息已读未读详情页面. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/readDetail")
    public String readDetail() {
        return PREFIX + "readDetail";
    }

    /**
     * 获取查看消息已读未读详情数据. <br/>
     * 
     * @param id
     * @return
     */
    @RequestMapping("/systemMsg/do_readDetail")
    @ResponseBody
    public Object do_readDetail(Long id) {
        return systemMsgService.getSystemMsgReadDetail(id);
    }

    /**
     * 删除已发送列表中的数据. <br/>
     * 
     * @param ids
     * @return
     */
    @RequestMapping("/systemMsg/do_deleteSentMsg")
    @ResponseBody
    public Object do_deleteSentMsg(MsgReadState msgRead) {
        return systemMsgService.deleteSentMsg(msgRead);
    }

    /**
     * 进入消息管理列表页面. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/messageManageList")
    public String messageManageList(Model model) {
        model.addAttribute("msgTypeList", dicService.findByParentCode(MsgTypeDict.CODE));
        return PREFIX + "messageManageList";
    }

    /**
     * 分页查询消息管理列表数据. <br/>
     * 
     * @param ids
     * @return
     */
    @RequestMapping("/systemMsg/do_messageManageList")
    @ResponseBody
    public Object do_messageManageList(SearchSystemMsg search) {
        return systemMsgService.findMessageManageList(search);
    }

    /**
     * 批量/单条已读、未读. <br/>
     * 
     * @param msgIds
     * @param readState
     * @return
     */
    @RequestMapping("/systemMsg/do_updateReadState")
    @ResponseBody
    public Object do_updateReadState(MsgReadState msgRead) {
        return systemMsgService.updateReadState(msgRead);
    }

    /**
     * 进入消息管理列表中的查看页面. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/msgView")
    public String msgView() {
        return PREFIX + "msgView";
    }

    /**
     * 获取消息管理列表中查看详情数据. <br/>
     * 
     * @param msgIds
     * @param readState
     * @return
     */
    @RequestMapping("/systemMsg/do_getMsgDetail")
    @ResponseBody
    public Object do_getMsgDetail(Long id) {
        return systemMsgService.getMsgDetail(id);
    }

    /**
     * 删除消息管理列表中数据. <br/>
     * 
     * @param ids
     * @return
     */
    @RequestMapping("/systemMsg/do_deleteMsg")
    @ResponseBody
    public Object do_deleteMsg(MsgReadState msg) {
        return systemMsgService.deleteMsg(msg);
    }

    /**
     * 获取用户所有未读消息数量. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/do_getUnreadMessageNum")
    @ResponseBody
    public Object do_getUnreadMessageNum() {
        return systemMsgService.getUnreadMessageNum();
    }

    /**
     * 获取当前系统时间. <br/>
     * 
     * @return
     */
    @RequestMapping("/systemMsg/do_getNowDateTime")
    @ResponseBody
    public Object do_getNowDateTime() {
        return DateUtil.dateToString(DateUtil.addMinute(new Date(), 5), "yyyy-MM-dd HH:mm");
    }

    @GetMapping("/systemMsg/do_existByTaskId")
    @ResponseBody
    public Object do_existByTaskId(String taskId) {
        return systemMsgService.existByTaskId(taskId);
    }
}
