tags/yfai-pcn-ext-v1.0
王杰 11 months ago
commit 6716d7c978

@ -24,13 +24,12 @@ 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.ValidatorBean;
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.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@ -113,72 +112,242 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
@Override
public MesProduceSnPrintModel doPrint(MesProduceSnPrintModel mesProduceSnPrintModel) {
String organizeCode = mesProduceSnPrintModel.getOrganizeCode();
// 获取工厂名称
MesConfig mesConfig = configService.getMesConfigByCfgCode(MesPcnExtConstWords.ORGANIZE_NAME,mesProduceSnPrintModel.getOrganizeCode());
if (null == mesConfig || StringUtils.isEmpty(mesConfig.getCfgValue())){
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(), 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;
}
MesPart mesPart = mesPartService.getMesPartByPartNo(mesProduceSnPrintModel.getPartNo(), organizeCode);
//条码生成
if (StringUtils.isEmpty(mesProduceSnPrintModel.getProductSn())) {
ValidatorBean.checkNotNull(mesProduceSnPrintModel.getSnRule(), "条码规则不能为空");
ValidatorBean.checkNotNull(mesProduceSnPrintModel.getPrintTemplate(), "打印模板不能为空");
//打印模板
String printTemplate = mesProduceSnPrintModel.getPrintTemplate();
//打印规则
String snRule = mesProduceSnPrintModel.getSnRule();
//获取条码规则,根据条码规则中的序列号长度截取序列号
DdlPackBean mesRulePackBean = DdlPackBean.getDdlPackBean(mesProduceSnPrintModel.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getSnRule(),"ruleCode", mesRulePackBean);
DdlPackBean mesRulePackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(snRule, "ruleCode", mesRulePackBean);
List<MesNumberRule> ruleList = mesNumberRuleRDao.findByHqlWhere(mesRulePackBean);
if (ruleList.isEmpty()){
MesPcnException.throwMesBusiException("打印模板规则查询不到!");
if (ruleList.isEmpty()) {
MesPcnException.throwMesBusiException("零件号【】打印规则查询不到!", mesPart.getPartNo());
}
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, sn, mesProduceSnPrintModel.getUserName(), mesProduceSnPrintModel.getQty(), format);
//封装打印信息
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);
MesNumberRule numberRule = ruleList.get(0);
//打印日期格式
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);
}
}
//条码补打
} else {
ValidatorBean.checkNotNull(mesPart.getProductLabelTemplate(), "打印模板不能为空");
mesProduceSnPrintModel.setPrintTemplate(mesPart.getProductLabelTemplate());
MesProduceSn mesProduceSn = findMesProduceSn(mesProduceSnPrintModel);
String no = "";
String custPartNo = "";
if (MesPcnEnumUtil.PRINT_TEMPLATE.GQXNY.getCode().equals(mesProduceSnPrintModel.getPrintTemplate())
&& !Objects.isNull(mesProduceSn.getProductSn())
&& mesProduceSn.getProductSn().length() >= 40) {
//获取客户零件号
custPartNo = getMesCustomerPart(mesProduceSnPrintModel).getCustPartNo();
no = mesProduceSn.getProductSn().substring(36, 40);
//查找打印记录
DdlPackBean snLogPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(mesProduceSnPrintModel.getProductSn(),"barcode",snLogPackBean);
List<MesPrintedSnLog> snLogList = mesPrintedSnRao.findByHqlWhere(snLogPackBean);
if (snLogList.isEmpty()){
MesPcnException.throwMesBusiException("条码【】查询不到打印记录!", mesProduceSnPrintModel.getProductSn());
}
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(getModel(mesProduceSn, no, custPartNo, organizeName));
MesPrintedSnLog snLog = new MesPrintedSnLog();
ConvertBean.serviceModelInitialize(snLog, mesProduceSnPrintModel.getUserName());
snLog.setSn(mesProduceSn.getProductSn());
mesPrintedSnRao.insert(snLog);
MesPrintedSnLog mesPrintedSnLog = snLogList.get(0);
MesProduceSnPrintDataModel model = new MesProduceSnPrintDataModel();
BeanUtil.copyProperties(mesPrintedSnLog,model);
mesProduceSnPrintModel.getMesProduceSnPrintDataModelList().add(model);
}
//获取打印模板信息
mesProduceSnPrintModel.setMesLabelTemplate(mesTemplateService.getMesLabelTemplate(mesProduceSnPrintModel.getPrintTemplate()));
@ -310,6 +479,26 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
return dateTime.append(yearStr).append(monthStr).append(TimeTool.getDay(date)).toString();
}
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 String stringFormat(String data, Integer length) {
return stringFormat(data, length, true, "*");
@ -321,15 +510,19 @@ public class MesProduceSnPrintService implements IMesProduceSnPrintService {
return data;
}
StringBuilder dataBuffer = new StringBuilder();
//拼接
//拼接
if (left) {
dataBuffer.append(data);
for (int i = 0; i < length - data.length(); i++) {
dataBuffer.append(symbol);
}
}
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();

@ -1,7 +1,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.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import java.util.List;
import java.util.Map;
@ -20,5 +22,5 @@ public interface IPrintTemplateStrategyService {
* @param sn
* @return
*/
Map<String,Object> execute(StationRequestBean reqBean, MesProductionPsOutContext sn , String organizeCode);
MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn , String organizeCode);
}

