package com.jwipc.sys.controller.pc;

import com.jwipc.sys.dto.MsgNoticeDTO;
import com.jwipc.sys.logic.NoticeLogic;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
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 java.text.SimpleDateFormat;
import java.util.Date;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * @author shenyang.ou
 * @date 2024/1/31 15:14
 * @desc 公告
 */
@Controller
@RequestMapping(MODULE_ROOT + "/notice")
@RequiredArgsConstructor
public class NoticePageController {
    private final NoticeLogic noticeLogic;
    @GetMapping("/index")
    public String index() {
        return MODULE_ROOT + "/notice/list";
    }

    @GetMapping("/detail")
    public String detail(Model model, Long id) {
        MsgNoticeDTO msgNoticeDTO;
        if (id != null) {
            msgNoticeDTO = noticeLogic.getById(id);
        } else {
            msgNoticeDTO = new MsgNoticeDTO();
        }
        model.addAttribute("notice", msgNoticeDTO);
        return MODULE_ROOT + "/notice/detail";
    }

    /**
     * 查看通知公告详情
     *
     * @param model model
     * @param id 通知公告ID
     * @return 结果
     */
    @RequestMapping("/look")
    public String lookNoticeDetail(Model model, Long id) {
        MsgNoticeDTO msgNoticeDTO = noticeLogic.getById(id);
        if (StringUtils.isEmpty(msgNoticeDTO.getContent())) {
            model.addAttribute("biaoti", "暂无数据");
            model.addAttribute("content", "");
            model.addAttribute("publishTime", msgNoticeDTO.getPublishTime());
        } else {
            model.addAttribute("biaoti", msgNoticeDTO.getTitle());
            model.addAttribute("content", msgNoticeDTO.getContent());
            model.addAttribute("publishTime", msgNoticeDTO.getPublishTime());
        }
        return MODULE_ROOT + "/notice/notice_detail";
    }

    /**
     * 工作台通知公告更多列表页面
     *
     * @return 结果
     */
    @RequestMapping("/more")
    public String indexMorePage() {
        return MODULE_ROOT + "/notice/notice_more";
    }
}
