@ -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 mesPrintedSnR ao;
@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 ( ) ) ;