xiaoyi
3 天以前 b5e1bceabb36fe1d1e5e88397280d12e7044c6dd
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);
        }
    }
    /**