From f77522980f9898594e54ac115e4b3fc903c837c4 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Wed, 23 Nov 2022 12:26:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=AB=99=E5=86=85=E4=BF=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=B0=83=E6=95=B4):=20=E6=8E=A5=E5=8F=A3fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notify/NotifyMessageController.java | 45 ++++++++ .../notify/NotifyTemplateController.java | 16 ++- .../notify/UserNotifyMessageController.java | 102 ------------------ .../vo/message/NotifyMessageBaseVO.java | 4 +- .../vo/template/NotifyTemplateBaseVO.java | 2 +- .../vo/template/NotifyTemplateExcelVO.java | 5 +- .../template/NotifyTemplateExportReqVO.java | 2 +- .../vo/template/NotifyTemplateSendReqVO.java | 24 +++++ .../convert/notify/NotifyMessageConvert.java | 6 -- .../dataobject/notify/NotifyTemplateDO.java | 2 +- .../dal/mysql/notify/NotifyMessageMapper.java | 16 ++- .../service/notify/NotifyMessageService.java | 10 +- .../notify/NotifyMessageServiceImpl.java | 26 ++--- .../service/notify/NotifySendService.java | 51 +++++++++ .../service/notify/NotifySendServiceImpl.java | 77 +++++++++++++ 15 files changed, 248 insertions(+), 140 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java index 7c65e4961..7e14b86c7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.notify; +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; @@ -17,7 +19,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Api(tags = "管理后台 - 站内信") @RestController @@ -41,8 +48,46 @@ public class NotifyMessageController { @ApiOperation("获得站内信分页") @PreAuthorize("@ss.hasPermission('system:notify-message:query')") public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { + pageVO.setUserId(getLoginUserId()); + pageVO.setUserType(UserTypeEnum.ADMIN.getValue()); PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/get-recent-list") + @ApiOperation("获取当前用户最新站内信,默认10条") + @ApiImplicitParam(name = "size", value = "10", defaultValue = "10", dataTypeClass = Integer.class) + public CommonResult> getRecentList(@RequestParam(name = "size", defaultValue = "10") Integer size) { + NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO(); + reqVO.setUserId(getLoginUserId()); + reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); + + List pageResult = notifyMessageService.getNotifyMessageList(reqVO, size); + if (CollUtil.isNotEmpty(pageResult)) { + return success(NotifyMessageConvert.INSTANCE.convertList(pageResult)); + } + return success(Collections.emptyList()); + } + + @GetMapping("/get-unread-count") + @ApiOperation("获得未读站内信数量") + public CommonResult getUnreadCount() { + return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); + } + + @GetMapping("/update-list-read") + @ApiOperation("批量标记已读") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { + notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId()); + return success(Boolean.TRUE); + } + + @GetMapping("/update-all-read") + @ApiOperation("所有未读消息标记已读") + public CommonResult batchUpdateAllNotifyMessageReadStatus() { + notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); + return success(Boolean.TRUE); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java index 2be58771d..aa57a795e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java +++ b/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; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; import cn.iocoder.yudao.module.system.convert.notify.NotifyTemplateConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.service.notify.NotifySendService; import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -24,7 +25,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; -// TODO 芋艿:VO 类上的 swagger 注解完善下,例如说 swagger,枚举等等 @Api(tags = "管理后台 - 站内信模版") @RestController @RequestMapping("/system/notify-template") @@ -34,6 +34,10 @@ public class NotifyTemplateController { @Resource private NotifyTemplateService notifyTemplateService; + @Resource + private NotifySendService notifySendService; + + @PostMapping("/create") @ApiOperation("创建站内信模版") @PreAuthorize("@ss.hasPermission('system:notify-template:create')") @@ -87,8 +91,10 @@ public class NotifyTemplateController { ExcelUtils.write(response, "站内信模版.xls", "数据", NotifyTemplateExcelVO.class, datas); } - // TODO @芋艿:参考 SmsTemplateController 的 sendNotify 写一个发送站内信的接口 - - // TODO @芋艿:参考 SmsSendServiceImpl,新建一个 NotifySendServiceImpl,用于提供出来给发送消息。注意,不要考虑异步发送,直接 insert 就可以了。也不用考虑发送后的回调 - + @PostMapping("/send-notify") + @ApiOperation("发送站内信") + public CommonResult sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) { + return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(), + sendReqVO.getTemplateId(), sendReqVO.getTemplateParams())); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java deleted file mode 100644 index 04bd09160..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/UserNotifyMessageController.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notify; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; -import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; -import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; -import javax.validation.Valid; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; - -// TODO 芋艿:合并到 合并到 NotifyTemplateController 中 -@Api(tags = "管理后台 - 站内信-消息中心") -@RestController -@RequestMapping("/system/user/notify-message") -@Validated -public class UserNotifyMessageController { - - @Resource - private NotifyMessageService notifyMessageService; - - // TODO 芋艿:和 NotifyMessageController 的 page 合并 - @GetMapping("/page") - @ApiOperation("获得站内信分页") - public CommonResult> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) { - pageVO.setUserId(getLoginUserId()); - pageVO.setUserType(UserTypeEnum.ADMIN.getValue()); - PageResult pageResult = notifyMessageService.getNotifyMessagePage(pageVO); - return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult)); - } - - // TODO @芋艿:url 改成 get-recent-list;方法名也改下。默认传入 size = 10; - @GetMapping("/latest/list") - @ApiOperation("获得最新10站内信列表") - public CommonResult> getNotifyLatestMessageList() { - NotifyMessagePageReqVO reqVO = new NotifyMessagePageReqVO(); - reqVO.setUserId(getLoginUserId()); - reqVO.setUserType(UserTypeEnum.ADMIN.getValue()); - reqVO.setPageNo(1); - reqVO.setPageSize(10); - // TODO 芋艿:不要用分页写; - PageResult pageResult = notifyMessageService.getNotifyMessagePage(reqVO); - if (CollUtil.isNotEmpty(pageResult.getList())) { - return success(NotifyMessageConvert.INSTANCE.convertList(pageResult.getList())); - } - return success(Collections.emptyList()); - } - - // TODO @芋艿:get-unread-count - @GetMapping("/unread/count") - @ApiOperation("获得未读站内信数量") - public CommonResult getUnreadNotifyMessageCount() { - return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue())); - } - - // TODO @芋艿:把 get 站内信,和更新站内信已经读分开。其中更新单条和多条,使用一个接口就好列 - @GetMapping("/read") - @ApiOperation("获得站内信") - @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) - public CommonResult readNotifyMessage(@RequestParam("id") Long id) { - NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id); - // 记录消息已读。 - notifyMessageService.updateNotifyMessageReadStatus(id, NotifyReadStatusEnum.READ.getStatus()); - return success(NotifyMessageConvert.INSTANCE.convert(notifyMessage)); - } - - // TODO @芋艿:PutMapping;update-list-read - @GetMapping("/read/list") - @ApiOperation("批量标记已读") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - public CommonResult batchUpdateNotifyMessageReadStatus(@RequestParam("ids") Collection ids) { - notifyMessageService.batchUpdateNotifyMessageReadStatus(ids, getLoginUserId()); - return success(Boolean.TRUE); - } - - // TODO @芋艿:PutMapping:update-all-read - @GetMapping("/read/all") - @ApiOperation("所有未读消息标记已读") - public CommonResult batchUpdateAllNotifyMessageReadStatus() { - notifyMessageService.batchUpdateAllNotifyMessageReadStatus(getLoginUserId(), UserTypeEnum.ADMIN.getValue()); - return success(Boolean.TRUE); - } -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java index e7f7439c2..62d8a3113 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageBaseVO.java +++ b/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 { @NotNull(message = "内容不能为空") private String content; - @ApiModelProperty(value = "是否已读 0-未读 1-已读") - private Integer readStatus; + @ApiModelProperty(value = "是否已读 false-未读 true-已读") + private Boolean readStatus; @ApiModelProperty(value = "阅读时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java index bff746e14..84aa4b686 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateBaseVO.java +++ b/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 { @ApiModelProperty(value = "状态:1-启用 0-禁用", required = true) @NotNull(message = "状态:1-启用 0-禁用不能为空") @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") - private String status; + private Integer status; @ApiModelProperty(value = "备注") private String remarks; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java index e0402da8c..6790f1858 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExcelVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; import lombok.*; import java.util.*; import io.swagger.annotations.*; @@ -30,8 +31,8 @@ public class NotifyTemplateExcelVO { private String content; @ExcelProperty(value = "状态:1-启用 0-禁用", converter = DictConvert.class) - @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 - private String status; + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; @ExcelProperty("备注") private String remarks; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java index a9f8877e2..b3a997933 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateExportReqVO.java +++ b/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 { private String title; @ApiModelProperty(value = "状态:1-启用 0-禁用") - private String status; + private Integer status; @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java new file mode 100644 index 000000000..abfcb2b36 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/template/NotifyTemplateSendReqVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.system.controller.admin.notify.vo.template; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.Map; + +@ApiModel("管理后台 - 站内信模板的发送 Request VO") +@Data +public class NotifyTemplateSendReqVO { + + @ApiModelProperty(value = "用户id", required = true, example = "01") + @NotNull(message = "用户id不能为空") + private Long userId; + + @ApiModelProperty(value = "模板Id", required = true, example = "01") + @NotNull(message = "模板Id不能为空") + private Long templateId; + + @ApiModelProperty(value = "模板参数") + private Map templateParams; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java index b5bce25d4..a111827fe 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notify/NotifyMessageConvert.java +++ b/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.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; @@ -21,10 +19,6 @@ public interface NotifyMessageConvert { NotifyMessageConvert INSTANCE = Mappers.getMapper(NotifyMessageConvert.class); - NotifyMessageDO convert(NotifyMessageCreateReqVO bean); - - NotifyMessageDO convert(NotifyMessageUpdateReqVO bean); - NotifyMessageRespVO convert(NotifyMessageDO bean); List convertList(List list); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java index ab8b128ea..28fa83406 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyTemplateDO.java +++ b/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 { * * 枚举 {@link CommonStatusEnum} */ - private String status; + private Integer status; /** * 备注 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java index 2c9137f11..9523264d1 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java +++ b/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; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -28,16 +27,27 @@ public interface NotifyMessageMapper extends BaseMapperX { .orderByDesc(NotifyMessageDO::getId)); } + default List selectList(NotifyMessagePageReqVO reqVO, Integer size) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(NotifyMessageDO::getTitle, reqVO.getTitle()) + .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus()) + .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime()) + .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId()) + .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType()) + .orderByDesc(NotifyMessageDO::getId) + .last("limit " + size)); + } + default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) { return selectCount(new LambdaQueryWrapperX() - .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) + .eq(NotifyMessageDO::getReadStatus, false) .eq(NotifyMessageDO::getUserId, userId) .eq(NotifyMessageDO::getUserType, userType)); } default List selectUnreadListByUserIdAndUserType(Long userId, Integer userType) { return selectList(new LambdaQueryWrapperX() - .eq(NotifyMessageDO::getReadStatus, NotifyReadStatusEnum.UNREAD.getStatus()) + .eq(NotifyMessageDO::getReadStatus, false) .eq(NotifyMessageDO::getUserId, userId) .eq(NotifyMessageDO::getUserType, userType)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java index e6057bef0..10f397505 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java @@ -30,6 +30,14 @@ public interface NotifyMessageService { */ List getNotifyMessageList(Collection ids); + /** + * 获得站内信集合 + * + * @param pageReqVO 分页查询 + * @return 站内信分页 + */ + List getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size); + /** * 获得站内信分页 * @@ -53,7 +61,7 @@ public interface NotifyMessageService { * @param id 站内信编号 * @param status 状态 */ - void updateNotifyMessageReadStatus(Long id, Integer status); + void updateNotifyMessageReadStatus(Long id, Boolean status); /** * 批量修改站内信阅读状态 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java index 8150ee453..0597fd689 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java +++ b/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; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageCreateReqVO; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessagePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notify.NotifyMessageConvert; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; -import cn.iocoder.yudao.module.system.enums.notify.NotifyReadStatusEnum; import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -87,6 +84,11 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { return notifyMessageMapper.selectBatchIds(ids); } + @Override + public List getNotifyMessageList(NotifyMessagePageReqVO pageReqVO, Integer size) { + return notifyMessageMapper.selectList(pageReqVO, size); + } + @Override public PageResult getNotifyMessagePage(NotifyMessagePageReqVO pageReqVO) { return notifyMessageMapper.selectPage(pageReqVO); @@ -111,7 +113,7 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { * @param status 状态 */ @Override - public void updateNotifyMessageReadStatus(Long id, Integer status) { + public void updateNotifyMessageReadStatus(Long id, Boolean status) { // 校验消息是否存在 this.validateNotifyMessageExists(id); // 更新状态 @@ -155,20 +157,12 @@ public class NotifyMessageServiceImpl implements NotifyMessageService { List list = notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType); if (CollUtil.isNotEmpty(list)) { batchUpdateReadStatus(CollectionUtils.convertList(list, NotifyMessageDO::getId)); - } } - // TODO 芋艿:批量更新,不要单条遍历哈。 private void batchUpdateReadStatus(Collection ids) { - if (CollUtil.isNotEmpty(ids)) { - for (Long id : ids) { - NotifyMessageDO updateObj = new NotifyMessageDO(); - updateObj.setId(id); - updateObj.setReadStatus(NotifyReadStatusEnum.READ.getStatus()); - notifyMessageMapper.updateById(updateObj); - } - } - + NotifyMessageDO updateObj = new NotifyMessageDO(); + updateObj.setReadStatus(false); + notifyMessageMapper.update(updateObj, new LambdaQueryWrapperX().in(NotifyMessageDO::getId, ids)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java new file mode 100644 index 000000000..bbf8c2dc5 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import java.util.List; +import java.util.Map; + +public interface NotifySendService { + + + /** + * 发送单条站内信给管理后台的用户 + * + * 在 mobile 为空时,使用 userId 加载对应管理员的手机号 + * + * @param userId 用户编号 + * @param templateId 短信模板编号 + * @param templateParams 短信模板参数 + * @return 发送日志编号 + */ + Long sendSingleNotifyToAdmin(Long userId, + Long templateId, Map templateParams); + /** + * 发送单条站内信给用户 APP 的用户 + * + * 在 mobile 为空时,使用 userId 加载对应会员的手机号 + * + * @param userId 用户编号 + * @param templateId 站内信模板编号 + * @param templateParams 站内信模板参数 + * @return 发送日志编号 + */ + Long sendSingleNotifyToMember(Long userId, + Long templateId, Map templateParams); + + /** + * 发送单条站内信给用户 + * + * @param userId 用户编号 + * @param userType 用户类型 + * @param templateId 站内信模板编号 + * @param templateParams 站内信模板参数 + * @return 发送日志编号 + */ + Long sendSingleNotify( Long userId, Integer userType, + Long templateId, Map templateParams); + + default void sendBatchNotify(List mobiles, List userIds, Integer userType, + String templateCode, Map templateParams) { + throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!"); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java new file mode 100644 index 000000000..63237e79b --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.module.system.service.notify; + +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO; +import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; +import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyMessageMapper; +import com.google.common.annotations.VisibleForTesting; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND; + +/** + * 站内信发送 Service 实现类 + * + * @author xrcoder + */ +@Service +@Validated +@Slf4j +public class NotifySendServiceImpl implements NotifySendService { + + @Resource + private NotifyTemplateService notifyTemplateService; + + @Resource + private NotifyMessageMapper notifyMessageMapper; + + @Override + public Long sendSingleNotifyToAdmin(Long userId, Long templateId, Map templateParams) { + + return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateId, templateParams); + } + + @Override + public Long sendSingleNotifyToMember(Long userId, Long templateId, Map templateParams) { + return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateId, templateParams); + } + + @Override + public Long sendSingleNotify(Long userId, Integer userType, Long templateId, Map templateParams) { + // 校验短信模板是否合法 + NotifyTemplateDO template = this.checkNotifyTemplateValid(templateId); + String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams); + + // todo 模板状态未开启时的业务 + NotifyMessageDO notifyMessageDO = new NotifyMessageDO(); + notifyMessageDO.setContent(content); + notifyMessageDO.setTitle(template.getTitle()); + notifyMessageDO.setReadStatus(false); + notifyMessageDO.setReadTime(new Date()); + notifyMessageDO.setTemplateId(templateId); + notifyMessageDO.setUserId(userId); + notifyMessageDO.setUserType(userType); + notifyMessageMapper.insert(notifyMessageDO); + return notifyMessageDO.getId(); + } + + // 此注解的含义 + @VisibleForTesting + public NotifyTemplateDO checkNotifyTemplateValid(Long templateId) { + // 获得短信模板。考虑到效率,从缓存中获取 + NotifyTemplateDO template = notifyTemplateService.getNotifyTemplate(templateId); + // 短信模板不存在 + if (template == null) { + throw exception(NOTICE_NOT_FOUND); + } + return template; + } + +}