Commit f77522980f9898594e54ac115e4b3fc903c837c4

Authored by luowenfeng
1 parent e8dd66c6

fix(站内信功能调整): 接口fix

Showing 15 changed files with 248 additions and 140 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.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;
@@ -17,7 +19,12 @@ import org.springframework.web.bind.annotation.*; @@ -17,7 +19,12 @@ import org.springframework.web.bind.annotation.*;
17 import javax.annotation.Resource; 19 import javax.annotation.Resource;
18 import javax.validation.Valid; 20 import javax.validation.Valid;
19 21
  22 +import java.util.Collection;
  23 +import java.util.Collections;
  24 +import java.util.List;
  25 +
20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  27 +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
21 28
22 @Api(tags = "管理后台 - 站内信") 29 @Api(tags = "管理后台 - 站内信")
23 @RestController 30 @RestController
@@ -41,8 +48,46 @@ public class NotifyMessageController { @@ -41,8 +48,46 @@ public class NotifyMessageController {
41 @ApiOperation("获得站内信分页") 48 @ApiOperation("获得站内信分页")
42 @PreAuthorize("@ss.hasPermission('system:notify-message:query')") 49 @PreAuthorize("@ss.hasPermission('system:notify-message:query')")
43 public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { 50 public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
  51 + pageVO.setUserId(getLoginUserId());
  52 + pageVO.setUserType(UserTypeEnum.ADMIN.getValue());
44 PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO); 53 PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
45 return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); 54 return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
46 } 55 }
47 56
  57 + @GetMapping("/get-recent-list")
  58 + @ApiOperation("获取当前用户最新站内信,默认10条")
  59 + @ApiImplicitParam(name = "size", value = "10", defaultValue = "10", dataTypeClass = Integer.class)
  60 + public CommonResult<List<NotifyMessageRespVO>> getRecentList(@RequestParam(name = "size", defaultValue = "10") Integer size) {
  61 + NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO();
  62 + reqVO.setUserId(getLoginUserId());
  63 + reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
  64 +
  65 + List<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessageList(reqVO, size);
  66 + if (CollUtil.isNotEmpty(pageResult)) {
  67 + return success(NotifyMessageConvert.INSTANCE.convertList(pageResult));
  68 + }
  69 + return success(Collections.emptyList());
  70 + }
  71 +
  72 + @GetMapping("/get-unread-count")
  73 + @ApiOperation("获得未读站内信数量")
  74 + public CommonResult<Long> getUnreadCount() {
  75 + return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
  76 + }
  77 +
  78 + @GetMapping("/update-list-read")
  79 + @ApiOperation("批量标记已读")
  80 + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
  81 + public CommonResult<Boolean> batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection<Long> ids) {
  82 + notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId());
  83 + return success(Boolean.TRUE);
  84 + }
  85 +
  86 + @GetMapping("/update-all-read")
  87 + @ApiOperation("所有未读消息标记已读")
  88 + public CommonResult<Boolean> batchUpdateAllNotifyMessageReadStatus() {
  89 + notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue());
  90 + return success(Boolean.TRUE);
  91 + }
  92 +
48 } 93 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*;
8 import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; 8 import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert;
9 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; 9 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
  10 +import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
10 import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; 11 import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService;
11 import io.swagger.annotations.Api; 12 import io.swagger.annotations.Api;
12 import io.swagger.annotations.ApiImplicitParam; 13 import io.swagger.annotations.ApiImplicitParam;
@@ -24,7 +25,6 @@ import java.util.List; @@ -24,7 +25,6 @@ import java.util.List;
24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 25 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
25 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; 26 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
26 27
27 -// TODO 芋艿:VO 类上的 swagger 注解完善下,例如说 swagger,枚举等等  
28 @Api(tags = "管理后台 - 站内信模版") 28 @Api(tags = "管理后台 - 站内信模版")
29 @RestController 29 @RestController
30 @RequestMapping("/system/notify-template") 30 @RequestMapping("/system/notify-template")
@@ -34,6 +34,10 @@ public class NotifyTemplateController { @@ -34,6 +34,10 @@ public class NotifyTemplateController {
34 @Resource 34 @Resource
35 private NotifyTemplateService notifyTemplateService; 35 private NotifyTemplateService notifyTemplateService;
36 36
  37 + @Resource
  38 + private NotifySendService notifySendService;
  39 +
  40 +
37 @PostMapping("/create") 41 @PostMapping("/create")
38 @ApiOperation("创建站内信模版") 42 @ApiOperation("创建站内信模版")
39 @PreAuthorize("@ss.hasPermission('system:notify-template:create')") 43 @PreAuthorize("@ss.hasPermission('system:notify-template:create')")
@@ -87,8 +91,10 @@ public class NotifyTemplateController { @@ -87,8 +91,10 @@ public class NotifyTemplateController {
87 ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas); 91 ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas);
88 } 92 }
89 93
90 - // TODO @芋艿:参考 SmsTemplateController 的 sendNotify 写一个发送站内信的接口  
91 -  
92 - // TODO @芋艿:参考 SmsSendServiceImpl,新建一个 NotifySendServiceImpl,用于提供出来给发送消息。注意,不要考虑异步发送,直接 insert 就可以了。也不用考虑发送后的回调  
93 - 94 + @PostMapping("/send-notify")
  95 + @ApiOperation("发送站内信")
  96 + public CommonResult<Long> sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) {
  97 + return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
  98 + sendReqVO.getTemplateId(), sendReqVO.getTemplateParams()));
  99 + }
