生产计划自动化-工序工具匹配修改 5.14

master
zhc077 2 years ago
parent 5561512756
commit f7c7784166
  1. 70
      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.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.demo.pro.entity.ZyProcessMachine; import org.jeecg.modules.demo.pro.entity.ZyProcessMachine;
@ -34,12 +35,12 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j
public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapper, ZyProductPlan> implements IZyProductPlanAutoService { public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapper, ZyProductPlan> implements IZyProductPlanAutoService {
@Autowired @Autowired
@ -374,54 +375,72 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp
List<ZyPlanProcess> updateList = new LinkedList<>(); List<ZyPlanProcess> updateList = new LinkedList<>();
if (ObjectUtils.isEmpty(stationList) || ObjectUtils.isEmpty(planProcessList)) return false; 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++) { for (int i = 0; i < planProcessList.size(); i++) {
ZyPlanProcess obj = planProcessList.get(i); ZyPlanProcess obj = planProcessList.get(i);
List<ZyProcessMachine> machineList = iZyProcessMachineService.list(new LambdaQueryWrapper<ZyProcessMachine>().eq(ZyProcessMachine::getProcessId, obj.getProcessId())); List<ZyProcessMachine> machineList = iZyProcessMachineService.list(new LambdaQueryWrapper<ZyProcessMachine>().eq(ZyProcessMachine::getProcessId, obj.getProcessId()));
List<ZyOperationtool> toolList = iZyOperationtoolService.list(new LambdaQueryWrapper<ZyOperationtool>().eq(ZyOperationtool::getOperationid, obj.getProcessId())); List<ZyOperationtool> toolList = iZyOperationtoolService.list(new LambdaQueryWrapper<ZyOperationtool>().eq(ZyOperationtool::getOperationid, obj.getProcessId()));
List<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList()); List<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList());
List<String> zyProcessCodes = machineList.stream().map(ZyProcessMachine::getCode).collect(Collectors.toList()); List<String> zyProcessCodes = machineList.stream().map(ZyProcessMachine::getCode).collect(Collectors.toList());
List<String> zyProcessToolIds = toolList.stream().map(ZyOperationtool::getOperationid).collect(Collectors.toList());
ZyPlanProcess diffMachine = this.diffMachine(obj, zyProcessMachineIds, zyProcessCodes, stationList); ZyPlanProcess diffMachine = this.diffMachine(obj, zyProcessMachineIds, zyProcessCodes, stationList);
//设备匹配失败,直接结束
if (ObjectUtils.isEmpty(diffMachine)) { if (ObjectUtils.isEmpty(diffMachine)) {
b.set(false); //设备匹配失败,删除该生产计划相半数据,直接结束
break flag; this.doException(planId, obj, "工序设备匹配");
} else { // 设备匹配,则匹配工具 return false;
ZyPlanProcess diffTool = this.diffTool(diffMachine, zyProcessToolIds, stationList); } /*else { // 设备匹配成功,则匹配工具 //TODO 暂时注释掉 工序工具匹配
ZyPlanProcess diffTool = this.diffTool(diffMachine, toolList, stationList);
if (ObjectUtils.isEmpty(diffTool)) { if (ObjectUtils.isEmpty(diffTool)) {
b.set(false); //设备匹配失败,删除该生产计划相半数据,直接结束
break flag; this.doException(planId, obj, "工序工具匹配");
return false;
} else { // 匹配工人 } else { // 匹配工人
updateList.add(diffTool); updateList.add(diffTool);
//匹配下一个工序的设备和工具 //匹配下一个工序的设备和工具
continue planProcessList; continue;
}
} }
}*/
updateList.add(diffMachine);
} }
zyPlanProcessService.saveOrUpdateBatch(updateList); zyPlanProcessService.saveOrUpdateBatch(updateList);
return true; return true;
} else { }
/**
* 只要有生产计划工序(设备工具)匹配不上就算匹配失败删除相关生产计划数据标记该工单异常然后匹配下一个工单
*
* @param planId
*/
@Transactional(rollbackFor = Exception.class, readOnly = false)
public void doException(String planId, ZyPlanProcess zyPlanProcess, String mess) {
ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId); ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId);
if (ObjectUtils.isEmpty(zyProductPlan)) {
throw new JeecgBootException(zyProductPlan.getId() + "生产计划不存在");
}
// 1,作工单异常处理, // 1,作工单异常处理,
iWorkOrderService.lambdaUpdate() iWorkOrderService.lambdaUpdate()
.set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.EXCEPTION.getCode()) .set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.EXCEPTION.getCode())
.eq(WorkOrder::getProductCode, zyProductPlan.getProductCode()).update(); .eq(WorkOrder::getProductCode, zyProductPlan.getProductCode()).update();
log.info(">>>>>>>>>>工单:{},工序:{}-{}失败,自动化生成生产计划异常!", zyProductPlan.getProductCode(), zyPlanProcess.getProcessId(), mess);
List<ZyPlanProcess> planProcessList = this.zyPlanProcessService.list(new LambdaQueryWrapper<ZyPlanProcess>().eq(ZyPlanProcess::getPlanId, planId));
if (!ObjectUtils.isEmpty(planProcessList)) {
List<String> collect = Optional.ofNullable(planProcessList).orElse(new ArrayList<>()).stream().map(ZyPlanProcess::getId).collect(Collectors.toList());
// 2,删除生产计划工序面料 // 2,删除生产计划工序面料
iZyPlanProcessFabricService.remove(new LambdaQueryWrapper<ZyPlanProcessFabric>().in(ZyPlanProcessFabric::getPlanId, planId)); iZyPlanProcessFabricService.remove(new LambdaQueryWrapper<ZyPlanProcessFabric>().in(ZyPlanProcessFabric::getPlanProcessId, collect));
// 3,删除生产计划工序辅料 // 3,删除生产计划工序辅料
iZyPlanProcessAccessoriesService.remove(new LambdaQueryWrapper<ZyPlanProcessAccessories>().in(ZyPlanProcessAccessories::getPlanId, planId)); iZyPlanProcessAccessoriesService.remove(new LambdaQueryWrapper<ZyPlanProcessAccessories>().in(ZyPlanProcessAccessories::getPlanProcessId, collect));
// 4,删除生产计划工序 // 4,删除生产计划工序
zyPlanProcessService.remove(new LambdaQueryWrapper<ZyPlanProcess>().in(ZyPlanProcess::getPlanId, planId)); zyPlanProcessService.remove(new LambdaQueryWrapper<ZyPlanProcess>().in(ZyPlanProcess::getPlanId, planId));
}
// 5,删除生产计划 // 5,删除生产计划
iZyProductPlanService.remove(new LambdaQueryWrapper<ZyProductPlan>().in(ZyProductPlan::getId, planId)); iZyProductPlanService.remove(new LambdaQueryWrapper<ZyProductPlan>().in(ZyProductPlan::getId, planId));
return false; //方便查看数据 ,暂时做状态处理
} // iZyProductPlanService.lambdaUpdate()
return false; // .set(ZyProductPlan::getStatus, ProductPlanStatusEnum.EXCEPTION.getCode())
// .eq(ZyProductPlan::getId, planId).update();
} }
@Transactional(rollbackFor = Exception.class, readOnly = false) @Transactional(rollbackFor = Exception.class, readOnly = false)
@ -490,19 +509,24 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp
return null; return null;
} }
ZyPlanProcess diffTool(ZyPlanProcess zyPlanProcess, List<String> zyProcessToolIds, List<Station> stationList) { ZyPlanProcess diffTool(ZyPlanProcess zyPlanProcess, List<ZyOperationtool> zyOperationtools, List<Station> stationList) {
for (int j = 0; j < stationList.size(); j++) { for (int j = 0; j < stationList.size(); j++) {
Station station = stationList.get(j); Station station = stationList.get(j);
List<StationTool> stationToolList = iStationToolService.list(new LambdaQueryWrapper<StationTool>().eq(StationTool::getToolsId, station.getId())); List<StationTool> stationToolList = iStationToolService.list(new LambdaQueryWrapper<StationTool>().eq(StationTool::getStationId, station.getId()));
List<String> stationToolIds = Optional.ofNullable(stationToolList).orElse(new ArrayList<>()).stream() List<String> stationToolIds = Optional.ofNullable(stationToolList).orElse(new ArrayList<>()).stream()
.map(StationTool::getToolsId).collect(Collectors.toList()); .map(StationTool::getToolsId).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(stationToolList)) {
List<String> zyProcessToolIds = zyOperationtools.stream().map(ZyOperationtool::getToolid).collect(Collectors.toList());
List<String> zyProcessToolNames = zyOperationtools.stream().map(ZyOperationtool::getCodeName).collect(Collectors.toList());
// 工具匹配成功 // 工具匹配成功
if (stationToolIds.containsAll(zyProcessToolIds)) { if (stationToolIds.containsAll(zyProcessToolIds)) {
String toolIds = zyProcessToolIds.stream().collect(Collectors.joining(",")); String toolIds = zyProcessToolIds.stream().collect(Collectors.joining(","));
zyPlanProcess.setToolsIds(toolIds); zyPlanProcess.setToolsIds(toolIds);
zyPlanProcess.setToolsNames(zyProcessToolNames.stream().collect(Collectors.joining(",")));
return zyPlanProcess; return zyPlanProcess;
} }
} }
}
return null; return null;
} }
} }

Loading…
Cancel
Save