hyy hai 6 meses
pai
achega
778b8c86a0

+ 1 - 0
yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoRedisAutoConfiguration.java

@@ -10,6 +10,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.serializer.RedisSerializer;
 
+
 /**
  * Redis 配置类
  */

+ 1 - 1
yudao-module-museums/yudao-module-museums-api/src/main/java/cn/iocoder/yudao/module/museums/enums/social/LogRecordConstants.java

@@ -32,6 +32,6 @@ public interface LogRecordConstants {
     String MUSEUMS_SPECIMEN_CREATE_OUTBOUND_SUCCESS = "成功创建标本出库单【{{#specimenOutbound.id}}】,申请人: {{#createReqVO.applicantName}},申请单位: {{#createReqVO.applicationUsage}},研究项目: {{#createReqVO.projectName}}";
     String MUSEUMS_SPECIMEN_UPDATE_RETURN_SUCCESS = "成功更新标本回库单【{{#existingSpecimen.id}}】, 标本状况: {{#existingSpecimen.specimenCondition}}, 退还人: {{#updateReqVO.returner}}, 点收人: {{#updateReqVO.receiver}}, 备注: {{#updateReqVO.remarks}}";
     String MUSEUMS_SPECIMEN_UPDATE_RECOMPILE_SUCCESS = "成功修改标本出库单【{{#updateReqVO.id}}】:{_DIFF{#updateReqVO}}";
-    String MUSEUMS_SPECIMEN_CREATE_CONFIEM_OUTBOUND_SUCCESS = "{{#operator}}确认了标本出库";
+    String MUSEUMS_SPECIMEN_CREATE_CONFIEM_OUTBOUND_SUCCESS = "{{#operatorNickname}}和{{#twoOperatorNickname}}确认了标本出库";
     String MUSEUMS_SPECIMEN_APPROVE_OUTBOUND_SUCCESS = "审批结果:{{#approvalMessage}},审批人:{{#userNickname}},审批意见:{{#processInstanceId}}{{#rejectionReasons}}";
 }

+ 13 - 0
yudao-module-museums/yudao-module-museums-biz/pom.xml

@@ -115,6 +115,19 @@
             <version>2.2.0-jdk8-snapshot</version>
             <scope>compile</scope>
         </dependency>
+
+        <!-- 目的是引入站内信功能 -->
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-module-system-api</artifactId>
+            <version>${revision}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-jsr310</artifactId>
+            <version>2.13.0</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 2 - 21
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimenoutbound/SpecimenOutboundController.java

