|
|
@ -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); |
|
|
|
for (int i = 0; i < planProcessList.size(); i++) { |
|
|
|
flag: |
|
|
|
ZyPlanProcess obj = planProcessList.get(i); |
|
|
|
if (b.get()) { |
|
|
|
List<ZyProcessMachine> machineList = iZyProcessMachineService.list(new LambdaQueryWrapper<ZyProcessMachine>().eq(ZyProcessMachine::getProcessId, obj.getProcessId())); |
|
|
|
planProcessList: |
|
|
|
List<ZyOperationtool> toolList = iZyOperationtoolService.list(new LambdaQueryWrapper<ZyOperationtool>().eq(ZyOperationtool::getOperationid, obj.getProcessId())); |
|
|
|
for (int i = 0; i < planProcessList.size(); i++) { |
|
|
|
List<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList()); |
|
|
|
ZyPlanProcess obj = planProcessList.get(i); |
|
|
|
List<String> zyProcessCodes = machineList.stream().map(ZyProcessMachine::getCode).collect(Collectors.toList()); |
|
|
|
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())); |
|
|
|
ZyPlanProcess diffMachine = this.diffMachine(obj, zyProcessMachineIds, zyProcessCodes, stationList); |
|
|
|
List<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
List<String> zyProcessCodes = machineList.stream().map(ZyProcessMachine::getCode).collect(Collectors.toList()); |
|
|
|
if (ObjectUtils.isEmpty(diffMachine)) { |
|
|
|
List<String> zyProcessToolIds = toolList.stream().map(ZyOperationtool::getOperationid).collect(Collectors.toList()); |
|
|
|
//设备匹配失败,删除该生产计划相半数据,直接结束
|
|
|
|
|
|
|
|
this.doException(planId, obj, "工序设备匹配"); |
|
|
|
ZyPlanProcess diffMachine = this.diffMachine(obj, zyProcessMachineIds, zyProcessCodes, stationList); |
|
|
|
return false; |
|
|
|
//设备匹配失败,直接结束
|
|
|
|
} /*else { // 设备匹配成功,则匹配工具 //TODO 暂时注释掉 工序工具匹配
|
|
|
|
if (ObjectUtils.isEmpty(diffMachine)) { |
|
|
|
ZyPlanProcess diffTool = this.diffTool(diffMachine, toolList, stationList); |
|
|
|
b.set(false); |
|
|
|
if (ObjectUtils.isEmpty(diffTool)) { |
|
|
|
break flag; |
|
|
|
//设备匹配失败,删除该生产计划相半数据,直接结束
|
|
|
|
} else { // 设备匹配,则匹配工具
|
|
|
|
this.doException(planId, obj, "工序工具匹配"); |
|
|
|
ZyPlanProcess diffTool = this.diffTool(diffMachine, zyProcessToolIds, stationList); |
|
|
|
return false; |
|
|
|
if (ObjectUtils.isEmpty(diffTool)) { |
|
|
|
} else { // 匹配工人
|
|
|
|
b.set(false); |
|
|
|
updateList.add(diffTool); |
|
|
|
break flag; |
|
|
|
//匹配下一个工序的设备和工具
|
|
|
|
} else { // 匹配工人
|
|
|
|
continue; |
|
|
|
updateList.add(diffTool); |
|
|
|
|
|
|
|
//匹配下一个工序的设备和工具
|
|
|
|
|
|
|
|
continue planProcessList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}*/ |
|
|
|
zyPlanProcessService.saveOrUpdateBatch(updateList); |
|
|
|
|
|
|
|
return true; |
|
|
|
updateList.add(diffMachine); |
|
|
|
} else { |
|
|
|
} |
|
|
|
ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId); |
|
|
|
|
|
|
|
// 1,作工单异常处理,
|
|
|
|
zyPlanProcessService.saveOrUpdateBatch(updateList); |
|
|
|
iWorkOrderService.lambdaUpdate() |
|
|
|
return true; |
|
|
|
.set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.EXCEPTION.getCode()) |
|
|
|
} |
|
|
|
.eq(WorkOrder::getProductCode, zyProductPlan.getProductCode()).update(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 只要有生产计划工序(设备、工具)匹配不上就算匹配失败,删除相关生产计划数据,标记该工单异常,然后匹配下一个工单 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @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,删除生产计划工序面料
|
|
|
|
// 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,删除生产计划
|
|
|
|
|
|
|
|
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) |
|
|
|
@Transactional(rollbackFor = Exception.class, readOnly = false) |
|
|
@ -490,17 +509,22 @@ 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)) { |
|
|
|
if (stationToolIds.containsAll(zyProcessToolIds)) { |
|
|
|
List<String> zyProcessToolIds = zyOperationtools.stream().map(ZyOperationtool::getToolid).collect(Collectors.toList()); |
|
|
|
String toolIds = zyProcessToolIds.stream().collect(Collectors.joining(",")); |
|
|
|
List<String> zyProcessToolNames = zyOperationtools.stream().map(ZyOperationtool::getCodeName).collect(Collectors.toList()); |
|
|
|
zyPlanProcess.setToolsIds(toolIds); |
|
|
|
// 工具匹配成功
|
|
|
|
return zyPlanProcess; |
|
|
|
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; |
|
|
|
return null; |
|
|
|