@ -2,11 +2,13 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
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.pojo.base.bean.DdlPackBean;
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;
@ -37,7 +39,7 @@ public class AionPrintStrategy implements IPrintTemplateStrategyService {
@Autowired
private MesPartRepository mesPartRao;
@Override
public Map<String,Object> execute(StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
//partNo零件号
String partNo = sn.getPartNo();
@ -93,7 +95,8 @@ public class AionPrintStrategy implements IPrintTemplateStrategyService {
map.put("productDate",productDate);
map.put("no",noStr);
map.put("barcode",productSn);
return map;
// return map;
return null;
}
}

@ -2,7 +2,9 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
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.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -23,7 +25,7 @@ import java.util.Map;
@Slf4j
public class GqaaPrintStrategy implements IPrintTemplateStrategyService {
@Override
public Map<String, Object> execute(StationRequestBean reqBean,MesProductionPsOutContext sn, String organizeCode) {
public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
Map<String,Object> map = new HashMap<>();
String partNo = sn.getPartNo();
@ -51,6 +53,6 @@ public class GqaaPrintStrategy implements IPrintTemplateStrategyService {
map.put("factoryName", factoryName);
map.put("productDate", productDate);
map.put("barcode", barcode.toString());
return map;
return null;
}
}

@ -2,7 +2,9 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
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.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -23,7 +25,7 @@ import java.util.Map;
@Slf4j
public class GqxnyPrintStrategy implements IPrintTemplateStrategyService {
@Override
public Map<String, Object> execute(StationRequestBean reqBean,MesProductionPsOutContext sn, String organizeCode) {
public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
Map<String,Object> map = new HashMap<>();
String partNo = sn.getPartNo();
@ -51,6 +53,6 @@ public class GqxnyPrintStrategy implements IPrintTemplateStrategyService {
map.put("factoryName", factoryName);
map.put("productDate", productDate);
map.put("barcode", barcode.toString());
return map;
return null;
}
}

@ -1,9 +1,13 @@
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.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel;
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.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -24,11 +28,17 @@ import java.util.Map;
@Slf4j
public class NoSortBarCodeGzStrategy implements IPrintTemplateStrategyService {
@Autowired
private MesConfigService mesConfigService;
private IConfigService configService;
@Override
public Map<String, Object> execute(StationRequestBean reqBean,MesProductionPsOutContext sn, String organizeCode) {
public MesProduceSnPrintDataModel execute(StepResult stepResult,StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
//获取供应商编码
String supplierCode = mesConfigService.getCfgValue(reqBean.getOrganizeCode(), "supplierCode");
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;
}
String supplierCode = mesConfig.getCfgValue();
//1.根据零件号获取 零件扩展信息
Map<String,Object> map = new HashMap<>();
String partNo = sn.getPartNo();
@ -36,16 +46,17 @@ public class NoSortBarCodeGzStrategy implements IPrintTemplateStrategyService {
String factoryName = reqBean.getOrganizeName();
String productSn = sn.getProductSn();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String productDateTime = now.format(formatter);
map.put("partNo", partNo);
map.put("partName", partName);
map.put("factoryName", factoryName);
map.put("supplierCode", supplierCode);
map.put("productDate", productDateTime);
map.put("no", productSn.substring(productSn.length()-4));
map.put("barcode", productSn);
return map;
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;
}
}

@ -2,14 +2,14 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.strategy;
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.pojo.mes.model.StationRequestBean;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -22,9 +22,9 @@ import java.util.Map;
**/
@Service
@Slf4j
public class NoSortBarCodeGzNewStrategy implements IPrintTemplateStrategyService {
public class XiaoPengPrintStrategy implements IPrintTemplateStrategyService {
@Override
public Map<String, Object> execute(StationRequestBean reqBean,MesProductionPsOutContext sn, String organizeCode) {
public MesProduceSnPrintDataModel execute(StepResult stepResult, StationRequestBean reqBean, MesProductionPsOutContext sn, String organizeCode) {
//从条码中截取流水号,流水号 后四位
String productSn = sn.getProductSn();
Map<String,Object> map = new HashMap<>();
@ -33,10 +33,11 @@ public class NoSortBarCodeGzNewStrategy implements IPrintTemplateStrategyService
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
String productDateTime = now.format(formatter);
map.put("partNo",partNo);
map.put("partName",partName);
map.put("productDateTime",productDateTime);
map.put("barcode",productSn);
return map;
MesProduceSnPrintDataModel model = new MesProduceSnPrintDataModel();
model.setPartNo(partNo);
model.setBarcode(productSn);
model.setPartName(partName);
model.setProductDate(productDateTime);
return model;
}
}

@ -109,7 +109,7 @@ public class MesAssemblyShowSortStepService extends BaseStepService {
//上下文中不存在进料主条码数据信息
if (CollectionUtils.isEmpty(productionPsInContextList) || CollectionUtils.isEmpty(productionPartContextList))
execNonCompleteAndSendMsg(reqBean, resultBean.writeDbLog(), stepResult, String.format("生产线[%s]工位[%s]的上下文中已不存在加工单或条码数据信息,请重置工序!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()));
execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("生产线[%s]工位[%s]的上下文中已不存在加工单或条码数据信息,请重置工序!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()));
//拿到当前最大的foreignKey
Optional<MesProductionPsInContext> maxForeignKeyOptional = productionPsInContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).max(Comparator.comparing(MesProductionPsInContext::getForeignKey));

@ -5,19 +5,24 @@ import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepServ
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.print.IPrintTemplateStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProduceSnPrintDataModel;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
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.MesLabelTemplate;
import cn.estsh.i3plus.pojo.mes.bean.MesLabelTemplateParam;
import cn.estsh.i3plus.pojo.mes.bean.MesPrintedSnLog;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import cn.estsh.i3plus.pojo.mes.repository.IMesPrintedSnLogRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateParamRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesLabelTemplateRepository;
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;
@ -33,8 +38,6 @@ import java.util.stream.Collectors;
**/
@Service
public class MesProductSnPrintStepService extends BaseStepService {
@Autowired
private IMesProductionProcessContextStepService productionProcessContextStepService;
@Autowired
private IMesProductionDispatchContextStepService mesProductionDispatchContextStepService;
@ -45,6 +48,9 @@ public class MesProductSnPrintStepService extends BaseStepService {
@Autowired
private MesLabelTemplateParamRepository labelTemplateParamRao;
@Autowired
private IMesPrintedSnLogRepository snLogRao;
@Override
public StepResult execute(StationRequestBean reqBean) {
/**
@ -65,7 +71,7 @@ public class MesProductSnPrintStepService extends BaseStepService {
List<MesProdRuleContext> prodRuleDataContext = mesProductionDispatchContextStepService.getProdRuleDataContext(reqBean);
Map<Integer, List<MesProdRuleContext>> prodRuleContextMap = prodRuleDataContext.stream().collect(Collectors.groupingBy(MesProdRuleContext::getForeignKey));
//需要打印的数据 String 是打印模板code
Map<String, List<Map<String, Object>>> resultData = new HashMap<>();
Map<String, List<MesProduceSnPrintDataModel>> resultData = new HashMap<>();
//用于保存客户模板代码 和 模板信息关系
Map<String, MesLabelTemplate> labelTemplateMap = new HashMap<>();
//返回打印标识 给前端
@ -105,14 +111,17 @@ public class MesProductSnPrintStepService extends BaseStepService {
execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("零件号[%s]的模板代码[%s]的反射类丢失,请配置!", sn.getPartNo(), prodLabelTemplate));
}
IPrintTemplateStrategyService strategyService = (IPrintTemplateStrategyService) SpringContextsUtil.getBean(methodCode);
Map<String, Object> snData = strategyService.execute(reqBean,sn, organizeCode);
List<Map<String, Object>> printData;
MesProduceSnPrintDataModel model = strategyService.execute(stepResult, reqBean, sn, organizeCode);
if (!stepResult.isCompleted()){
execExpSendMsgAndThrowEx(reqBean, resultBean, stepResult.getMsg());
}
List<MesProduceSnPrintDataModel> printData;
if (resultData.containsKey(labelTemplate.getTemplateCode())) {
printData = resultData.get(labelTemplate.getTemplateCode());
printData.add(snData);
printData.add(model);
} else {
printData = new ArrayList<>();
printData.add(snData);
printData.add(model);
resultData.put(labelTemplate.getTemplateCode(), printData);
}
}
@ -127,9 +136,17 @@ public class MesProductSnPrintStepService extends BaseStepService {
*/
List<Map<String, Object>> printData = new ArrayList<>();
Set<String> labelKeys = labelTemplateMap.keySet();
List<MesPrintedSnLog> snLogList = new ArrayList<>();
for (String labelKey : labelKeys) {
Map<String,Object> paramInfo = new HashMap<>();
List<Map<String, Object>> dataMaps = resultData.get(labelKey);
List<MesProduceSnPrintDataModel> 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);
@ -148,7 +165,8 @@ public class MesProductSnPrintStepService extends BaseStepService {
this.sendMessage(reqBean, resultBean);
//todo 更新打印状态
//todo 保存打印条码
//保存打印条码记录
snLogRao.saveAll(snLogList);
return stepResult;
}

@ -27,6 +27,10 @@ public class MesPcnExtConstWords {
public static final String ORGANIZE_CODE = "organizeCode";
//工厂名称常量
public static final String ORGANIZE_NAME = "ORGANIZE_NAME";
//供应商常量
public static final String SUPPLIER_CODE = "SUPPLIER_CODE";
//获取供应商广州key
public static final String SUPPLIER_CODE_NO_SORT_GZ = "SUPPLIER_CODE_NO_SORT_GZ";
// 系统配置代码
public static final String CFG_CODE = "cfgCode";
// 用户ID

Loading…
Cancel
Save