打印校验

tags/yfai-pcn-ext-v1.0
administrator 11 months ago
parent d3767119fa
commit 1c65a74374

@ -2,24 +2,28 @@ 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.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.tool.CheckTool;
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.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.*;
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.estsh.impp.framework.boot.util.ValidatorBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -63,11 +67,18 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
@Autowired
private MesCustomerPartRepository mesCustomerPartRDao;
@Autowired
private IConfigService configService;
@Autowired
private ISyncFuncService syncFuncService;
@Autowired
private IMesConfigService mesConfigService;
private MesNumberRuleRepository mesNumberRuleRDao;
@Autowired
private MesConfigRepository mesConfigRDao;
private IMesPrintedSnLogRepository mesPrintedSnRao;
@Override
public MesProduceSnPrintModel findMesPackingDefine(MesProduceSnPrintModel mesProduceSnPrintModel) {
@ -102,7 +113,13 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
@Override
public MesProduceSnPrintModel doPrint(MesProduceSnPrintModel mesProduceSnPrintModel) {
String organizeName = AuthUtil.getOrganize().getName();
// 获取工厂名称
MesConfig mesConfig = configService.getMesConfigByCfgCode(MesPcnExtConstWords.ORGANIZE_NAME,mesProduceSnPrintModel.getOrganizeCode());
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(), mesProduceSnPrintModel.getOrganizeCode());
//打印日期格式
@ -114,20 +131,35 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
if (StringUtils.isEmpty(mesProduceSnPrintModel.getProductSn())) {
ValidatorBean.checkNotNull(mesProduceSnPrintModel.getSnRule(), "条码规则不能为空");
ValidatorBean.checkNotNull(mesProduceSnPrintModel.getPrintTemplate(), "打印模板不能为空");
//流水号
List<String> serialNoList = getSerialNoList(mesProduceSnPrintModel);
//条码二维码模板
String template = getTemplate(mesProduceSnPrintModel, mesPart);
List<MesProduceSn> mesMesProduceSnList = new ArrayList<>();
for (String no : serialNoList) {
//获取条码规则,根据条码规则中的序列号长度截取序列号
DdlPackBean mesRulePackBean = DdlPackBean.getDdlPackBean(mesProduceSnPrintModel.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getSnRule(),"ruleCode", mesRulePackBean);
List<MesNumberRule> ruleList = mesNumberRuleRDao.findByHqlWhere(mesRulePackBean);
if (ruleList.isEmpty()){
MesPcnException.throwMesBusiException("打印模板规则查询不到!");
}
MesNumberRule mesNumberRule = ruleList.get(0);
int serialNoLength = mesNumberRule.getSerialnoLength();
GenSerialNoModel genSerialNoModel = new GenSerialNoModel();
genSerialNoModel.setRuleCode(mesPart.getProductMatchRule());
genSerialNoModel.setPartNo(mesPart.getPartNo());
int printQty = mesProduceSnPrintModel.getPrintQty();
String sn;
for (int i = 0; i < printQty; i++) {
ResultBean resultBean = syncFuncService.syncSerialNo(genSerialNoModel, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getOrganizeCode(), 1);
sn = resultBean.getResultList().get(0).toString();
//保存条码信息
MesProduceSn produceSn = generateMesProduceSn(mesPart, template.replace("serialNo", no), mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format);
mesMesProduceSnList.add(produceSn);
MesProduceSn produceSn = generateMesProduceSn(mesPart, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format);
//封装打印信息
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(produceSn, no, mesProduceSnPrintModel.getCustPartNo(), organizeName));
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(produceSn, sn.substring(sn.length()-serialNoLength), mesProduceSnPrintModel.getCustPartNo(), organizeName));
mesProduceSnRDao.insert(produceSn);
//保存打印记录
MesPrintedSnLog snLog = new MesPrintedSnLog();
ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName());
snLog.setSn(sn);
mesPrintedSnRao.insert(snLog);
}
mesProduceSnRDao.saveAll(mesMesProduceSnList);
//条码补打
} else {
ValidatorBean.checkNotNull(mesPart.getProductLabelTemplate(), "打印模板不能为空");
@ -143,6 +175,10 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
no = mesProduceSn.getProductSn().substring(36, 40);
}
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(mesProduceSn, no, custPartNo, organizeName));
MesPrintedSnLog snLog = new MesPrintedSnLog();
ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName());
snLog.setSn(mesProduceSn.getProductSn());
mesPrintedSnRao.insert(snLog);
}
//获取打印模板信息
mesProduceSnPrintModel.setMesLabelTemplate(mesTemplateService.getMesLabelTemplate(mesProduceSnPrintModel.getPrintTemplate()));
@ -191,44 +227,44 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
return mesProduceSnPrintDataModel;
}
private List<String> getSerialNoList(MesProduceSnPrintModel mesProduceSnPrintModel) {
List<String> 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 List<String> getSerialNoList(MesProduceSnPrintModel mesProduceSnPrintModel) {
// List<String> 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());

@ -38,11 +38,13 @@ public class AionPrintStrategy implements IPrintTemplateStrategyService {
private MesPartRepository mesPartRao;
@Override
public Map<String,Object> execute(StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
//partNo零件号
String partNo = sn.getPartNo();
//零件条码中获取 serialNo
String productSn = sn.getProductSn();
//构造标签
Map<String,Object> map = new HashMap<>();
String partNo = sn.getPartNo();
String partName = sn.getPartName();
String factoryName = reqBean.getOrganizeName();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
@ -52,37 +54,37 @@ public class AionPrintStrategy implements IPrintTemplateStrategyService {
String noStr = String.format("%07d", no);
//构造二维码
StringBuilder barcode = new StringBuilder();
barcode.append("+");
// StringBuilder barcode = new StringBuilder();
// barcode.append("+");
//第二位 是零件简号 零件扩展信息中的 零件条码参数 字段
DdlPackBean partPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(partNo,"partNo",partPackBean);
List<MesPart> 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);
}
}
// List<MesPart> 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 supplierCode = "VD501";
// barcode.append(supplierCode);
//第四位 生产线代号 // 配置表
String workCenterCode = "1";
barcode.append(workCenterCode);
// 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);
// 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);
@ -90,7 +92,7 @@ public class AionPrintStrategy implements IPrintTemplateStrategyService {
map.put("factoryName",factoryName);
map.put("productDate",productDate);
map.put("no",noStr);
map.put("barcode",barcode.toString());
map.put("barcode",productSn);
return map;
}

@ -1,10 +1,11 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.MesConfigService;
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.pojo.mes.model.StationRequestBean;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@ -22,35 +23,29 @@ import java.util.Map;
@Service
@Slf4j
public class NoSortBarCodeGzStrategy implements IPrintTemplateStrategyService {
@Autowired
private MesConfigService mesConfigService;
@Override
public Map<String, Object> execute(StationRequestBean reqBean,MesProductionPsOutContext sn, String organizeCode) {
//获取供应商编码
String supplierCode = mesConfigService.getCfgValue(reqBean.getOrganizeCode(), "supplierCode");
//1.根据零件号获取 零件扩展信息
Map<String,Object> map = new HashMap<>();
String partNo = sn.getPartNo();
String partName = sn.getPartName();
String factoryName = reqBean.getOrganizeName();
String supplierCode = "VD501";
int no = 1;
String noStr = String.format("%04d", no);
String productSn = sn.getProductSn();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
String productDateTime = now.format(formatter);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String productDate = now.format(dateFormatter);
StringBuilder barcode = new StringBuilder(partNo);
barcode.append(partName);
barcode.append(productDate);
barcode.append(noStr);
map.put("partNo", partNo);
map.put("partName", partName);
map.put("factoryName", factoryName);
map.put("supplierCode", supplierCode);
map.put("productDate", productDateTime);
map.put("no", noStr);
map.put("barcode", barcode.toString());
map.put("no", productSn.substring(productSn.length()-4));
map.put("barcode", productSn);
return map;
}
}

@ -148,6 +148,7 @@ public class MesProductSnPrintStepService extends BaseStepService {
this.sendMessage(reqBean, resultBean);
//todo 更新打印状态
//todo 保存打印条码
return stepResult;
}

@ -25,6 +25,8 @@ public class MesPcnExtConstWords {
public static final String PID = "pid";
// 工厂的常量
public static final String ORGANIZE_CODE = "organizeCode";
//工厂名称常量
public static final String ORGANIZE_NAME = "ORGANIZE_NAME";
// 系统配置代码
public static final String CFG_CODE = "cfgCode";
// 用户ID

Loading…
Cancel
Save