diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java index de904ef..1e55809 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java @@ -12,6 +12,8 @@ import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.mapper.OperMaintenancePlanMapper; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; import com.hnac.hzims.operational.maintenance.template.service.TemplateService; +import com.hnac.hzims.operational.maintenance.vo.OperMaintenanceTaskEntityVo; +import com.hnac.hzims.operational.maintenance.vo.OperMaintenanceTaskVO; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; @@ -21,6 +23,7 @@ import org.apache.commons.lang.StringUtils; import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; +import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; @@ -106,9 +109,6 @@ public class MaintenanceTaskCreateTask { taskEntity.setEmCode(emCode); this.fillTask(taskEntity,planEntity); } -// emCodeList.forEach(emCode -> { -// -// }); } else { this.fillTask(taskEntity,planEntity); @@ -154,14 +154,19 @@ public class MaintenanceTaskCreateTask { taskService.save(taskEntity); //生成工作流实例 String processInstanceId = this.startProcessInstance(planEntity.getProcDefId(), taskEntity); - taskEntity.setProcessInstanceId(processInstanceId); - taskService.updateById(taskEntity); + if(Func.isNotEmpty(processInstanceId)) { + taskEntity.setProcessInstanceId(processInstanceId); + taskService.updateById(taskEntity); + this.pushTaskMessage(taskEntity); + } + else { + if(ObjectUtil.isNotEmpty(taskService.getById(taskEntity.getId()))) { + taskService.removeById(taskEntity.getId()); + } + } planEntity.setCreateTaskTime(DateUtil.now()); planMapper.updateById(planEntity); - taskEntity = taskService.getById(taskEntity.getId()); - //taskEntity.setMessageTemplateId(1646694238095732738L); - this.pushTaskMessage(taskEntity); } /** @@ -170,19 +175,20 @@ public class MaintenanceTaskCreateTask { * @author xiashandong **/ private String startProcessInstance(String processDefinitionKey, OperMaintenanceTaskEntity taskEntity) { + if(Func.isEmpty(taskEntity.getDisposer())) { + return null; + } + OperMaintenanceTaskEntityVo vo = BeanUtil.copy(taskEntity,OperMaintenanceTaskEntityVo.class); Map params = new HashMap() {{ put("taskId", taskEntity.getId()); String userId = taskEntity.getDisposer(); List userIdList = Stream.of(userId.split(",")).collect(Collectors.toList()); - String taskUsers = userIdList.stream().filter(o -> StringUtils.isNotBlank(o)).map(s -> { - return "taskUser_".concat(s); - }).collect(Collectors.joining(",")); + String taskUsers = userIdList.stream().filter(o -> StringUtils.isNotBlank(o)).map(s -> "taskUser_".concat(s)).collect(Collectors.joining(",")); put("initUserIds", taskUsers); + put("operMaintenanceTaskEntityVo",vo); }}; - - return flowClient.startProcessInstanceContainNameByKey(processDefinitionKey,"maintenance:task:" + taskEntity.getId(),taskEntity.getTitle(), params) - .getData() - .getProcessInstanceId(); + R flowResult = flowClient.startProcessInstanceContainNameByKey(processDefinitionKey, "maintenance:task:" + taskEntity.getId(), taskEntity.getTitle(), params); + return Optional.ofNullable(flowResult).filter(r -> r.isSuccess()).map(R::getData).map(BladeFlow::getProcessInstanceId).orElse(null); } /** @Author hx