94 } 100 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java deleted
1 -package cn.iocoder.yudao.module.system.controller.admin.notify;  
2 -  
3 -import cn.hutool.core.collection.CollUtil;  
4 -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;  
5 -import cn.iocoder.yudao.framework.common.pojo.CommonResult;  
6 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
7 -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;  
8 -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;  
9 -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert;  
10 -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;  
11 -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum;  
12 -import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;  
13 -import io.swagger.annotations.Api;  
14 -import io.swagger.annotations.ApiImplicitParam;  
15 -import io.swagger.annotations.ApiOperation;  
16 -import org.springframework.validation.annotation.Validated;  
17 -import org.springframework.web.bind.annotation.GetMapping;  
18 -import org.springframework.web.bind.annotation.RequestMapping;  
19 -import org.springframework.web.bind.annotation.RequestParam;  
20 -import org.springframework.web.bind.annotation.RestController;  
21 -  
22 -import javax.annotation.Resource;  
23 -import javax.validation.Valid;  
24 -import java.util.Collection;  
25 -import java.util.Collections;  
26 -import java.util.List;  
27 -  
28 -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;  
29 -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;  
30 -  
31 -// TODO 芋艿:合并到 合并到 NotifyTemplateController 中  
32 -@Api(tags = "管理后台 - 站内信-消息中心")  
33 -@RestController  
34 -@RequestMapping("/system/user/notify-message")  
35 -@Validated  
36 -public class UserNotifyMessageController {  
37 -  
38 - @Resource  
39 - private NotifyMessageService notifyMessageService;  
40 -  
41 - // TODO 芋艿:和 NotifyMessageController 的 page 合并  
42 - @GetMapping("/page")  
43 - @ApiOperation("获得站内信分页")  
44 - public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {  
45 - pageVO.setUserId(getLoginUserId());  
46 - pageVO.setUserType(UserTypeEnum.ADMIN.getValue());  
47 - PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);  
48 - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));  
49 - }  
50 -  
51 - // TODO @芋艿:url 改成 get-recent-list;方法名也改下。默认传入 size = 10;  
52 - @GetMapping("/latest/list")  
53 - @ApiOperation("获得最新10站内信列表")  
54 - public CommonResult<List<NotifyMessageRespVO>> getNotifyLatestMessageList() {  
55 - NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO();  
56 - reqVO.setUserId(getLoginUserId());  
57 - reqVO.setUserType(UserTypeEnum.ADMIN.getValue());  
58 - reqVO.setPageNo(1);  
59 - reqVO.setPageSize(10);  
60 - // TODO 芋艿:不要用分页写;  
61 - PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(reqVO);  
62 - if (CollUtil.isNotEmpty(pageResult.getList())) {  
63 - return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList()));  
64 - }  
65 - return success(Collections.emptyList());  
66 - }  
67 -  
68 - // TODO @芋艿:get-unread-count  
69 - @GetMapping("/unread/count")  
70 - @ApiOperation("获得未读站内信数量")  
71 - public CommonResult<Long> getUnreadNotifyMessageCount() {  
72 - return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));  
73 - }  
74 -  
75 - // TODO @芋艿:把 get 站内信,和更新站内信已经读分开。其中更新单条和多条,使用一个接口就好列  
76 - @GetMapping("/read")  
77 - @ApiOperation("获得站内信")  
78 - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)  
79 - public CommonResult<NotifyMessageRespVO> readNotifyMessage(@RequestParam("id") Long id) {  
80 - NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id);  
81 - // 记录消息已读。  
82 - notifyMessageService.updateNotifyMessageReadStatus(id, NotifyReadStatusEnum.READ.getStatus());  
83 - return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage));  
84 - }  
85 -  
86 - // TODO @芋艿:PutMapping;update-list-read  
87 - @GetMapping("/read/list")  
88 - @ApiOperation("批量标记已读")  
89 - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)  
90 - public CommonResult<Boolean> batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection<Long> ids) {  
91 - notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId());  
92 - return success(Boolean.TRUE);  
93 - }  
94 -  
95 - // TODO @芋艿:PutMapping:update-all-read  
96 - @GetMapping("/read/all")  
97 - @ApiOperation("所有未读消息标记已读")  
98 - public CommonResult<Boolean> batchUpdateAllNotifyMessageReadStatus() {  
99 - notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue());  
100 - return success(Boolean.TRUE);  
101 - }  
102 -}  
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java
@@ -34,8 +34,8 @@ public class NotifyMessageBaseVO { @@ -34,8 +34,8 @@ public class NotifyMessageBaseVO {
34 @NotNull(message = "内容不能为空") 34 @NotNull(message = "内容不能为空")
35 private String content; 35 private String content;
36 36
37 - @ApiModelProperty(value = "是否已读 0-未读 1-已读")  
38 - private Integer readStatus; 37 + @ApiModelProperty(value = "是否已读 false-未读 true-已读")
  38 + private Boolean readStatus;
39 39
40 @ApiModelProperty(value = "阅读时间") 40 @ApiModelProperty(value = "阅读时间")
41 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) 41 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java
@@ -29,7 +29,7 @@ public class NotifyTemplateBaseVO { @@ -29,7 +29,7 @@ public class NotifyTemplateBaseVO {
29 @ApiModelProperty(value = "状态:1-启用 0-禁用", required = true) 29 @ApiModelProperty(value = "状态:1-启用 0-禁用", required = true)
30 @NotNull(message = "状态:1-启用 0-禁用不能为空") 30 @NotNull(message = "状态:1-启用 0-禁用不能为空")
31 @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") 31 @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
32 - private String status; 32 + private Integer status;
33 33
34 @ApiModelProperty(value = "备注") 34 @ApiModelProperty(value = "备注")
35 private String remarks; 35 private String remarks;
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java
1 package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; 1 package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
2 2
  3 +import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
3 import lombok.*; 4 import lombok.*;
4 import java.util.*; 5 import java.util.*;
5 import io.swagger.annotations.*; 6 import io.swagger.annotations.*;
@@ -30,8 +31,8 @@ public class NotifyTemplateExcelVO { @@ -30,8 +31,8 @@ public class NotifyTemplateExcelVO {
30 private String content; 31 private String content;
31 32
32 @ExcelProperty(value = "状态:1-启用 0-禁用", converter = DictConvert.class) 33 @ExcelProperty(value = "状态:1-启用 0-禁用", converter = DictConvert.class)
33 - @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中  
34 - private String status; 34 + @DictFormat(DictTypeConstants.COMMON_STATUS)
  35 + private Integer status;
35 36
36 @ExcelProperty("备注") 37 @ExcelProperty("备注")
37 private String remarks; 38 private String remarks;
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java
@@ -19,7 +19,7 @@ public class NotifyTemplateExportReqVO { @@ -19,7 +19,7 @@ public class NotifyTemplateExportReqVO {
19 private String title; 19 private String title;
20 20
21 @ApiModelProperty(value = "状态:1-启用 0-禁用") 21 @ApiModelProperty(value = "状态:1-启用 0-禁用")
22 - private String status; 22 + private Integer status;
23 23
24 @ApiModelProperty(value = "创建时间") 24 @ApiModelProperty(value = "创建时间")
25 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) 25 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +import javax.validation.constraints.NotNull;
  8 +import java.util.Map;
  9 +
  10 +@ApiModel("管理后台 - 站内信模板的发送 Request VO")
  11 +@Data
  12 +public class NotifyTemplateSendReqVO {
  13 +
  14 + @ApiModelProperty(value = "用户id", required = true, example = "01")
  15 + @NotNull(message = "用户id不能为空")
  16 + private Long userId;
  17 +
  18 + @ApiModelProperty(value = "模板Id", required = true, example = "01")
  19 + @NotNull(message = "模板Id不能为空")
  20 + private Long templateId;
  21 +
  22 + @ApiModelProperty(value = "模板参数")
  23 + private Map<String, Object> templateParams;
  24 +}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java
@@ -4,9 +4,7 @@ import java.util.*; @@ -4,9 +4,7 @@ import java.util.*;
4 4
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 6
7 -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO;  
8 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; 7 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO;
9 -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;  
10 import org.mapstruct.Mapper; 8 import org.mapstruct.Mapper;
11 import org.mapstruct.factory.Mappers; 9 import org.mapstruct.factory.Mappers;
12 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; 10 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
@@ -21,10 +19,6 @@ public interface NotifyMessageConvert { @@ -21,10 +19,6 @@ public interface NotifyMessageConvert {
21 19
22 NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class); 20 NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class);
23 21
24 - NotifyMessageDO convert(NotifyMessageCreateReqVO bean);  
25 -  
26 - NotifyMessageDO convert(NotifyMessageUpdateReqVO bean);  
27 -  
28 NotifyMessageRespVO convert(NotifyMessageDO bean); 22 NotifyMessageRespVO convert(NotifyMessageDO bean);
29 23
30 List<NotifyMessageRespVO> convertList(List<NotifyMessageDO> list); 24 List<NotifyMessageRespVO> convertList(List<NotifyMessageDO> list);
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java
@@ -53,7 +53,7 @@ public class NotifyTemplateDO extends BaseDO { @@ -53,7 +53,7 @@ public class NotifyTemplateDO extends BaseDO {
53 * 53 *
54 * 枚举 {@link CommonStatusEnum} 54 * 枚举 {@link CommonStatusEnum}
55 */ 55 */
56 - private String status; 56 + private Integer status;
57 /** 57 /**
58 * 备注 58 * 备注
59 */ 59 */
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java
@@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 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;  
9 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
10 9
11 import java.util.List; 10 import java.util.List;
@@ -28,16 +27,27 @@ public interface NotifyMessageMapper extends BaseMapperX&lt;NotifyMessageDO&gt; { @@ -28,16 +27,27 @@ public interface NotifyMessageMapper extends BaseMapperX&lt;NotifyMessageDO&gt; {
28 .orderByDesc(NotifyMessageDO::getId)); 27 .orderByDesc(NotifyMessageDO::getId));
29 } 28 }
30 29
  30 + default List<NotifyMessageDO> selectList(NotifyMessagePageReqVO reqVO, Integer size) {
  31 + return selectList(new LambdaQueryWrapperX<NotifyMessageDO>()
  32 + .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle())
  33 + .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus())
  34 + .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime())
  35 + .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId())
  36 + .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType())
  37 + .orderByDesc(NotifyMessageDO::getId)
  38 + .last("limit " + size));
  39 + }
  40 +
31 default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) { 41 default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) {
32 return selectCount(new LambdaQueryWrapperX<NotifyMessageDO>() 42 return selectCount(new LambdaQueryWrapperX<NotifyMessageDO>()
33 - .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) 43 + .eq(NotifyMessageDO::getReadStatus, false)
34 .eq(NotifyMessageDO::getUserId, userId) 44 .eq(NotifyMessageDO::getUserId, userId)
35 .eq(NotifyMessageDO::getUserType, userType)); 45 .eq(NotifyMessageDO::getUserType, userType));
36 } 46 }
37 47
38 default List<NotifyMessageDO> selectUnreadListByUserIdAndUserType(Long userId, Integer userType) { 48 default List<NotifyMessageDO> selectUnreadListByUserIdAndUserType(Long userId, Integer userType) {
39 return selectList(new LambdaQueryWrapperX<NotifyMessageDO>() 49 return selectList(new LambdaQueryWrapperX<NotifyMessageDO>()
40 - .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) 50 + .eq(NotifyMessageDO::getReadStatus, false)
41 .eq(NotifyMessageDO::getUserId, userId) 51 .eq(NotifyMessageDO::getUserId, userId)
42 .eq(NotifyMessageDO::getUserType, userType)); 52 .eq(NotifyMessageDO::getUserType, userType));
43 } 53 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java
@@ -31,6 +31,14 @@ public interface NotifyMessageService { @@ -31,6 +31,14 @@ public interface NotifyMessageService {
31 List<NotifyMessageDO> getNotifyMessageList(Collection<Long> ids); 31 List<NotifyMessageDO> getNotifyMessageList(Collection<Long> ids);
32 32
33 /** 33 /**
  34 + * 获得站内信集合
  35 + *
  36 + * @param pageReqVO 分页查询
  37 + * @return 站内信分页
  38 + */
  39 + List<NotifyMessageDO> getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size);
  40 +
  41 + /**
34 * 获得站内信分页 42 * 获得站内信分页
35 * 43 *
36 * @param pageReqVO 分页查询 44 * @param pageReqVO 分页查询
@@ -53,7 +61,7 @@ public interface NotifyMessageService { @@ -53,7 +61,7 @@ public interface NotifyMessageService {
53 * @param id 站内信编号 61 * @param id 站内信编号
54 * @param status 状态 62 * @param status 状态
55 */ 63 */
56 - void updateNotifyMessageReadStatus(Long id, Integer status); 64 + void updateNotifyMessageReadStatus(Long id, Boolean status);
57 65
58 /** 66 /**
59 * 批量修改站内信阅读状态 67 * 批量修改站内信阅读状态
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java
@@ -5,14 +5,11 @@ import cn.hutool.core.util.NumberUtil; @@ -5,14 +5,11 @@ import cn.hutool.core.util.NumberUtil;
5 import cn.iocoder.yudao.framework.common.core.KeyValue; 5 import cn.iocoder.yudao.framework.common.core.KeyValue;
6 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 7 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
8 -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; 8 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
9 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; 9 import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO;
10 -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO;  
11 -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert;  
12 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; 10 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
13 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; 11 import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
14 import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; 12 import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
15 -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum;  
16 import com.google.common.annotations.VisibleForTesting; 13 import com.google.common.annotations.VisibleForTesting;
17 import org.springframework.stereotype.Service; 14 import org.springframework.stereotype.Service;
18 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
@@ -88,6 +85,11 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @@ -88,6 +85,11 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
88 } 85 }
89 86
90 @Override 87 @Override
  88 + public List<NotifyMessageDO> getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size) {
  89 + return notifyMessageMapper.selectList(pageReqVO, size);
  90 + }
  91 +
  92 + @Override
91 public PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { 93 public PageResult<NotifyMessageDO> getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) {
92 return notifyMessageMapper.selectPage(pageReqVO); 94 return notifyMessageMapper.selectPage(pageReqVO);
93 } 95 }
@@ -111,7 +113,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @@ -111,7 +113,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
111 * @param status 状态 113 * @param status 状态
112 */ 114 */
113 @Override 115 @Override
114 - public void updateNotifyMessageReadStatus(Long id, Integer status) { 116 + public void updateNotifyMessageReadStatus(Long id, Boolean status) {
115 // 校验消息是否存在 117 // 校验消息是否存在
116 this.validateNotifyMessageExists(id); 118 this.validateNotifyMessageExists(id);
117 // 更新状态 119 // 更新状态
@@ -155,20 +157,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { @@ -155,20 +157,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
155 List<NotifyMessageDO> list = notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType); 157 List<NotifyMessageDO> list = notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType);
156 if (CollUtil.isNotEmpty(list)) { 158 if (CollUtil.isNotEmpty(list)) {
157 batchUpdateReadStatus(CollectionUtils.convertList(list, NotifyMessageDO::getId)); 159 batchUpdateReadStatus(CollectionUtils.convertList(list, NotifyMessageDO::getId));
158 -  
159 } 160 }
160 } 161 }
161 162
162 - // TODO 芋艿:批量更新,不要单条遍历哈。  
163 private void batchUpdateReadStatus(Collection<Long> ids) { 163 private void batchUpdateReadStatus(Collection<Long> ids) {
164 - if (CollUtil.isNotEmpty(ids)) {  
165 - for (Long id : ids) {  
166 - NotifyMessageDO updateObj = new NotifyMessageDO();  
167 - updateObj.setId(id);  
168 - updateObj.setReadStatus(NotifyReadStatusEnum.READ.getStatus());  
169 - notifyMessageMapper.updateById(updateObj);  
170 - }  
171 - }  
172 - 164 + NotifyMessageDO updateObj = new NotifyMessageDO();
  165 + updateObj.setReadStatus(false);
  166 + notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX<NotifyMessageDO>().in(NotifyMessageDO::getId, ids));
173 } 167 }
174 } 168 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.service.notify;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +public interface NotifySendService {
  7 +
  8 +
  9 + /**
  10 + * 发送单条站内信给管理后台的用户
  11 + *
  12 + * 在 mobile 为空时,使用 userId 加载对应管理员的手机号
  13 + *
  14 + * @param userId 用户编号
  15 + * @param templateId 短信模板编号
  16 + * @param templateParams 短信模板参数
  17 + * @return 发送日志编号
  18 + */
  19 + Long sendSingleNotifyToAdmin(Long userId,
  20 + Long templateId, Map<String, Object> templateParams);
  21 + /**
  22 + * 发送单条站内信给用户 APP 的用户
  23 + *
  24 + * 在 mobile 为空时,使用 userId 加载对应会员的手机号
  25 + *
  26 + * @param userId 用户编号
  27 + * @param templateId 站内信模板编号
  28 + * @param templateParams 站内信模板参数
  29 + * @return 发送日志编号
  30 + */
  31 + Long sendSingleNotifyToMember(Long userId,
  32 + Long templateId, Map<String, Object> templateParams);
  33 +
  34 + /**
  35 + * 发送单条站内信给用户
  36 + *
  37 + * @param userId 用户编号
  38 + * @param userType 用户类型
  39 + * @param templateId 站内信模板编号
  40 + * @param templateParams 站内信模板参数
  41 + * @return 发送日志编号
  42 + */
  43 + Long sendSingleNotify( Long userId, Integer userType,
  44 + Long templateId, Map<String, Object> templateParams);
  45 +
  46 + default void sendBatchNotify(List<String> mobiles, List<Long> userIds, Integer userType,
  47 + String templateCode, Map<String, Object> templateParams) {
  48 + throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!");
  49 + }
  50 +
  51 +}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.service.notify;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
  4 +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
  5 +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
  6 +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper;
  7 +import com.google.common.annotations.VisibleForTesting;
  8 +import lombok.extern.slf4j.Slf4j;
  9 +import org.springframework.stereotype.Service;
  10 +import org.springframework.validation.annotation.Validated;
  11 +
  12 +import javax.annotation.Resource;
  13 +import java.util.Date;
  14 +import java.util.Map;
  15 +
  16 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  17 +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
  18 +
  19 +/**
  20 + * 站内信发送 Service 实现类
  21 + *
  22 + * @author xrcoder
  23 + */
  24 +@Service
  25 +@Validated
  26 +@Slf4j
  27 +public class NotifySendServiceImpl implements NotifySendService {
  28 +
  29 + @Resource
  30 + private NotifyTemplateService notifyTemplateService;
  31 +
  32 + @Resource
  33 + private NotifyMessageMapper notifyMessageMapper;
  34 +
  35 + @Override
  36 + public Long sendSingleNotifyToAdmin(Long userId, Long templateId, Map<String, Object> templateParams) {
  37 +
  38 + return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateId, templateParams);
  39 + }
  40 +
  41 + @Override
  42 + public Long sendSingleNotifyToMember(Long userId, Long templateId, Map<String, Object> templateParams) {
  43 + return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateId, templateParams);
  44 + }
  45 +
  46 + @Override
  47 + public Long sendSingleNotify(Long userId, Integer userType, Long templateId, Map<String, Object> templateParams) {
  48 + // 校验短信模板是否合法
  49 + NotifyTemplateDO template = this.checkNotifyTemplateValid(templateId);
  50 + String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
  51 +
  52 + // todo 模板状态未开启时的业务
  53 + NotifyMessageDO notifyMessageDO = new NotifyMessageDO();
  54 + notifyMessageDO.setContent(content);
  55 + notifyMessageDO.setTitle(template.getTitle());
  56 + notifyMessageDO.setReadStatus(false);
  57 + notifyMessageDO.setReadTime(new Date());
  58 + notifyMessageDO.setTemplateId(templateId);
  59 + notifyMessageDO.setUserId(userId);
  60 + notifyMessageDO.setUserType(userType);
  61 + notifyMessageMapper.insert(notifyMessageDO);
  62 + return notifyMessageDO.getId();
  63 + }
  64 +
  65 + // 此注解的含义
  66 + @VisibleForTesting
  67 + public NotifyTemplateDO checkNotifyTemplateValid(Long templateId) {
  68 + // 获得短信模板。考虑到效率,从缓存中获取
  69 + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(templateId);
  70 + // 短信模板不存在
  71 + if (template == null) {
  72 + throw exception(NOTICE_NOT_FOUND);
  73 + }
  74 + return template;
  75 + }
  76 +
  77 +}