mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 10:57:13 +08:00 
			
		
		
		
	refactor: 优化通知公告相关代码
This commit is contained in:
		| @@ -33,7 +33,12 @@ public enum NoticeMethodEnum implements BaseEnum<Integer> { | ||||
|     /** | ||||
|      * 系统消息 | ||||
|      */ | ||||
|     SYSTEM_MESSAGE(1, "系统消息"),; | ||||
|     SYSTEM_MESSAGE(1, "系统消息"), | ||||
|  | ||||
|     /** | ||||
|      * 登录弹窗 | ||||
|      */ | ||||
|     POPUP(2, "登录弹窗"),; | ||||
|  | ||||
|     private final Integer value; | ||||
|     private final String description; | ||||
|   | ||||
| @@ -45,12 +45,13 @@ public interface NoticeMapper extends BaseMapper<NoticeDO> { | ||||
|     IPage<NoticeResp> selectNoticePage(@Param("page") Page<NoticeDO> page, @Param("query") NoticeQuery query); | ||||
|  | ||||
|     /** | ||||
|      * 查询未读公告数量 | ||||
|      * 查询未读公告 ID 列表 | ||||
|      * | ||||
|      * @param userId 用户 ID | ||||
|      * @return 未读公告数量 | ||||
|      * @param noticeMethod 通知方式 | ||||
|      * @param userId       用户 ID | ||||
|      * @return 未读公告 ID 列表 | ||||
|      */ | ||||
|     Long selectUnreadCountByUserId(@Param("userId") Long userId); | ||||
|     List<Long> selectUnreadIdsByUserId(@Param("noticeMethod") Integer noticeMethod, @Param("userId") Long userId); | ||||
|  | ||||
|     /** | ||||
|      * 查询仪表盘公告列表 | ||||
|   | ||||
| @@ -24,15 +24,15 @@ import java.io.Serial; | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| /** | ||||
|  * 未读公告响应参数 | ||||
|  * 未读公告数量响应参数 | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @since 2025/5/20 22:00 | ||||
|  * @since 2025/5/22 22:15 | ||||
|  */ | ||||
| @Data | ||||
| @NoArgsConstructor | ||||
| @Schema(description = "未读公告响应参数") | ||||
| public class NoticeUnreadResp implements Serializable { | ||||
| @Schema(description = "未读公告数量响应参数") | ||||
| public class NoticeUnreadCountResp implements Serializable { | ||||
| 
 | ||||
|     @Serial | ||||
|     private static final long serialVersionUID = 1L; | ||||
| @@ -41,9 +41,9 @@ public class NoticeUnreadResp implements Serializable { | ||||
|      * 未读公告数量 | ||||
|      */ | ||||
|     @Schema(description = "未读公告数量", example = "1") | ||||
|     private Long total; | ||||
|     private Integer total; | ||||
| 
 | ||||
|     public NoticeUnreadResp(Long total) { | ||||
|     public NoticeUnreadCountResp(Integer total) { | ||||
|         this.total = total; | ||||
|     } | ||||
| } | ||||
| @@ -16,13 +16,13 @@ | ||||
|  | ||||
| package top.continew.admin.system.service; | ||||
|  | ||||
| import top.continew.admin.system.enums.NoticeMethodEnum; | ||||
| import top.continew.admin.system.model.entity.NoticeDO; | ||||
| import top.continew.admin.system.model.query.NoticeQuery; | ||||
| import top.continew.admin.system.model.req.NoticeReq; | ||||
| import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp; | ||||
| import top.continew.admin.system.model.resp.notice.NoticeDetailResp; | ||||
| import top.continew.admin.system.model.resp.notice.NoticeResp; | ||||
| import top.continew.admin.system.model.resp.notice.NoticeUnreadResp; | ||||
| import top.continew.starter.data.mp.service.IService; | ||||
| import top.continew.starter.extension.crud.service.BaseService; | ||||
|  | ||||
| @@ -44,12 +44,13 @@ public interface NoticeService extends BaseService<NoticeResp, NoticeDetailResp, | ||||
|     void publish(NoticeDO notice); | ||||
|  | ||||
|     /** | ||||
|      * 查询未读公告数量 | ||||
|      *  | ||||
|      * 查询未读公告 ID 列表 | ||||
|      * | ||||
|      * @param method 通知方式 | ||||
|      * @param userId 用户 ID | ||||
|      * @return 未读公告响应参数 | ||||
|      * @return 未读公告 ID 响应参数 | ||||
|      */ | ||||
|     NoticeUnreadResp countUnreadByUserId(Long userId); | ||||
|     List<Long> listUnreadIdsByUserId(NoticeMethodEnum method, Long userId); | ||||
|  | ||||
|     /** | ||||
|      * 阅读公告 | ||||
|   | ||||
| @@ -31,7 +31,6 @@ import top.continew.admin.system.model.req.NoticeReq; | ||||
| import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp; | ||||
| import top.continew.admin.system.model.resp.notice.NoticeDetailResp; | ||||
| import top.continew.admin.system.model.resp.notice.NoticeResp; | ||||
| import top.continew.admin.system.model.resp.notice.NoticeUnreadResp; | ||||
| import top.continew.admin.system.service.MessageService; | ||||
| import top.continew.admin.system.service.NoticeLogService; | ||||
| import top.continew.admin.system.service.NoticeService; | ||||
| @@ -169,8 +168,8 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, NoticeDO, N | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public NoticeUnreadResp countUnreadByUserId(Long userId) { | ||||
|         return new NoticeUnreadResp(baseMapper.selectUnreadCountByUserId(userId)); | ||||
|     public List<Long> listUnreadIdsByUserId(NoticeMethodEnum method, Long userId) { | ||||
|         return baseMapper.selectUnreadIdsByUserId(method != null ? method.getValue() : null, userId); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -24,7 +24,7 @@ | ||||
|         LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id | ||||
|         <where> | ||||
|             <if test="query.userId != null"> | ||||
|                 (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_EXTRACT(t1.notice_users, "$[0]") = CAST(#{query.userId} AS CHAR))) | ||||
|                 (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{userId}, '"')))) | ||||
|             </if> | ||||
|             <if test="query.title != null and query.title != ''"> | ||||
|                 AND t1.title LIKE CONCAT('%', #{query.title}, '%') | ||||
| @@ -41,12 +41,15 @@ | ||||
|         </if> | ||||
|     </select> | ||||
|  | ||||
|     <select id="selectUnreadCountByUserId" resultType="java.lang.Long"> | ||||
|     <select id="selectUnreadIdsByUserId" resultType="java.lang.Long"> | ||||
|         SELECT | ||||
|             COUNT(1) | ||||
|             t1.id | ||||
|         FROM sys_notice AS t1 | ||||
|             LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id | ||||
|         LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id | ||||
|         WHERE (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{userId}, '"')))) | ||||
|         <if test="noticeMethod != null"> | ||||
|             AND JSON_CONTAINS(t1.notice_methods, CAST(#{noticeMethod} AS CHAR)) | ||||
|         </if> | ||||
|         AND t2.read_time IS NULL | ||||
|     </select> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user