@@ -91,27 +91,8 @@ public class SpecimenOutboundController {
     @Operation(summary = "修改标本出库信息")
     @PreAuthorize("@ss.hasPermission('museums:specimen-outbound:recompile')")
     public CommonResult<Boolean> recompileSpecimenOutbound(@Valid @RequestBody SpecimenOutboundSaveReqVO updateReqVO) {
-        // 从数据库获取当前标本出库信息
-        SpecimenOutboundDO specimenOutbound = specimenOutboundMapper.selectById(updateReqVO.getId());
-        if (specimenOutbound == null) {
-            throw exception(SPECIMEN_OUTBOUND_NOT_EXISTS);
-        }
-        int currentStatus = specimenOutbound.getStatus();
-
-        // 校验状态
-        if (currentStatus == 0 || currentStatus == 2 || currentStatus == 6) {
-            // 根据当前状态更新
-            if (currentStatus == 2) {
-                updateReqVO.setStatus(0); // 编辑后将状态变为0
-            } else if (currentStatus == 6) {
-                updateReqVO.setStatus(1); // 编辑后将状态变为1
-            }
-            // 调用服务层更新方法
-            specimenOutboundService.recompileSpecimenOutbound(updateReqVO);
-            return success(true);
-        } else {
-            throw exception(INVALID_APPROVAL_STATUS);
-        }
+        specimenOutboundService.recompileSpecimenOutbound(updateReqVO);
+        return success(true);
     }
 
     @PostMapping("/confirmOutbound")

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

@@ -5,8 +5,9 @@ import cn.iocoder.yudao.module.museums.controller.admin.specimeninfo.vo.Specimen
 import cn.iocoder.yudao.module.museums.controller.admin.specimeninfo.vo.SpecimenInfoRespVO;
 import cn.iocoder.yudao.module.museums.dal.dataobject.specimeninfo.SpecimenInfoDO;
 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;
@@ -25,6 +26,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.museums.dal.mysql.specimenoutbound.SpecimenOutboundMapper;
 
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -34,6 +36,8 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
 import static cn.iocoder.yudao.module.museums.enums.ErrorCodeConstants.*;
 import static cn.iocoder.yudao.module.museums.enums.social.LogRecordConstants.*;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 
 /**
  * 标本出库回库信息 Service 实现类
@@ -53,6 +57,9 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
     @Resource
     private AdminUserMapper adminUserMapper;
 
+    @Resource
+    private NotifyMessageSendApi notifySendApi;
+
     //创建出库申请
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -84,6 +91,21 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
         LogRecordContext.putVariable("specimenOutbound", specimenOutbound);
         LogRecordContext.putVariable("validInfoIds", validInfoIds);
 
+        //发送站内信
+        String templateCode = "specimen_withdrawal_request_submitted";
+        Map<String, Object> templateParams = new HashMap<>();
+
+        // 定义格式化模板
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        // 转换 LocalDateTime 为字符串
+        String formattedDate = specimenOutbound.getCreateTime().format(formatter);
+        templateParams.put("createTime",formattedDate);
+        templateParams.put("operator",getLoginUserNickname());
+
+        notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                .setUserId(143L).setTemplateCode(templateCode).setTemplateParams(templateParams));
+
         // 返回出库记录ID
         return specimenOutbound.getId();
     }
@@ -124,7 +146,7 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
             specimenOutbound.setStatus(req.getStatus());
             specimenOutbound.setProcessInstanceId(req.getProcessInstanceId());
             specimenOutbound.setApprovalTime(req.getApprovalTime()); // 设置当前审批时间
-//            specimenOutbound.setApproveUsers(getLoginUserId()); // 设置一审操作员
+            specimenOutbound.setApproveUsers(getLoginUserId()); // 设置一审操作员
         }
 
         // 二审逻辑
@@ -143,6 +165,48 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
         LogRecordContext.putVariable("rejectionReasons", req.getRejectionReasons());
         LogRecordContext.putVariable("processInstanceId", req.getProcessInstanceId());
 
+        // 发送站内信
+        String templateCode = "";
+        Map<String, Object> templateParams = new HashMap<>();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        // 获取出库申请的提交时间
+        String formattedDate = specimenOutbound.getCreateTime().format(formatter);
+        templateParams.put("createTime", formattedDate);
+
+        // 根据审批状态选择不同的模板
+        if (req.getStatus() == 1 || req.getStatus() == 2) {
+            if (req.getStatus() == 1) {
+                templateCode = "specimen_withdrawal_request_one_approved";
+            } else if (req.getStatus() == 2) {
+                templateCode = "specimen_withdrawal_request_rejected";
+                templateParams.put("processInstanceId", req.getProcessInstanceId());
+            }
+        } else if (req.getStatus() == 5 || req.getStatus() == 6) {
+            if (req.getStatus() == 5) {
+                templateCode = "specimen_withdrawal_request_two_approved";
+            } else if (req.getStatus() == 6) {
+                templateCode = "specimen_withdrawal_two_request_rejected";
+                templateParams.put("rejectionReasons", req.getRejectionReasons());
+            }
+        }
+
+        // 发送通知
+        notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                .setUserId(Long.valueOf(specimenOutbound.getCreator()))
+                .setTemplateCode(templateCode)
+                .setTemplateParams(templateParams));
+
+        if (req.getStatus() == 1) {
+            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));
+        }
+
         // 更新数据库
         specimenOutboundMapper.updateById(specimenOutbound);
     }
@@ -165,6 +229,22 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
         // 校验存在
         validateSpecimenOutboundExists(updateReqVO.getId());
 
+        // 从数据库获取当前标本出库信息
+        SpecimenOutboundDO specimenOutbound = specimenOutboundMapper.selectById(updateReqVO.getId());
+        int currentStatus = specimenOutbound.getStatus();
+
+        // 校验状态
+        if (currentStatus == 0 || currentStatus == 2 || currentStatus == 6) {
+            // 根据当前状态更新
+            if (currentStatus == 2) {
+                updateReqVO.setStatus(0); // 编辑后将状态变为0
+            } else if (currentStatus == 6) {
+                updateReqVO.setStatus(1); // 编辑后将状态变为1
+            }
+        } else {
+            throw exception(INVALID_APPROVAL_STATUS);
+        }
+
         List<String> validInfoIds = new ArrayList<>();
 
         for (String number : updateReqVO.getNumber()) {
@@ -184,6 +264,30 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
         updateObj.setInfoId(validInfoIds.toString());
         specimenOutboundMapper.updateById(updateObj);
 
+        // 1. 准备参数
+        if(currentStatus == 2 || currentStatus == 6){
+            Long userId = null;
+            if(currentStatus == 2){
+                 userId = 143L;
+            }else{
+                 userId = 142L;
+            }
+            String templateCode = "";
+            Map<String, Object> templateParams = new HashMap<>();
+            String operatorNickname = adminUserMapper.selectNicknameByUserId(Long.valueOf(specimenOutbound.getCreator()));
+            templateParams.put("operator", operatorNickname);
+
+            // 获取出库申请的提交时间
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            String formattedDate = specimenOutbound.getCreateTime().format(formatter);
+            templateParams.put("createTime", formattedDate);
+
+            // 2. 发送站内信
+            notifySendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
+                    .setUserId(userId).setTemplateCode(templateCode).setTemplateParams(templateParams));
+        }
+
+
         // 记录日志上下文
         LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(specimenInfo, SpecimenOutboundSaveReqVO.class));
     }
@@ -239,13 +343,18 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
                 specimenInfoMapper.updateCollectionStatus(Long.valueOf(infoId.trim()), 1);  // 设为借出状态
             }
 
+//            System.out.println(existingSpecimen+"==================================================================");
+            // 记录日志上下文
+            String operatorNickname = adminUserMapper.selectNicknameByUserId(existingSpecimen.getOperator());
+            String twoOperatorNickname = adminUserMapper.selectNicknameByUserId(existingSpecimen.getTwoOperator());
+            LogRecordContext.putVariable("operatorNickname", operatorNickname);
+            LogRecordContext.putVariable("twoOperatorNickname", twoOperatorNickname);
             return "标本ID:" + existingSpecimen.getInfoId() + "出库确认成功";
         } else {
             // 如果只确认了一个操作员,更新出库单的信息但不修改状态
             specimenOutboundMapper.updateById(existingSpecimen);
             return "标本编号:" + existingSpecimen.getNumber() + "等待第二个操作员确认";
         }
-        //TODO 日志还没做
     }