forked from I3-YF/i3plus-mes-pcn-yfai
重新提交自定义打印功能,用于合并test
parent
9953e8a9ac
commit
17b7c10a7a
@ -0,0 +1,156 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesCustomerPartService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPartService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesTemplateService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesPrintedSnLogService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel;
|
||||||
|
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.api.iservice.busi.ISyncFuncService;
|
||||||
|
import cn.estsh.i3plus.mes.pcn.util.DateUtil;
|
||||||
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||||
|
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesCustomerPart;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesNumberRule;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
||||||
|
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.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :通用打印方式
|
||||||
|
* @Reference :
|
||||||
|
* @Author : junsheng.li
|
||||||
|
* @CreateDate 2024/9/26 18:20
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class CustomFieldPrintStrategy implements IPrintTemplateStrategyService {
|
||||||
|
@Autowired
|
||||||
|
private ISyncFuncService syncFuncService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SnowflakeIdMaker snowflakeIdMaker;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesPartService mesPartService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesPrintedSnLogService mesPrintedSnLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesCustomerPartService mesCustomerPartService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesTemplateService mesTemplateService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MesProduceSnPrintModel execute(GenSerialNoModel genSerialNoModel, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule, StepResult stepResult, StationRequestBean reqBean, Boolean isStep) {
|
||||||
|
String organizeCode = mesProduceSnPrintModel.getOrganizeCode();
|
||||||
|
//物料信息
|
||||||
|
MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode);
|
||||||
|
MesCustomerPart customerPart = (!Objects.isNull(genSerialNoModel) && !CollectionUtils.isEmpty(genSerialNoModel.getDataMap()) && genSerialNoModel.getDataMap().containsKey(MesCustomerPart.class.getSimpleName())) ? (MesCustomerPart) genSerialNoModel.getDataMap().get(MesCustomerPart.class.getSimpleName()) : mesCustomerPartService.getMesCustomerPart(organizeCode,mesProduceSnPrintModel.getPartNo());
|
||||||
|
Map<String, Object> customParamValue = mesTemplateService.queryMesLabelTemplateParamPartValue(mesPart.getPartNo(), mesPart.getProductLabelTemplate(), organizeCode);
|
||||||
|
if (!isStep){
|
||||||
|
if (!Objects.isNull(customerPart)) {
|
||||||
|
genSerialNoModel.setCustPartNo(customerPart.getCustPartNo());
|
||||||
|
}
|
||||||
|
for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) {
|
||||||
|
//保存条码信息
|
||||||
|
MesProduceSn produceSn = generateMesProduceSn(mesPart, syncFuncService.syncSerialNo(genSerialNoModel.partSnParam(mesPart.getPartSnParam()), mesProduceSnPrintModel.getUserName(), organizeCode, 1).getResultList().get(0).toString(), mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty());
|
||||||
|
//封装打印信息
|
||||||
|
MesProduceSnPrintDataModel printDataModel = getModel(produceSn, customerPart);
|
||||||
|
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().clear();
|
||||||
|
mesProduceSnPrintModel.getMesProduceSnList().add(produceSn);
|
||||||
|
Map<String, Object> printTemplateData = new HashMap<>(getPrintContextMap(produceSn, customerPart));
|
||||||
|
printTemplateData.putAll(customParamValue);
|
||||||
|
mesProduceSnPrintModel.getPrintContextList().add(printTemplateData);
|
||||||
|
//保存打印记录
|
||||||
|
mesProduceSnPrintModel.getMesPrintedSnLogList().add(mesPrintedSnLogService.getMesCustomPrintedSnLog(mesProduceSnPrintModel.getUserName(), organizeCode, printDataModel, printTemplateData));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
MesProduceSn mesProduceSn = mesProduceSnPrintModel.getMesProduceSnList().get(0);
|
||||||
|
//封装打印信息
|
||||||
|
MesProduceSnPrintDataModel printDataModel = getModel(mesProduceSn, customerPart);
|
||||||
|
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().clear();
|
||||||
|
Map<String, Object> printTemplateData = new HashMap<>(getPrintContextMap(mesProduceSn, customerPart));
|
||||||
|
printTemplateData.putAll(customParamValue);
|
||||||
|
List<Map<String, Object>> printDataMapList = new ArrayList<>();
|
||||||
|
printDataMapList.add(printTemplateData);
|
||||||
|
mesProduceSnPrintModel.getPrintContextList().add(packResultMap(mesProduceSnPrintModel, printDataMapList));
|
||||||
|
|
||||||
|
//保存打印记录
|
||||||
|
mesProduceSnPrintModel.getMesPrintedSnLogList().add(mesPrintedSnLogService.getMesCustomPrintedSnLog(mesProduceSnPrintModel.getUserName(), organizeCode, printDataModel, printTemplateData));
|
||||||
|
}
|
||||||
|
return mesProduceSnPrintModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, String userName, Double qty) {
|
||||||
|
MesProduceSn mesProduceSn = new MesProduceSn();
|
||||||
|
mesProduceSn.setSerialNumber(snowflakeIdMaker.nextId() + "");
|
||||||
|
mesProduceSn.setProductSn(sn);
|
||||||
|
mesProduceSn.setCustSn(sn);
|
||||||
|
mesProduceSn.setPartNo(mesPart.getPartNo());
|
||||||
|
mesProduceSn.setPartName(mesPart.getPartName());
|
||||||
|
mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate());
|
||||||
|
mesProduceSn.setCustLabelTemplate(mesPart.getCustLabelTemplate());
|
||||||
|
mesProduceSn.setProdLabelTemplate(mesPart.getProductLabelTemplate());
|
||||||
|
mesProduceSn.setQty(qty);
|
||||||
|
mesProduceSn.setSnStatus(MesExtEnumUtil.PRODUCE_SN_STATUS.CREATE.getValue());
|
||||||
|
mesProduceSn.setQcStatus(MesExtEnumUtil.PRODUCE_QC_STATUS.QUALIFIED.getValue());
|
||||||
|
mesProduceSn.setLotNo(TimeTool.getToday());
|
||||||
|
mesProduceSn.setPrintCount(MesPcnExtConstWords.ONE);
|
||||||
|
mesProduceSn.setPrintStatus(MesExtEnumUtil.PRINT_STATUS.PRINTED.getValue());
|
||||||
|
mesProduceSn.setOrganizeCode(mesPart.getOrganizeCode());
|
||||||
|
ConvertBean.serviceModelInitialize(mesProduceSn, userName);
|
||||||
|
return mesProduceSn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MesProduceSnPrintDataModel getModel(MesProduceSn produceSn, MesCustomerPart customerPart) {
|
||||||
|
MesProduceSnPrintDataModel mesProduceSnPrintDataModel = new MesProduceSnPrintDataModel();
|
||||||
|
mesProduceSnPrintDataModel.setPartNo(produceSn.getPartNo());
|
||||||
|
mesProduceSnPrintDataModel.setPartName(produceSn.getPartName());
|
||||||
|
if (!Objects.isNull(customerPart)) {
|
||||||
|
mesProduceSnPrintDataModel.setCustPartNo(customerPart.getCustPartNo());
|
||||||
|
}
|
||||||
|
mesProduceSnPrintDataModel.setBarcode(produceSn.getProductSn());
|
||||||
|
mesProduceSnPrintDataModel.setPrintDate(TimeTool.getNowTime(true));
|
||||||
|
mesProduceSnPrintDataModel.setUserName(produceSn.getCreateUser());
|
||||||
|
mesProduceSnPrintDataModel.setProductDate(TimeTool.parseStringFormat(produceSn.getLotNo(), DateUtil.SHORT_FORMAT, "yyyy/MM/dd"));
|
||||||
|
return mesProduceSnPrintDataModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> getPrintContextMap(MesProduceSn produceSn, MesCustomerPart customerPart) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put(MesPcnExtConstWords.PART_NO, produceSn.getPartNo());
|
||||||
|
result.put(MesPcnExtConstWords.PART_NAME, produceSn.getPartName());
|
||||||
|
if (!Objects.isNull(customerPart)) {
|
||||||
|
result.put(MesPcnExtConstWords.CUST_PART_NO, customerPart.getCustPartNo());
|
||||||
|
}
|
||||||
|
result.put(MesPcnExtConstWords.PRINT_BAR_CODE, produceSn.getProductSn());
|
||||||
|
result.put(MesPcnExtConstWords.PRINT_DATE, TimeTool.getNowTime(true));
|
||||||
|
result.put(MesPcnExtConstWords.USER_NAME, produceSn.getCreateUser());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> packResultMap(MesProduceSnPrintModel printModel, List<Map<String, Object>> printTemplateDateList) {
|
||||||
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
|
resultMap.put(MesPcnExtConstWords.LABEL_TEMPLATE, printModel.getMesLabelTemplate());
|
||||||
|
resultMap.put(MesPcnExtConstWords.TEMPLATE_DATA, printTemplateDateList);
|
||||||
|
resultMap.put(MesPcnExtConstWords.TEMPLATE_CODE, printModel.getMesLabelTemplate().getTemplateCode());
|
||||||
|
resultMap.put(MesPcnExtConstWords.PRINTER, printModel.getPrinter());
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue