|
|
|
@ -1,13 +1,12 @@
|
|
|
|
|
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.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintModel;
|
|
|
|
|
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.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
|
|
|
@ -15,19 +14,23 @@ import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesLabelTemplate;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesLabelTemplateParam;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesPrintedSnLog;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
|
|
|
|
|
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.IMesPrintedSnLogRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateParamRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -52,6 +55,9 @@ public class MesProductSnPrintStepService extends BaseStepService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesPrintedSnLogRepository snLogRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesProduceSnRepository mesProduceSnRao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
|
// /**
|
|
|
|
@ -65,111 +71,81 @@ public class MesProductSnPrintStepService extends BaseStepService {
|
|
|
|
|
// * 根据foreign找出加工规则对应的上下文,判断是否需要打印
|
|
|
|
|
// *
|
|
|
|
|
// */
|
|
|
|
|
// String organizeCode = reqBean.getOrganizeCode();
|
|
|
|
|
// StationResultBean resultBean = new StationResultBean();
|
|
|
|
|
// StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
|
// // 根据foreign找出加工规则对应的上下文,判断是否需要打印
|
|
|
|
|
// List<MesProdRuleContext> prodRuleDataContext = mesProductionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
|
|
|
|
// Map<Integer, List<MesProdRuleContext>> prodRuleContextMap = prodRuleDataContext.stream().collect(Collectors.groupingBy(MesProdRuleContext::getForeignKey));
|
|
|
|
|
// //需要打印的数据 String 是打印模板code
|
|
|
|
|
// Map<String, List<MesProduceSnPrintDataModel>> resultData = new HashMap<>();
|
|
|
|
|
// //用于保存客户模板代码 和 模板信息关系
|
|
|
|
|
// Map<String, MesLabelTemplate> labelTemplateMap = new HashMap<>();
|
|
|
|
|
// //返回打印标识 给前端
|
|
|
|
|
// //1. 获取上下文中生成的主条码
|
|
|
|
|
// List<MesProductionPsOutContext> productionPsOutContextList = mesProductionDispatchContextStepService.getProductionPsOutContext(reqBean);
|
|
|
|
|
// //2. 获取条码需要模板、模板代码、打印机 --- 循环遍历条码 封装数据
|
|
|
|
|
// for (MesProductionPsOutContext sn : productionPsOutContextList) {
|
|
|
|
|
// List<MesProdRuleContext> mesProdRuleContexts = prodRuleContextMap.get(sn.getForeignKey());
|
|
|
|
|
// if (mesProdRuleContexts == null || mesProdRuleContexts.isEmpty()) {
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的加工规则丢失,请配置!", sn.getPartNo()));
|
|
|
|
|
// }
|
|
|
|
|
// MesProdRuleContext mesProdRuleContext = mesProdRuleContexts.get(0);
|
|
|
|
|
// Integer isPrint = mesProdRuleContext.getIsPrint();
|
|
|
|
|
// if (isPrint == null || isPrint == CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// String prodLabelTemplate = sn.getProdLabelTemplate();
|
|
|
|
|
// if (prodLabelTemplate == null) {
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的模板信息丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
|
|
|
|
|
// }
|
|
|
|
|
// MesLabelTemplate labelTemplate;
|
|
|
|
|
// // 查模板代码
|
|
|
|
|
// if (!labelTemplateMap.containsKey(prodLabelTemplate)) {
|
|
|
|
|
// labelTemplate = getLabelTemplate(prodLabelTemplate, organizeCode);
|
|
|
|
|
// //模板信息丢失抛出异常
|
|
|
|
|
// if (labelTemplate == null) {
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的模板信息丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
|
|
|
|
|
// }
|
|
|
|
|
// labelTemplateMap.put(prodLabelTemplate, labelTemplate);
|
|
|
|
|
// } else {
|
|
|
|
|
// labelTemplate = labelTemplateMap.get(prodLabelTemplate);
|
|
|
|
|
// }
|
|
|
|
|
// //根据反射获取策略类--封装打印数据
|
|
|
|
|
// String methodCode = labelTemplate.getMethodCode();
|
|
|
|
|
// //模板信息丢失抛出异常
|
|
|
|
|
// if (methodCode == null) {
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的反射类丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
|
|
|
|
|
// }
|
|
|
|
|
// IPrintTemplateStrategyService strategyService = (IPrintTemplateStrategyService) SpringContextsUtil.getBean(methodCode);
|
|
|
|
|
// MesProduceSnPrintDataModel model = strategyService.execute(stepResult, reqBean, sn, organizeCode);
|
|
|
|
|
// if (!stepResult.isCompleted()){
|
|
|
|
|
// execExpSendMsgAndThrowEx(reqBean, resultBean, stepResult.getMsg());
|
|
|
|
|
// }
|
|
|
|
|
// List<MesProduceSnPrintDataModel> printData;
|
|
|
|
|
// if (resultData.containsKey(labelTemplate.getTemplateCode())) {
|
|
|
|
|
// printData = resultData.get(labelTemplate.getTemplateCode());
|
|
|
|
|
// printData.add(model);
|
|
|
|
|
// } else {
|
|
|
|
|
// printData = new ArrayList<>();
|
|
|
|
|
// printData.add(model);
|
|
|
|
|
// resultData.put(labelTemplate.getTemplateCode(), printData);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /** Map<String,Object>
|
|
|
|
|
// * valueList:List<Map<String,Object>>
|
|
|
|
|
// * paramInfo:{
|
|
|
|
|
// * templateContent:xxxx,
|
|
|
|
|
// * labelTemplateParamList: List<Map<String,Object>>
|
|
|
|
|
// * }
|
|
|
|
|
// *
|
|
|
|
|
// */
|
|
|
|
|
// List<Map<String, Object>> printData = new ArrayList<>();
|
|
|
|
|
// Set<String> labelKeys = labelTemplateMap.keySet();
|
|
|
|
|
// List<MesPrintedSnLog> snLogList = new ArrayList<>();
|
|
|
|
|
// for (String labelKey : labelKeys) {
|
|
|
|
|
// Map<String,Object> paramInfo = new HashMap<>();
|
|
|
|
|
// List<MesProduceSnPrintDataModel> dataMaps = resultData.get(labelKey);
|
|
|
|
|
// for (MesProduceSnPrintDataModel dataModel : dataMaps) {
|
|
|
|
|
// MesPrintedSnLog snLog = new MesPrintedSnLog();
|
|
|
|
|
// BeanUtil.copyProperties(dataModel,snLog);
|
|
|
|
|
// snLog.setOrganizeCode(reqBean.getOrganizeCode());
|
|
|
|
|
// ConvertBean.saveOrUpdate(snLog,reqBean.getUserInfo());
|
|
|
|
|
// snLogList.add(snLog);
|
|
|
|
|
// }
|
|
|
|
|
// MesLabelTemplate mesLabelTemplate = labelTemplateMap.get(labelKey);
|
|
|
|
|
// String templateContent = mesLabelTemplate.getTemplateContent();
|
|
|
|
|
// paramInfo.put("templateContent",templateContent);
|
|
|
|
|
// paramInfo.put("labelTemplateParamList",mesLabelTemplate.getLabelTemplateParamList());
|
|
|
|
|
// Map<String, Object> data = new HashMap<>();
|
|
|
|
|
// data.put("paramInfo", paramInfo);
|
|
|
|
|
// data.put("valueList", dataMaps);
|
|
|
|
|
// printData.add(data);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //前端接收到busiTyep是customComponent,并且 dataType是file类型的消息,就需要打印后续消息里的数据,一个模板对应多个打印数据
|
|
|
|
|
// resultBean.setBusiType(MesPcnEnumUtil.STATION_BUSI_TYPE.CUSTOM_COMPONENT.getValue());
|
|
|
|
|
// resultBean.setDataType(MesPcnEnumUtil.STATION_DATA_TYPE.FILE.getValue());
|
|
|
|
|
// resultBean.setResultObj(printData);
|
|
|
|
|
// //3. 发送数据给到前端
|
|
|
|
|
// this.sendMessage(reqBean, resultBean);
|
|
|
|
|
//
|
|
|
|
|
// //todo 更新打印状态
|
|
|
|
|
// //保存打印条码记录
|
|
|
|
|
// snLogRao.saveAll(snLogList);
|
|
|
|
|
// return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesExtEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), stepResult, "执行打印成功!");
|
|
|
|
|
return null;
|
|
|
|
|
String organizeCode = reqBean.getOrganizeCode();
|
|
|
|
|
StationResultBean resultBean = new StationResultBean();
|
|
|
|
|
StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
|
// 根据foreign找出加工规则对应的上下文,判断是否需要打印
|
|
|
|
|
List<MesProdRuleContext> prodRuleDataContext = mesProductionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
|
|
|
|
Map<Integer, List<MesProdRuleContext>> prodRuleContextMap = prodRuleDataContext.stream().collect(Collectors.groupingBy(MesProdRuleContext::getForeignKey));
|
|
|
|
|
//需要打印的数据 String 是打印模板code
|
|
|
|
|
Map<String, List<MesProduceSnPrintDataModel>> resultData = new HashMap<>();
|
|
|
|
|
//用于保存客户模板代码 和 模板信息关系
|
|
|
|
|
Map<String, MesLabelTemplate> labelTemplateMap = new HashMap<>();
|
|
|
|
|
//返回打印标识 给前端
|
|
|
|
|
//1. 获取上下文中生成的主条码
|
|
|
|
|
List<MesProductionPsOutContext> productionPsOutContextList = mesProductionDispatchContextStepService.getProductionPsOutContext(reqBean);
|
|
|
|
|
/**
|
|
|
|
|
* 重构,返回给前端打印数据
|
|
|
|
|
*/
|
|
|
|
|
List<MesProduceSnPrintModel> printModelList = new ArrayList<>();
|
|
|
|
|
//2. 获取条码需要模板、模板代码、打印机 --- 循环遍历条码 封装数据
|
|
|
|
|
for (MesProductionPsOutContext sn : productionPsOutContextList) {
|
|
|
|
|
List<MesProdRuleContext> mesProdRuleContexts = prodRuleContextMap.get(sn.getForeignKey());
|
|
|
|
|
if (mesProdRuleContexts == null || mesProdRuleContexts.isEmpty()) {
|
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的加工规则丢失,请配置!", sn.getPartNo()));
|
|
|
|
|
}
|
|
|
|
|
MesProdRuleContext mesProdRuleContext = mesProdRuleContexts.get(0);
|
|
|
|
|
Integer isPrint = mesProdRuleContext.getIsPrint();
|
|
|
|
|
if (isPrint == null || isPrint == CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String prodLabelTemplate = sn.getProdLabelTemplate();
|
|
|
|
|
if (prodLabelTemplate == null) {
|
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的模板信息丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesProduceSnPrintModel mesProduceSnPrintModel = new MesProduceSnPrintModel();
|
|
|
|
|
// 查模板代码
|
|
|
|
|
MesLabelTemplate labelTemplate = getLabelTemplate(prodLabelTemplate, organizeCode);
|
|
|
|
|
mesProduceSnPrintModel.setMesLabelTemplate(labelTemplate);
|
|
|
|
|
mesProduceSnPrintModel.setProductSn(sn.getProductSn());
|
|
|
|
|
mesProduceSnPrintModel.setOrganizeCode(organizeCode);
|
|
|
|
|
List<MesProduceSn> snList = new ArrayList<>();
|
|
|
|
|
snList.add(sn);
|
|
|
|
|
mesProduceSnPrintModel.getMesProduceSnList().addAll(snList);
|
|
|
|
|
//模板信息丢失抛出异常
|
|
|
|
|
if (labelTemplate == null) {
|
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的模板信息丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
|
|
|
|
|
}
|
|
|
|
|
//根据反射获取策略类--封装打印数据
|
|
|
|
|
String methodCode = labelTemplate.getMethodCode();
|
|
|
|
|
//模板信息丢失抛出异常
|
|
|
|
|
if (methodCode == null) {
|
|
|
|
|
execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的反射类丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//前端接收到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 (MesProductionPsOutContext outSn : productionPsOutContextList) {
|
|
|
|
|
Long id = outSn.getId();
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(outSn.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getNumberSmallerEqualPack(id,"id",ddlPackBean);
|
|
|
|
|
mesProduceSnRao.updateByProperties("printStatus",MesExtEnumUtil.PRINT_STATUS.PRINTED.getValue(),ddlPackBean);
|
|
|
|
|
}
|
|
|
|
|
//保存打印条码记录
|
|
|
|
|
snLogRao.saveAll(snLogList);
|
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesExtEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), stepResult, "执行打印成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -184,8 +160,8 @@ public class MesProductSnPrintStepService extends BaseStepService {
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(templateCode, "templateCode", templatePackBean);
|
|
|
|
|
List<MesLabelTemplate> mesLabelTemplateList = labelTemplateRao.findByHqlWhere(templatePackBean);
|
|
|
|
|
MesLabelTemplate mesLabelTemplate = null;
|
|
|
|
|
if (!mesLabelTemplateList.isEmpty()){
|
|
|
|
|
mesLabelTemplate = mesLabelTemplateList.get(0);
|
|
|
|
|
if (!mesLabelTemplateList.isEmpty()) {
|
|
|
|
|
mesLabelTemplate = mesLabelTemplateList.get(0);
|
|
|
|
|
//级联获取labelTemplateParam
|
|
|
|
|
DdlPackBean templateParamPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(mesLabelTemplate.getId(), "templateId", templateParamPackBean);
|
|
|
|
|