package com.vverp.controller.api; import com.vverp.util.DateUtil; import com.vverp.entity.Admin; import com.vverp.entity.Notice; import com.vverp.entity.NoticeEntity; import com.vverp.moli.util.Page; import com.vverp.moli.util.Pageable; import com.vverp.moli.util.RespData; import com.vverp.service.AdminService; import com.vverp.service.NoticeEntityService; import com.vverp.service.NoticeService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 消息通知 * * @author dealsky * @date 2020/1/15 10:21 上午 */ @RestController("apiNoticeController") @RequestMapping("/api/notice") public class NoticeController { @Resource private NoticeEntityService noticeEntityService; @Resource private AdminService adminService; @Resource private NoticeService noticeService; @RequestMapping(value = "/list", method = RequestMethod.GET) public RespData list(Pageable pageable) { Admin admin = adminService.getApp(); Page page = noticeEntityService.findPage(pageable, admin); List> list = new ArrayList<>(); for (NoticeEntity entity : page.getContent()) { Map map = new HashMap<>(); map.put("id", entity.getId()); map.put("title", entity.getNotice().getTitle()); map.put("type", entity.getNotice().getType()); map.put("read", entity.getRead()); map.put("date", DateUtil.format(entity.getCreateDate(), "yyyy-MM-dd HH:mm")); list.add(map); } return RespData.success(new Page<>(list, page.getTotal(), page.getPageable())); } @RequestMapping(value = "/view", method = RequestMethod.GET) public RespData view(Long id) { Map map = new HashMap<>(); NoticeEntity entity = noticeEntityService.find(id); map.put("title", entity.getNotice().getTitle()); map.put("type", entity.getNotice().getType()); map.put("date", DateUtil.formatDateTime(entity.getCreateDate())); map.put("content", entity.getNotice().getContent()); noticeEntityService.read(entity); return RespData.success(map); } @RequestMapping(value = "/hasNotRead", method = RequestMethod.GET) public RespData hasNotRead() { Admin admin = adminService.getApp(); return RespData.success(noticeEntityService.hasNotRead(admin)); } @RequestMapping("/option/list") public RespData optionList(Pageable pageable) { Page page = noticeService.findPage(pageable); List> list = new ArrayList<>(); for (Notice notice : page.getContent()) { Map map = new HashMap<>(); map.put("id", notice.getId()); map.put("title", notice.getTitle()); map.put("publisher", notice.getPublisher()); map.put("createDate", DateUtil.formatDate(notice.getCreateDate())); list.add(map); } return RespData.success(new Page<>(list, page.getTotal(), page.getPageable())); } @RequestMapping("/option/view") public RespData optionView(Long id) { Notice notice = noticeService.find(id); Map map = new HashMap<>(); map.put("id", notice.getId()); map.put("title", notice.getTitle()); map.put("publisher", notice.getPublisher()); map.put("content", notice.getContent()); map.put("date", DateUtil.formatDateTime(notice.getCreateDate())); return RespData.success(map); } @RequestMapping("/option/save") public RespData optionSave(Notice notice) { noticeService.saveNotice(notice); return RespData.success(); } }