diff --git a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/IMesConfigService.java b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/IMesConfigService.java index 61935a7..a9315a3 100644 --- a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/IMesConfigService.java +++ b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/IMesConfigService.java @@ -15,5 +15,8 @@ public interface IMesConfigService { @ApiOperation(value = "获取配置表模板代码") MesConfig getCfgValueByCode(String key); + @ApiOperation(value = "获取配置表模板代码") + MesConfig getMesConfig(String org, String key); + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/controller/busi/MesProduceSnPrintController.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/controller/busi/MesProduceSnPrintController.java index db6be92..29a8448 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/controller/busi/MesProduceSnPrintController.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/controller/busi/MesProduceSnPrintController.java @@ -19,14 +19,14 @@ import org.springframework.web.bind.annotation.RestController; import java.util.Objects; /** - * @Description : 物料信息主数据 + * @Description : 条码补打 * @Reference : * @Author : junsheng.li * @CreateDate 2024/6/13 15:13 * @Modify: **/ @RestController -@Api(tags = "物料信息") +@Api(tags = "条码补打") @RequestMapping(MesCommonConstant.MES_YANFEN + "/mes-produce-sn-print") public class MesProduceSnPrintController { @@ -68,7 +68,7 @@ public class MesProduceSnPrintController { ValidatorBean.checkNotNull(mesProduceSnPrintModel.getPartNo(), "ERP零件号不能为空"); ValidatorBean.checkNotNull(mesProduceSnPrintModel.getOrganizeCode(), "工厂代码不能为空"); if (Objects.isNull(mesProduceSnPrintModel.getPrintQty()) || mesProduceSnPrintModel.getPrintQty() <= 0) { - MesPcnException.throwFlowException("打印数量不能小于等于零"); + MesPcnException.throwMesBusiException("打印数量不能小于等于零"); } mesProduceSnPrintModel.setUserName(AuthUtil.getSessionUser().getUserName()); return ResultBean.success("查询成功").setResultObject(mesProduceSnPrintService.doPrint(mesProduceSnPrintModel)); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesPartServiceImpl.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesPartServiceImpl.java index 5a4678b..32a9997 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesPartServiceImpl.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesPartServiceImpl.java @@ -49,7 +49,7 @@ public class MesPartServiceImpl implements IMesPartService { DdlPreparedPack.getStringEqualPack(partNo, "partNo", packBean); MesPart mesPart = mesPartRDao.getByProperty(packBean); if(Objects.isNull(mesPart)){ - MesPcnException.throwFlowException("物料【%s】信息不存在",partNo); + MesPcnException.throwMesBusiException("物料【%s】信息不存在",partNo); } return mesPart; } @@ -60,7 +60,7 @@ public class MesPartServiceImpl implements IMesPartService { DdlPreparedPack.getStringEqualPack(partNo, "partNo", packBean); MesPartSap mesPartSap = mesPartSapRDao.getByProperty(packBean); if(Objects.isNull(mesPartSap)){ - MesPcnException.throwFlowException("SAP物料【%s】信息不存在",partNo); + MesPcnException.throwMesBusiException("SAP物料【%s】信息不存在",partNo); } return mesPartSap; } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesReworkTaskServiceImpl.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesReworkTaskServiceImpl.java index d758459..cbbc2f0 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesReworkTaskServiceImpl.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesReworkTaskServiceImpl.java @@ -143,7 +143,7 @@ public class MesReworkTaskServiceImpl implements IMesReworkTaskService { List mesReworkTaskDetailList = mesReworkTaskDetailRepository.findByHqlWhere(packBean); if (CollectionUtils.isEmpty(mesReworkTaskDetailList)) { - MesPcnException.throwFlowException("返工单详情不存在"); + MesPcnException.throwMesBusiException("返工单详情不存在"); } mesReworkTaskDetailList.forEach(mesReworkTaskDetail->{ mesReworkTaskDetail.setStatus(MesExtEnumUtil.REWORK_TASK_DETAIL_STATUS.REWORK_TASK_DETAIL_STATUS_20.getValue()); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesTemplateServiceImpl.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesTemplateServiceImpl.java index c769840..1a83688 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesTemplateServiceImpl.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/base/MesTemplateServiceImpl.java @@ -38,7 +38,7 @@ public class MesTemplateServiceImpl implements IMesTemplateService { new Object[]{CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), templateCode}); if (labelTemplate == null) { - MesPcnException.throwFlowException("标签模板代码【%s】在标签模板表不存在!", templateCode); + MesPcnException.throwMesBusiException("标签模板代码【%s】在标签模板表不存在!", templateCode); } // 根据模板代码查询模板参数信息 @@ -48,7 +48,7 @@ public class MesTemplateServiceImpl implements IMesTemplateService { CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()}); if (CollectionUtils.isEmpty(templateParamList)) { - MesPcnException.throwFlowException("标签模板代码【%s】在标签模板明细表不存在!", templateCode); + MesPcnException.throwMesBusiException("标签模板代码【%s】在标签模板明细表不存在!", templateCode); } labelTemplate.setLabelTemplateParamList(templateParamList); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesConfigService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesConfigService.java index b36166c..8ac5ace 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesConfigService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesConfigService.java @@ -40,4 +40,19 @@ public class MesConfigService implements IMesConfigService { return this.configRepository.getByProperty(new String[]{"isDeleted", "isValid", "cfgCode"}, new Object[]{CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), cfgCode}); } + + @Override + public MesConfig getMesConfig(String org, String key) { + MesConfig config = configRepository.getByProperty( + new String[]{"cfgKey", "organizeCode", "isValid", "isDeleted"}, + new Object[]{key, org, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.IS_DEAL.NO.getValue()}); + + if (config == null) { + throw ImppExceptionBuilder.newInstance().setErrorCode(cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode()) + .setErrorDetail(String.format("配置表数据不存在,请维护key【%s】", key)) + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .build(); + } + return config; + } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintServiceImpl.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintServiceImpl.java index 6b83d24..290f203 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintServiceImpl.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesProduceSnPrintServiceImpl.java @@ -2,23 +2,21 @@ 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.IMesConfigService; import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProduceSnPrintService; 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.mes.pcn.api.iservice.busi.ISyncFuncService; +import cn.estsh.i3plus.mes.pcn.util.DateUtil; import cn.estsh.i3plus.platform.common.convert.ConvertBean; +import cn.estsh.i3plus.platform.common.tool.CheckTool; 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.MesPcnEnumUtil; 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.repository.MesPackingDefineDetailsRepository; -import cn.estsh.i3plus.pojo.mes.repository.MesPackingDefineRepository; -import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository; +import cn.estsh.i3plus.pojo.mes.repository.*; import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.util.ValidatorBean; @@ -28,6 +26,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -55,9 +54,6 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { private SnowflakeIdMaker snowflakeIdMaker; @Autowired - private ISyncFuncService syncFuncService; - - @Autowired private IMesPartService mesPartService; @Autowired @@ -66,6 +62,12 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { @Autowired private MesCustomerPartRepository mesCustomerPartRDao; + @Autowired + private IMesConfigService mesConfigService; + + @Autowired + private MesConfigRepository mesConfigRDao; + @Override public MesProduceSnPrintModel findMesPackingDefine(MesProduceSnPrintModel mesProduceSnPrintModel) { //查询SAP下发物料信息 @@ -77,7 +79,7 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getPartNo(), "partNo", ddlPackBean); List packingDefineDetails = mesPackingDefineDetailsRDao.findByHqlWhere(ddlPackBean); if (CollectionUtils.isEmpty(packingDefineDetails)) { - MesPcnException.throwFlowException("物料【%s】未维护包装定义信息", mesProduceSnPrintModel.getPartNo()); + MesPcnException.throwMesBusiException("物料【%s】未维护包装定义信息", mesProduceSnPrintModel.getPartNo()); } //查询包装定义主表 ddlPackBean = DdlPackBean.getDdlPackBean(mesProduceSnPrintModel.getOrganizeCode()); @@ -92,7 +94,7 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getProductSn(), "productSn", ddlPackBean); MesProduceSn mesProduceSn = mesProduceSnRDao.getByProperty(ddlPackBean); if (Objects.isNull(mesProduceSn)) { - MesPcnException.throwFlowException("条码【%s】信息不存在", mesProduceSnPrintModel.getProductSn()); + MesPcnException.throwMesBusiException("条码【%s】信息不存在", mesProduceSnPrintModel.getProductSn()); } return mesProduceSn; } @@ -102,27 +104,27 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { String organizeName = AuthUtil.getOrganize().getName(); //物料信息 MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), mesProduceSnPrintModel.getOrganizeCode()); + //打印日期格式 + String format = "yyyy/MM/dd"; + 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())) { + format = DateUtil.BASE_FORMAT; + } //条码生成 if (StringUtils.isEmpty(mesProduceSnPrintModel.getProductSn())) { ValidatorBean.checkNotNull(mesProduceSnPrintModel.getSnRule(), "条码规则不能为空"); ValidatorBean.checkNotNull(mesProduceSnPrintModel.getPrintTemplate(), "打印模板不能为空"); - //流水码 - List resultList = getStringList(mesProduceSnPrintModel); - //条码模板 - StringBuilder template = getTemplate(mesProduceSnPrintModel); + //流水号 + List serialNoList = getSerialNoList(mesProduceSnPrintModel); + //条码二维码模板 + String template = getTemplate(mesProduceSnPrintModel, mesPart); List mesMesProduceSnList = new ArrayList<>(); - for (String no : resultList) { - String reportSn = no; - if (MesPcnEnumUtil.PRINT_TEMPLATE.GQXNY.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { - no = no.replace(MesPcnEnumUtil.PRINT_TEMPLATE.GQXNY.getValue(), ""); - reportSn = template.toString().replace("serialNo", no); - } + for (String no : serialNoList) { //保存条码信息 - MesProduceSn produceSn = generateMesProduceSn(mesPart, reportSn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty()); + MesProduceSn produceSn = generateMesProduceSn(mesPart, template.replace("serialNo", no), mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format); mesMesProduceSnList.add(produceSn); //封装打印信息 - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(produceSn, no, mesProduceSnPrintModel.getCustPartNo(),organizeName)); + mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(produceSn, no, mesProduceSnPrintModel.getCustPartNo(), organizeName)); } mesProduceSnRDao.saveAll(mesMesProduceSnList); //条码补打 @@ -139,27 +141,44 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo(); no = mesProduceSn.getProductSn().substring(36, 40); } - mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(mesProduceSn, no,custPartNo ,organizeName)); + mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(mesProduceSn, no, custPartNo, organizeName)); } //获取打印模板信息 mesProduceSnPrintModel.setMesLabelTemplate(mesTemplateService.getMesLabelTemplate(mesProduceSnPrintModel.getPrintTemplate())); return mesProduceSnPrintModel; } - private StringBuilder getTemplate(MesProduceSnPrintModel mesProduceSnPrintModel) { + private String getTemplate(MesProduceSnPrintModel mesProduceSnPrintModel, MesPart mesPart) { + Date date = new Date(); StringBuilder template = new StringBuilder(); - //广乘 GQXNY.btw - if (MesPcnEnumUtil.PRINT_TEMPLATE.GQXNY.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { + if (MesPcnEnumUtil.PRINT_TEMPLATE.B2M.getCode().equals(mesProduceSnPrintModel.getPrintTemplate()) || MesPcnEnumUtil.PRINT_TEMPLATE.GQAA.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { + //获取客户零件号 + MesCustomerPart mesCustomerPart = getMesCustomerPart(mesProduceSnPrintModel); + mesProduceSnPrintModel.setCustPartNo(mesCustomerPart.getCustPartNo()); + //"+"(1)+零件简号(4)+ 供应商代码(SE103)+生产线代号(1)+生产日期(4)+供应商生产流水号(4) +软件版本代号(2) + template.append("+").append(mesPart.getPartSnParam()).append("SE103").append("1").append(getDateTime(date)).append("serialNo").append("01"); + } else if (MesPcnEnumUtil.PRINT_TEMPLATE.GQXNY.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { //获取客户零件号 MesCustomerPart mesCustomerPart = getMesCustomerPart(mesProduceSnPrintModel); mesProduceSnPrintModel.setCustPartNo(mesCustomerPart.getCustPartNo()); //零件号(17)+扩展位(2)+供应商代码(7)+扩展位(3)+产线(1)+年月日(6位)+流水号(4)+扩展位(4)+"+" - template.append(stringFormat(mesCustomerPart.getCustPartNo(), 17)).append("00").append(stringFormat("VD501", 7)).append("000").append("1").append(TimeTool.getNowTime("yyMMdd")).append("serialNo").append("0000").append("+"); + template.append(stringFormat(mesCustomerPart.getCustPartNo(), 17)).append("00").append(stringFormat("VD501", 7)).append("000").append("1").append(TimeTool.pareDateToString("yyMMdd", date)).append("serialNo").append("0000").append("+"); + } else if (MesPcnEnumUtil.PRINT_TEMPLATE.NO_SORT_BAR_CODE_GZ.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { + //内部条码:M00061102-R619+"10158" + //条码拼接规则:零件号+年月日+5位流水号 + template.append(mesPart.getPartNo()).append("-").append(getDateTime(date)).append("serialNo"); + } else if (MesPcnEnumUtil.PRINT_TEMPLATE.NO_SORT_BAR_CODE_GZ_NEW.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())) { + //获取客户零件号 + MesCustomerPart mesCustomerPart = getMesCustomerPart(mesProduceSnPrintModel); + mesProduceSnPrintModel.setCustPartNo(mesCustomerPart.getCustPartNo()); + //小鹏客户条码:6205100EF3-S5-06-R61910027 + //条码拼接规则:客户零件号+中杠+年月日+5位流水号(按天递增) + template.append(mesCustomerPart.getCustPartNo()).append("-").append(getDateTime(date)).append("serialNo"); } - return template; + return template.toString(); } - private MesProduceSnPrintDataModel getModel(MesProduceSn produceSn, String no,String custPartNo, String factoryName) { + private MesProduceSnPrintDataModel getModel(MesProduceSn produceSn, String no, String custPartNo, String factoryName) { MesProduceSnPrintDataModel mesProduceSnPrintDataModel = new MesProduceSnPrintDataModel(); mesProduceSnPrintDataModel.setFactoryName(factoryName); mesProduceSnPrintDataModel.setPartNo(produceSn.getPartNo()); @@ -167,14 +186,47 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { mesProduceSnPrintDataModel.setNo(no); mesProduceSnPrintDataModel.setBarcode(produceSn.getProductSn()); mesProduceSnPrintDataModel.setCustPartNo(custPartNo); - mesProduceSnPrintDataModel.setProductDate(TimeTool.getDateTimeShort()); + mesProduceSnPrintDataModel.setProductDate(produceSn.getLotNo()); return mesProduceSnPrintDataModel; } - private List getStringList(MesProduceSnPrintModel mesProduceSnPrintModel) { - GenSerialNoModel genSerialNoModel = new GenSerialNoModel(mesProduceSnPrintModel.getSnRule()); - List resultList = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getOrganizeCode(), mesProduceSnPrintModel.getPrintQty()).getResultList(); - return resultList; + 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) { @@ -187,7 +239,7 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { return mesCustomerPart; } - private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, String userName, Double qty) { + private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, String userName, Double qty, String format) { MesProduceSn mesProduceSn = new MesProduceSn(); mesProduceSn.setSerialNumber(snowflakeIdMaker.nextId() + ""); mesProduceSn.setProductSn(sn); @@ -200,7 +252,7 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { mesProduceSn.setQty(qty); mesProduceSn.setSnStatus(10); mesProduceSn.setQcStatus(MesExtEnumUtil.PRODUCE_QC_STATUS.QUALIFIED.getValue()); - mesProduceSn.setLotNo(TimeTool.getDateTimeShort()); + mesProduceSn.setLotNo(TimeTool.getNowTime(format)); mesProduceSn.setPrintCount(1); mesProduceSn.setPrintStatus(20); mesProduceSn.setOrganizeCode(mesPart.getOrganizeCode()); @@ -208,16 +260,54 @@ public class MesProduceSnPrintServiceImpl implements IMesProduceSnPrintService { return mesProduceSn; } + private String getDateTime(Date date) { + StringBuilder dateTime = new StringBuilder(); + String yearStr = MesExtEnumUtil.YEAR_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date))); + if (StringUtils.isEmpty(yearStr)) { + MesPcnException.throwMesBusiException("【%s】年月简号不存在", TimeTool.getYear(date)); + } + String monthStr = MesExtEnumUtil.MONTH_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getMonth(date))); + if (StringUtils.isEmpty(monthStr)) { + MesPcnException.throwMesBusiException("【%s】月简号不存在", TimeTool.getMonth(date)); + } + return dateTime.append(yearStr).append(monthStr).append(TimeTool.getDay(date)).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(); - dataBuffer.append(data); + //左拼接 + if (left) { + dataBuffer.append(data); + } for (int i = 0; i < length - data.length(); i++) { - dataBuffer.append('*'); + dataBuffer.append(symbol); + } + //右拼接 + if (!left) { + 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(); + } } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSortShippingCheckService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSortShippingCheckService.java index f70be2d..e6551c1 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSortShippingCheckService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSortShippingCheckService.java @@ -392,7 +392,7 @@ public class MesSortShippingCheckService implements IMesSortShippingCheckService DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"createDatetime"}, packBean); MesProduceSn produceSn = produceSnRepository.getByProperty(packBean); if(Objects.isNull(produceSn)){ - MesPcnException.throwFlowException("【%s】此产品条码不存在,请检查数据!", detail.getBarcode()); + MesPcnException.throwMesBusiException("【%s】此产品条码不存在,请检查数据!", detail.getBarcode()); } produceSn.setSnStatus(MesExtEnumUtil.PRODUCE_SN_STATUS.SHIPPED.getValue());