|
|
@ -11,7 +11,10 @@ import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
|
|
|
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
|
|
|
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
|
|
@ -25,8 +28,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -52,6 +58,9 @@ public class MesWorkOrderSaveStepService extends BaseStepService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private MesWorkOrderRepository workOrderRepository;
|
|
|
|
private MesWorkOrderRepository workOrderRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
|
|
|
|
|
|
|
@ -96,56 +105,100 @@ public class MesWorkOrderSaveStepService extends BaseStepService {
|
|
|
|
//保存生产工单数据
|
|
|
|
//保存生产工单数据
|
|
|
|
private void doHandleWorkOrderData(StationRequestBean reqBean, StationResultBean resultBean, List<MesProductionPartContext> productionPartContextList, List<MesProdRuleContext> prodRuleContextList, List<MesProductionPsOutContext> productionPsOutContextList, MesWorkCenter workCenter) {
|
|
|
|
private void doHandleWorkOrderData(StationRequestBean reqBean, StationResultBean resultBean, List<MesProductionPartContext> productionPartContextList, List<MesProdRuleContext> prodRuleContextList, List<MesProductionPsOutContext> productionPsOutContextList, MesWorkCenter workCenter) {
|
|
|
|
|
|
|
|
|
|
|
|
//根据生产工单分组
|
|
|
|
//产出零件信息根据生产工单分组
|
|
|
|
Map<String, List<MesProductionPartContext>> ppMap = productionPartContextList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesProductionPartContext::getWorkOrderNo));
|
|
|
|
Map<String, List<MesProductionPartContext>> ppMap = productionPartContextList.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(MesProductionPartContext::getWorkOrderNo));
|
|
|
|
|
|
|
|
|
|
|
|
//根据生产工单分组
|
|
|
|
|
|
|
|
Map<String, List<MesProductionPsOutContext>> proMap = productionPsOutContextList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesProductionPsOutContext::getWorkOrderNo));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//产出条码 根据生产工单分组
|
|
|
|
|
|
|
|
Map<String, List<MesProductionPsOutContext>> proMap = productionPsOutContextList.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(MesProductionPsOutContext::getWorkOrderNo));
|
|
|
|
|
|
|
|
//产品加工规则 根据foreignKey分组
|
|
|
|
Map<Integer, MesProdRuleContext> prMap = prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).collect(Collectors.toMap(MesProdRuleContext::getForeignKey, o -> o));
|
|
|
|
Map<Integer, MesProdRuleContext> prMap = prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).collect(Collectors.toMap(MesProdRuleContext::getForeignKey, o -> o));
|
|
|
|
|
|
|
|
//遍历产出零件信息
|
|
|
|
for(Map.Entry<String, List<MesProductionPartContext>> entry : ppMap.entrySet()) {
|
|
|
|
for(Map.Entry<String, List<MesProductionPartContext>> entry : ppMap.entrySet()) {
|
|
|
|
|
|
|
|
|
|
|
|
if (null == entry) continue;
|
|
|
|
if (null == entry) continue;
|
|
|
|
|
|
|
|
//获取对应的加工规则
|
|
|
|
List<MesProductionPsOutContext> produceSnContextList = proMap.get(entry.getKey());
|
|
|
|
List<MesProductionPsOutContext> produceSnContextList = proMap.get(entry.getKey());
|
|
|
|
|
|
|
|
//生产数量
|
|
|
|
Integer calcCompleteQty = 0;
|
|
|
|
Integer calcCompleteQty = 0;
|
|
|
|
Integer reportQty = 0;
|
|
|
|
//遍历产出物料
|
|
|
|
|
|
|
|
|
|
|
|
for (MesProductionPsOutContext productionPsOutContext : produceSnContextList) {
|
|
|
|
for (MesProductionPsOutContext productionPsOutContext : produceSnContextList) {
|
|
|
|
if (null == productionPsOutContext) continue;
|
|
|
|
if (null == productionPsOutContext) continue;
|
|
|
|
|
|
|
|
//产出零件是否是
|
|
|
|
if (productionPsOutContext.getIsCalcCompleteQty() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) calcCompleteQty += 1;
|
|
|
|
if (productionPsOutContext.getIsCalcCompleteQty() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) calcCompleteQty += 1;
|
|
|
|
if (prMap.get(productionPsOutContext.getForeignKey()).getReportType().compareTo(MesExtEnumUtil.NOSORT_REPORT_TYPE.NO_REPORT.getValue()) != 0) reportQty += 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) == 0 && reportQty.compareTo(MesPcnExtConstWords.ZERO) == 0) continue;
|
|
|
|
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) == 0 ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
MesWorkOrder workOrder = workOrderExtService.getWorkOrder(reqBean.getOrganizeCode(), entry.getValue().get(0).getId());
|
|
|
|
MesWorkOrder workOrder = workOrderExtService.getWorkOrder(reqBean.getOrganizeCode(), entry.getValue().get(0).getId());
|
|
|
|
|
|
|
|
entityManager.detach(workOrder);
|
|
|
|
if (null == workOrder) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息不存在!", entry.getKey()));
|
|
|
|
if (null == workOrder) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息不存在!", entry.getKey()));
|
|
|
|
|
|
|
|
//工单状态分 排序工单 和非排序工单; 现在必须是非排序工单
|
|
|
|
if (!MesExtEnumUtil.ORDER_STATUS.checkAllowStatus(workCenter.getCenterType(), workOrder.getWorkOrderStatus()))
|
|
|
|
if (!MesExtEnumUtil.ORDER_STATUS.checkAllowStatus(workCenter.getCenterType(), workOrder.getWorkOrderStatus()))
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息工单状态[%s]!", entry.getKey(), MesExtEnumUtil.ORDER_STATUS.valueOfDescription(workOrder.getWorkOrderStatus())));
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息工单状态[%s]!", entry.getKey(), MesExtEnumUtil.ORDER_STATUS.valueOfDescription(workOrder.getWorkOrderStatus())));
|
|
|
|
|
|
|
|
//工单产线要和当前产线一致
|
|
|
|
if (!workOrder.getWorkCenterCode().equals(reqBean.getWorkCenterCode()))
|
|
|
|
if (!workOrder.getWorkCenterCode().equals(reqBean.getWorkCenterCode()))
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息所属生产线[%s]与当前生产线[%s]不一致!", entry.getKey(), workOrder.getWorkCenterCode(), reqBean.getWorkCenterCode()));
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息所属生产线[%s]与当前生产线[%s]不一致!", entry.getKey(), workOrder.getWorkCenterCode(), reqBean.getWorkCenterCode()));
|
|
|
|
|
|
|
|
|
|
|
|
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) > 0) workOrder.setCompleteQty(MathOperation.add(workOrder.getCompleteQty(), calcCompleteQty));
|
|
|
|
List<String> propertyNameList = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Object> propertyValueList = new ArrayList<>();
|
|
|
|
|
|
|
|
//修改完成数量
|
|
|
|
|
|
|
|
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) > 0) {
|
|
|
|
|
|
|
|
workOrder.setCompleteQty(MathOperation.add(workOrder.getCompleteQty(), calcCompleteQty));
|
|
|
|
|
|
|
|
propertyNameList.add("completeQty");
|
|
|
|
|
|
|
|
propertyValueList.add(workOrder.getCompleteQty());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//修改未完成数量
|
|
|
|
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) > 0 && workOrder.getUnCompleteQty().compareTo(new Double(0)) > 0 &&
|
|
|
|
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) > 0 && workOrder.getUnCompleteQty().compareTo(new Double(0)) > 0 &&
|
|
|
|
MathOperation.compareTo(MathOperation.sub(workOrder.getUnCompleteQty(), new Double(calcCompleteQty)), new Double(0)) >= 0) workOrder.setUnCompleteQty(MathOperation.sub(workOrder.getUnCompleteQty(), new Double(calcCompleteQty)));
|
|
|
|
MathOperation.compareTo(MathOperation.sub(workOrder.getUnCompleteQty(), new Double(calcCompleteQty)), new Double(0)) >= 0) {
|
|
|
|
if (reportQty.compareTo(MesPcnExtConstWords.ZERO) > 0) workOrder.setReportedQty(MathOperation.add(workOrder.getReportedQty(), reportQty));
|
|
|
|
workOrder.setUnCompleteQty(MathOperation.sub(workOrder.getUnCompleteQty(), new Double(calcCompleteQty)));
|
|
|
|
|
|
|
|
propertyNameList.add("unCompleteQty");
|
|
|
|
//TODO 可疑品数量 报废数量 上下线时间
|
|
|
|
propertyValueList.add(workOrder.getUnCompleteQty());
|
|
|
|
|
|
|
|
}
|
|
|
|
if (MathOperation.compareTo(workOrder.getCompleteQty(), workOrder.getQty()) >= 0 && workOrder.getWorkOrderStatus().compareTo(MesExtEnumUtil.ORDER_STATUS.COMPLETE.getValue()) != 0) workOrder.setWorkOrderStatus(MesExtEnumUtil.ORDER_STATUS.COMPLETE.getValue());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConvertBean.serviceModelUpdate(workOrder, reqBean.getUserInfo());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
workOrderRepository.save(workOrder);
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 可疑品、报废数量、上下线时间;
|
|
|
|
|
|
|
|
* sql改成修改固定字段
|
|
|
|
|
|
|
|
* 在上下文中获取busi中获取prodResult上下文 是数字 (标志着条码质量状态,与条码质量状态枚举一致)
|
|
|
|
|
|
|
|
* 上下文中 已经按照工单分组了,因为有一模多腔问题
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String prodResult = productionDispatchContextStepService.getProductResultContext(reqBean);
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(prodResult)) {
|
|
|
|
|
|
|
|
//可疑品
|
|
|
|
|
|
|
|
boolean isSuspicious = MesExtEnumUtil.PRODUCE_QC_STATUS.SUSPICIOUS.getValue() == Integer.parseInt(prodResult);
|
|
|
|
|
|
|
|
if (isSuspicious && !productionPsOutContextList.isEmpty()){
|
|
|
|
|
|
|
|
int suspiciousQty = productionPsOutContextList.size();
|
|
|
|
|
|
|
|
workOrder.setSuspiciousPartQty(MathOperation.sub(workOrder.getSuspiciousPartQty(), new Double(suspiciousQty)));
|
|
|
|
|
|
|
|
propertyNameList.add("suspiciousPartQty");
|
|
|
|
|
|
|
|
propertyValueList.add(workOrder.getSuspiciousPartQty());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//报废数量
|
|
|
|
|
|
|
|
boolean isScrap = MesExtEnumUtil.PRODUCE_QC_STATUS.SCRAP.getValue() == Integer.parseInt(prodResult);
|
|
|
|
|
|
|
|
if (isScrap && !productionPsOutContextList.isEmpty()){
|
|
|
|
|
|
|
|
int scrapQty = productionPsOutContextList.size();
|
|
|
|
|
|
|
|
workOrder.setScrapPartQty(MathOperation.sub(workOrder.getScrapPartQty(), new Double(scrapQty)));
|
|
|
|
|
|
|
|
propertyNameList.add("scrapPartQty");
|
|
|
|
|
|
|
|
propertyValueList.add(workOrder.getScrapPartQty());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (MathOperation.compareTo(workOrder.getCompleteQty(), workOrder.getQty()) >= 0 && workOrder.getWorkOrderStatus().compareTo(MesExtEnumUtil.ORDER_STATUS.COMPLETE.getValue()) != 0) {
|
|
|
|
|
|
|
|
workOrder.setWorkOrderStatus(MesExtEnumUtil.ORDER_STATUS.COMPLETE.getValue());
|
|
|
|
|
|
|
|
propertyNameList.add("workOrderStatus");
|
|
|
|
|
|
|
|
propertyValueList.add(workOrder.getWorkOrderStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//如果数量都没有修改,不操作数据库
|
|
|
|
|
|
|
|
if (!propertyNameList.isEmpty()) {
|
|
|
|
|
|
|
|
ConvertBean.serviceModelUpdate(workOrder, reqBean.getUserInfo());
|
|
|
|
|
|
|
|
propertyNameList.add("modifyUser");
|
|
|
|
|
|
|
|
propertyValueList.add(reqBean.getUserInfo());
|
|
|
|
|
|
|
|
propertyNameList.add("modifyDatetime");
|
|
|
|
|
|
|
|
propertyValueList.add(TimeTool.getNowTime(true));
|
|
|
|
|
|
|
|
DdlPackBean workOrderPackBean = DdlPackBean.getDdlPackBean(reqBean.getOrganizeCode());
|
|
|
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(workOrder.getId(),"id",workOrderPackBean);
|
|
|
|
|
|
|
|
workOrderRepository.updateByProperties(propertyNameList.toArray(new String[]{}), propertyValueList.toArray(), workOrderPackBean);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|