From b5e1bceabb36fe1d1e5e88397280d12e7044c6dd Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期五, 06 十一月 2026 15:32:31 +0800
Subject: [PATCH] 完善设备采集、安全管理及采购业务

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyHazardService.java |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyHazardService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyHazardService.java
index 255d851..e52c09e 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyHazardService.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/safety/SafetyHazardService.java
@@ -19,6 +19,10 @@
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.Map;
+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.service.user.AdminUserService;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.mes.enums.SafetyErrorCodeConstants.*;
@@ -41,6 +45,10 @@
     private SafetyHazardMapper hazardMapper;
     @Resource
     private SafetyRefResolver refResolver;
+    @Resource
+    private NotifyMessageSendApi notifyMessageSendApi;
+    @Resource
+    private AdminUserService adminUserService;
 
     /**
      * 闅愭偅涓婃姤锛堝惈绉诲姩绔媿鐓т笂浼犵殑 photoUrls锛�
@@ -83,7 +91,8 @@
      */
     @Transactional(rollbackFor = Exception.class)
     public void assignHazard(SafetyHazardAssignReqVO reqVO) {
-        SafetyHazardDO hazard = validateHazardExists(reqVO.getId());
+        SafetyHazardDO hazard = hazardMapper.selectByIdForUpdate(reqVO.getId());
+        if (hazard == null) throw exception(SAFETY_HAZARD_NOT_EXISTS);
         if (!SafetyHazardStatusEnum.REPORTED.getStatus().equals(hazard.getStatus())
                 && !SafetyHazardStatusEnum.REJECTED.getStatus().equals(hazard.getStatus())) {
             throw exception(SAFETY_HAZARD_STATUS_ERROR);
@@ -92,6 +101,8 @@
             throw exception(SAFETY_HAZARD_ASSIGNEE_REQUIRED);
         }
         var assignee = refResolver.requireEmployee(reqVO.getAssigneeId(), SAFETY_HAZARD_ASSIGNEE_REQUIRED);
+        if (assignee.getUserId() == null) throw exception(SAFETY_HAZARD_ASSIGNEE_NO_ACCOUNT);
+        adminUserService.validateUserList(List.of(assignee.getUserId()));
         SafetyHazardDO update = new SafetyHazardDO();
         update.setId(hazard.getId());
         update.setAssigneeId(assignee.getId());
@@ -103,6 +114,14 @@
             update.setRemark(reqVO.getRemark().trim());
         }
         hazardMapper.updateById(update);
+        NotifySendSingleToUserReqDTO notice = new NotifySendSingleToUserReqDTO();
+        notice.setUserId(assignee.getUserId());
+        notice.setTemplateCode("safety_hazard_assigned");
+        notice.setTemplateParams(Map.of("code", hazard.getCode(), "title", hazard.getTitle(),
+                "deadline", reqVO.getRectifyDeadline() == null ? "鏈缃�" : reqVO.getRectifyDeadline().toString()));
+        if (notifyMessageSendApi.sendSingleMessageToAdmin(notice) == null) {
+            throw exception(SAFETY_HAZARD_NOTICE_UNAVAILABLE);
+        }
     }
 
     /**

--
Gitblit v1.9.3