forked from I3-YF/i3plus-mes-pcn-yfai
steo
parent
a249d62688
commit
7894c6922f
@ -1,146 +1,165 @@
|
||||
//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.IMesProductionProcessContextStepService;
|
||||
//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesWorkOrderExtService;
|
||||
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
|
||||
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
|
||||
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
||||
//import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
||||
//import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
//import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
//import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
||||
//import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
//import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
||||
//import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
|
||||
//import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
||||
//import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
||||
//import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
//import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.util.CollectionUtils;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
///**
|
||||
// * @Description : 保存加工单信息工步
|
||||
// * @Reference :
|
||||
// * @Author : wangjie
|
||||
// * @CreateDate : 2024/6/11 18:50
|
||||
// * @Modify:
|
||||
// **/
|
||||
//@Slf4j
|
||||
//@Service("mesWorkOrderSaveStepService")
|
||||
//public class MesWorkOrderSaveStepService extends BaseStepService {
|
||||
//
|
||||
// @Autowired
|
||||
// private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
//
|
||||
// @Autowired
|
||||
// private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
//
|
||||
// @Autowired
|
||||
// private IMesWorkOrderExtService workOrderExtService;
|
||||
//
|
||||
// @Override
|
||||
// public StepResult execute(StationRequestBean reqBean) {
|
||||
//
|
||||
// StationResultBean resultBean = new StationResultBean();
|
||||
//
|
||||
// StepResult stepResult = StepResult.getSuccessComplete();
|
||||
//
|
||||
// //获取上下文信息
|
||||
// MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean);
|
||||
//
|
||||
// //配置错误 抛出异常
|
||||
// if (!productionProcessContext.getSuccess()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
//
|
||||
// //存储生产过程上下文对象
|
||||
// productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext);
|
||||
//
|
||||
// //获取上下文产品加工规则数据信息集合
|
||||
// List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
||||
//
|
||||
// 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());
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
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.IMesProductionProcessContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesWorkOrderExtService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
||||
import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
||||
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesWorkOrderRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description : 保存加工单信息工步
|
||||
* @Reference :
|
||||
* @Author : wangjie
|
||||
* @CreateDate : 2024/6/11 18:50
|
||||
* @Modify:
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesWorkOrderSaveStepService")
|
||||
public class MesWorkOrderSaveStepService extends BaseStepService {
|
||||
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesWorkOrderExtService workOrderExtService;
|
||||
|
||||
@Autowired
|
||||
private MesWorkOrderRepository workOrderRepository;
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
//获取上下文信息
|
||||
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean);
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContext.getSuccess()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
|
||||
//存储生产过程上下文对象
|
||||
productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext);
|
||||
|
||||
//获取上下文产品加工规则数据信息集合
|
||||
List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
||||
|
||||
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);
|
||||
|
||||
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "保存加工单信息成功!");
|
||||
|
||||
}
|
||||
|
||||
//保存生产工单数据
|
||||
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()));
|
||||
|
||||
//TODO 超工单数量验证
|
||||
/*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));*/
|
||||
|
||||
if (calcCompleteQty.compareTo(MesPcnExtConstWords.ZERO) > 0) workOrder.setCompleteQty(MathOperation.add(workOrder.getCompleteQty(), calcCompleteQty));
|
||||
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)));
|
||||
if (reportQty.compareTo(MesPcnExtConstWords.ZERO) > 0) workOrder.setReportedQty(MathOperation.add(workOrder.getReportedQty(), reportQty));
|
||||
|
||||
//TODO 可疑品数量 报废数量 上下线时间
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue