src/main/java/com/mindskip/xzs/controller/admin/DepartmentExamineController.java
@@ -5,13 +5,18 @@ import com.mindskip.xzs.base.BaseApiController; import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.domain.DepartmentExamine; import com.mindskip.xzs.domain.Notify; import com.mindskip.xzs.domain.enums.NotifyRefType; import com.mindskip.xzs.domain.vo.DepartmentExamineVO; import com.mindskip.xzs.service.DepartmentExamineService; import com.mindskip.xzs.service.NotifyService; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.ObjectUtils; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; import java.util.Date; /** * <p> @@ -27,6 +32,7 @@ public class DepartmentExamineController extends BaseApiController { private final DepartmentExamineService departmentExamineService; private final NotifyService notifyService; @RequestMapping(value = "list", method = RequestMethod.POST) public RestResponse<PageInfo<DepartmentExamineVO>> list(@RequestBody DepartmentExamineVO departmentExamineVO) { @@ -34,11 +40,23 @@ return RestResponse.ok(departmentExamineService.pageInfo(departmentExamineVO)); } @Transactional(rollbackFor = Exception.class) @RequestMapping(value = "save", method = RequestMethod.POST) public RestResponse<Boolean> save(@RequestBody DepartmentExamine departmentExamine) { departmentExamine.setCreateTime(LocalDateTime.now()); departmentExamine.setCreateUser(getCurrentUser().getId()); return RestResponse.ok(departmentExamineService.save(departmentExamine)); departmentExamineService.save(departmentExamine); // 添加通知 Notify notify = new Notify(); notify.setCreateTime(new Date()); notify.setReadStatus(2); notify.setRefId(departmentExamine.getId()); notify.setRefType(NotifyRefType.FEEDBACK.getValue()); notify.setCreateUserId(webContext.getCurrentUser().getId()); notifyService.add(notify); return RestResponse.ok(); } @RequestMapping(value = "delete/{id}", method = RequestMethod.POST) src/main/java/com/mindskip/xzs/controller/admin/NotifyController.java
New file @@ -0,0 +1,60 @@ package com.mindskip.xzs.controller.admin; import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.domain.Notify; import com.mindskip.xzs.domain.enums.NotifyRefType; import com.mindskip.xzs.domain.vo.AdminNotifyVO; import com.mindskip.xzs.service.NotifyService; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotEmpty; import java.util.List; import java.util.stream.Collectors; /** * @author:xp * @date:2024/7/15 15:05 */ @Validated @RestController @RequiredArgsConstructor @RequestMapping("/api/admin/notify") public class NotifyController { private final NotifyService notifyService; /** * 管理员通知列表 * * @return */ @GetMapping("/admin") public RestResponse adminNotifyList() { List<Notify> notifies = notifyService.adminNotifyList(); AdminNotifyVO data = new AdminNotifyVO(); data.setTotal(notifies.size()); long feedback = notifies.stream().filter(notify -> NotifyRefType.FEEDBACK.getValue().equals(notify.getRefType())).count(); long mobilize = notifies.stream().filter(notify -> NotifyRefType.MOBILIZE.getValue().equals(notify.getRefType())).count(); long status = notifies.stream().filter(notify -> NotifyRefType.STATUS.getValue().equals(notify.getRefType())).count(); data.setFeedBack(feedback); data.setMobilize(mobilize); data.setStatus(status); List<Integer> ids = notifies.stream().map(Notify::getId).collect(Collectors.toList()); data.setIds(ids); return RestResponse.ok(data); } @GetMapping("/me") public RestResponse notifyMeList() { return RestResponse.ok(notifyService.notifyMeList()); } @PostMapping("/read") public RestResponse readNotify(@RequestBody @NotEmpty List<Integer> ids) { notifyService.setHasRead(ids); return RestResponse.ok(); } } src/main/java/com/mindskip/xzs/domain/Notify.java
New file @@ -0,0 +1,43 @@ package com.mindskip.xzs.domain; import lombok.Data; import java.util.Date; /** * 通知 * * @author:xp * @date:2024/7/15 14:23 */ @Data public class Notify { private Integer id; /** 通知谁 */ private Integer notifyWho; /** 关联数据 */ private Integer refId; /** 关联数据类型 */ private String refType; /** 通知时间 */ private Date createTime; /** 通知类型 */ private String notifyType; /** 通知谁 */ private Integer readStatus; /** 发起人ID */ private Integer createUserId; /** 发起人部门ID */ private Integer createDeptId; private Integer deleted; } src/main/java/com/mindskip/xzs/domain/enums/NotifyRefType.java
New file @@ -0,0 +1,27 @@ package com.mindskip.xzs.domain.enums; import lombok.Getter; /** * @author:xp * @date:2024/7/15 15:30 */ @Getter public enum NotifyRefType { FEEDBACK("feedback", "错题反馈"), MOBILIZE("mobilize", "调动部门"), STATUS("status", "状态设置"), ; private final String value; private final String desc; NotifyRefType(String value, String desc) { this.value = value; this.desc = desc; } } src/main/java/com/mindskip/xzs/domain/vo/AdminNotifyVO.java
New file @@ -0,0 +1,42 @@ package com.mindskip.xzs.domain.vo; import lombok.Data; import java.util.List; /** * 管理员通知 * * @author:xp * @date:2024/7/15 16:45 */ @Data public class AdminNotifyVO { private List<Integer> ids; /** * 所有代办 * */ private Integer total; /** * 错题反馈代办 * */ private Long feedBack; /** * 部门调动代办 * */ private Long mobilize; /** * 状态设置 * */ private Long status; } src/main/java/com/mindskip/xzs/repository/NotifyMapper.java
New file @@ -0,0 +1,43 @@ package com.mindskip.xzs.repository; import com.mindskip.xzs.domain.Notify; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** * @author:xp * @date:2024/7/15 14:36 */ @Mapper public interface NotifyMapper { /** * 添加 * * @param notify */ void add(Notify notify); /** * 查询通知我的 * * @return */ List<Notify> notifyMeList(@Param("userId") Integer userId); /** * 设置为已读 * * @param ids */ void setHasRead(@Param("ids") List<Integer> ids); /** * 管理员通知列表 * * @return */ List<Notify> adminNotifyList(); } src/main/java/com/mindskip/xzs/service/NotifyService.java
New file @@ -0,0 +1,38 @@ package com.mindskip.xzs.service; import com.mindskip.xzs.domain.Notify; import java.util.List; /** * @author:xp * @date:2024/7/15 15:00 */ public interface NotifyService { /** * 添加 * * @param notify */ void add(Notify notify); /** * 通知我的 * */ List<Notify> notifyMeList(); /** * 已读 * */ void setHasRead(List<Integer> ids); /** * 管理员通知 * * @return */ List<Notify> adminNotifyList(); } src/main/java/com/mindskip/xzs/service/impl/FeedbackServiceImpl.java
@@ -4,18 +4,25 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.mindskip.xzs.context.WebContext; import com.mindskip.xzs.domain.Feedback; import com.mindskip.xzs.domain.Notify; import com.mindskip.xzs.domain.enums.NotifyRefType; import com.mindskip.xzs.domain.question.QuestionObject; import com.mindskip.xzs.domain.vo.FeedbackVO; import com.mindskip.xzs.repository.FeedbackMapper; import com.mindskip.xzs.repository.UserMapper; import com.mindskip.xzs.service.FeedbackService; import com.mindskip.xzs.service.NotifyService; import com.mindskip.xzs.utility.JsonUtil; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.Date; import java.util.stream.Collectors; /** @@ -28,12 +35,23 @@ public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService { private final FeedbackMapper feedbackMapper; private final WebContext webContext; private final NotifyService notifyService; @Override @Transactional(rollbackFor = Exception.class) public void saveFeedback(FeedbackVO feedbackVO) { Feedback feedback = new Feedback(); BeanUtils.copyProperties(feedbackVO, feedback); feedbackMapper.insert(feedback); // 添加通知 Notify notify = new Notify(); notify.setCreateTime(new Date()); notify.setReadStatus(2); notify.setRefId(feedback.getId()); notify.setRefType(NotifyRefType.FEEDBACK.getValue()); notify.setCreateUserId(webContext.getCurrentUser().getId()); notifyService.add(notify); } @Override src/main/java/com/mindskip/xzs/service/impl/NotifyServiceImpl.java
New file @@ -0,0 +1,42 @@ package com.mindskip.xzs.service.impl; import com.mindskip.xzs.context.WebContext; import com.mindskip.xzs.domain.Notify; import com.mindskip.xzs.repository.NotifyMapper; import com.mindskip.xzs.service.NotifyService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; /** * @author:xp * @date:2024/7/15 15:02 */ @Service @RequiredArgsConstructor public class NotifyServiceImpl implements NotifyService { private final NotifyMapper notifyMapper; private final WebContext webContext; @Override public void add(Notify notify) { notifyMapper.add(notify); } @Override public List<Notify> notifyMeList() { return notifyMapper.notifyMeList(webContext.getCurrentUser().getId()); } @Override public void setHasRead(List<Integer> ids) { notifyMapper.setHasRead(ids); } @Override public List<Notify> adminNotifyList() { return notifyMapper.adminNotifyList(); } } src/main/resources/application-dev.yml
@@ -11,3 +11,7 @@ username: root password: 321$YcYl@1970! driver-class-name: com.mysql.cj.jdbc.Driver # url: jdbc:mysql://127.0.0.1:3306/xzsqy?useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true # username: root # password: 123456 # driver-class-name: com.mysql.cj.jdbc.Driver src/main/resources/mapper/NotifyMapper.xml
New file @@ -0,0 +1,42 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.mindskip.xzs.repository.NotifyMapper"> <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.Notify"> <id property="id" column="id"/> <result property="notifyWho" column="notify_who"/> <result property="refId" column="ref_id"/> <result property="refType" column="ref_type"/> <result property="createTime" column="create_time"/> <result property="notifyType" column="notify_type"/> <result property="readStatus" column="read_status"/> <result property="createUserId" column="create_user_id"/> <result property="createDeptId" column="create_dept_id"/> </resultMap> <sql id="Base_Column_List"> id,question_id,content_id, describe,user_id,fix, fix_time </sql> <insert id="add" keyProperty="id" useGeneratedKeys="true" keyColumn="id" parameterType="com.mindskip.xzs.domain.Notify"> insert into t_notify(notify_who, ref_id, ref_type, create_time, notify_type, read_status, create_user_id, create_dept_id) value ( #{notifyWho}, #{refId}, #{refType}, #{createTime}, #{notifyType}, #{readStatus}, #{createUserId}, #{createDeptId} ) </insert> <select id="notifyMeList" resultMap="BaseResultMap"> SELECT * FROM t_notify WHERE notify_who = #{userId} AND deleted = 0 ORDER BY read_status,create_time DESC </select> <select id="adminNotifyList" resultMap="BaseResultMap"> SELECT * FROM t_notify WHERE read_status = 2 AND deleted = 0 ORDER BY read_status,create_time DESC </select> <update id="setHasRead" parameterType="integer"> update t_notify set read_status = 1 where id in <foreach collection="ids" open="(" separator="," close=")" item="id">#{id}</foreach> </update> </mapper>