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

master
zhc077 2 years ago
parent 5561512756
commit f7c7784166
  1. 124
      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<ZyProductPlanMapper, ZyProductPlan> implements IZyProductPlanAutoService {
@Autowired
@ -374,54 +375,72 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp
List<ZyPlanProcess> 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<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<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).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);
//设备匹配失败,直接结束
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<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<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList());
List<String> 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<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,删除生产计划工序面料
iZyPlanProcessFabricService.remove(new LambdaQueryWrapper<ZyPlanProcessFabric>().in(ZyPlanProcessFabric::getPlanId, planId));
iZyPlanProcessFabricService.remove(new LambdaQueryWrapper<ZyPlanProcessFabric>().in(ZyPlanProcessFabric::getPlanProcessId, collect));
// 3,删除生产计划工序辅料
iZyPlanProcessAccessoriesService.remove(new LambdaQueryWrapper<ZyPlanProcessAccessories>().in(ZyPlanProcessAccessories::getPlanId, planId));
iZyPlanProcessAccessoriesService.remove(new LambdaQueryWrapper<ZyPlanProcessAccessories>().in(ZyPlanProcessAccessories::getPlanProcessId, collect));
// 4,删除生产计划工序
zyPlanProcessService.remove(new LambdaQueryWrapper<ZyPlanProcess>().in(ZyPlanProcess::getPlanId, planId));
// 5,删除生产计划
iZyProductPlanService.remove(new LambdaQueryWrapper<ZyProductPlan>().in(ZyProductPlan::getId, planId));
return false;
}
return false;
// 5,删除生产计划
iZyProductPlanService.remove(new LambdaQueryWrapper<ZyProductPlan>().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<ZyProductPlanMapp
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++) {
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()
.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<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)) {
String toolIds = zyProcessToolIds.stream().collect(Collectors.joining(","));
zyPlanProcess.setToolsIds(toolIds);
zyPlanProcess.setToolsNames(zyProcessToolNames.stream().collect(Collectors.joining(",")));
return zyPlanProcess;
}
}
}
return null;

Loading…
Cancel
Save