diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintService.java index 0e950aa..d4aae9a 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintService.java @@ -3,11 +3,13 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi; 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.IMesProduceSnPrintService; +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.INumberRulePackAttributeStrategyService; 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; @@ -24,15 +26,14 @@ import cn.estsh.i3plus.pojo.mes.repository.*; 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.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 org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -79,6 +80,9 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService { @Autowired private IMesPrintedSnLogRepository mesPrintedSnRao; + @Autowired + private MesLabelTemplateRepository templateRao; + @Override public MesProduceSnPrintModel findMesPackingDefine(MesProduceSnPrintModel mesProduceSnPrintModel) { //查询SAP下发物料信息 @@ -113,13 +117,7 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService { @Override public MesProduceSnPrintModel doPrint(MesProduceSnPrintModel mesProduceSnPrintModel) { String organizeCode = mesProduceSnPrintModel.getOrganizeCode(); - // 获取工厂名称 - 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(); + //物料信息 MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode); //条码生成 @@ -136,217 +134,64 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService { MesPcnException.throwMesBusiException("零件号【】打印规则查询不到!", mesPart.getPartNo()); } MesNumberRule numberRule = ruleList.get(0); + String methodNameExt = numberRule.getMethodNameExt(); + if (StringUtils.isEmpty(methodNameExt)) { + throw ImppExceptionBuilder.newInstance().setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode()) + .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode()) + .setErrorDetail(String.format("当前编码规则【%s】未维护构造入参方法名", snRule)).build(); - //打印日期格式 - String format = "yyyy/MM/dd"; - if (MesExtEnumUtil.MES_PRINT_TEMPLATE.NO_SORT_BAR_CODE_GZ.getCode().equals(printTemplate) || MesExtEnumUtil.MES_PRINT_TEMPLATE.XIAO_PENG.getCode().equals(printTemplate) || MesExtEnumUtil.MES_PRINT_TEMPLATE.XIAO_PENG_NEW.getCode().equals(printTemplate)) { - format = DateUtil.BASE_FORMAT; } - int printQty = mesProduceSnPrintModel.getPrintQty(); - Date date = new Date(); - - //if 1B2M || GQAA_BARCODE - if (MesExtEnumUtil.MES_PRINT_TEMPLATE.B2M.getCode().equals(printTemplate) || MesExtEnumUtil.MES_PRINT_TEMPLATE.GQAA.getCode().equals(printTemplate)) { - GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); - 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 = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo(); - //供应商生产流水号 ${serialNo} 采用34进制 获取条码是十进制,需要截取转换成34位 - //软件版本号${versionNo} ${SPILTRULE} - for (int i = 0; i < printQty; i++) { - ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), organizeCode, 1); - String sn = resultBean.getResultList().get(0).toString(); - int versionNoLength = numberRule.getSpiltRule().substring(numberRule.getSpiltRule().lastIndexOf(",") + 1).length(); - Integer serialNoLength = numberRule.getSerialnoLength(); - String snPrefix = sn.substring(0, sn.length() - versionNoLength - serialNoLength); - String snSuffix = sn.substring(sn.length() - versionNoLength); - String serialNo = sn.substring(sn.length() - versionNoLength - serialNoLength, sn.length() - versionNoLength); - String serialNo34 = toBase34(Integer.parseInt(serialNo)); - serialNo34 = stringFormat(serialNo34, 4, false, "0"); - sn = snPrefix + serialNo34 + snSuffix; - //保存条码信息 - MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format); - //封装打印信息 - MesProduceSnPrintDataModel model = getModel(produceSn, serialNo, custPartNo, organizeName); - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); - mesProduceSnRDao.insert(produceSn); - //保存打印记录 - MesPrintedSnLog snLog = new MesPrintedSnLog(); - ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); - BeanUtil.copyProperties(model,snLog); - mesPrintedSnRao.insert(snLog); - } - - } else if (MesExtEnumUtil.MES_PRINT_TEMPLATE.GQXNY.getCode().equals(printTemplate)) { - - // else if GQXNY - //----广乘 45位 GQXNY - //{custPartNo}{SPILTURE}{custCode}{spiltrure}{spiltrule}{year}{serialNo}{spilture}{spiltrule} - //客户零件号-扩展位-客户代码-预留位000-产线1-年月日-条码-扩展0000-追溯位+ - //零件长号---17位,不足17位 右边补* - GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); - genSerialNoModel.setRuleCode(numberRule.getRuleCode()); - //获取客户零件号 - String custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo(); - String custPartNoFormat = stringFormat(custPartNo, 17); - genSerialNoModel.setCustPartNo(custPartNoFormat); - //拓展位 2位 00 包含0~9,A~Z 不使用时,补“0”填充 {SPILTRULE} - //供应商代码 7位 供应商代码 0~9,A~Z;不足7位 右测补* - MesConfig supplierConfig = configService.getMesConfigByCfgCodeKeyOrg(MesPcnExtConstWords.SUPPLIER_CODE, MesExtEnumUtil.MES_PRINT_TEMPLATE.GQXNY.getValue(), organizeCode); - String supplierCode = supplierConfig.getCfgValue(); - String supplierCodeFormat = stringFormat(supplierCode, 7); - genSerialNoModel.setCustCode(supplierCodeFormat); - //扩展位 3位 预留扩展位0~9 A~Z 不使用时,补 0 {SPILTRULE} - //产线 1位 供应商产线号,表示由数字1~9 和字母A~Z(I/O除外)组成; {SPILTRULE} - //年月日 6位 yyMMdd 零部件生产日期,年月日各2位 - String year = TimeTool.pareDateToString("yyMMdd", date); - genSerialNoModel.setYear(year); - //流水号 4位 采用34进制 0001~ZZZZ (I、O除外)顺位进行标注 (同广汽 & 广新) {serialNo} - //扩展位 4位 预留扩展位信息,包含0~9和字母A~Z,不使用时,补“0” 填充; {SPILTRULE} - //追溯标识 1位 + 代表精确按件追溯,$标识按批追溯, % 代表按生产方式追溯 {SPILTRULE} - for (int i = 0; i < printQty; i++) { - ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), organizeCode, 1); - String sn = resultBean.getResultList().get(0).toString(); - String snPrefix = sn.substring(0, sn.length() - 12); - String snSuffix = sn.substring(sn.length() - 5); - String serialNo = sn.substring(sn.length() - 12, sn.length() - 5); - String serialNo34 = toBase34(Integer.parseInt(serialNo)); - serialNo34 = stringFormat(serialNo34, 4, false, "0"); - sn = snPrefix + serialNo34 + snSuffix; - //保存条码信息 - MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format); - //封装打印信息 - MesProduceSnPrintDataModel model = getModel(produceSn, serialNo, custPartNo, organizeName); - model.setSupplierCode(supplierCode); - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); - mesProduceSnRDao.insert(produceSn); - //保存打印记录 - MesPrintedSnLog snLog = new MesPrintedSnLog(); - ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); - BeanUtil.copyProperties(model,snLog); - mesPrintedSnRao.insert(snLog); - } - - } else if (MesExtEnumUtil.MES_PRINT_TEMPLATE.NO_SORT_BAR_CODE_GZ.getCode().equals(printTemplate)) { - // noSortBarCodeGz - //{partNo}{year}{month}{day}{serialNo} - //内部条码, 批量打印 NoSortBarCodeGZ - //零件号 partNo - String partNo = mesPart.getPartNo(); - GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); - genSerialNoModel.setRuleCode(numberRule.getRuleCode()); - genSerialNoModel.setPartNo(partNo); - //年月日 yyyyMMdd - //流水号 4位 每天从1开始 - for (int i = 0; i < printQty; 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); - //封装打印信息 - MesProduceSnPrintDataModel model = getModel(produceSn, serialNo, mesProduceSnPrintModel.getCustPartNo(), organizeName); - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); - mesProduceSnRDao.insert(produceSn); - //保存打印记录 - MesPrintedSnLog snLog = new MesPrintedSnLog(); - ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); - BeanUtil.copyProperties(model,snLog); - mesPrintedSnRao.insert(snLog); - } - } else if (MesExtEnumUtil.MES_PRINT_TEMPLATE.XIAO_PENG.getCode().equals(printTemplate)) { - format = DateUtil.BASE_FORMAT; - // XIAO_PENG 原客户条码.小鹏汽车 NoSortBarCodeGZ-new - //{custPartNo}{SPILTRULE}{year}{month}{day}{hour}{minute}{second}{serialNo} - GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); - genSerialNoModel.setRuleCode(numberRule.getRuleCode()); - //客户零件号 - String custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo(); - genSerialNoModel.setCustPartNo(custPartNo); - //日期${dateShort} - genSerialNoModel.setYear(getYearShort(date)); - genSerialNoModel.setMonth(getMonthShort(date)); - genSerialNoModel.setDay(getDayShort(date)); - //中杠 - - //生产日期 + 时间 yyyyMMddHHmmss - //流水号 5位 每天从1开始 - for (int i = 0; i < printQty; 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); - //封装打印信息 - MesProduceSnPrintDataModel model = getModel(produceSn, serialNo, mesProduceSnPrintModel.getCustPartNo(), organizeName); - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); - mesProduceSnRDao.insert(produceSn); - //保存打印记录 - MesPrintedSnLog snLog = new MesPrintedSnLog(); - ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); - BeanUtil.copyProperties(model,snLog); - mesPrintedSnRao.insert(snLog); - } - - } else if (MesExtEnumUtil.MES_PRINT_TEMPLATE.XIAO_PENG_NEW.getCode().equals(printTemplate)) { - format = "yyyy-MM-dd"; - //gz-xiaopeng - //客户条码-小鹏汽车 gz-xiaopeng - //{custPartNo}{year}{month}{day}{serialNo} - GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); - //客户零件号 - String custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo(); - genSerialNoModel.setCustPartNo(custPartNo); - //年月日缩写 - genSerialNoModel.setYear(getYearShort(date)); - genSerialNoModel.setMonth(getMonthShort(date)); - genSerialNoModel.setDay(getDayShort(date)); - genSerialNoModel.setRuleCode(numberRule.getRuleCode()); - //流水号 5位 每天从1开始 - for (int i = 0; i < printQty; 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 model = getModel(produceSn, serialNo, custPartNo, organizeName); - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); - mesProduceSnRDao.insert(produceSn); - //保存打印记录 - MesPrintedSnLog snLog = new MesPrintedSnLog(); - ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); - BeanUtil.copyProperties(model,snLog); - mesPrintedSnRao.insert(snLog); - } + // 获取打印模板 + MesLabelTemplate mesLabelTemplate = mesTemplateService.getMesLabelTemplate(printTemplate); + String methodCode = mesLabelTemplate.getMethodCode(); + if (StringUtils.isEmpty(methodCode)) { + throw ImppExceptionBuilder.newInstance().setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode()) + .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode()) + .setErrorDetail(String.format("当前打印模板【%s】未维护方法名", printTemplate)).build(); } + + INumberRulePackAttributeStrategyService packStrategy = (INumberRulePackAttributeStrategyService) SpringContextsUtil.getBean(methodNameExt); + GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); + genSerialNoModel.setRuleCode(numberRule.getRuleCode()); + genSerialNoModel.setPartNo(mesPart.getPartNo()); + genSerialNoModel = packStrategy.execute(genSerialNoModel); + MesCustomerPart mesCustomerPart = getMesCustomerPart(mesProduceSnPrintModel); + genSerialNoModel.setCustPartNo(mesCustomerPart.getCustPartNo()); + Map dataMap = new HashMap<>(); + dataMap.put("mesPart", mesPart); + dataMap.put("mesCustomerPart", mesCustomerPart); + IPrintTemplateStrategyService templateStrategy = (IPrintTemplateStrategyService) SpringContextsUtil.getBean(methodCode); + + MesProduceSnPrintModel resultModel = templateStrategy.execute(genSerialNoModel, mesProduceSnPrintModel, numberRule); + + resultModel.getMesProduceSnList().forEach(mesProduceSn -> { + //保存条码 + mesProduceSnRDao.insert(mesProduceSn); + }); + resultModel.getMesPrintedSnLogList().forEach(model -> { + //保存打印记录 + MesPrintedSnLog snLog = new MesPrintedSnLog(); + ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); + BeanUtil.copyProperties(model, snLog); + mesPrintedSnRao.insert(snLog); + }); + + resultModel.setMesLabelTemplate(mesLabelTemplate); + resultModel.setMesPrintedSnLogList(null); + resultModel.setMesProduceSnList(null); + return resultModel; //条码补打 } else { //查找打印记录 DdlPackBean snLogPackBean = DdlPackBean.getDdlPackBean(organizeCode); - DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getProductSn(),"barcode",snLogPackBean); + DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getProductSn(), "barcode", snLogPackBean); List snLogList = mesPrintedSnRao.findByHqlWhere(snLogPackBean); - if (snLogList.isEmpty()){ + if (snLogList.isEmpty()) { MesPcnException.throwMesBusiException("条码【】查询不到打印记录!", mesProduceSnPrintModel.getProductSn()); } MesPrintedSnLog mesPrintedSnLog = snLogList.get(0); MesProduceSnPrintDataModel model = new MesProduceSnPrintDataModel(); - BeanUtil.copyProperties(mesPrintedSnLog,model); + BeanUtil.copyProperties(mesPrintedSnLog, model); mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); } //获取打印模板信息 @@ -396,44 +241,6 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService { return mesProduceSnPrintDataModel; } -// private List getSerialNoList(MesProduceSnPrintModel mesProduceSnPrintModel) { -// List serialNoList = new ArrayList<>(); -// //获取系统参数 -// String configKey = MesPcnEnumUtil.PRINT_TEMPLATE.codeOfValue(mesProduceSnPrintModel.getPrintTemplate()); -// if (StringUtils.isEmpty(configKey)) { -// MesPcnException.throwMesBusiException("打印模板未匹配到流水码规则"); -// } -// MesConfig mesConfig = mesConfigService.getMesConfig(mesProduceSnPrintModel.getOrganizeCode(), configKey); -// int cfgValue = StringUtils.isEmpty(mesConfig.getCfgValue()) || !CheckTool.isInteger(mesConfig.getCfgValue()) ? 1 : Integer.parseInt(mesConfig.getCfgValue()); -// if (MesPcnEnumUtil.PRINT_TEMPLATE.B2M.getCode().equals(mesProduceSnPrintModel.getPrintTemplate()) || MesPcnEnumUtil.PRINT_TEMPLATE.GQAA.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { -// if (StringUtils.isEmpty(mesConfig.getCfgValueDesc()) || !TimeTool.getYear().equals(mesConfig.getCfgValueDesc())) { -// cfgValue = 1; -// mesConfig.setCfgValueDesc(TimeTool.getYear()); -// } -// for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) { -// serialNoList.add(stringFormat(toBase34(cfgValue), 4, false, "0")); -// cfgValue++; -// } -// } else if (MesPcnEnumUtil.PRINT_TEMPLATE.GQXNY.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { -// for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) { -// serialNoList.add(String.format("%04d", cfgValue)); -// cfgValue++; -// } -// } else if (MesPcnEnumUtil.PRINT_TEMPLATE.NO_SORT_BAR_CODE_GZ.getCode().equals(mesProduceSnPrintModel.getPrintTemplate()) || MesPcnEnumUtil.PRINT_TEMPLATE.NO_SORT_BAR_CODE_GZ_NEW.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { -// if (StringUtils.isEmpty(mesConfig.getCfgValueDesc()) || !TimeTool.getToday().equals(mesConfig.getCfgValueDesc())) { -// cfgValue = 1; -// mesConfig.setCfgValueDesc(TimeTool.getToday()); -// } -// for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) { -// serialNoList.add(String.format("%05d", cfgValue)); -// cfgValue++; -// } -// } -// mesConfig.setCfgValue(String.valueOf(cfgValue)); -// ConvertBean.serviceModelUpdate(mesConfig, mesProduceSnPrintModel.getUserName()); -// mesConfigRDao.update(mesConfig); -// return serialNoList; -// } private MesCustomerPart getMesCustomerPart(MesProduceSnPrintModel mesProduceSnPrintModel) { DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(mesProduceSnPrintModel.getOrganizeCode()); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/B2mAndGqaaNumberRuleStrategyService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/B2mAndGqaaNumberRuleStrategyService.java new file mode 100644 index 0000000..11dade0 --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/B2mAndGqaaNumberRuleStrategyService.java @@ -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); + } +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/GqxnyNumberRuleStrategyService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/GqxnyNumberRuleStrategyService.java new file mode 100644 index 0000000..a5ba133 --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/GqxnyNumberRuleStrategyService.java @@ -0,0 +1,88 @@ +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.numberrule; + +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.INumberRulePackAttributeStrategyService; +import cn.estsh.i3plus.platform.common.tool.TimeTool; +import cn.estsh.i3plus.pojo.mes.bean.MesConfig; +import cn.estsh.i3plus.pojo.mes.bean.MesCustomerPart; +import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel; +import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * @Description : + * @Reference : + * @Author : Castle + * @CreateDate : 2024/7/6 14:01 + * @Modify: + **/ +@Component +public class GqxnyNumberRuleStrategyService implements INumberRulePackAttributeStrategyService { + @Autowired + private IConfigService configService; + @Override + public GenSerialNoModel execute(GenSerialNoModel genSerialNoModel) { + Date date = new Date(); + //----广乘 45位 GQXNY + //{custPartNo}{SPILTURE}{custCode}{spiltrure}{spiltrule}{year}{serialNo}{spilture}{spiltrule} + //客户零件号-扩展位-客户代码-预留位000-产线1-年月日-条码-扩展0000-追溯位+ + //零件长号---17位,不足17位 右边补* + //获取客户零件号 + Map dataMap = genSerialNoModel.getDataMap(); + MesCustomerPart mesCustomerPart = (MesCustomerPart)dataMap.get("mesCustomerPart"); + String custPartNo = mesCustomerPart.getCustPartNo(); + String custPartNoFormat = stringFormat(custPartNo, 17); + genSerialNoModel.setCustPartNo(custPartNoFormat); + //拓展位 2位 00 包含0~9,A~Z 不使用时,补“0”填充 {SPILTRULE} + //供应商代码 7位 供应商代码 0~9,A~Z;不足7位 右测补* + MesConfig supplierConfig = configService.getMesConfigByCfgCodeKeyOrg(MesPcnExtConstWords.SUPPLIER_CODE, MesExtEnumUtil.MES_PRINT_TEMPLATE.GQXNY.getValue(), genSerialNoModel.getOrganizeCode()); + String supplierCode = supplierConfig.getCfgValue(); + String supplierCodeFormat = stringFormat(supplierCode, 7); + genSerialNoModel.setCustCode(supplierCodeFormat); + //扩展位 3位 预留扩展位0~9 A~Z 不使用时,补 0 {SPILTRULE} + //产线 1位 供应商产线号,表示由数字1~9 和字母A~Z(I/O除外)组成; {SPILTRULE} + //年月日 6位 yyMMdd 零部件生产日期,年月日各2位 + String year = TimeTool.pareDateToString("yyMMdd", date); + genSerialNoModel.setYear(year); + //流水号 4位 采用34进制 0001~ZZZZ (I、O除外)顺位进行标注 (同广汽 & 广新) {serialNo} + //扩展位 4位 预留扩展位信息,包含0~9和字母A~Z,不使用时,补“0” 填充; {SPILTRULE} + //追溯标识 1位 + 代表精确按件追溯,$标识按批追溯, % 代表按生产方式追溯 {SPILTRULE} + + return genSerialNoModel; + } + + private String stringFormat(String data, Integer length) { + return stringFormat(data, length, true, "*"); + } + + private String stringFormat(String data, Integer length, boolean left, String symbol) { + //数据长途大于填充位数直接返回 + if (data.length() >= length) { + return data; + } + StringBuilder dataBuffer = new StringBuilder(); + //右拼接 + if (left) { + dataBuffer.append(data); + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + } + + //左拼接 + if (!left) { + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + dataBuffer.append(data); + } + return dataBuffer.toString(); + } + +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNewNumberRuleStrategyService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNewNumberRuleStrategyService.java new file mode 100644 index 0000000..56a3cf1 --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNewNumberRuleStrategyService.java @@ -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); + } +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNumberRuleStrategyService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNumberRuleStrategyService.java index cca8012..0c17cac 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNumberRuleStrategyService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/numberrule/XiaoPengNumberRuleStrategyService.java @@ -1,19 +1,18 @@ 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.stereotype.Service; -import org.springframework.util.StringUtils; import java.util.Date; +import java.util.HashMap; +import java.util.Map; /** * @Description : @@ -22,38 +21,25 @@ import java.util.Date; * @CreateDate : 2024/6/26 9:38 * @Modify: **/ -@Service +@Component public class XiaoPengNumberRuleStrategyService 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()); - + public GenSerialNoModel execute(GenSerialNoModel genSerialNoModel) { Date date = new Date(); - // XIAO_PENG 原客户条码.小鹏汽车 NoSortBarCodeGZ-new - //{custPartNo}{SPILTRULE}{year}{month}{day}{hour}{minute}{second}{serialNo} + Map dataMap =genSerialNoModel.getDataMap(); + MesCustomerPart customerPart = (MesCustomerPart) dataMap.get("mesCustomerPart"); //客户零件号 - String custPartNo = model.getCustPartNo(); - //日期${dateShort} - model.setYear(getYearShort(date)); - model.setMonth(getMonthShort(date)); - model.setDay(getDayShort(date)); - //中杠 - - //生产日期 + 时间 yyyyMMddHHmmss - //流水号 5位 每天从1开始 - return model; + String custPartNo = customerPart.getCustPartNo(); + genSerialNoModel.setCustPartNo(custPartNo); + //年月日缩写 + genSerialNoModel.setYear(getYearShort(date)); + genSerialNoModel.setMonth(getMonthShort(date)); + genSerialNoModel.setDay(getDayShort(date)); + return genSerialNoModel; } private String getYearShort(Date date) { diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/IPrintTemplateStrategyService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/IPrintTemplateStrategyService.java index c512d1d..97c6e7e 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/IPrintTemplateStrategyService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/IPrintTemplateStrategyService.java @@ -2,6 +2,9 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print; 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.pojo.mes.bean.MesNumberRule; +import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel; import cn.estsh.i3plus.pojo.mes.model.StationRequestBean; import cn.estsh.i3plus.pojo.mes.model.StepResult; @@ -22,5 +25,14 @@ public interface IPrintTemplateStrategyService { * @param sn * @return */ - MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn , String organizeCode); +// MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn , String organizeCode); + + /** + * GenSerialNoModel 生成条码的规则 + * mesProduceSnPrintModel 需要的数据 + * @param model + * @param mesProduceSnPrintModel + * @return + */ + MesProduceSnPrintModel execute(GenSerialNoModel model , MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule); } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/AionPrintStrategy.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/AionPrintStrategy.java index f4ffe67..3264411 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/AionPrintStrategy.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/AionPrintStrategy.java @@ -1,29 +1,32 @@ 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.pojo.context.MesProductionPsOutContext; +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.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.MesCustomerOriganze; -import cn.estsh.i3plus.pojo.mes.bean.MesPart; -import cn.estsh.i3plus.pojo.mes.model.StationRequestBean; -import cn.estsh.i3plus.pojo.mes.model.StepResult; -import cn.estsh.i3plus.pojo.mes.repository.MesCustomerOriganizeRepository; -import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateRepository; -import cn.estsh.i3plus.pojo.mes.repository.MesPartRepository; +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.auth.AuthUtil; +import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; +import cn.estsh.impp.framework.boot.util.ResultBean; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; -import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.Month; -import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.Objects; /** * @Description : 广州打印主条码使用 @@ -32,71 +35,144 @@ import java.util.*; * @CreateDate : 2024/6/6 17:03 * @Modify: **/ -@Service +@Component @Slf4j public class AionPrintStrategy implements IPrintTemplateStrategyService { + @Autowired + private ISyncFuncService syncFuncService; + + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; + + @Autowired + private IMesPartService mesPartService; + + @Autowired + private IConfigService configService; @Autowired - private MesPartRepository mesPartRao; + private MesCustomerPartRepository mesCustomerPartRDao; + + @Override - public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) { - //partNo零件号 - String partNo = sn.getPartNo(); - - //零件条码中获取 serialNo - String productSn = sn.getProductSn(); - //构造标签 - Map map = new HashMap<>(); - String partName = sn.getPartName(); - String factoryName = reqBean.getOrganizeName(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); - LocalDateTime now = LocalDateTime.now(); - String productDate = now.format(formatter); - int no = 1; - String noStr = String.format("%07d", no); - - //构造二维码 -// StringBuilder barcode = new StringBuilder(); -// barcode.append("+"); - //第二位 是零件简号 零件扩展信息中的 零件条码参数 字段 - DdlPackBean partPackBean = DdlPackBean.getDdlPackBean(organizeCode); - DdlPreparedPack.getStringEqualPack(partNo,"partNo",partPackBean); -// List parts = mesPartRao.findByHqlWhere(partPackBean); -// if (!parts.isEmpty()){ -// MesPart mesPart = parts.get(0); -// String partSnParam = mesPart.getPartSnParam(); -// if (partSnParam!=null && !partSnParam.isEmpty()){ -// barcode.append(partSnParam); -// }else { -// log.error("零件号:{},缺少配置零件扩展属性的 零件条码参数",partNo); -// } -// } - //第三位 供应商代码 // 配置表 -// String supplierCode = "VD501"; -// barcode.append(supplierCode); - //第四位 生产线代号 // 配置表 -// String workCenterCode = "1"; -// barcode.append(workCenterCode); - //第五位 生产年月日 -// int year = now.getYear(); -// int month = now.getMonth().getValue(); -// int day = now.getDayOfMonth(); -// String yearStr = MesExtEnumUtil.YEAR_SHORT.valueOfDescription(year); -// String monthStr = MesExtEnumUtil.MONTH_SHORT.valueOfDescription(month); -// String dayStr = MesExtEnumUtil.NUM_SCALE_34.valueOfDescription(day); -// barcode.append(yearStr); -// barcode.append(monthStr); -// barcode.append(dayStr); - //第六位 供应商生产流水号 - //第七位 软件版本代号 - map.put("partNo",partNo); - map.put("partName",partName); - map.put("factoryName",factoryName); - map.put("productDate",productDate); - map.put("no",noStr); - map.put("barcode",productSn); -// return map; - return null; + public MesProduceSnPrintModel execute(GenSerialNoModel genSerialNoModel, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule) { + // 获取工厂名称 + String organizeCode = mesProduceSnPrintModel.getOrganizeCode(); + 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(); + + String format ="yyyy/MM/dd"; + + MesCustomerPart mesCustomerPart = getMesCustomerPart(mesProduceSnPrintModel); + //物料信息 + MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode); + for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) { + ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), organizeCode, 1); + String sn = resultBean.getResultList().get(0).toString(); + int versionNoLength = numberRule.getSpiltRule().substring(numberRule.getSpiltRule().lastIndexOf(",") + 1).length(); + Integer serialNoLength = numberRule.getSerialnoLength(); + String snPrefix = sn.substring(0, sn.length() - versionNoLength - serialNoLength); + String snSuffix = sn.substring(sn.length() - versionNoLength); + String serialNo = sn.substring(sn.length() - versionNoLength - serialNoLength, sn.length() - versionNoLength); + String serialNo34 = toBase34(Integer.parseInt(serialNo)); + serialNo34 = stringFormat(serialNo34, 4, false, "0"); + sn = snPrefix + serialNo34 + snSuffix; + //保存条码信息 + MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format); + //封装打印信息 + MesProduceSnPrintDataModel model = getModel(produceSn, serialNo, mesCustomerPart.getCustPartNo(), organizeName); + mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); + mesProduceSnPrintModel.getMesProduceSnList().add(produceSn); + } + return mesProduceSnPrintModel; + } + + 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; } + // 34进制字符集 + private String toBase34(int number) { + String base34Chars = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"; + StringBuilder sb = new StringBuilder(); + + while (number > 0) { + int remainder = number % 34; + sb.append(base34Chars.charAt(remainder)); + number /= 34; + } + return sb.reverse().toString(); + } + + + private String stringFormat(String data, Integer length) { + return stringFormat(data, length, true, "*"); + } + + private String stringFormat(String data, Integer length, boolean left, String symbol) { + //数据长途大于填充位数直接返回 + if (data.length() >= length) { + return data; + } + StringBuilder dataBuffer = new StringBuilder(); + //右拼接 + if (left) { + dataBuffer.append(data); + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + } + + //左拼接 + if (!left) { + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + dataBuffer.append(data); + } + return dataBuffer.toString(); + } + + 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 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; + } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqaaPrintStrategy.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqaaPrintStrategy.java index 2e6c111..ada0d89 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqaaPrintStrategy.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqaaPrintStrategy.java @@ -1,18 +1,33 @@ 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.pojo.context.MesProductionPsOutContext; +import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException; import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel; -import cn.estsh.i3plus.pojo.mes.model.StationRequestBean; -import cn.estsh.i3plus.pojo.mes.model.StepResult; -import cn.estsh.impp.framework.boot.auth.AuthUtil; +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.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 lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.HashMap; -import java.util.Map; +import java.util.Objects; /** * @Description : @@ -21,38 +36,144 @@ import java.util.Map; * @CreateDate : 2024/6/17 16:10 * @Modify: **/ -@Service +@Component @Slf4j public class GqaaPrintStrategy implements IPrintTemplateStrategyService { + @Autowired + private ISyncFuncService syncFuncService; + + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; + + @Autowired + private IMesPartService mesPartService; + + @Autowired + private IConfigService configService; + + @Autowired + private MesCustomerPartRepository mesCustomerPartRDao; + + @Override - public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) { - Map map = new HashMap<>(); - - String partNo = sn.getPartNo(); - String partName = sn.getPartName(); - String factoryName = reqBean.getOrganizeName(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy/MM/dd"); - LocalDateTime now = LocalDateTime.now(); - String productDate = now.format(formatter); - - //构造二维码 - StringBuilder barcode = new StringBuilder(); - - //第三位 供应商代码 // 配置表 - String supplierCode = "VD501"; - barcode.append(supplierCode); - //第四位 生产线代号 // 配置表 - String workCenterCode = "1"; - barcode.append(workCenterCode); - - int no = 1; - String noStr = String.format("%07d", no); - map.put("no",noStr); - map.put("partNo", partNo); - map.put("partName", partName); - map.put("factoryName", factoryName); - map.put("productDate", productDate); - map.put("barcode", barcode.toString()); - return null; + public MesProduceSnPrintModel execute(GenSerialNoModel genSerialNoModel, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule) { + // 获取工厂名称 + String organizeCode = mesProduceSnPrintModel.getOrganizeCode(); + 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(); + + String format ="yyyy/MM/dd"; + + MesCustomerPart mesCustomerPart = getMesCustomerPart(mesProduceSnPrintModel); + //物料信息 + MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode); + for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) { + ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), organizeCode, 1); + String sn = resultBean.getResultList().get(0).toString(); + int versionNoLength = numberRule.getSpiltRule().substring(numberRule.getSpiltRule().lastIndexOf(",") + 1).length(); + Integer serialNoLength = numberRule.getSerialnoLength(); + String snPrefix = sn.substring(0, sn.length() - versionNoLength - serialNoLength); + String snSuffix = sn.substring(sn.length() - versionNoLength); + String serialNo = sn.substring(sn.length() - versionNoLength - serialNoLength, sn.length() - versionNoLength); + String serialNo34 = toBase34(Integer.parseInt(serialNo)); + serialNo34 = stringFormat(serialNo34, 4, false, "0"); + sn = snPrefix + serialNo34 + snSuffix; + //保存条码信息 + MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format); + //封装打印信息 + MesProduceSnPrintDataModel model = getModel(produceSn, serialNo, mesCustomerPart.getCustPartNo(), organizeName); + mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model); + mesProduceSnPrintModel.getMesProduceSnList().add(produceSn); + } + return mesProduceSnPrintModel; + } + + 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; + } + + // 34进制字符集 + private String toBase34(int number) { + String base34Chars = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"; + StringBuilder sb = new StringBuilder(); + + while (number > 0) { + int remainder = number % 34; + sb.append(base34Chars.charAt(remainder)); + number /= 34; + } + return sb.reverse().toString(); + } + + + private String stringFormat(String data, Integer length) { + return stringFormat(data, length, true, "*"); + } + + private String stringFormat(String data, Integer length, boolean left, String symbol) { + //数据长途大于填充位数直接返回 + if (data.length() >= length) { + return data; + } + StringBuilder dataBuffer = new StringBuilder(); + //右拼接 + if (left) { + dataBuffer.append(data); + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + } + + //左拼接 + if (!left) { + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + dataBuffer.append(data); + } + return dataBuffer.toString(); + } + + 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 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; } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqxnyPrintStrategy.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqxnyPrintStrategy.java index 8f9b6af..fb289ac 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqxnyPrintStrategy.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/GqxnyPrintStrategy.java @@ -1,18 +1,44 @@ 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.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.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.model.StationRequestBean; import cn.estsh.i3plus.pojo.mes.model.StepResult; +import cn.estsh.i3plus.pojo.mes.repository.MesCustomerPartRepository; +import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil; +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.stereotype.Service; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * @Description : @@ -21,38 +47,169 @@ import java.util.Map; * @CreateDate : 2024/6/17 16:10 * @Modify: **/ -@Service +@Component @Slf4j public class GqxnyPrintStrategy implements IPrintTemplateStrategyService { + @Autowired + private ISyncFuncService syncFuncService; + + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; + + @Autowired + private IMesPartService mesPartService; + + @Autowired + private IConfigService configService; + + @Autowired + private MesCustomerPartRepository mesCustomerPartRDao; + @Override - public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) { - Map map = new HashMap<>(); - - String partNo = sn.getPartNo(); - String partName = sn.getPartName(); - String factoryName = reqBean.getOrganizeName(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy/MM/dd"); - LocalDateTime now = LocalDateTime.now(); - String productDate = now.format(formatter); - - //构造二维码 - StringBuilder barcode = new StringBuilder(); - - //第三位 供应商代码 // 配置表 - String supplierCode = "VD501"; - barcode.append(supplierCode); - //第四位 生产线代号 // 配置表 - String workCenterCode = "1"; - barcode.append(workCenterCode); - - int no = 1; - String noStr = String.format("%07d", no); - map.put("no",noStr); - map.put("partNo", partNo); - map.put("partName", partName); - map.put("factoryName", factoryName); - map.put("productDate", productDate); - map.put("barcode", barcode.toString()); - return null; + public MesProduceSnPrintModel execute(GenSerialNoModel model, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule) { + String format = DateUtil.BASE_FORMAT; + // 获取工厂名称 + String organizeCode = mesProduceSnPrintModel.getOrganizeCode(); + 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(); + //物料信息 + MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode); + Date date = new Date(); + //----广乘 45位 GQXNY + //{custPartNo}{SPILTURE}{custCode}{spiltrure}{spiltrule}{year}{serialNo}{spilture}{spiltrule} + //客户零件号-扩展位-客户代码-预留位000-产线1-年月日-条码-扩展0000-追溯位+ + //零件长号---17位,不足17位 右边补* + GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); + genSerialNoModel.setRuleCode(numberRule.getRuleCode()); + //获取客户零件号 + String custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo(); + String custPartNoFormat = stringFormat(custPartNo, 17); + genSerialNoModel.setCustPartNo(custPartNoFormat); + //拓展位 2位 00 包含0~9,A~Z 不使用时,补“0”填充 {SPILTRULE} + //供应商代码 7位 供应商代码 0~9,A~Z;不足7位 右测补* + MesConfig supplierConfig = configService.getMesConfigByCfgCodeKeyOrg(MesPcnExtConstWords.SUPPLIER_CODE, MesExtEnumUtil.MES_PRINT_TEMPLATE.GQXNY.getValue(), organizeCode); + String supplierCode = supplierConfig.getCfgValue(); + String supplierCodeFormat = stringFormat(supplierCode, 7); + genSerialNoModel.setCustCode(supplierCodeFormat); + //扩展位 3位 预留扩展位0~9 A~Z 不使用时,补 0 {SPILTRULE} + //产线 1位 供应商产线号,表示由数字1~9 和字母A~Z(I/O除外)组成; {SPILTRULE} + //年月日 6位 yyMMdd 零部件生产日期,年月日各2位 + String year = TimeTool.pareDateToString("yyMMdd", date); + genSerialNoModel.setYear(year); + //流水号 4位 采用34进制 0001~ZZZZ (I、O除外)顺位进行标注 (同广汽 & 广新) {serialNo} + //扩展位 4位 预留扩展位信息,包含0~9和字母A~Z,不使用时,补“0” 填充; {SPILTRULE} + //追溯标识 1位 + 代表精确按件追溯,$标识按批追溯, % 代表按生产方式追溯 {SPILTRULE} + for (int i = 0; i < mesProduceSnPrintModel.getPrintQty(); i++) { + ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), organizeCode, 1); + String sn = resultBean.getResultList().get(0).toString(); + String snPrefix = sn.substring(0, sn.length() - 12); + String snSuffix = sn.substring(sn.length() - 5); + String serialNo = sn.substring(sn.length() - 12, sn.length() - 5); + String serialNo34 = toBase34(Integer.parseInt(serialNo)); + serialNo34 = stringFormat(serialNo34, 4, false, "0"); + sn = snPrefix + serialNo34 + snSuffix; + //保存条码信息 + MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format); + //封装打印信息 + MesProduceSnPrintDataModel printDataModel = getModel(produceSn, serialNo, custPartNo, organizeName); + printDataModel.setSupplierCode(supplierCode); + mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(printDataModel); + + //保存打印记录 + MesPrintedSnLog snLog = new MesPrintedSnLog(); + ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName()); + BeanUtil.copyProperties(printDataModel, snLog); + mesProduceSnPrintModel.getMesProduceSnList().add(produceSn); + } + 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 stringFormat(String data, Integer length) { + return stringFormat(data, length, true, "*"); + } + + private String stringFormat(String data, Integer length, boolean left, String symbol) { + //数据长途大于填充位数直接返回 + if (data.length() >= length) { + return data; + } + StringBuilder dataBuffer = new StringBuilder(); + //右拼接 + if (left) { + dataBuffer.append(data); + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + } + + //左拼接 + if (!left) { + for (int i = 0; i < length - data.length(); i++) { + dataBuffer.append(symbol); + } + dataBuffer.append(data); + } + return dataBuffer.toString(); + } + + // 34进制字符集 + private String toBase34(int number) { + String base34Chars = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"; + StringBuilder sb = new StringBuilder(); + + while (number > 0) { + int remainder = number % 34; + sb.append(base34Chars.charAt(remainder)); + number /= 34; + } + return sb.reverse().toString(); + } + + 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; + } + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/NoSortBarCodeGzStrategy.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/NoSortBarCodeGzStrategy.java index 3367cfe..fd403c6 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/NoSortBarCodeGzStrategy.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/NoSortBarCodeGzStrategy.java @@ -1,16 +1,32 @@ 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.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.ext.mes.pcn.pojo.util.MesPcnExtConstWords; import cn.estsh.i3plus.mes.pcn.api.iservice.base.IConfigService; -import cn.estsh.i3plus.pojo.mes.bean.MesConfig; +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.codemaker.SnowflakeIdMaker; +import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; +import cn.estsh.i3plus.pojo.mes.bean.*; +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 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.stereotype.Service; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -24,39 +40,88 @@ import java.util.Map; * @CreateDate : 2024/6/17 16:31 * @Modify: **/ -@Service +@Component @Slf4j public class NoSortBarCodeGzStrategy implements IPrintTemplateStrategyService { @Autowired private IConfigService configService; + @Autowired + private IMesPartService mesPartService; + + @Autowired + private ISyncFuncService syncFuncService; + + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; + + @Override - public MesProduceSnPrintDataModel execute(StepResult stepResult,StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) { - //获取供应商编码 - MesConfig mesConfig = configService.getMesConfigByCfgCodeKeyOrg(MesPcnExtConstWords.SUPPLIER_CODE, MesPcnExtConstWords.SUPPLIER_CODE_NO_SORT_GZ, reqBean.getOrganizeCode()); - if (null == mesConfig) { - stepResult.setCompleted(false); - stepResult.setMsg(String.format("缺少供应商编码配置,请配置系统参数,配置代码【%s】,配置key为【%s】", MesPcnExtConstWords.SUPPLIER_CODE,MesPcnExtConstWords.SUPPLIER_CODE_NO_SORT_GZ)); - return null; + public MesProduceSnPrintModel execute(GenSerialNoModel model, MesProduceSnPrintModel mesProduceSnPrintModel, MesNumberRule numberRule) { + // noSortBarCodeGz + String format = DateUtil.BASE_FORMAT; + //{partNo}{year}{month}{day}{serialNo} + String organizeCode = mesProduceSnPrintModel.getOrganizeCode(); + MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode); + String partNo = mesPart.getPartNo(); + 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(); + GenSerialNoModel genSerialNoModel = new GenSerialNoModel(); + genSerialNoModel.setRuleCode(numberRule.getRuleCode()); + genSerialNoModel.setPartNo(partNo); + //年月日 yyyyMMdd + //流水号 4位 每天从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); + //封装打印信息 + MesProduceSnPrintDataModel printDataModel = getModel(produceSn, serialNo, mesProduceSnPrintModel.getCustPartNo(), 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); } - String supplierCode = mesConfig.getCfgValue(); - //1.根据零件号获取 零件扩展信息 - Map map = new HashMap<>(); - String partNo = sn.getPartNo(); - String partName = sn.getPartName(); - String factoryName = reqBean.getOrganizeName(); - String productSn = sn.getProductSn(); - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - String productDateTime = now.format(formatter); - - MesProduceSnPrintDataModel model = new MesProduceSnPrintDataModel(); - model.setPartNo(partNo); - model.setPartName(partName); - model.setFactoryName(factoryName); - model.setSupplierCode(supplierCode); - model.setProductDate(productDateTime); - model.setNo( productSn.substring(productSn.length()-4)); - model.setBarcode(productSn); - return model; + return mesProduceSnPrintModel; + } + + 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; } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengNewPrintStrategy.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengNewPrintStrategy.java new file mode 100644 index 0000000..b8c4436 --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengNewPrintStrategy.java @@ -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; + } + +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengPrintStrategy.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengPrintStrategy.java index 52a8e63..c787282 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengPrintStrategy.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/print/strategy/XiaoPengPrintStrategy.java @@ -1,17 +1,35 @@ 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.pojo.context.MesProductionPsOutContext; +import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException; import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel; -import cn.estsh.i3plus.pojo.mes.model.StationRequestBean; -import cn.estsh.i3plus.pojo.mes.model.StepResult; +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.stereotype.Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.HashMap; -import java.util.Map; +import java.util.Date; +import java.util.Objects; /** * @Description : @@ -20,23 +38,133 @@ import java.util.Map; * @CreateDate : 2024/6/17 16:43 * @Modify: **/ -@Service +@Component @Slf4j public class XiaoPengPrintStrategy implements IPrintTemplateStrategyService { + @Autowired + private MesCustomerPartRepository mesCustomerPartRDao; + + @Autowired + private ISyncFuncService syncFuncService; + + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; + + @Autowired + private IMesPartService mesPartService; + + @Autowired + private IConfigService configService; + @Override - public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) { - //从条码中截取流水号,流水号 后四位 - String productSn = sn.getProductSn(); - String partNo = sn.getPartNo(); - String partName = sn.getPartName(); - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); - String productDateTime = now.format(formatter); - MesProduceSnPrintDataModel model = new MesProduceSnPrintDataModel(); - model.setPartNo(partNo); - model.setBarcode(productSn); - model.setPartName(partName); - model.setProductDate(productDateTime); - return model; + 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; + } + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnPrintStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnPrintStepService.java index 8b79f57..464f63e 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnPrintStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnPrintStepService.java @@ -54,121 +54,122 @@ public class MesProductSnPrintStepService extends BaseStepService { @Override public StepResult execute(StationRequestBean reqBean) { - /** - * Map - * valueList:List> - * paramInfo:{ - * templateContent:xxxx, - * labelTemplateParamList: List> - * } - * - * 根据foreign找出加工规则对应的上下文,判断是否需要打印 - * - */ - String organizeCode = reqBean.getOrganizeCode(); - StationResultBean resultBean = new StationResultBean(); - StepResult stepResult = StepResult.getSuccessComplete(); - // 根据foreign找出加工规则对应的上下文,判断是否需要打印 - List prodRuleDataContext = mesProductionDispatchContextStepService.getProdRuleDataContext(reqBean); - Map> prodRuleContextMap = prodRuleDataContext.stream().collect(Collectors.groupingBy(MesProdRuleContext::getForeignKey)); - //需要打印的数据 String 是打印模板code - Map> resultData = new HashMap<>(); - //用于保存客户模板代码 和 模板信息关系 - Map labelTemplateMap = new HashMap<>(); - //返回打印标识 给前端 - //1. 获取上下文中生成的主条码 - List productionPsOutContextList = mesProductionDispatchContextStepService.getProductionPsOutContext(reqBean); - //2. 获取条码需要模板、模板代码、打印机 --- 循环遍历条码 封装数据 - for (MesProductionPsOutContext sn : productionPsOutContextList) { - List 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 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 - * valueList:List> - * paramInfo:{ - * templateContent:xxxx, - * labelTemplateParamList: List> - * } - * - */ - List> printData = new ArrayList<>(); - Set labelKeys = labelTemplateMap.keySet(); - List snLogList = new ArrayList<>(); - for (String labelKey : labelKeys) { - Map paramInfo = new HashMap<>(); - List 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 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, "执行打印成功!"); +// /** +// * Map +// * valueList:List> +// * paramInfo:{ +// * templateContent:xxxx, +// * labelTemplateParamList: List> +// * } +// * +// * 根据foreign找出加工规则对应的上下文,判断是否需要打印 +// * +// */ +// String organizeCode = reqBean.getOrganizeCode(); +// StationResultBean resultBean = new StationResultBean(); +// StepResult stepResult = StepResult.getSuccessComplete(); +// // 根据foreign找出加工规则对应的上下文,判断是否需要打印 +// List prodRuleDataContext = mesProductionDispatchContextStepService.getProdRuleDataContext(reqBean); +// Map> prodRuleContextMap = prodRuleDataContext.stream().collect(Collectors.groupingBy(MesProdRuleContext::getForeignKey)); +// //需要打印的数据 String 是打印模板code +// Map> resultData = new HashMap<>(); +// //用于保存客户模板代码 和 模板信息关系 +// Map labelTemplateMap = new HashMap<>(); +// //返回打印标识 给前端 +// //1. 获取上下文中生成的主条码 +// List productionPsOutContextList = mesProductionDispatchContextStepService.getProductionPsOutContext(reqBean); +// //2. 获取条码需要模板、模板代码、打印机 --- 循环遍历条码 封装数据 +// for (MesProductionPsOutContext sn : productionPsOutContextList) { +// List 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 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 +// * valueList:List> +// * paramInfo:{ +// * templateContent:xxxx, +// * labelTemplateParamList: List> +// * } +// * +// */ +// List> printData = new ArrayList<>(); +// Set labelKeys = labelTemplateMap.keySet(); +// List snLogList = new ArrayList<>(); +// for (String labelKey : labelKeys) { +// Map paramInfo = new HashMap<>(); +// List 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 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; } /** diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/MesProduceSnPrintModel.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/MesProduceSnPrintModel.java index 2450766..187601e 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/MesProduceSnPrintModel.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/MesProduceSnPrintModel.java @@ -2,6 +2,8 @@ package cn.estsh.i3plus.ext.mes.pcn.pojo.model; import cn.estsh.i3plus.pojo.mes.bean.MesLabelTemplate; import cn.estsh.i3plus.pojo.mes.bean.MesPackingDefine; +import cn.estsh.i3plus.pojo.mes.bean.MesPrintedSnLog; +import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn; import io.swagger.annotations.ApiParam; import lombok.Data; @@ -63,6 +65,10 @@ public class MesProduceSnPrintModel { @ApiParam(name = "产品条码信息") private List mesProduceSnPrintDataModelList = new ArrayList<>(); + private List mesProduceSnList = new ArrayList<>(); + + private List mesPrintedSnLogList = new ArrayList<>(); + public Double getQty() { return qty == null || qty <= 0d ? 1d : qty; }