| | |
| | | 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.*; |
| | |
| | | private SafetyHazardMapper hazardMapper; |
| | | @Resource |
| | | private SafetyRefResolver refResolver; |
| | | @Resource |
| | | private NotifyMessageSendApi notifyMessageSendApi; |
| | | @Resource |
| | | private AdminUserService adminUserService; |
| | | |
| | | /** |
| | | * 隐患上报(含移动端拍照上传的 photoUrls) |
| | |
| | | */ |
| | | @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); |
| | |
| | | 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()); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | /** |