Browse Source

站内信

hyy 1 month ago
parent
commit
0d8f0659f2

+ 29 - 12
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimenoutbound/SpecimenOutboundServiceImpl.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.museums.dal.mysql.specimeninfo.SpecimenInfoMapper
 import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
 import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
 import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
+import cn.iocoder.yudao.module.system.service.user.AdminUserService;
 import com.mzt.logapi.context.LogRecordContext;
 import com.mzt.logapi.service.impl.DiffParseFunction;
 import com.mzt.logapi.starter.annotation.LogRecord;
@@ -57,6 +58,9 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
     @Resource
     private NotifyMessageSendApi notifySendApi;
 
+    @Resource
+    private AdminUserService adminUserService;
+
     //创建出库申请
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -99,9 +103,13 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
         String formattedDate = specimenOutbound.getCreateTime().format(formatter);
         templateParams.put("createTime",formattedDate);
         templateParams.put("operator",getLoginUserNickname());
-
-        notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
-                .setUserId(143L).setTemplateCode(templateCode).setTemplateParams(templateParams));
+        List<Long> userId = adminUserService.selectUserIdByRoleCode("deputy_leader");
+        for (Long id :userId){
+            notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                    .setUserId(id)
+                    .setTemplateCode(templateCode)
+                    .setTemplateParams(templateParams));
+        }
 
         // 返回出库记录ID
         return specimenOutbound.getId();
@@ -198,10 +206,14 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
             templateCode = "specimen_withdrawal_request_two_submitted";
             String operatorNickname = adminUserMapper.selectNicknameByUserId(Long.valueOf(specimenOutbound.getCreator()));
             templateParams.put("operator", operatorNickname);
-            notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
-                    .setUserId(142L)
-                    .setTemplateCode(templateCode)
-                    .setTemplateParams(templateParams));
+            List<Long> userId = adminUserService.selectUserIdByRoleCode("leadership");
+
+            for (Long id :userId){
+                notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                        .setUserId(id)
+                        .setTemplateCode(templateCode)
+                        .setTemplateParams(templateParams));
+            }
         }
 
         // 更新数据库
@@ -261,13 +273,14 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
         updateObj.setInfoId(validInfoIds.toString());
         specimenOutboundMapper.updateById(updateObj);
 
+
         // 1. 准备参数
+        List<Long> userId;
         if(currentStatus == 2 || currentStatus == 6){
-            Long userId = null;
             if(currentStatus == 2){
-                 userId = 143L;
+                userId = adminUserService.selectUserIdByRoleCode("deputy_leader");
             }else{
-                 userId = 142L;
+                userId = adminUserService.selectUserIdByRoleCode("leadership");
             }
             String templateCode = "sample_outbound_request_modified";
             Map<String, Object> templateParams = new HashMap<>();
@@ -280,8 +293,12 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
             templateParams.put("createTime", formattedDate);
 
             // 2. 发送站内信
-            notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
-                    .setUserId(userId).setTemplateCode(templateCode).setTemplateParams(templateParams));
+            for (Long id :userId){
+                notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                        .setUserId(id)
+                        .setTemplateCode(templateCode)
+                        .setTemplateParams(templateParams));
+            }
         }
 
         // 记录日志上下文

+ 11 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/AdminUserMapper.java

@@ -6,6 +6,9 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Collection;
 import java.util.List;
@@ -52,4 +55,12 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
         return user != null ? user.getNickname() : null;
     }
 
+
+    // 通过角色的code查找角色ID
+    @Select("SELECT id FROM system_role WHERE code = #{code} AND deleted = 0")
+    Long selectRoleIdByCode(@Param("code") String code);
+
+    // 通过角色ID查找对应的用户ID
+    @Select("SELECT user_id FROM system_user_role WHERE role_id = #{roleId} AND deleted = 0")
+    List<Long> selectUserIdByRoleId(@Param("roleId") Long roleId);
 }

+ 9 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java

@@ -201,4 +201,13 @@ public interface AdminUserService {
      */
     boolean isPasswordMatch(String rawPassword, String encodedPassword);
 
+
+    /**
+     * 判断密码是否匹配
+     *
+     * @param roleCode 未加密的密码
+     * @return 用户id
+     */
+    List<Long> selectUserIdByRoleCode(String roleCode);
+
 }

+ 10 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java

@@ -502,4 +502,14 @@ public class AdminUserServiceImpl implements AdminUserService {
         return passwordEncoder.encode(password);
     }
 
+    @Override
+    public List<Long> selectUserIdByRoleCode(String roleCode) {
+        // 获取角色ID
+        Long roleId = userMapper.selectRoleIdByCode(roleCode);
+        if (roleId != null) {
+            // 根据角色ID查找用户ID
+            return userMapper.selectUserIdByRoleId(roleId);
+        }
+        return null; // 如果角色不存在,返回null
+    }
 }