Commit af4290784e852ba0f673e848af75955f03eca7c4

Authored by xrcoder
1 parent d16f8735

添加用户查询站内信分页列表数据,未读站内信数量。

yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
@@ -145,6 +145,7 @@ public interface ErrorCodeConstants { @@ -145,6 +145,7 @@ public interface ErrorCodeConstants {
145 // ========== 站内信模版 1002023000 ========== 145 // ========== 站内信模版 1002023000 ==========
146 ErrorCode NOTIFY_TEMPLATE_NOT_EXISTS = new ErrorCode(1002023000, "站内信模版不存在"); 146 ErrorCode NOTIFY_TEMPLATE_NOT_EXISTS = new ErrorCode(1002023000, "站内信模版不存在");
147 ErrorCode NOTIFY_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002023001, "已经存在编码为【{}】的站内信模板"); 147 ErrorCode NOTIFY_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002023001, "已经存在编码为【{}】的站内信模板");
  148 + ErrorCode NOTIFY_TEMPLATE_PARAM_MISS = new ErrorCode(1002023002, "模板参数({})缺失");
148 149
149 // ========== 站内信 1002024000 ========== 150 // ========== 站内信 1002024000 ==========
150 ErrorCode NOTIFY_MESSAGE_NOT_EXISTS = new ErrorCode(1002024000, "站内信不存在"); 151 ErrorCode NOTIFY_MESSAGE_NOT_EXISTS = new ErrorCode(1002024000, "站内信不存在");
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java
1 package cn.iocoder.yudao.module.system.controller.admin.notify; 1 package cn.iocoder.yudao.module.system.controller.admin.notify;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
@@ -23,6 +25,7 @@ import java.util.Collections; @@ -23,6 +25,7 @@ import java.util.Collections;
23 import java.util.List; 25 import java.util.List;
24 26
25 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 27 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  28 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
26 29
27 /** 30 /**
28 * 管理后台 - 站内信-消息中心 31 * 管理后台 - 站内信-消息中心
@@ -42,6 +45,8 @@ public class UserNotifyMessageController { @@ -42,6 +45,8 @@ public class UserNotifyMessageController {
42 @GetMapping("/page") 45 @GetMapping("/page")
43 @ApiOperation("获得站内信分页") 46 @ApiOperation("获得站内信分页")
44 public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { 47 public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
  48 + pageVO.setUserId(getLoginUserId());
  49 + pageVO.setUserType(UserTypeEnum.ADMIN.getValue());
45 PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO); 50 PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
46 return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); 51 return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
47 } 52 }
@@ -49,13 +54,22 @@ public class UserNotifyMessageController { @@ -49,13 +54,22 @@ public class UserNotifyMessageController {
49 @GetMapping("/latest/list") 54 @GetMapping("/latest/list")
50 @ApiOperation("获得最新10站内信列表") 55 @ApiOperation("获得最新10站内信列表")
51 public CommonResult<List<NotifyMessageRespVO>> getNotifyLatestMessageList() { 56 public CommonResult<List<NotifyMessageRespVO>> getNotifyLatestMessageList() {
  57 + NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO();
  58 + reqVO.setUserId(getLoginUserId());
  59 + reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
  60 + reqVO.setPageNo(1);
  61 + reqVO.setPageSize(10);
  62 + PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(reqVO);
  63 + if (CollUtil.isNotEmpty(pageResult.getList())) {
  64 + return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList()));
  65 + }
52 return success(Collections.emptyList()); 66 return success(Collections.emptyList());
53 } 67 }
54 68
55 @GetMapping("/unread/count") 69 @GetMapping("/unread/count")
56 @ApiOperation("获得未读站内信数量") 70 @ApiOperation("获得未读站内信数量")
57 public CommonResult<Long> getUnreadNotifyMessageCount() { 71 public CommonResult<Long> getUnreadNotifyMessageCount() {
58 - return success(1L); 72 + return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
59 } 73 }
60 74
61 @GetMapping("/read") 75 @GetMapping("/read")
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java
@@ -24,4 +24,10 @@ public class NotifyMessagePageReqVO extends PageParam { @@ -24,4 +24,10 @@ public class NotifyMessagePageReqVO extends PageParam {
24 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) 24 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
25 private Date[] createTime; 25 private Date[] createTime;
26 26
  27 +
  28 + @ApiModelProperty(value = "用户编号", hidden = true)
  29 + private Long userId;
  30 +
  31 + @ApiModelProperty(value = "用户类型", hidden = true)
  32 + private Integer userType;
27 } 33 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java
1 package cn.iocoder.yudao.module.system.dal.mysql.notify; 1 package cn.iocoder.yudao.module.system.dal.mysql.notify;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;  
5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; 6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
7 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; 7 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
  8 +import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum;
8 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
9 10
  11 +import java.util.List;
  12 +
10 /** 13 /**
11 * 站内信 Mapper 14 * 站内信 Mapper
12 * 15 *
@@ -20,6 +23,15 @@ public interface NotifyMessageMapper extends BaseMapperX&lt;NotifyMessageDO&gt; { @@ -20,6 +23,15 @@ public interface NotifyMessageMapper extends BaseMapperX&lt;NotifyMessageDO&gt; {
20 .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) 23 .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle())
21 .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) 24 .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus())
22 .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) 25 .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime())
  26 + .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId())
  27 + .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType())
23 .orderByDesc(NotifyMessageDO::getId)); 28 .orderByDesc(NotifyMessageDO::getId));
24 } 29 }
  30 +
  31 + default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) {
  32 + return selectCount(new LambdaQueryWrapperX<NotifyMessageDO>()
  33 + .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus())
  34 + .eq(NotifyMessageDO::getUserId, userId)
  35 + .eq(NotifyMessageDO::getUserType, userType));
  36 + }
25 } 37 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java
1 package cn.iocoder.yudao.module.system.service.notify; 1 package cn.iocoder.yudao.module.system.service.notify;
2 2
3 -import java.util.*;  
4 -import javax.validation.*;  
5 - 3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; 4 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO;
7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; 5 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
8 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; 6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;
9 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; 7 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
10 -import cn.iocoder.yudao.framework.common.pojo.PageResult; 8 +
  9 +import javax.validation.Valid;
  10 +import java.util.Collection;
  11 +import java.util.List;
11 12
12 /** 13 /**
13 * 站内信 Service 接口 14 * 站内信 Service 接口
@@ -62,4 +63,12 @@ public interface NotifyMessageService { @@ -62,4 +63,12 @@ public interface NotifyMessageService {
62 */ 63 */
63 PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO); 64 PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO);
64 65
  66 + /**
  67 + * 统计用户未读站内信条数
  68 + *
  69 + * @param userId 用户ID
  70 + * @param userType 用户类型
  71 + * @return 返回未读站内信条数
  72 + */
  73 + Long getUnreadNotifyMessageCount(Long userId, Integer userType);
