|
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.pms.service.failure;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
|
|
|
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
|
@@ -15,8 +17,6 @@ import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.failure.IotFailureReportMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.maintain.IotMaintainMapper;
|
|
|
import cn.iocoder.yudao.module.pms.enums.common.FailureAuditStatusEnum;
|
|
|
-import cn.iocoder.yudao.module.supplier.dal.dataobject.product.SupplierDO;
|
|
|
-import cn.iocoder.yudao.module.supplier.enums.common.SupplierAuditStatusEnum;
|
|
|
import cn.iocoder.yudao.module.system.api.dingtalk.DingtalkSendApi;
|
|
|
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
|
|
|
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
|
@@ -24,23 +24,16 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
-import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
-import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import javax.annotation.Resource;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-
|
|
|
-
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_FAILURE_REPORT_NOT_EXISTS;
|
|
|
|
|
@@ -83,7 +76,7 @@ public class IotFailureReportServiceImpl implements IotFailureReportService {
|
|
|
BeanUtils.copyProperties(failureReportDO, iotMaintainDO);
|
|
|
iotMaintainDO.setStatus("tx");
|
|
|
iotMaintainDO.setAuditStatus(0);
|
|
|
- iotMaintainDO.setMaintainPerson(failureReportDO.getAssigneeUserId());
|
|
|
+ iotMaintainDO.setMaintainPerson(Objects.isNull(failureReportDO.getAssigneeUserId())? Long.valueOf(failureReportDO.getCreator()) :failureReportDO.getAssigneeUserId());
|
|
|
iotMaintainDO.setFailureId(failureReportDO.getId());
|
|
|
iotMaintainMapper.insert(iotMaintainDO);
|
|
|
}
|
|
@@ -91,8 +84,8 @@ public class IotFailureReportServiceImpl implements IotFailureReportService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long submitForApproval(Long id) {
|
|
|
- IotFailureReportDO iotFailureReportDO = iotFailureReportMapper.selectById(id);
|
|
|
- if (Objects.isNull(iotFailureReportDO)) {throw new ServiceException(IOT_FAILURE_REPORT_NOT_EXISTS);}
|
|
|
+// IotFailureReportDO iotFailureReportDO = iotFailureReportMapper.selectById(id);
|
|
|
+// if (Objects.isNull(iotFailureReportDO)) {throw new ServiceException(IOT_FAILURE_REPORT_NOT_EXISTS);}
|
|
|
// 发起BPM流程
|
|
|
// 获取当前登录人信息
|
|
|
String processInstanceId = processInstanceApi.createProcessInstance(SecurityFrameworkUtils.getLoginUserId(),
|
|
@@ -117,34 +110,50 @@ public class IotFailureReportServiceImpl implements IotFailureReportService {
|
|
|
iotFailureReport.setDeleted(false);
|
|
|
if (iotFailureReport.getIfDeal()) {
|
|
|
iotFailureReport.setStatus("finished");
|
|
|
- //todo 发送站内信及钉钉
|
|
|
- Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
- DeptDO dept = deptService.getDept(loginUserDeptId);
|
|
|
- List<AdminUserRespDTO> users = adminUserApi.getUserListByDept(dept.getParentId());
|
|
|
- String templateCode = "failure-report"; // 站内信模版,记得在【站内信管理】中配置噢
|
|
|
- Map<String, Object> templateParams = new HashMap<>();
|
|
|
- templateParams.put("name", iotFailureReport.getDeviceName());
|
|
|
- CompletableFuture.runAsync(() -> users.forEach(e ->{
|
|
|
- notifyMessageSendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
|
|
- .setUserId(e.getId()).setTemplateCode(templateCode).setTemplateParams(templateParams));
|
|
|
- String msg = "【PMS】故障上报 - "+iotFailureReport.getFailureName()+"故障已解决。"+"["+new Date()+"]";
|
|
|
- dingtalkSendApi.send(e.getMobile(), msg);
|
|
|
- }));
|
|
|
+ iotFailureReportMapper.insert(iotFailureReport);
|
|
|
+ sendMessage(iotFailureReport);
|
|
|
} else {
|
|
|
iotFailureReport.setStatus("reporting");
|
|
|
- iotFailureReport.setAuditStatus(FailureAuditStatusEnum.DRAFT.getStatus());
|
|
|
+ iotFailureReport.setAuditStatus(FailureAuditStatusEnum.PROCESS.getStatus());
|
|
|
+ iotFailureReportMapper.insert(iotFailureReport);
|
|
|
+ //直接发起流程
|
|
|
+ submitForApproval(iotFailureReport.getId());
|
|
|
+ sendMessage(iotFailureReport);
|
|
|
}
|
|
|
- iotFailureReportMapper.insert(iotFailureReport);
|
|
|
// 返回
|
|
|
return iotFailureReport.getId();
|
|
|
}
|
|
|
|
|
|
+ private void sendMessage(IotFailureReportDO iotFailureReport) {
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
+ DeptDO dept = deptService.getDept(loginUserDeptId);
|
|
|
+ DeptDO parentDept = deptService.getDept(dept.getParentId());
|
|
|
+ String templateCode = "failure-report"; // 站内信模版,记得在【站内信管理】中配置噢
|
|
|
+ Map<String, Object> templateParams = new HashMap<>();
|
|
|
+ templateParams.put("name", iotFailureReport.getDeviceName());
|
|
|
+ CompletableFuture.runAsync(() ->{
|
|
|
+ if (Objects.nonNull(parentDept.getLeaderUserId())){
|
|
|
+// parentDept.getLeaderUserId().forEach(e ->{
|
|
|
+ notifyMessageSendApi.sendSingleMessageToAdmin(new NotifySendSingleToUserReqDTO()
|
|
|
+ .setUserId(parentDept.getLeaderUserId()).setTemplateCode(templateCode).setTemplateParams(templateParams));
|
|
|
+ String msg = "【PMS】故障上报 - "+iotFailureReport.getFailureName()+"故障已解决。"+"["+new Date()+"]";
|
|
|
+ AdminUserRespDTO user = adminUserApi.getUser(parentDept.getParentId());
|
|
|
+ if (Objects.nonNull(user)) {
|
|
|
+ dingtalkSendApi.send(user.getMobile(), msg);
|
|
|
+ }
|
|
|
+// })
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Long updateIotFailureReportProcess(IotFailureReportProcessVO processVO) {
|
|
|
IotFailureReportDO reportDO = iotFailureReportMapper.selectById(processVO.getId());
|
|
|
reportDO.setAssigneeUserId(processVO.getAssigneeUserId());
|
|
|
reportDO.setType(processVO.getType());
|
|
|
iotFailureReportMapper.insertOrUpdate(reportDO);
|
|
|
+ sendMessage(reportDO);
|
|
|
return reportDO.getId();
|
|
|
}
|
|
|
|