forked from I3-YF/i3plus-mes-pcn-yfai
重构打印
parent
6ab4f0f323
commit
bc571b6173
@ -0,0 +1,60 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.numberrule;
|
||||
|
||||
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.INumberRulePackAttributeStrategyService;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
|
||||
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : Castle
|
||||
* @CreateDate : 2024/7/6 13:51
|
||||
* @Modify:
|
||||
**/
|
||||
@Component
|
||||
public class B2mAndGqaaNumberRuleStrategyService implements INumberRulePackAttributeStrategyService {
|
||||
@Override
|
||||
public GenSerialNoModel execute(GenSerialNoModel genSerialNoModel) {
|
||||
|
||||
MesPart mesPart = (MesPart) genSerialNoModel.getDataMap().get("mesPart");
|
||||
Date date = new Date();
|
||||
// genSerialNoModel.setRuleCode(numberRule.getRuleCode());
|
||||
//${SPILTRULE}${partNo}${SPILTRULE}${SPILTRULE}${year}${month}${day}${serialNo}${SPILTRULE}
|
||||
//规格号,零件号,供应商,生产线代码,年,月,日,序列号,软件版本号
|
||||
// ----广汽 1B2M & 广新 GQAA_BARCODE 21位
|
||||
//规格号 ${SPILTRULE} +
|
||||
//零件简号 {partNo} - mesPart.getPartSnParam()
|
||||
genSerialNoModel.setPartNo(mesPart.getPartSnParam());
|
||||
//供应商号 supplierNo ---固定VD501 ${SPILTRULE}拼接
|
||||
//生产线代码 workCenterCode 或者 fixWorkCenterCode (取配置值) ${SPILTRULE}
|
||||
//日期${dateShort}
|
||||
genSerialNoModel.setYear(getYearShort(date));
|
||||
genSerialNoModel.setMonth(getMonthShort(date));
|
||||
genSerialNoModel.setDay(getDayShort(date));
|
||||
//获取客户零件号
|
||||
// String custPartNo = custPart.getCustPartNo();
|
||||
//供应商生产流水号 ${serialNo} 采用34进制 获取条码是十进制,需要截取转换成34位
|
||||
//软件版本号${versionNo} ${SPILTRULE}
|
||||
return genSerialNoModel;
|
||||
|
||||
}
|
||||
|
||||
private String getYearShort(Date date) {
|
||||
return MesExtEnumUtil.YEAR_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date)));
|
||||
}
|
||||
|
||||
private String getMonthShort(Date date) {
|
||||
|
||||
return MesExtEnumUtil.MONTH_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getMonth(date)));
|
||||
}
|
||||
|
||||
private String getDayShort(Date date) {
|
||||
return TimeTool.getDay(date);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.numberrule;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
|
||||
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.INumberRulePackAttributeStrategyService;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
||||
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesCustomerPart;
|
||||
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesCustomerPartRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : Castle
|
||||
* @CreateDate : 2024/6/26 9:38
|
||||
* @Modify:
|
||||
**/
|
||||
@Component
|
||||
public class XiaoPengNewNumberRuleStrategyService implements INumberRulePackAttributeStrategyService {
|
||||
|
||||
@Autowired
|
||||
private MesCustomerPartRepository customerPartRepository;
|
||||
|
||||
@Override
|
||||
public GenSerialNoModel execute(GenSerialNoModel model) {
|
||||
|
||||
if (StringUtils.isEmpty(model.getOrganizeCode()))
|
||||
MesPcnException.throwMesBusiException("XiaoPengNumberRuleStrategyService执行异常:缺失组织代码参数");
|
||||
if (StringUtils.isEmpty(model.getPartNo()))
|
||||
MesPcnException.throwMesBusiException("XiaoPengNumberRuleStrategyService执行异常:缺失零件编码参数");
|
||||
|
||||
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
|
||||
DdlPreparedPack.getStringEqualPack(model.getPartNo(), "erpPartNo", ddlPackBean);
|
||||
MesCustomerPart customerPart = customerPartRepository.getByProperty(ddlPackBean);
|
||||
if (null == customerPart)
|
||||
MesPcnException.throwMesBusiException("请检查客户零件信息,零件[%s]客户零件关系未维护", model.getPartNo());
|
||||
|
||||
model.setCustPartNo(customerPart.getCustPartNo());
|
||||
|
||||
Date date = new Date();
|
||||
// XIAO_PENG 原客户条码.小鹏汽车 NoSortBarCodeGZ-new
|
||||
//{custPartNo}{SPILTRULE}{year}{month}{day}{hour}{minute}{second}{serialNo}
|
||||
//客户零件号
|
||||
//String custPartNo = model.getCustPartNo();
|
||||
//日期${dateShort}
|
||||
model.setYear(getYearShort(date));
|
||||
model.setMonth(getMonthShort(date));
|
||||
model.setDay(getDayShort(date));
|
||||
//中杠 -
|
||||
//生产日期 + 时间 yyyyMMddHHmmss
|
||||
//流水号 5位 每天从1开始
|
||||
return model;
|
||||
}
|
||||
|
||||
private String getYearShort(Date date) {
|
||||
return MesExtEnumUtil.YEAR_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date)));
|
||||
}
|
||||
|
||||
private String getMonthShort(Date date) {
|
||||
|
||||
return MesExtEnumUtil.MONTH_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getMonth(date)));
|
||||
}
|
||||
|
||||
private String getDayShort(Date date) {
|
||||
return TimeTool.getDay(date);
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPartService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
|
||||
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.base.IConfigService;
|
||||
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.exception.ImppExceptionEnum;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
||||
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.*;
|
||||
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesCustomerPartRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : Castle
|
||||
* @CreateDate : 2024/6/17 16:43
|
||||
* @Modify:
|
||||
**/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class XiaoPengNewPrintStrategy implements IPrintTemplateStrategyService {
|
||||
@Autowired
|
||||
private MesCustomerPartRepository mesCustomerPartRDao;
|
||||
|
||||
@Autowired
|
||||
private ISyncFuncService syncFuncService;
|
||||
|
||||
@Autowired
|
||||
private SnowflakeIdMaker snowflakeIdMaker;
|
||||
|
||||
@Autowired
|
||||
private IMesPartService mesPartService;
|
||||
|
||||
@Autowired
|
||||
private IConfigService configService;
|
||||
|
||||
@Override
|
||||
public MesProduceSnPrintModel execute(GenSerialNoModel genSerialNoModel, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule) {
|
||||
String format = DateUtil.BASE_FORMAT;
|
||||
Date date = new Date();
|
||||
String organizeCode = mesProduceSnPrintModel.getOrganizeCode();
|
||||
//gz-xiaopeng
|
||||
//客户条码-小鹏汽车 gz-xiaopeng
|
||||
//{custPartNo}{year}{month}{day}{serialNo}
|
||||
//客户零件号
|
||||
String custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo();
|
||||
genSerialNoModel.setCustPartNo(custPartNo);
|
||||
//年月日缩写
|
||||
genSerialNoModel.setYear(getYearShort(date));
|
||||
genSerialNoModel.setMonth(getMonthShort(date));
|
||||
genSerialNoModel.setDay(getDayShort(date));
|
||||
genSerialNoModel.setRuleCode(numberRule.getRuleCode());
|
||||
|
||||
MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode);
|
||||
|
||||
MesConfig mesConfig = configService.getMesConfigByCfgCode(MesPcnExtConstWords.ORGANIZE_NAME, organizeCode);
|
||||
if (null == mesConfig || StringUtils.isEmpty(mesConfig.getCfgValue())) {
|
||||
throw ImppExceptionBuilder.newInstance().setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode()).setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode()).setErrorDetail("没有维护当前工厂的系统参数!").build();
|
||||
}
|
||||
String organizeName = mesConfig.getCfgValue();
|
||||
|
||||
//流水号 5位 每天从1开始
|
||||
for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) {
|
||||
ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), organizeCode, 1);
|
||||
String sn = resultBean.getResultList().get(0).toString();
|
||||
Integer serialNoLength = numberRule.getSerialnoLength();
|
||||
String serialNo = sn.substring(sn.length() - serialNoLength);
|
||||
//保存条码信息
|
||||
MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format);
|
||||
produceSn.setCustPartNo(custPartNo);
|
||||
//封装打印信息
|
||||
MesProduceSnPrintDataModel printDataModel = getModel(produceSn, serialNo, custPartNo, organizeName);
|
||||
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(printDataModel);
|
||||
mesProduceSnPrintModel.getMesProduceSnList().add(produceSn);
|
||||
//保存打印记录
|
||||
MesPrintedSnLog snLog = new MesPrintedSnLog();
|
||||
ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName());
|
||||
BeanUtil.copyProperties(printDataModel,snLog);
|
||||
mesProduceSnPrintModel.getMesPrintedSnLogList().add(snLog);
|
||||
}
|
||||
|
||||
return mesProduceSnPrintModel;
|
||||
}
|
||||
|
||||
private MesCustomerPart getMesCustomerPart(MesProduceSnPrintModel mesProduceSnPrintModel) {
|
||||
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(mesProduceSnPrintModel.getOrganizeCode());
|
||||
DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getPartNo(), "erpPartNo", ddlPackBean);
|
||||
MesCustomerPart mesCustomerPart = mesCustomerPartRDao.getByProperty(ddlPackBean);
|
||||
if (Objects.isNull(mesCustomerPart)) {
|
||||
MesPcnException.throwMesBusiException("物料【%s】客户零件关系未维护", mesProduceSnPrintModel.getPartNo());
|
||||
}
|
||||
return mesCustomerPart;
|
||||
}
|
||||
|
||||
private String getYearShort(Date date) {
|
||||
String yearStr = MesExtEnumUtil.YEAR_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date)));
|
||||
if (StringUtils.isEmpty(yearStr)) {
|
||||
MesPcnException.throwMesBusiException("【%s】年月简号不存在", TimeTool.getYear(date));
|
||||
}
|
||||
return yearStr;
|
||||
}
|
||||
|
||||
private String getMonthShort(Date date) {
|
||||
String monthStr = MesExtEnumUtil.MONTH_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getMonth(date)));
|
||||
if (StringUtils.isEmpty(monthStr)) {
|
||||
MesPcnException.throwMesBusiException("【%s】月简号不存在", TimeTool.getMonth(date));
|
||||
}
|
||||
return monthStr;
|
||||
}
|
||||
|
||||
private String getDayShort(Date date) {
|
||||
String day = TimeTool.getDay(date);
|
||||
return day;
|
||||
}
|
||||
|
||||
private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, String userName, Double qty, String format) {
|
||||
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.getNowTime(format));
|
||||
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, String no, String custPartNo, String factoryName) {
|
||||
MesProduceSnPrintDataModel mesProduceSnPrintDataModel = new MesProduceSnPrintDataModel();
|
||||
mesProduceSnPrintDataModel.setFactoryName(factoryName);
|
||||
mesProduceSnPrintDataModel.setPartNo(produceSn.getPartNo());
|
||||
mesProduceSnPrintDataModel.setPartName(produceSn.getPartName());
|
||||
mesProduceSnPrintDataModel.setNo(no);
|
||||
mesProduceSnPrintDataModel.setBarcode(produceSn.getProductSn());
|
||||
mesProduceSnPrintDataModel.setCustPartNo(custPartNo);
|
||||
mesProduceSnPrintDataModel.setProductDate(produceSn.getLotNo());
|
||||
return mesProduceSnPrintDataModel;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue