|
|
@ -1,71 +1,146 @@
|
|
|
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
|
|
|
//package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
|
|
|
|
|
|
|
//
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesWorkOrderExtService;
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
|
|
|
|
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
|
|
|
//import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
|
|
|
//import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
//import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
//import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
|
|
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
|
|
|
|
import java.util.List;
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
|
|
|
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
|
|
|
/**
|
|
|
|
//import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
* @Description : 保存加工单信息工步
|
|
|
|
//import lombok.extern.slf4j.Slf4j;
|
|
|
|
* @Reference :
|
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
* @Author : Castle
|
|
|
|
//import org.springframework.stereotype.Service;
|
|
|
|
* @CreateDate : 2024/6/11 18:50
|
|
|
|
//import org.springframework.util.CollectionUtils;
|
|
|
|
* @Modify:
|
|
|
|
//import org.springframework.util.StringUtils;
|
|
|
|
**/
|
|
|
|
//
|
|
|
|
@Slf4j
|
|
|
|
//import java.util.List;
|
|
|
|
@Service("mesWorkOrderSaveStepService")
|
|
|
|
//import java.util.Map;
|
|
|
|
public class MesWorkOrderSaveStepService extends BaseStepService {
|
|
|
|
//import java.util.stream.Collectors;
|
|
|
|
@Autowired
|
|
|
|
//
|
|
|
|
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
|
|
|
///**
|
|
|
|
|
|
|
|
// * @Description : 保存加工单信息工步
|
|
|
|
@Autowired
|
|
|
|
// * @Reference :
|
|
|
|
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
|
|
|
// * @Author : wangjie
|
|
|
|
|
|
|
|
// * @CreateDate : 2024/6/11 18:50
|
|
|
|
@Override
|
|
|
|
// * @Modify:
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
// **/
|
|
|
|
StationResultBean resultBean = new StationResultBean();
|
|
|
|
//@Slf4j
|
|
|
|
StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
//@Service("mesWorkOrderSaveStepService")
|
|
|
|
//1. 获取上下文中的MesProductionPartContext 产出零件
|
|
|
|
//public class MesWorkOrderSaveStepService extends BaseStepService {
|
|
|
|
List<MesProductionPartContext> productionPartContext = productionDispatchContextStepService.getProductionPartContext(reqBean);
|
|
|
|
//
|
|
|
|
if (productionPartContext.isEmpty()){
|
|
|
|
// @Autowired
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "没有可保存的加工单信息");
|
|
|
|
// private IMesProductionProcessContextStepService productionProcessContextStepService;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// 判断为空腔 isFinishedCode = true 就是空腔
|
|
|
|
// @Autowired
|
|
|
|
// stream 过滤 isFinishedCode = false 并且 foreignKey != null 并且 加工单code 为不为空;
|
|
|
|
// private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
|
|
|
List<MesProductionPartContext> filteredPartContext = productionPartContext.stream().filter(item -> item.getIsFinishCode() == CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue() && item.getForeignKey() != null && item.getWorkOrderNo() != null).collect(Collectors.toList());
|
|
|
|
//
|
|
|
|
if (filteredPartContext.isEmpty()){
|
|
|
|
// @Autowired
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "过滤后,没有可保存的加工单信息");
|
|
|
|
// private IMesWorkOrderExtService workOrderExtService;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// 怎么判断条码生成过了? 看产出零件和入料,in 要判端relateId有值也需要新增, out生成条码 上下文
|
|
|
|
// @Override
|
|
|
|
// 如果没有in 需要加,
|
|
|
|
// public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
// 如果有out条码,则判断id是否为空,不为空则是新生成的
|
|
|
|
//
|
|
|
|
|
|
|
|
// StationResultBean resultBean = new StationResultBean();
|
|
|
|
//2. 判断是否为空,id是否为空,如果没有则返回,id为工单id
|
|
|
|
//
|
|
|
|
List<MesProductionPartContext> collectContext = productionPartContext.stream().filter(item -> item.getId() != null).collect(Collectors.toList());
|
|
|
|
// StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
//3. 如果id不为空,查询工单信息
|
|
|
|
//
|
|
|
|
if (collectContext.isEmpty()){
|
|
|
|
// //获取上下文信息
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "没有可保存的加工单信息");
|
|
|
|
// MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//4. 判断当前产出的零件MesProductionPsOutContext中是否有id,如果有就是新生成的
|
|
|
|
// //配置错误 抛出异常
|
|
|
|
List<MesProductionPsOutContext> productionPsOutContext = productionDispatchContextStepService.getProductionPsOutContext(reqBean);
|
|
|
|
// if (!productionProcessContext.getSuccess()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
|
|
|
//过滤出新生成的条码,没有条码id就是新生成的
|
|
|
|
//
|
|
|
|
List<MesProductionPsOutContext> produceSnList = productionPsOutContext.stream().filter(item -> item.getId() != null).collect(Collectors.toList());
|
|
|
|
// //存储生产过程上下文对象
|
|
|
|
if (produceSnList.isEmpty()){
|
|
|
|
// productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext);
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "没有可保存的加工单信息");
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// //获取上下文产品加工规则数据信息集合
|
|
|
|
// productionPsOutContext.stream().collect(Collectors.groupingBy(MesProductionPsOutContext::getId))
|
|
|
|
// List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
|
|
|
//5. 修改完成数量,完成数量大于计划数量,就需要修改工单的状态为完成
|
|
|
|
//
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "保存加工单信息成功");
|
|
|
|
// if (CollectionUtils.isEmpty(prodRuleContextList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "上下文中不存在加工规则信息,请重置工序解决!");
|
|
|
|
}
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// //获取上下文产出零件数据信息集合
|
|
|
|
|
|
|
|
// List<MesProductionPartContext> productionPartContextList = productionDispatchContextStepService.getProductionPartContext(reqBean);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// //没有产出零件或者没有工单
|
|
|
|
|
|
|
|
// if (CollectionUtils.isEmpty(productionPartContextList) || StringUtils.isEmpty(
|
|
|
|
|
|
|
|
// productionPartContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).findFirst().get().getWorkOrderNo())) return stepResult;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// //获取上下文产出零件数据信息集合
|
|
|
|
|
|
|
|
// List<MesProductionPsOutContext> productionPsOutContextList = productionDispatchContextStepService.getProductionPsOutContext(reqBean);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// //从上下文中取出生产线对象
|
|
|
|
|
|
|
|
// MesWorkCenter workCenter = productionProcessContext.getWorkCenter();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// //保存生产工单数据
|
|
|
|
|
|
|
|
// doHandleWorkOrderData(reqBean, resultBean, productionPartContextList, prodRuleContextList, productionPsOutContextList, 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<MesProductionPsOutContext>> proMap = productionPsOutContextList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesProductionPsOutContext::getWorkOrderNo));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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()) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (null == entry) continue;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// List<MesProductionPsOutContext> produceSnContextList = proMap.get(entry.getKey());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Integer calcCompleteQty = 0;
|
|
|
|
|
|
|
|
// Integer reportQty = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// for (MesProductionPsOutContext productionPsOutContext : produceSnContextList) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (null == productionPsOutContext) continue;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// MesWorkOrder workOrder = workOrderExtService.getWorkOrder(reqBean.getOrganizeCode(), entry.getValue().get(0).getId());
|
|
|
|
|
|
|
|
// if (null == workOrder) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息不存在!", entry.getKey()));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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())));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!workOrder.getWorkCenterCode().equals(reqBean.getWorkCenterCode()))
|
|
|
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息,加工单[%s]信息所属生产线[%s]与当前生产线[%s]不一致!", entry.getKey(), workOrder.getWorkCenterCode(), reqBean.getWorkCenterCode()));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) > 0 && (StringUtils.isEmpty(workCenter.getIsCheckOrderQty()) || workCenter.getIsCheckOrderQty().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0) && workOrder.getCompleteQty().compareTo(workOrder.getQty()) >= 0)
|
|
|
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息及生产线信息,生产线[%s]不允许超工单生产,且加工单[%s]信息已完成数量[%s]累加当前完成数量[%s]将超过计划数量[%s]!", entry.getKey(), reqBean.getWorkCenterCode(), workOrder.getCompleteQty(), calcCompleteQty, workOrder.getQty()));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (reportQty.compareTo(MesPcnExtConstWords.ZERO) > 0 && (!StringUtils.isEmpty(workCenter.getIsCheckOrderQty()) && workCenter.getIsCheckOrderQty().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) &&
|
|
|
|
|
|
|
|
// workOrder.getReportedQty().compareTo(MathOperation.mul(workOrder.getQty(), MathOperation.div(MathOperation.add(workCenter.getOrderRate(), new Double(100)), new Double(100)))) >= 0)
|
|
|
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查工单信息及生产线信息,生产线[%s]允许超工单生产,且加工单[%s]信息已汇报数量[%s]已满足计划数量[%s]超出比例[%s]!",
|
|
|
|
|
|
|
|
// reqBean.getWorkCenterCode(), entry.getKey(), workOrder.getReportedQty(), workOrder.getQty(), workCenter.getOrderRate() + MesPcnExtConstWords.PERCENT));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// workOrder.setCompleteQty(MathOperation.add());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//}
|
|
|
|