|
|
|
@ -0,0 +1,238 @@
|
|
|
|
|
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.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintModel;
|
|
|
|
|
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.pojo.base.bean.DdlPackBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.*;
|
|
|
|
|
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.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
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.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : 打印客户条码
|
|
|
|
|
* @Reference :
|
|
|
|
|
* @Author : Castle
|
|
|
|
|
* @CreateDate : 2024/6/6 13:39
|
|
|
|
|
* @Modify:
|
|
|
|
|
**/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class MesProductSnPrintSortStepService extends BaseStepService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesLabelTemplateRepository labelTemplateRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesLabelTemplateParamRepository labelTemplateParamRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesPrintedSnLogRepository snLogRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesWorkOrderRepository workOrderRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesNumberRuleRepository numberRuleRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
|
// /**
|
|
|
|
|
// * Map<String,Object>
|
|
|
|
|
// * valueList:List<Map<String,Object>>
|
|
|
|
|
// * paramInfo:{
|
|
|
|
|
// * templateContent:xxxx,
|
|
|
|
|
// * labelTemplateParamList: List<Map<String,Object>>
|
|
|
|
|
// * }
|
|
|
|
|
// *
|
|
|
|
|
// * 根据foreign找出加工规则对应的上下文,判断是否需要打印
|
|
|
|
|
// *
|
|
|
|
|
// */
|
|
|
|
|
String organizeCode = reqBean.getOrganizeCode();
|
|
|
|
|
StationResultBean resultBean = new StationResultBean();
|
|
|
|
|
StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
|
|
|
|
|
|
//返回打印标识 给前端
|
|
|
|
|
//1. 获取上下文中生成的主条码
|
|
|
|
|
List<MesProductionPartContext> productionPartContextList = productionDispatchContextStepService.getProductionPartContext(reqBean);
|
|
|
|
|
|
|
|
|
|
// 排除掉空腔的partContext数据
|
|
|
|
|
productionPartContextList = CollectionUtils.isEmpty(productionPartContextList) ? null :productionPartContextList.stream().filter(o -> o.getForeignKey() != null).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重构,返回给前端打印数据
|
|
|
|
|
*/
|
|
|
|
|
List<MesProduceSnPrintModel> printModelList = new ArrayList<>();
|
|
|
|
|
//2. 获取条码需要模板、模板代码、打印机 --- 循环遍历条码 封装数据
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(productionPartContextList)) return stepResult;
|
|
|
|
|
|
|
|
|
|
// 根据工单号分组
|
|
|
|
|
Map<String, MesWorkOrder> workOrderMap = getMesWorkOrderMap(reqBean, productionPartContextList);
|
|
|
|
|
|
|
|
|
|
// 获取零件信息上下文
|
|
|
|
|
Map<String, MesPart> partDataContext = productionDispatchContextStepService.getPartDataContext(reqBean);
|
|
|
|
|
|
|
|
|
|
List<MesWorkOrder> needModifyWorkOrderList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack("WH_CUST_SN_RULE", MesPcnExtConstWords.RULE_CODE, packBean);
|
|
|
|
|
MesNumberRule numberRule = numberRuleRepository.getByProperty(packBean);
|
|
|
|
|
|
|
|
|
|
if (numberRule == null) {
|
|
|
|
|
log.error("MesCustSnPrintStepService --- exec --- 客户条码编码规则[WH_CUST_SN_RULE]无效");
|
|
|
|
|
return stepResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (MesProductionPartContext sn : productionPartContextList) {
|
|
|
|
|
|
|
|
|
|
// 根据工单号获取工单信息
|
|
|
|
|
MesWorkOrder workOrder = workOrderMap.get(sn.getWorkOrderNo());
|
|
|
|
|
|
|
|
|
|
if (workOrder == null) {
|
|
|
|
|
log.error("MesCustSnPrintStepService --- exec --- 工单号:{}无效", sn.getWorkOrderNo());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((partDataContext == null) || (!partDataContext.containsKey(workOrder.getPartNo()))) {
|
|
|
|
|
log.error("MesCustSnPrintStepService --- exec --- 工单号:{}零件{}丢失缓存", sn.getWorkOrderNo(), sn.getPartNo());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从物料信息中获取标签模板
|
|
|
|
|
String labelTemplateCode = partDataContext.get(sn.getPartNo()).getProductLabelTemplate();
|
|
|
|
|
|
|
|
|
|
// 从物料信息中获取打印机
|
|
|
|
|
String productPrinterCode = partDataContext.get(sn.getPartNo()).getProductPrinterCode();
|
|
|
|
|
|
|
|
|
|
if (labelTemplateCode == null) {
|
|
|
|
|
stepExpSendMsgAndThrowEx(reqBean, resultBean, String.format("工单号[%s]零件号[%s]未在ERP物料信息维护打印模板,请检查并修改!", sn.getWorkOrderNo(), sn.getPartNo()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(productPrinterCode)) {
|
|
|
|
|
stepExpSendMsgAndThrowEx(reqBean, resultBean, String.format("工单号[%s]零件号[%s]未在ERP物料信息维护打印机,请检查并修改!", sn.getWorkOrderNo(), sn.getPartNo()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesProduceSnPrintModel mesProduceSnPrintModel = new MesProduceSnPrintModel();
|
|
|
|
|
// 查模板代码
|
|
|
|
|
MesLabelTemplate labelTemplate = getLabelTemplate(labelTemplateCode, organizeCode);
|
|
|
|
|
|
|
|
|
|
if (labelTemplate == null) {
|
|
|
|
|
stepExpSendMsgAndThrowEx(reqBean, resultBean, String.format("工单号[%s]零件号[%s]的模板代码[%s]无效,请检查并修改!", sn.getWorkOrderNo(), sn.getPartNo(), labelTemplateCode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mesProduceSnPrintModel.setMesLabelTemplate(labelTemplate);
|
|
|
|
|
mesProduceSnPrintModel.setPrinter(productPrinterCode);
|
|
|
|
|
mesProduceSnPrintModel.setPartNo(sn.getPartNo());
|
|
|
|
|
mesProduceSnPrintModel.setOrganizeCode(organizeCode);
|
|
|
|
|
mesProduceSnPrintModel.setSourceData(workOrder);
|
|
|
|
|
|
|
|
|
|
//根据反射获取策略类--封装打印数据
|
|
|
|
|
String methodCode = labelTemplate.getMethodCode();
|
|
|
|
|
//模板信息丢失抛出异常
|
|
|
|
|
if (StringUtils.isEmpty(methodCode)) {
|
|
|
|
|
stepExpSendMsgAndThrowEx(reqBean, resultBean, String.format("工单号[%s]零件号[%s]的模板代码[%s]的反射类丢失,请配置!", sn.getWorkOrderNo(), sn.getPartNo(), labelTemplateCode));
|
|
|
|
|
}
|
|
|
|
|
IPrintTemplateStrategyService strategyService = (IPrintTemplateStrategyService) SpringContextsUtil.getBean(methodCode);
|
|
|
|
|
// GenSerialNoModel model , MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule, StepResult stepResult, StationRequestBean reqBean, Boolean isStep
|
|
|
|
|
MesProduceSnPrintModel printModel = strategyService.execute(null, mesProduceSnPrintModel, null, stepResult, reqBean, true);
|
|
|
|
|
printModelList.add(printModel);
|
|
|
|
|
needModifyWorkOrderList.add(workOrder);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//前端接收到busiTyep是customComponent,并且 dataType是file类型的消息,就需要打印后续消息里的数据,一个模板对应多个打印数据
|
|
|
|
|
resultBean.setBusiType(MesPcnEnumUtil.STATION_BUSI_TYPE.CUSTOM_COMPONENT.getValue());
|
|
|
|
|
resultBean.setDataType(MesPcnEnumUtil.STATION_DATA_TYPE.FILE.getValue());
|
|
|
|
|
resultBean.setResultObj(printModelList);
|
|
|
|
|
//3. 发送数据给到前端
|
|
|
|
|
this.sendMessage(reqBean, resultBean);
|
|
|
|
|
List<MesPrintedSnLog> snLogList = printModelList.stream().map(MesProduceSnPrintModel::getMesPrintedSnLogList).flatMap(List::stream).collect(Collectors.toList());
|
|
|
|
|
//更新打印状态
|
|
|
|
|
for (MesWorkOrder workOrder : needModifyWorkOrderList) {
|
|
|
|
|
MesPrintedSnLog snLog = new MesPrintedSnLog();
|
|
|
|
|
snLog.setBarcode(workOrder.getCustSn());
|
|
|
|
|
snLog.setCustPartNo(workOrder.getCustPartNo());
|
|
|
|
|
snLog.setWorkOrderNo(workOrder.getWorkOrderNo());
|
|
|
|
|
snLog.setPartNo(workOrder.getPartNo());
|
|
|
|
|
snLog.setPartName(workOrder.getPartName());
|
|
|
|
|
ConvertBean.serviceModelInitialize(snLog, reqBean.getUserInfo());
|
|
|
|
|
snLog.setOrganizeCode(reqBean.getOrganizeCode());
|
|
|
|
|
snLogList.add(snLog);
|
|
|
|
|
}
|
|
|
|
|
//保存打印条码记录
|
|
|
|
|
snLogRao.saveAll(snLogList);
|
|
|
|
|
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), stepResult, "打印成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, MesWorkOrder> getMesWorkOrderMap(StationRequestBean reqBean, List<MesProductionPartContext> productionPartContextList) {
|
|
|
|
|
// 从产成物料上下文中获取 工单号集合
|
|
|
|
|
List<String> workOrderNoList = productionPartContextList.stream().map(MesProductionPartContext::getWorkOrderNo).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(reqBean.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getInPackList(workOrderNoList, MesPcnExtConstWords.WORK_ORDER_NO, packBean);
|
|
|
|
|
List<MesWorkOrder> workOrderList = workOrderRepository.findByHqlWhere(packBean);
|
|
|
|
|
|
|
|
|
|
// 根据工单号分组
|
|
|
|
|
Map<String, MesWorkOrder> workOrderMap = workOrderList.stream().collect(Collectors.toMap(MesWorkOrder::getWorkOrderNo, Function.identity(), (x, y) -> y));
|
|
|
|
|
return workOrderMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//验证加工结果是否满足参数条件: 可疑/报废是否打印
|
|
|
|
|
private Boolean checkIsMatchProdResult(StationRequestBean reqBean, String prodResult, MesExtEnumUtil.PRODUCT_RESULT_EQUIP_PARAM prodResultEnum) {
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(prodResult)) return false;
|
|
|
|
|
if (!prodResult.equals(prodResultEnum.getCode())) return false;
|
|
|
|
|
|
|
|
|
|
Optional<Map<String, MesProdRouteOptParam>> stepParamMap = getStepParams(reqBean);
|
|
|
|
|
String unPrintParam = (null != stepParamMap && stepParamMap.isPresent() && stepParamMap.get().containsKey(prodResultEnum.name())) ? stepParamMap.get().get(prodResultEnum.name()).getParamValue() : null;
|
|
|
|
|
if (StringUtils.isEmpty(unPrintParam)) return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据templateCode 获取模板信息
|
|
|
|
|
*
|
|
|
|
|
* @param templateCode
|
|
|
|
|
* @param organizeCode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private MesLabelTemplate getLabelTemplate(String templateCode, String organizeCode) {
|
|
|
|
|
DdlPackBean templatePackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(templateCode, "templateCode", templatePackBean);
|
|
|
|
|
List<MesLabelTemplate> mesLabelTemplateList = labelTemplateRao.findByHqlWhere(templatePackBean);
|
|
|
|
|
MesLabelTemplate mesLabelTemplate = null;
|
|
|
|
|
if (!mesLabelTemplateList.isEmpty()) {
|
|
|
|
|
mesLabelTemplate = mesLabelTemplateList.get(0);
|
|
|
|
|
//级联获取labelTemplateParam
|
|
|
|
|
DdlPackBean templateParamPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(mesLabelTemplate.getId(), "templateId", templateParamPackBean);
|
|
|
|
|
List<MesLabelTemplateParam> params = labelTemplateParamRao.findByHqlWhere(templateParamPackBean);
|
|
|
|
|
mesLabelTemplate.setLabelTemplateParamList(params);
|
|
|
|
|
}
|
|
|
|
|
return mesLabelTemplate;
|
|
|
|
|
}
|
|
|
|
|
}
|