Ver Fonte

app消息融合站内信

车车 há 4 meses atrás
pai
commit
d9db8a3090
16 ficheiros alterados com 208 adições e 118 exclusões
  1. 3 3
      yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/workdesign/WorkflowWorkNodeServiceImpl.java
  2. 2 2
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApiImpl.java
  3. 100 0
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/AppNotifyMessageController.java
  4. 6 4
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java
  5. 2 2
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java
  6. 3 0
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageMyPageReqVO.java
  7. 3 0
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java
  8. 4 0
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java
  9. 10 4
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java
  10. 19 53
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/appnotify/AppNotifySendServiceImpl.java
  11. 8 5
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java
  12. 23 21
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java
  13. 4 3
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java
  14. 8 8
      yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java
  15. 5 5
      yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImplTest.java
  16. 8 8
      yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImplTest.java

+ 3 - 3
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/workdesign/WorkflowWorkNodeServiceImpl.java

@@ -210,7 +210,7 @@ public class WorkflowWorkNodeServiceImpl extends ServiceImpl<WorkflowWorkNodeMap
             try {
                 sendByType(nodeDO);
             } catch (Exception e) {
-                log.error("发送异常---------------" + nodeDO.getId());
+                log.error("发送异常---------------" + nodeDO.getId() + "----" + e);
             }
 
         }
@@ -372,14 +372,14 @@ public class WorkflowWorkNodeServiceImpl extends ServiceImpl<WorkflowWorkNodeMap
             if (notifyTemplate != null) {
                 notifySendService.sendSingleNotifyToAdmin(userId, notifyTemplate.getCode(), templateParams);
             }*/
-            notifySendService.sendSingleNotifyToAdmin(userId, Objects.requireNonNull(MessageEnum.getByKey(templateKey)).znx, templateParams);
+            notifySendService.sendSingleNotifyToAdmin(userId, Objects.requireNonNull(MessageEnum.getByKey(templateKey)).znx, templateParams, 0);
         }
         if (StringUtils.isNotBlank(nodeDO.getEmailTemplateCode()) && "true".equals(nodeDO.getEmailTemplateCode())) {
             // 邮件
         }
         if (StringUtils.isNotBlank(nodeDO.getAppTemplateCode()) && "true".equals(nodeDO.getAppTemplateCode())) {
             // app
-            appNotifySendService.sendSingleAppNotifyToAdmin(userId, templateKey, templateParams);
+            appNotifySendService.sendSingleAppNotifyToAdmin(userId, Objects.requireNonNull(MessageEnum.getByKey(templateKey)).znx, templateParams);
         }
 
     }

+ 2 - 2
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/api/notify/NotifyMessageSendApiImpl.java

@@ -20,13 +20,13 @@ public class NotifyMessageSendApiImpl implements NotifyMessageSendApi {
     @Override
     public Long sendSingleMessageToAdmin(NotifySendSingleToUserReqDTO reqDTO) {
         return notifySendService.sendSingleNotifyToAdmin(reqDTO.getUserId(),
-                reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
+                reqDTO.getTemplateCode(), reqDTO.getTemplateParams(), 0);
     }
 
     @Override
     public Long sendSingleMessageToMember(NotifySendSingleToUserReqDTO reqDTO) {
         return notifySendService.sendSingleNotifyToMember(reqDTO.getUserId(),
-                reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
+                reqDTO.getTemplateCode(), reqDTO.getTemplateParams(), 0);
     }
 
 }

+ 100 - 0
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/AppNotifyMessageController.java

