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 411f20c..a85c2f0 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 @@ -11,6 +11,7 @@ import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; 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.service.MaintenanceService; 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; @@ -27,8 +28,12 @@ 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; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.DefaultTransactionDefinition; import java.time.Instant; import java.time.LocalDateTime; @@ -58,6 +63,11 @@ public class MaintenanceTaskCreateTask { private final BladeLogger logger; + private final DataSourceTransactionManager dataSourceTransactionManager; + + + private final MaintenanceService maintenanceService; + private final List templateService; @Value("${hzims.operation.task.templateCode.maintenance.taskDispose}") @@ -107,11 +117,11 @@ public class MaintenanceTaskCreateTask { List emCodeList = Arrays.asList(planEntity.getEmCode().split(",")); for(String emCode : emCodeList){ taskEntity.setEmCode(emCode); - this.fillTask(taskEntity,planEntity); + maintenanceService.fillTask(taskEntity,planEntity); } } else { - this.fillTask(taskEntity,planEntity); + maintenanceService.fillTask(taskEntity,planEntity); } } @@ -121,6 +131,9 @@ public class MaintenanceTaskCreateTask { * @param planEntity */ private void fillTask(OperMaintenanceTaskEntity taskEntity,OperMaintenancePlanEntity planEntity) { + DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); + defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition); taskEntity.setId(null); taskEntity.setCreateTime(DateUtil.now()); taskEntity.setUpdateTime(DateUtil.now()); @@ -152,6 +165,7 @@ public class MaintenanceTaskCreateTask { } // BeanUtil.copyProperties(planEntity, taskEntity); taskService.save(taskEntity); + dataSourceTransactionManager.commit(transaction); //生成工作流实例 String processInstanceId = this.startProcessInstance(planEntity.getProcDefId(), taskEntity); if(Func.isNotEmpty(processInstanceId)) { @@ -186,7 +200,7 @@ public class MaintenanceTaskCreateTask { put("initUserIds", taskUsers); put("operMaintenanceTaskEntityVo",vo); }}; - R flowResult = flowClient.startProcessInstanceContainNameByKey(processDefinitionKey, "maintenance:task:" + taskEntity.getId(), taskEntity.getTitle(), params); + R flowResult = flowClient.startProcessInstanceContainNameByKey(processDefinitionKey, String.valueOf(taskEntity.getId()), taskEntity.getTitle(), params); return Optional.ofNullable(flowResult).filter(r -> r.isSuccess()).map(R::getData).map(BladeFlow::getProcessInstanceId).orElse(null); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/MaintenanceService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/MaintenanceService.java index 164901e..c370508 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/MaintenanceService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/MaintenanceService.java @@ -1,8 +1,9 @@ package com.hnac.hzims.operational.maintenance.service; - import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; +import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; +import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import java.util.List; @@ -16,6 +17,7 @@ public interface MaintenanceService { /** * 日常维护生成任务 + * * @param ids */ @@ -24,7 +26,17 @@ public interface MaintenanceService { /** * 日常维护待处理 + * * @param response */ void findPending(ProcessWorkFlowResponse response); + + + /** + * 通过计划生成任务 + * + * @param taskEntity + * @param finalPlanEntity + */ + void fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java index 2031df8..8983c96 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java @@ -291,7 +291,7 @@ public class MaintenanceServiceImpl implements MaintenanceService { * @param taskEntity * @param finalPlanEntity */ - private void fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity) { + public void fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity) { DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition);