From f6d3a26ec2ce6a36b53d85fc48a6d407e70f9174 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 16 Oct 2023 14:15:02 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E8=A7=A3=E5=86=B3=E6=97=A5=E5=B8=B8?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E4=BB=BB=E5=8A=A1=E7=94=9F=E6=88=90=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/MaintenanceTaskCreateTask.java | 22 ++++++------ .../service/impl/MaintenanceServiceImpl.java | 40 ++++++++++------------ 2 files changed, 28 insertions(+), 34 deletions(-) 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 7e1ff0c..32e1ffa 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 @@ -114,20 +114,18 @@ public class MaintenanceTaskCreateTask { * @return */ public void generateTaskByPlan(OperMaintenancePlanEntity planEntity,Boolean flag) { - threadPoolExecutor.execute(() -> { - OperMaintenanceTaskEntity taskEntity = BeanUtil.copy(planEntity,OperMaintenanceTaskEntity.class); - //拆分设备 每个设备生成一条任务 - if(StringUtil.isNotBlank(planEntity.getEmCode())){ - List emCodeList = Arrays.asList(planEntity.getEmCode().split(",")); - for(String emCode : emCodeList){ - taskEntity.setEmCode(emCode); - maintenanceService.fillTask(taskEntity,planEntity,flag); - } - } - else { + OperMaintenanceTaskEntity taskEntity = BeanUtil.copy(planEntity,OperMaintenanceTaskEntity.class); + //拆分设备 每个设备生成一条任务 + if(StringUtil.isNotBlank(planEntity.getEmCode())){ + List emCodeList = Arrays.asList(planEntity.getEmCode().split(",")); + for(String emCode : emCodeList){ + taskEntity.setEmCode(emCode); maintenanceService.fillTask(taskEntity,planEntity,flag); } - }); + } + else { + maintenanceService.fillTask(taskEntity,planEntity,flag); + } } /** 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 445c4e7..77dd011 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 @@ -6,6 +6,7 @@ import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.message.MessageConstants; @@ -288,10 +289,11 @@ public class MaintenanceServiceImpl implements MaintenanceService { * @param taskEntity * @param finalPlanEntity */ + @Override public void fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity,Boolean flag) { - DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); - defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition); +// DefaultTransactionDefinition = new DefaultTransactionDefinition(); +// defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); +// TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition); taskEntity.setId(null); taskEntity.setCreateTime(new Date()); taskEntity.setUpdateTime(new Date()); @@ -322,27 +324,21 @@ public class MaintenanceServiceImpl implements MaintenanceService { } } taskService.save(taskEntity); - dataSourceTransactionManager.commit(transaction); +// dataSourceTransactionManager.commit(transaction); //启动流程 String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), taskEntity,flag); - //推送消息 - CompletableFuture operMaintenanceTaskEntityCompletableFuture = - CompletableFuture.runAsync(() -> { - taskEntity.setProcessInstanceId(processInstanceId); - taskService.updateById(taskEntity); - finalPlanEntity.setCreateTaskTime(new Date()); - maintenancePlanService.updateById(finalPlanEntity); - OperMaintenanceTaskEntity maintenanceTask = taskService.getById(taskEntity.getId()); - //推送消息 - this.pushTaskMessage(maintenanceTask); - }, executor); - //启动队列 - try { - CompletableFuture.allOf(operMaintenanceTaskEntityCompletableFuture).get(); - } catch (Exception e) { - e.printStackTrace(); - } - + LambdaUpdateWrapper taskQueryWrapper = Wrappers.lambdaUpdate() + .set(OperMaintenanceTaskEntity::getProcessInstanceId, processInstanceId) + .eq(OperMaintenanceTaskEntity::getId, taskEntity.getId()); + taskService.update(taskQueryWrapper); + LambdaUpdateWrapper planQueryWrapper = Wrappers.lambdaUpdate() + .set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()) + .eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); + maintenancePlanService.update(planQueryWrapper); + executor.execute(() -> { + OperMaintenanceTaskEntity maintenanceTask = taskService.getById(taskEntity.getId()); + this.pushTaskMessage(maintenanceTask); + }); }