@@ -0,0 +1,100 @@
+package cn.iocoder.yudao.module.system.controller.admin.notify;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+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.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.system.controller.admin.notify.vo.message.NotifyMessageMyPageReqVO;
+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.dal.dataobject.notify.NotifyMessageDO;
+import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+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;
+
+@Tag(name = "管理后台 - 我的站内信")
+@RestController
+@RequestMapping("/system/app-notify-message")
+@Validated
+public class AppNotifyMessageController {
+
+    @Resource
+    private NotifyMessageService notifyMessageService;
+
+    // ========== 管理所有的站内信 ==========
+
+    @GetMapping("/get")
+    @Operation(summary = "获得app消息")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('system:notify-message:query')")
+    public CommonResult<NotifyMessageRespVO> getNotifyMessage(@RequestParam("id") Long id) {
+        NotifyMessageDO message = notifyMessageService.getNotifyMessage(id);
+        return success(BeanUtils.toBean(message, NotifyMessageRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得app消息分页")
+    @PreAuthorize("@ss.hasPermission('system:notify-message:query')")
+    public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
+        pageVO.setType(1);
+        PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
+        return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class));
+    }
+
+    // ========== 查看自己的站内信 ==========
+
+    @GetMapping("/my-page")
+    @Operation(summary = "获得我的app消息分页")
+    public CommonResult<PageResult<NotifyMessageRespVO>> getMyMyNotifyMessagePage(@Valid NotifyMessageMyPageReqVO pageVO) {
+        pageVO.setType(1);
+        PageResult<NotifyMessageDO> pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO,
+                getLoginUserId(), UserTypeEnum.ADMIN.getValue());
+        return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class));
+    }
+
+    @PutMapping("/update-read")
+    @Operation(summary = "标记app消息为已读")
+    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
+    public CommonResult<Boolean> updateNotifyMessageRead(@RequestParam("ids") List<Long> ids) {
+        notifyMessageService.updateNotifyMessageRead(ids, getLoginUserId(), UserTypeEnum.ADMIN.getValue(), 1);
+        return success(Boolean.TRUE);
+    }
+
+    @PutMapping("/update-all-read")
+    @Operation(summary = "标记所有app消息为已读")
+    public CommonResult<Boolean> updateAllNotifyMessageRead() {
+        notifyMessageService.updateAllNotifyMessageRead(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), 1);
+        return success(Boolean.TRUE);
+    }
+
+    @GetMapping("/get-unread-list")
+    @Operation(summary = "获取当前用户的最新app消息列表,默认 10 条")
+    @Parameter(name = "size", description = "10")
+    public CommonResult<List<NotifyMessageRespVO>> getUnreadNotifyMessageList(
+            @RequestParam(name = "size", defaultValue = "10") Integer size) {
+        List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(
+                getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size, 1);
+        return success(BeanUtils.toBean(list, NotifyMessageRespVO.class));
+    }
+
+    @GetMapping("/get-unread-count")
+    @Operation(summary = "获得当前用户的未读app消息数量")
+    @ApiAccessLog(enable = false) // 由于前端会不断轮询该接口,记录日志没有意义
+    public CommonResult<Long> getUnreadNotifyMessageCount() {
+        return success(notifyMessageService.getUnreadNotifyMessageCount(
+                getLoginUserId(), UserTypeEnum.ADMIN.getValue(), 1));
+    }
+
+}

+ 6 - 4
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyMessageController.java

@@ -48,6 +48,7 @@ public class NotifyMessageController {
     @Operation(summary = "获得站内信分页")
     @PreAuthorize("@ss.hasPermission('system:notify-message:query')")
     public CommonResult<PageResult<NotifyMessageRespVO>> getNotifyMessagePage(@Valid NotifyMessagePageReqVO pageVO) {
+        pageVO.setType(0);
         PageResult<NotifyMessageDO> pageResult = notifyMessageService.getNotifyMessagePage(pageVO);
         return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class));
     }
@@ -57,6 +58,7 @@ public class NotifyMessageController {
     @GetMapping("/my-page")
     @Operation(summary = "获得我的站内信分页")
     public CommonResult<PageResult<NotifyMessageRespVO>> getMyMyNotifyMessagePage(@Valid NotifyMessageMyPageReqVO pageVO) {
+        pageVO.setType(0);
         PageResult<NotifyMessageDO> pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO,
                 getLoginUserId(), UserTypeEnum.ADMIN.getValue());
         return success(BeanUtils.toBean(pageResult, NotifyMessageRespVO.class));
@@ -66,14 +68,14 @@ public class NotifyMessageController {
     @Operation(summary = "标记站内信为已读")
     @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
     public CommonResult<Boolean> updateNotifyMessageRead(@RequestParam("ids") List<Long> ids) {
-        notifyMessageService.updateNotifyMessageRead(ids, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
+        notifyMessageService.updateNotifyMessageRead(ids, getLoginUserId(), UserTypeEnum.ADMIN.getValue(), 0);
         return success(Boolean.TRUE);
     }
 
     @PutMapping("/update-all-read")
     @Operation(summary = "标记所有站内信为已读")
     public CommonResult<Boolean> updateAllNotifyMessageRead() {
-        notifyMessageService.updateAllNotifyMessageRead(getLoginUserId(), UserTypeEnum.ADMIN.getValue());
+        notifyMessageService.updateAllNotifyMessageRead(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), 0);
         return success(Boolean.TRUE);
     }
 
@@ -83,7 +85,7 @@ public class NotifyMessageController {
     public CommonResult<List<NotifyMessageRespVO>> getUnreadNotifyMessageList(
             @RequestParam(name = "size", defaultValue = "10") Integer size) {
         List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(
-                getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size);
+                getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size, 0);
         return success(BeanUtils.toBean(list, NotifyMessageRespVO.class));
     }
 
@@ -92,7 +94,7 @@ public class NotifyMessageController {
     @ApiAccessLog(enable = false) // 由于前端会不断轮询该接口,记录日志没有意义
     public CommonResult<Long> getUnreadNotifyMessageCount() {
         return success(notifyMessageService.getUnreadNotifyMessageCount(
-                getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
+                getLoginUserId(), UserTypeEnum.ADMIN.getValue(), 0));
     }
 
 }

+ 2 - 2
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java

@@ -79,10 +79,10 @@ public class NotifyTemplateController {
     public CommonResult<Long> sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) {
         if (UserTypeEnum.MEMBER.getValue().equals(sendReqVO.getUserType())) {
             return success(notifySendService.sendSingleNotifyToMember(sendReqVO.getUserId(),
-                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
+                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams(), 0));
         } else {
             return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
-                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
+                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams(), 0));
         }
     }
 }

+ 3 - 0
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessageMyPageReqVO.java

@@ -27,4 +27,7 @@ public class NotifyMessageMyPageReqVO extends PageParam {
     @Schema(description = "标题", example = "true")
     private String title;
 
+    @Schema(description = "类型(0-站内信 1-app消息)", example = "1")
+    private Integer type;
+
 }

+ 3 - 0
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/vo/message/NotifyMessagePageReqVO.java

@@ -29,6 +29,9 @@ public class NotifyMessagePageReqVO extends PageParam {
     @Schema(description = "模版类型", example = "2")
     private Integer templateType;
 
+    @Schema(description = "类型(0-站内信 1-app消息)", example = "1")
+    private Integer type;
+
     @Schema(description = "创建时间")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;

+ 4 - 0
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/notify/NotifyMessageDO.java

@@ -95,6 +95,10 @@ public class NotifyMessageDO extends BaseDO {
      * 阅读时间
      */
     private LocalDateTime readTime;
+    /**
+     * 类型(0-站内信 1-app消息)
+     */
+    private Integer type;
 
     @TableField(exist = false)
     private String title;

+ 10 - 4
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/notify/NotifyMessageMapper.java

@@ -20,6 +20,7 @@ public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
 
     default PageResult<NotifyMessageDO> selectPage(NotifyMessagePageReqVO reqVO) {
         return selectPage(reqVO, new LambdaQueryWrapperX<NotifyMessageDO>()
+                .eqIfPresent(NotifyMessageDO::getType, reqVO.getType())
                 .eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId())
                 .eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType())
                 .likeIfPresent(NotifyMessageDO::getTemplateCode, reqVO.getTemplateCode())
@@ -39,6 +40,7 @@ public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
 
     default PageResult<NotifyMessageDO> selectPage(NotifyMessageMyPageReqVO reqVO, Long userId, Integer userType) {
         return selectPage(reqVO, new MPJLambdaWrapperX<NotifyMessageDO>()
+                .eqIfPresent(NotifyMessageDO::getType, reqVO.getType())
                 .eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus())
                 .betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime())
                 .eq(NotifyMessageDO::getUserId, userId)
@@ -50,33 +52,37 @@ public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
                 .selectAs(NotifyTemplateDO::getName, "title"));
     }
 
-    default int updateListRead(Collection<Long> ids, Long userId, Integer userType) {
+    default int updateListRead(Collection<Long> ids, Long userId, Integer userType, Integer type) {
         return update(new NotifyMessageDO().setReadStatus(true).setReadTime(LocalDateTime.now()),
                 new LambdaQueryWrapperX<NotifyMessageDO>()
                         .in(NotifyMessageDO::getId, ids)
+                        .eq(NotifyMessageDO::getType, type)
                         .eq(NotifyMessageDO::getUserId, userId)
                         .eq(NotifyMessageDO::getUserType, userType)
                         .eq(NotifyMessageDO::getReadStatus, false));
     }
 
-    default int updateListRead(Long userId, Integer userType) {
+    default int updateListRead(Long userId, Integer userType, Integer type) {
         return update(new NotifyMessageDO().setReadStatus(true).setReadTime(LocalDateTime.now()),
                 new LambdaQueryWrapperX<NotifyMessageDO>()
+                        .eq(NotifyMessageDO::getType, type)
                         .eq(NotifyMessageDO::getUserId, userId)
                         .eq(NotifyMessageDO::getUserType, userType)
                         .eq(NotifyMessageDO::getReadStatus, false));
     }
 
-    default List<NotifyMessageDO> selectUnreadListByUserIdAndUserType(Long userId, Integer userType, Integer size) {
+    default List<NotifyMessageDO> selectUnreadListByUserIdAndUserType(Long userId, Integer userType, Integer size, Integer type) {
         return selectList(new QueryWrapperX<NotifyMessageDO>() // 由于要使用 limitN 语句,所以只能用 QueryWrapperX
+                .eq("type", type)
                 .eq("user_id", userId)
                 .eq("user_type", userType)
                 .eq("read_status", false)
                 .orderByDesc("id").limitN(size));
     }
 
-    default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) {
+    default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType, Integer type) {
         return selectCount(new LambdaQueryWrapperX<NotifyMessageDO>()
+                .eq(NotifyMessageDO::getType, type)
                 .eq(NotifyMessageDO::getReadStatus, false)
                 .eq(NotifyMessageDO::getUserId, userId)
                 .eq(NotifyMessageDO::getUserType, userType));

+ 19 - 53
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/appnotify/AppNotifySendServiceImpl.java

@@ -1,9 +1,8 @@
 package cn.iocoder.yudao.module.system.service.appnotify;
 
-import cn.hutool.core.util.StrUtil;
-import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
-import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO;
-import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService;
+import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyMessageDO;
+import cn.iocoder.yudao.module.system.service.notify.NotifyMessageService;
+import cn.iocoder.yudao.module.system.service.notify.NotifySendService;
 import com.aliyun.auth.credentials.utils.ParameterHelper;
 import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.IAcsClient;
@@ -12,7 +11,6 @@ import com.aliyuncs.exceptions.ServerException;
 import com.aliyuncs.profile.DefaultProfile;
 import com.aliyuncs.push.model.v20160801.PushRequest;
 import com.aliyuncs.push.model.v20160801.PushResponse;
-import com.google.common.annotations.VisibleForTesting;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -21,11 +19,6 @@ import org.springframework.validation.annotation.Validated;
 
 import java.util.Date;
 import java.util.Map;
-import java.util.Objects;
-
-import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTICE_NOT_FOUND;
-import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.NOTIFY_SEND_TEMPLATE_PARAM_MISS;
 
 /**
  * App消息推送服务实现类(阿里云推送)
@@ -96,7 +89,9 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
      */
 
     @Autowired
-    private NotifyTemplateService notifyTemplateService;
+    private NotifySendService notifySendService;
+    @Autowired
+    private NotifyMessageService notifyMessageService;
 
 
     @Override
@@ -110,14 +105,15 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
         }
 
         // 2. 第二步:通过notifyId获取站内信已经发送的消息,进行消息复制发送
-        String content = getMessageByNotify(userId, templateCode, templateParams);
+        NotifyMessageDO notifyMessage = getMessageByNotify(userId, templateCode, templateParams);
 
         try {
             // 3. 第三步:创建阿里云ACS客户端(修复Push类找不到的兼容方案)
             IAcsClient client = createAcsClient();
 
             // 4. 第四步:构建单设备推送请求(封装Android/iOS双端配置)
-            PushRequest pushRequest = buildSingleDevicePushRequest(deviceId, "博士安全", content);
+            // PushRequest pushRequest = buildSingleDevicePushRequest(deviceId, "博士安全", notifyMessage.getTemplateContent());
+            PushRequest pushRequest = buildAllDevicePushRequest("博士安全", notifyMessage.getTemplateContent());
 
             // 5. 第五步:发送推送请求,调用阿里云Push接口
             PushResponse response = client.getAcsResponse(pushRequest);
@@ -145,7 +141,7 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
      *
      * @return 推送结果:true-成功,false-失败
      */
-    public Boolean pushNotify() {
+    public Boolean pushAllNotify() {
         // 前置校验:AppKey未配置直接返回失败
         if (appKey == null || appKey == 0) {
             log.error("App全量推送失败:未配置阿里云Push的appKey,请检查application.yml配置");
@@ -209,8 +205,8 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
 
         // ========== 基础推送配置 ==========
         request.setAppKey(appKey); // 关联的阿里云Push应用ID
-        request.setTarget("DEVICE"); // 推送目标类型:DEVICE-按设备ID,ACCOUNT-按账号,TAG-按标签
-        request.setTargetValue(deviceId); // 目标值:对应DEVICE类型的设备ID
+        request.setTarget("DEVICE"); // 推送目标类型:DEVICE-按设备ID,ACCOUNT-按账号,TAG-按标签,ALL-全部
+        request.setTargetValue(deviceId); // 目标值:对应DEVICE类型的设备ID,all-全量
         request.setDeviceType("ALL"); // 推送设备类型:ALL-全部,ANDROID-安卓,IOS-iOS
         request.setPushType("NOTICE"); // 推送类型:NOTICE-通知,MESSAGE-透传消息
 
@@ -330,45 +326,15 @@ public class AppNotifySendServiceImpl implements AppNotifySendService {
      * 通过站内信获取相同发送信息
      * @return
      */
-    private String getMessageByNotify(Long userId, String templateCode, Map<String, Object> templateParams) {
-        // 校验模版
-        NotifyTemplateDO template = validateNotifyTemplate(templateCode);
-        if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
-            log.info("[sendSingleNotify][模版({})已经关闭,无法给用户({})发送]", templateCode, userId);
-            return null;
-        }
-        // 校验参数
-        validateTemplateParams(template, templateParams);
-
+    private NotifyMessageDO getMessageByNotify(Long userId, String templateCode, Map<String, Object> templateParams) {
         // 发送站内信
-        return StrUtil.format(template.getContent(), templateParams);
-    }
-
-    @VisibleForTesting
-    public NotifyTemplateDO validateNotifyTemplate(String templateCode) {
-        // 获得站内信模板。考虑到效率,从缓存中获取
-        NotifyTemplateDO template = notifyTemplateService.getNotifyTemplateByCodeFromCache(templateCode);
-        // 站内信模板不存在
-        if (template == null) {
-            throw exception(NOTICE_NOT_FOUND);
-        }
-        return template;
+        Long id = notifySendService.sendSingleNotifyToAdmin(userId,
+                templateCode, templateParams, 1);
+        NotifyMessageDO notifyMessage = notifyMessageService.getNotifyMessage(id);
+        // NotifyMessageDO notifyMessage = new NotifyMessageDO();
+        // notifyMessage.setTemplateContent("消息主体内容");
+        return notifyMessage;
     }
 
-    /**
-     * 校验站内信模版参数是否确实
-     *
-     * @param template 邮箱模板
-     * @param templateParams 参数列表
-     */
-    @VisibleForTesting
-    public void validateTemplateParams(NotifyTemplateDO template, Map<String, Object> templateParams) {
-        template.getParams().forEach(key -> {
-            Object value = templateParams.get(key);
-            if (value == null) {
-                throw exception(NOTIFY_SEND_TEMPLATE_PARAM_MISS, key);
-            }
-        });
-    }
 
 }

+ 8 - 5
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageService.java

@@ -28,7 +28,7 @@ public interface NotifyMessageService {
      * @return 站内信编号
      */
     Long createNotifyMessage(Long userId, Integer userType,
-                             NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams);
+                             NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams, Integer type);
 
     /**
      * 获得站内信分页
@@ -62,9 +62,10 @@ public interface NotifyMessageService {
      * @param userId   用户编号
      * @param userType 用户类型
      * @param size     数量
+     * @param type 消息类型
      * @return 站内信列表
      */
-    List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer userType, Integer size);
+    List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer userType, Integer size, Integer type);
 
     /**
      * 统计用户未读站内信条数
@@ -73,7 +74,7 @@ public interface NotifyMessageService {
      * @param userType 用户类型
      * @return 返回未读站内信条数
      */
-    Long getUnreadNotifyMessageCount(Long userId, Integer userType);
+    Long getUnreadNotifyMessageCount(Long userId, Integer userType, Integer type);
 
     /**
      * 标记站内信为已读
@@ -81,17 +82,19 @@ public interface NotifyMessageService {
      * @param ids    站内信编号集合
      * @param userId 用户编号
      * @param userType 用户类型
+     * @param type 消息类型
      * @return 更新到的条数
      */
-    int updateNotifyMessageRead(Collection<Long> ids, Long userId, Integer userType);
+    int updateNotifyMessageRead(Collection<Long> ids, Long userId, Integer userType, Integer type);
 
     /**
      * 标记所有站内信为已读
      *
      * @param userId   用户编号
      * @param userType 用户类型
+     * @param type 消息类型
      * @return 更新到的条数
      */
-    int updateAllNotifyMessageRead(Long userId, Integer userType);
+    int updateAllNotifyMessageRead(Long userId, Integer userType, Integer type);
 
 }

+ 23 - 21
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImpl.java

@@ -31,23 +31,25 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
 
     @Override
     public Long createNotifyMessage(Long userId, Integer userType,
-                                    NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams) {
+                                    NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams, Integer type) {
         NotifyMessageDO message = new NotifyMessageDO().setUserId(userId).setUserType(userType)
-                .setTemplateId(template.getId()).setTemplateCode(template.getCode())
+                .setTemplateId(template.getId()).setTemplateCode(template.getCode()).setType(type)
                 .setTemplateType(template.getType()).setTemplateNickname(template.getNickname())
                 .setTemplateContent(templateContent).setTemplateParams(templateParams).setReadStatus(false);
         notifyMessageMapper.insert(message);
-        // 发送socket
-        Map<String, Object> map = new HashMap<>();
-        map.put("userId", userId);
-        map.put("time", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
-        map.put("templateContent", templateContent);
-        try {
-            ObjectMapper objectMapper = new ObjectMapper();
-            String jsonStr = objectMapper.writeValueAsString(map); // 转换为紧凑格式的 JSON
-            WebSocketMessSend.sendMessage(String.valueOf(userId), jsonStr);
-        } catch (Exception e) {
-            log.error("实时站内信解析异常{}", e);
+        if (type.equals(0)) {
+            // 站内信,发送socket,app消息不需要
+            Map<String, Object> map = new HashMap<>();
+            map.put("userId", userId);
+            map.put("time", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
+            map.put("templateContent", templateContent);
+            try {
+                ObjectMapper objectMapper = new ObjectMapper();
+                String jsonStr = objectMapper.writeValueAsString(map); // 转换为紧凑格式的 JSON
+                WebSocketMessSend.sendMessage(String.valueOf(userId), jsonStr);
+            } catch (Exception e) {
+                log.error("实时站内信解析异常{}", e);
+            }
         }
         return message.getId();
     }
@@ -68,23 +70,23 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
     }
 
     @Override
-    public List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer userType, Integer size) {
-        return notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType, size);
+    public List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer userType, Integer size, Integer type) {
+        return notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType, size, type);
     }
 
     @Override
-    public Long getUnreadNotifyMessageCount(Long userId, Integer userType) {
-        return notifyMessageMapper.selectUnreadCountByUserIdAndUserType(userId, userType);
+    public Long getUnreadNotifyMessageCount(Long userId, Integer userType, Integer type) {
+        return notifyMessageMapper.selectUnreadCountByUserIdAndUserType(userId, userType, type);
     }
 
     @Override
-    public int updateNotifyMessageRead(Collection<Long> ids, Long userId, Integer userType) {
-        return notifyMessageMapper.updateListRead(ids, userId, userType);
+    public int updateNotifyMessageRead(Collection<Long> ids, Long userId, Integer userType, Integer type) {
+        return notifyMessageMapper.updateListRead(ids, userId, userType, type);
     }
 
     @Override
-    public int updateAllNotifyMessageRead(Long userId, Integer userType) {
-        return notifyMessageMapper.updateListRead(userId, userType);
+    public int updateAllNotifyMessageRead(Long userId, Integer userType, Integer type) {
+        return notifyMessageMapper.updateListRead(userId, userType, type);
     }
 
 }

+ 4 - 3
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendService.java

@@ -20,10 +20,11 @@ public interface NotifySendService {
      * @param userId 用户编号
      * @param templateCode 短信模板编号
      * @param templateParams 短信模板参数
+     * @param type 类型
      * @return 发送日志编号
      */
     Long sendSingleNotifyToAdmin(Long userId,
-                                 String templateCode, Map<String, Object> templateParams);
+                                 String templateCode, Map<String, Object> templateParams, Integer type);
     /**
      * 发送单条站内信给用户 APP 的用户
      *
@@ -35,7 +36,7 @@ public interface NotifySendService {
      * @return 发送日志编号
      */
     Long sendSingleNotifyToMember(Long userId,
-                                  String templateCode, Map<String, Object> templateParams);
+                                  String templateCode, Map<String, Object> templateParams, Integer type);
 
     /**
      * 发送单条站内信给用户
@@ -47,7 +48,7 @@ public interface NotifySendService {
      * @return 发送日志编号
      */
     Long sendSingleNotify( Long userId, Integer userType,
-                           String templateCode, Map<String, Object> templateParams);
+                           String templateCode, Map<String, Object> templateParams, Integer type);
 
     default void sendBatchNotify(List<String> mobiles, List<Long> userIds, Integer userType,
                                  String templateCode, Map<String, Object> templateParams) {

+ 8 - 8
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImpl.java

@@ -34,17 +34,17 @@ public class NotifySendServiceImpl implements NotifySendService {
     private NotifyMessageService notifyMessageService;
 
     @Override
-    public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams) {
-        return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
+    public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams, Integer type) {
+        return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams, type);
     }
 
     @Override
-    public Long sendSingleNotifyToMember(Long userId, String templateCode, Map<String, Object> templateParams) {
-        return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
+    public Long sendSingleNotifyToMember(Long userId, String templateCode, Map<String, Object> templateParams, Integer type) {
+        return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams, type);
     }
 
     @Override
-    public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) {
+    public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams, Integer type) {
         // 校验模版
         NotifyTemplateDO template = validateNotifyTemplate(templateCode);
         if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
@@ -56,7 +56,7 @@ public class NotifySendServiceImpl implements NotifySendService {
 
         // 发送站内信
         String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
-        return notifyMessageService.createNotifyMessage(userId, userType, template, content, templateParams);
+        return notifyMessageService.createNotifyMessage(userId, userType, template, content, templateParams, type);
     }
 
     @VisibleForTesting
@@ -90,10 +90,10 @@ public class NotifySendServiceImpl implements NotifySendService {
     public Long sendSingleNotifyFromPlan(NotifyTemplateSendReqVO sendReqVO) {
         if (UserTypeEnum.MEMBER.getValue().equals(sendReqVO.getUserType())) {
             return sendSingleNotifyToMember(sendReqVO.getUserId(),
-                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams());
+                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams(), 0);
         } else {
             return sendSingleNotifyToAdmin(sendReqVO.getUserId(),
-                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams());
+                    sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams(), 0);
         }
     }
 }

