|
|
@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
|
|
|
import com.hnac.hzims.common.utils.DateUtil; |
|
|
|
import com.hnac.hzims.common.utils.DateUtil; |
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
import com.hnac.hzims.message.dto.BusinessMessageDTO; |
|
|
|
import com.hnac.hzims.message.dto.BusinessMessageDTO; |
|
|
@ -38,10 +37,7 @@ import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.TransactionDefinition; |
|
|
|
|
|
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Instant; |
|
|
|
import java.time.Instant; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDate; |
|
|
@ -49,7 +45,6 @@ import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
import java.util.stream.Stream; |
|
|
@ -87,7 +82,7 @@ public class MaintenanceServiceImpl implements MaintenanceService { |
|
|
|
* @param ids |
|
|
|
* @param ids |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
|
|
public void createTask(List<String> ids) { |
|
|
|
public void createTask(List<String> ids) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
//获取日常维护计划
|
|
|
|
//获取日常维护计划
|
|
|
@ -95,21 +90,26 @@ public class MaintenanceServiceImpl implements MaintenanceService { |
|
|
|
planEntityLambdaQueryWrapper.in(BaseEntity::getId, ids); |
|
|
|
planEntityLambdaQueryWrapper.in(BaseEntity::getId, ids); |
|
|
|
List<OperMaintenancePlanEntity> planEntities = maintenancePlanService.list(planEntityLambdaQueryWrapper); |
|
|
|
List<OperMaintenancePlanEntity> planEntities = maintenancePlanService.list(planEntityLambdaQueryWrapper); |
|
|
|
//筛选当月没生成任务的计划
|
|
|
|
//筛选当月没生成任务的计划
|
|
|
|
List<OperMaintenancePlanEntity> finalPlanEntities = planEntities.stream().filter(planEntity -> ObjectUtil.isEmpty(planEntity.getCreateTaskTime()) || !DateUtil.judgeSameDay(DateUtil.DateToLocalDateTime(planEntity.getCreateTaskTime()), LocalDate.now())).collect(Collectors.toList()); |
|
|
|
List<OperMaintenancePlanEntity> finalPlanEntities = planEntities.stream(). |
|
|
|
|
|
|
|
filter(planEntity -> ObjectUtil.isEmpty(planEntity.getCreateTaskTime()) || |
|
|
|
|
|
|
|
!DateUtil.judgeSameDay(DateUtil.DateToLocalDateTime(planEntity.getCreateTaskTime()), LocalDate.now())) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
if (CollectionUtil.isEmpty(finalPlanEntities)) { |
|
|
|
if (CollectionUtil.isEmpty(finalPlanEntities)) { |
|
|
|
throw new ServiceException("所选计划当天已生成任务"); |
|
|
|
throw new ServiceException("所选计划当天已生成任务"); |
|
|
|
} |
|
|
|
} |
|
|
|
for (OperMaintenancePlanEntity finalPlanEntity : finalPlanEntities) { |
|
|
|
for (OperMaintenancePlanEntity finalPlanEntity : finalPlanEntities) { |
|
|
|
// 通过计划生成任务
|
|
|
|
// 通过计划生成任务
|
|
|
|
this.createTaskByPlan(finalPlanEntity); |
|
|
|
Boolean taskByPlan = this.createTaskByPlan(finalPlanEntity); |
|
|
|
//更新任务派发时间
|
|
|
|
if (taskByPlan) { |
|
|
|
LambdaUpdateWrapper<OperMaintenancePlanEntity> planEntityLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
//更新任务派发时间
|
|
|
|
planEntityLambdaUpdateWrapper.set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()); |
|
|
|
LambdaUpdateWrapper<OperMaintenancePlanEntity> planEntityLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
planEntityLambdaUpdateWrapper.eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); |
|
|
|
planEntityLambdaUpdateWrapper.set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()); |
|
|
|
boolean update = maintenancePlanService.update(planEntityLambdaUpdateWrapper); |
|
|
|
planEntityLambdaUpdateWrapper.eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); |
|
|
|
if (!update) { |
|
|
|
boolean update = maintenancePlanService.update(planEntityLambdaUpdateWrapper); |
|
|
|
log.error("maintenance:generateTask 更新任务派发失败"); |
|
|
|
if (!update) { |
|
|
|
throw new ServiceException("更新任务派发失败"); |
|
|
|
log.error("maintenance:generateTask 更新任务派发失败"); |
|
|
|
|
|
|
|
throw new ServiceException("更新任务派发失败"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -266,20 +266,40 @@ public class MaintenanceServiceImpl implements MaintenanceService { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param finalPlanEntity |
|
|
|
* @param finalPlanEntity |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void createTaskByPlan(OperMaintenancePlanEntity finalPlanEntity) { |
|
|
|
private Boolean createTaskByPlan(OperMaintenancePlanEntity finalPlanEntity) { |
|
|
|
OperMaintenanceTaskEntity taskEntity = BeanUtil.copy(finalPlanEntity, OperMaintenanceTaskEntity.class); |
|
|
|
OperMaintenanceTaskEntity taskEntity = BeanUtil.copy(finalPlanEntity, OperMaintenanceTaskEntity.class); |
|
|
|
//拆分设备 每个设备生成一条任务
|
|
|
|
//拆分设备 每个设备生成一条任务
|
|
|
|
|
|
|
|
List<Long> taskIds = new ArrayList<>(); |
|
|
|
if (StringUtil.isNotBlank(finalPlanEntity.getEmCode())) { |
|
|
|
if (StringUtil.isNotBlank(finalPlanEntity.getEmCode())) { |
|
|
|
log.info("finalPlanEntity.getEmCode() : {}", finalPlanEntity.getEmCode()); |
|
|
|
log.info("finalPlanEntity.getEmCode() : {}", finalPlanEntity.getEmCode()); |
|
|
|
String[] emCodeList = finalPlanEntity.getEmCode().split(","); |
|
|
|
String[] emCodeList = finalPlanEntity.getEmCode().split(","); |
|
|
|
for (String emCode : emCodeList) { |
|
|
|
for (String emCode : emCodeList) { |
|
|
|
taskEntity.setEmCode(emCode); |
|
|
|
try { |
|
|
|
this.fillTask(taskEntity, finalPlanEntity,false); |
|
|
|
taskEntity.setEmCode(emCode); |
|
|
|
|
|
|
|
Long task = this.fillTask(taskEntity, finalPlanEntity, false); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(task)) { |
|
|
|
|
|
|
|
taskIds.add(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("日常维护任务生成失败:" + "emCode:" + emCode + "错误原因:" + e); |
|
|
|
|
|
|
|
log.error("日常维护任务生成失败:" + "param:" + finalPlanEntity + "错误原因:" + e); |
|
|
|
|
|
|
|
taskService.deleteTaskBatch(taskIds); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.fillTask(taskEntity, finalPlanEntity,false); |
|
|
|
try { |
|
|
|
|
|
|
|
Long task = this.fillTask(taskEntity, finalPlanEntity, false); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(task)) { |
|
|
|
|
|
|
|
taskIds.add(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("日常维护任务生成失败:" + "param:" + finalPlanEntity + "错误原因:" + e); |
|
|
|
|
|
|
|
taskService.deleteTaskBatch(taskIds); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -290,7 +310,8 @@ public class MaintenanceServiceImpl implements MaintenanceService { |
|
|
|
* @param finalPlanEntity |
|
|
|
* @param finalPlanEntity |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity,Boolean flag) { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
|
|
public Long fillTask(OperMaintenanceTaskEntity taskEntity, OperMaintenancePlanEntity finalPlanEntity, Boolean flag) { |
|
|
|
// DefaultTransactionDefinition = new DefaultTransactionDefinition();
|
|
|
|
// DefaultTransactionDefinition = new DefaultTransactionDefinition();
|
|
|
|
// defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
|
|
|
// defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
|
|
|
// TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition);
|
|
|
|
// TransactionStatus transaction = dataSourceTransactionManager.getTransaction(defaultTransactionDefinition);
|
|
|
@ -320,29 +341,31 @@ public class MaintenanceServiceImpl implements MaintenanceService { |
|
|
|
taskEntity.setDisposer(userId.replaceAll("\\^", ",")); |
|
|
|
taskEntity.setDisposer(userId.replaceAll("\\^", ",")); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.info("计划ID为:{}未查询到排班记录", finalPlanEntity.getId()); |
|
|
|
log.info("计划ID为:{}未查询到排班记录", finalPlanEntity.getId()); |
|
|
|
LambdaUpdateWrapper<OperMaintenancePlanEntity> planQueryWrapper = Wrappers.<OperMaintenancePlanEntity>lambdaUpdate() |
|
|
|
// LambdaUpdateWrapper<OperMaintenancePlanEntity> planQueryWrapper = Wrappers.<OperMaintenancePlanEntity>lambdaUpdate()
|
|
|
|
.set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()) |
|
|
|
// .set(OperMaintenancePlanEntity::getCreateTaskTime, new Date())
|
|
|
|
.eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); |
|
|
|
// .eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId());
|
|
|
|
maintenancePlanService.update(planQueryWrapper); |
|
|
|
// maintenancePlanService.update(planQueryWrapper);
|
|
|
|
return; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
taskService.save(taskEntity); |
|
|
|
taskService.save(taskEntity); |
|
|
|
// dataSourceTransactionManager.commit(transaction);
|
|
|
|
// dataSourceTransactionManager.commit(transaction);
|
|
|
|
|
|
|
|
//等当前计划的所有任务生成后更新当前计划时间
|
|
|
|
|
|
|
|
// LambdaUpdateWrapper<OperMaintenancePlanEntity> planQueryWrapper = Wrappers.<OperMaintenancePlanEntity>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); |
|
|
|
|
|
|
|
}); |
|
|
|
//启动流程
|
|
|
|
//启动流程
|
|
|
|
String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), taskEntity,flag); |
|
|
|
String processInstanceId = this.startProcess(finalPlanEntity.getProcDefId(), taskEntity, flag); |
|
|
|
LambdaUpdateWrapper<OperMaintenanceTaskEntity> taskQueryWrapper = Wrappers.<OperMaintenanceTaskEntity>lambdaUpdate() |
|
|
|
LambdaUpdateWrapper<OperMaintenanceTaskEntity> taskQueryWrapper = Wrappers.<OperMaintenanceTaskEntity>lambdaUpdate() |
|
|
|
.set(OperMaintenanceTaskEntity::getProcessInstanceId, processInstanceId) |
|
|
|
.set(OperMaintenanceTaskEntity::getProcessInstanceId, processInstanceId) |
|
|
|
.eq(OperMaintenanceTaskEntity::getId, taskEntity.getId()); |
|
|
|
.eq(OperMaintenanceTaskEntity::getId, taskEntity.getId()); |
|
|
|
taskService.update(taskQueryWrapper); |
|
|
|
taskService.update(taskQueryWrapper); |
|
|
|
LambdaUpdateWrapper<OperMaintenancePlanEntity> planQueryWrapper = Wrappers.<OperMaintenancePlanEntity>lambdaUpdate() |
|
|
|
return taskEntity.getId(); |
|
|
|
.set(OperMaintenancePlanEntity::getCreateTaskTime, new Date()) |
|
|
|
|
|
|
|
.eq(OperMaintenancePlanEntity::getId, finalPlanEntity.getId()); |
|
|
|
|
|
|
|
maintenancePlanService.update(planQueryWrapper); |
|
|
|
|
|
|
|
executor.execute(() -> { |
|
|
|
|
|
|
|
OperMaintenanceTaskEntity maintenanceTask = taskService.getById(taskEntity.getId()); |
|
|
|
|
|
|
|
this.pushTaskMessage(maintenanceTask); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|