From f7c7784166eb90646a014ebc32d15948c2d68c83 Mon Sep 17 00:00:00 2001 From: zhc077 <565291854> Date: Sun, 14 May 2023 16:30:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=AE=A1=E5=88=92=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96-=E5=B7=A5=E5=BA=8F=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E4=BF=AE=E6=94=B9=205.14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/IZyProductPlanAutoServiceImpl.java | 124 +++++++++++------- 1 file changed, 74 insertions(+), 50 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/productplan/service/impl/IZyProductPlanAutoServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/productplan/service/impl/IZyProductPlanAutoServiceImpl.java index 76ac8dd6..396caa23 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/productplan/service/impl/IZyProductPlanAutoServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/productplan/service/impl/IZyProductPlanAutoServiceImpl.java @@ -2,6 +2,7 @@ package org.jeecg.modules.productplan.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.demo.pro.entity.ZyProcessMachine; @@ -34,12 +35,12 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Service +@Slf4j public class IZyProductPlanAutoServiceImpl extends ServiceImpl implements IZyProductPlanAutoService { @Autowired @@ -374,54 +375,72 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl updateList = new LinkedList<>(); if (ObjectUtils.isEmpty(stationList) || ObjectUtils.isEmpty(planProcessList)) return false; - AtomicBoolean b = new AtomicBoolean(true); - flag: - if (b.get()) { - planProcessList: - for (int i = 0; i < planProcessList.size(); i++) { - ZyPlanProcess obj = planProcessList.get(i); - List machineList = iZyProcessMachineService.list(new LambdaQueryWrapper().eq(ZyProcessMachine::getProcessId, obj.getProcessId())); - List toolList = iZyOperationtoolService.list(new LambdaQueryWrapper().eq(ZyOperationtool::getOperationid, obj.getProcessId())); - List zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList()); - List zyProcessCodes = machineList.stream().map(ZyProcessMachine::getCode).collect(Collectors.toList()); - List zyProcessToolIds = toolList.stream().map(ZyOperationtool::getOperationid).collect(Collectors.toList()); - - ZyPlanProcess diffMachine = this.diffMachine(obj, zyProcessMachineIds, zyProcessCodes, stationList); - //设备匹配失败,直接结束 - if (ObjectUtils.isEmpty(diffMachine)) { - b.set(false); - break flag; - } else { // 设备匹配,则匹配工具 - ZyPlanProcess diffTool = this.diffTool(diffMachine, zyProcessToolIds, stationList); - if (ObjectUtils.isEmpty(diffTool)) { - b.set(false); - break flag; - } else { // 匹配工人 - updateList.add(diffTool); - //匹配下一个工序的设备和工具 - continue planProcessList; - } + for (int i = 0; i < planProcessList.size(); i++) { + ZyPlanProcess obj = planProcessList.get(i); + List machineList = iZyProcessMachineService.list(new LambdaQueryWrapper().eq(ZyProcessMachine::getProcessId, obj.getProcessId())); + List toolList = iZyOperationtoolService.list(new LambdaQueryWrapper().eq(ZyOperationtool::getOperationid, obj.getProcessId())); + List zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList()); + List zyProcessCodes = machineList.stream().map(ZyProcessMachine::getCode).collect(Collectors.toList()); + + ZyPlanProcess diffMachine = this.diffMachine(obj, zyProcessMachineIds, zyProcessCodes, stationList); + + if (ObjectUtils.isEmpty(diffMachine)) { + //设备匹配失败,删除该生产计划相半数据,直接结束 + this.doException(planId, obj, "工序设备匹配"); + return false; + } /*else { // 设备匹配成功,则匹配工具 //TODO 暂时注释掉 工序工具匹配 + ZyPlanProcess diffTool = this.diffTool(diffMachine, toolList, stationList); + if (ObjectUtils.isEmpty(diffTool)) { + //设备匹配失败,删除该生产计划相半数据,直接结束 + this.doException(planId, obj, "工序工具匹配"); + return false; + } else { // 匹配工人 + updateList.add(diffTool); + //匹配下一个工序的设备和工具 + continue; } - } - zyPlanProcessService.saveOrUpdateBatch(updateList); - return true; - } else { - ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId); - // 1,作工单异常处理, - iWorkOrderService.lambdaUpdate() - .set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.EXCEPTION.getCode()) - .eq(WorkOrder::getProductCode, zyProductPlan.getProductCode()).update(); + }*/ + + updateList.add(diffMachine); + } + + zyPlanProcessService.saveOrUpdateBatch(updateList); + return true; + } + + /** + * 只要有生产计划工序(设备、工具)匹配不上就算匹配失败,删除相关生产计划数据,标记该工单异常,然后匹配下一个工单 + * + * @param planId + */ + @Transactional(rollbackFor = Exception.class, readOnly = false) + public void doException(String planId, ZyPlanProcess zyPlanProcess, String mess) { + ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId); + if (ObjectUtils.isEmpty(zyProductPlan)) { + throw new JeecgBootException(zyProductPlan.getId() + "生产计划不存在"); + } + // 1,作工单异常处理, + iWorkOrderService.lambdaUpdate() + .set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.EXCEPTION.getCode()) + .eq(WorkOrder::getProductCode, zyProductPlan.getProductCode()).update(); + log.info(">>>>>>>>>>工单:{},工序:{}-{}失败,自动化生成生产计划异常!", zyProductPlan.getProductCode(), zyPlanProcess.getProcessId(), mess); + List planProcessList = this.zyPlanProcessService.list(new LambdaQueryWrapper().eq(ZyPlanProcess::getPlanId, planId)); + if (!ObjectUtils.isEmpty(planProcessList)) { + List collect = Optional.ofNullable(planProcessList).orElse(new ArrayList<>()).stream().map(ZyPlanProcess::getId).collect(Collectors.toList()); // 2,删除生产计划工序面料 - iZyPlanProcessFabricService.remove(new LambdaQueryWrapper().in(ZyPlanProcessFabric::getPlanId, planId)); + iZyPlanProcessFabricService.remove(new LambdaQueryWrapper().in(ZyPlanProcessFabric::getPlanProcessId, collect)); // 3,删除生产计划工序辅料 - iZyPlanProcessAccessoriesService.remove(new LambdaQueryWrapper().in(ZyPlanProcessAccessories::getPlanId, planId)); + iZyPlanProcessAccessoriesService.remove(new LambdaQueryWrapper().in(ZyPlanProcessAccessories::getPlanProcessId, collect)); // 4,删除生产计划工序 zyPlanProcessService.remove(new LambdaQueryWrapper().in(ZyPlanProcess::getPlanId, planId)); - // 5,删除生产计划 - iZyProductPlanService.remove(new LambdaQueryWrapper().in(ZyProductPlan::getId, planId)); - return false; } - return false; + + // 5,删除生产计划 + iZyProductPlanService.remove(new LambdaQueryWrapper().in(ZyProductPlan::getId, planId)); + //方便查看数据 ,暂时做状态处理 +// iZyProductPlanService.lambdaUpdate() +// .set(ZyProductPlan::getStatus, ProductPlanStatusEnum.EXCEPTION.getCode()) +// .eq(ZyProductPlan::getId, planId).update(); } @Transactional(rollbackFor = Exception.class, readOnly = false) @@ -490,17 +509,22 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl zyProcessToolIds, List stationList) { + ZyPlanProcess diffTool(ZyPlanProcess zyPlanProcess, List zyOperationtools, List stationList) { for (int j = 0; j < stationList.size(); j++) { Station station = stationList.get(j); - List stationToolList = iStationToolService.list(new LambdaQueryWrapper().eq(StationTool::getToolsId, station.getId())); + List stationToolList = iStationToolService.list(new LambdaQueryWrapper().eq(StationTool::getStationId, station.getId())); List stationToolIds = Optional.ofNullable(stationToolList).orElse(new ArrayList<>()).stream() .map(StationTool::getToolsId).collect(Collectors.toList()); -// 工具匹配成功 - if (stationToolIds.containsAll(zyProcessToolIds)) { - String toolIds = zyProcessToolIds.stream().collect(Collectors.joining(",")); - zyPlanProcess.setToolsIds(toolIds); - return zyPlanProcess; + if (!ObjectUtils.isEmpty(stationToolList)) { + List zyProcessToolIds = zyOperationtools.stream().map(ZyOperationtool::getToolid).collect(Collectors.toList()); + List zyProcessToolNames = zyOperationtools.stream().map(ZyOperationtool::getCodeName).collect(Collectors.toList()); + // 工具匹配成功 + if (stationToolIds.containsAll(zyProcessToolIds)) { + String toolIds = zyProcessToolIds.stream().collect(Collectors.joining(",")); + zyPlanProcess.setToolsIds(toolIds); + zyPlanProcess.setToolsNames(zyProcessToolNames.stream().collect(Collectors.joining(","))); + return zyPlanProcess; + } } } return null;