+ 5 - 5
yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImplTest.java

@@ -52,7 +52,7 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
 
         // 调用
         Long messageId = notifyMessageService.createNotifyMessage(userId, userType,
-                template, templateContent, templateParams);
+                template, templateContent, templateParams, 0);
         // 断言
         NotifyMessageDO message = notifyMessageMapper.selectById(messageId);
         assertNotNull(message);
@@ -176,7 +176,7 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
         Integer size = 10;
 
         // 调用
-        List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(userId, userType, size);
+        List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(userId, userType, size, 0);
         // 断言
         assertEquals(1, list.size());
         assertPojoEquals(dbNotifyMessage, list.get(0));
@@ -203,7 +203,7 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
         Integer userType = UserTypeEnum.ADMIN.getValue();
 
         // 调用,并断言
-        assertEquals(1, notifyMessageService.getUnreadNotifyMessageCount(userId, userType));
+        assertEquals(1, notifyMessageService.getUnreadNotifyMessageCount(userId, userType, 0));
     }
 
     @Test
@@ -230,7 +230,7 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
         Integer userType = UserTypeEnum.ADMIN.getValue();
 
         // 调用
-        int updateCount = notifyMessageService.updateNotifyMessageRead(ids, userId, userType);
+        int updateCount = notifyMessageService.updateNotifyMessageRead(ids, userId, userType, 0);
         // 断言
         assertEquals(1, updateCount);
         NotifyMessageDO notifyMessage = notifyMessageMapper.selectById(dbNotifyMessage.getId());
@@ -260,7 +260,7 @@ public class NotifyMessageServiceImplTest extends BaseDbUnitTest {
         Integer userType = UserTypeEnum.ADMIN.getValue();
 
         // 调用
-        int updateCount = notifyMessageService.updateAllNotifyMessageRead(userId, userType);
+        int updateCount = notifyMessageService.updateAllNotifyMessageRead(userId, userType, 0);
         // 断言
         assertEquals(1, updateCount);
         NotifyMessageDO notifyMessage = notifyMessageMapper.selectById(dbNotifyMessage.getId());

+ 8 - 8
yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifySendServiceImplTest.java

@@ -54,10 +54,10 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
         // mock NotifyMessageService 的方法
         Long messageId = randomLongId();
         when(notifyMessageService.createNotifyMessage(eq(userId), eq(UserTypeEnum.ADMIN.getValue()),
-                eq(template), eq(content), eq(templateParams))).thenReturn(messageId);
+                eq(template), eq(content), eq(templateParams), 0)).thenReturn(messageId);
 
         // 调用
-        Long resultMessageId = notifySendService.sendSingleNotifyToAdmin(userId, templateCode, templateParams);
+        Long resultMessageId = notifySendService.sendSingleNotifyToAdmin(userId, templateCode, templateParams, 0);
         // 断言
         assertEquals(messageId, resultMessageId);
     }