65 } 74 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java
1 package cn.iocoder.yudao.module.system.service.notify; 1 package cn.iocoder.yudao.module.system.service.notify;
2 2
  3 +import cn.iocoder.yudao.framework.common.core.KeyValue;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; 5 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO;
5 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; 6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
6 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;
7 import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; 8 import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert;
8 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; 9 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
  10 +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
9 import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; 11 import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
  12 +import com.google.common.annotations.VisibleForTesting;
10 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
11 import org.springframework.validation.annotation.Validated; 14 import org.springframework.validation.annotation.Validated;
12 15
13 import javax.annotation.Resource; 16 import javax.annotation.Resource;
14 import java.util.Collection; 17 import java.util.Collection;
15 import java.util.List; 18 import java.util.List;
  19 +import java.util.Map;
  20 +import java.util.stream.Collectors;
16 21
17 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
18 -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_MESSAGE_NOT_EXISTS; 23 +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
19 24
20 /** 25 /**
21 * 站内信 Service 实现类 26 * 站内信 Service 实现类
@@ -29,6 +34,39 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @@ -29,6 +34,39 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
29 @Resource 34 @Resource
30 private NotifyMessageMapper notifyMessageMapper; 35 private NotifyMessageMapper notifyMessageMapper;
31 36
  37 + @Resource
  38 + private NotifyTemplateService notifyTemplateService;
  39 +
  40 +
  41 + @VisibleForTesting
  42 + public NotifyTemplateDO checkNotifyTemplateValid(String templateCode) {
  43 + // 获得站内信模板。考虑到效率,从缓存中获取
  44 + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode);
  45 + // 站内信模板不存在
  46 + if (template == null) {
  47 + throw exception(NOTIFY_TEMPLATE_NOT_EXISTS);
  48 + }
  49 + return template;
  50 + }
  51 +
  52 + /**
  53 + * 将参数模板,处理成有序的 KeyValue 数组
  54 + *
  55 + * @param template 站内信模板
  56 + * @param templateParams 原始参数
  57 + * @return 处理后的参数
  58 + */
  59 + @VisibleForTesting
  60 + public List<KeyValue<String, Object>> buildTemplateParams(NotifyTemplateDO template, Map<String, Object> templateParams) {
  61 + return template.getParams().stream().map(key -> {
  62 + Object value = templateParams.get(key);
  63 + if (value == null) {
  64 + throw exception(NOTIFY_TEMPLATE_PARAM_MISS, key);
  65 + }
  66 + return new KeyValue<>(key, value);
  67 + }).collect(Collectors.toList());
  68 + }
  69 +
32 @Override 70 @Override
33 public Long createNotifyMessage(NotifyMessageCreateReqVO createReqVO) { 71 public Long createNotifyMessage(NotifyMessageCreateReqVO createReqVO) {
34 // 插入 72 // 插入
@@ -75,4 +113,16 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @@ -75,4 +113,16 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
75 public PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { 113 public PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) {
76 return notifyMessageMapper.selectPage(pageReqVO); 114 return notifyMessageMapper.selectPage(pageReqVO);
77 } 115 }
  116 +
  117 + /**
  118 + * 统计用户未读站内信条数
  119 + *
  120 + * @param userId 用户ID
  121 + * @param userType 用户类型
  122 + * @return 返回未读站内信条数
  123 + */
  124 + @Override
  125 + public Long getUnreadNotifyMessageCount(Long userId, Integer userType) {
  126 + return notifyMessageMapper.selectUnreadCountByUserIdAndUserType(userId, userType);
  127 + }
78 } 128 }