@@ -82,10 +82,10 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
         // mock NotifyMessageService 的方法
         Long messageId = randomLongId();
         when(notifyMessageService.createNotifyMessage(eq(userId), eq(UserTypeEnum.MEMBER.getValue()),
-                eq(template), eq(content), eq(templateParams))).thenReturn(messageId);
+                eq(template), eq(content), eq(templateParams), 0)).thenReturn(messageId);
 
         // 调用
-        Long resultMessageId = notifySendService.sendSingleNotifyToMember(userId, templateCode, templateParams);
+        Long resultMessageId = notifySendService.sendSingleNotifyToMember(userId, templateCode, templateParams, 0);
         // 断言
         assertEquals(messageId, resultMessageId);
     }
@@ -114,10 +114,10 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
         // mock NotifyMessageService 的方法
         Long messageId = randomLongId();
         when(notifyMessageService.createNotifyMessage(eq(userId), eq(userType),
-                eq(template), eq(content), eq(templateParams))).thenReturn(messageId);
+                eq(template), eq(content), eq(templateParams), 0)).thenReturn(messageId);
 
         // 调用
-        Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams);
+        Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams, 0);
         // 断言
         assertEquals(messageId, resultMessageId);
     }
@@ -142,11 +142,11 @@ class NotifySendServiceImplTest extends BaseMockitoUnitTest {
         when(notifyTemplateService.getNotifyTemplateByCodeFromCache(eq(templateCode))).thenReturn(template);
 
         // 调用
-        Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams);
+        Long resultMessageId = notifySendService.sendSingleNotify(userId, userType, templateCode, templateParams, 0);
         // 断言
         assertNull(resultMessageId);
         verify(notifyTemplateService, never()).formatNotifyTemplateContent(anyString(), anyMap());
-        verify(notifyMessageService, never()).createNotifyMessage(anyLong(), anyInt(), any(), anyString(), anyMap());
+        verify(notifyMessageService, never()).createNotifyMessage(anyLong(), anyInt(), any(), anyString(), anyMap(), 0);
     }
 
     @Test