@ -1,10 +1,13 @@
package com.hw.mes.service.impl ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.hw.common.core.constant.* ;
import com.hw.common.core.domain.R ;
import com.hw.common.core.exception.ServiceException ;
import com.hw.common.core.utils.DateUtils ;
import com.hw.common.core.utils.StringUtils ;
import com.hw.common.core.utils.ip.IpUtils ;
import com.hw.common.core.utils.uuid.Seq ;
import com.hw.common.security.utils.SecurityUtils ;
import com.hw.mes.api.domain.* ;
@ -24,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Propagation ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.data.redis.core.StringRedisTemplate ;
import javax.annotation.Resource ;
import java.math.BigDecimal ;
@ -42,8 +46,8 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
@Autowired
private MesBaseBarcodeInfoMapper mesBaseBarcodeInfoMapper ;
@ Resource
private RemotePrinterService remotePrinterServic e;
@ Autowired
private StringRedisTemplate redisTemplat e;
@Autowired
private MesOrderBindMapper mesOrderBindMapper ;
@ -166,10 +170,10 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
if ( mesBaseMaterialInfo = = null ) {
throw new ServiceException ( "物料信息不存在" ) ;
}
if ( mesBaseMaterialInfo . getAlwaysFlag ( ) = = null ) {
throw new ServiceException ( "请先设置此物料信息[物料编码:" + mesBaseBarcodeInfo . getMaterialCode ( )
+ ",物料名称:" + mesBaseBarcodeInfo . getMaterialName ( ) + "]的常备物料标识" ) ;
}
// if (mesBaseMaterialInfo.getAlwaysFlag() == null) {
// throw new ServiceException("请先设置此物料信息[物料编码:" + mesBaseBarcodeInfo.getMaterialCode()
// + ",物料名称:" + mesBaseBarcodeInfo.getMaterialName() + "]的常备物料标识");
// }
//判断选择的采购订单信息,是否已经合并过
MesSaleOrderRelate querySaleOrderRelate = new MesSaleOrderRelate ( ) ;
@ -180,11 +184,11 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
}
// 如果物料信息为非常备物料,则 判断是否有绑定的信息
// 不管物料是否常备物料,都 判断是否有绑定的信息
BigDecimal barcodeAmount = mesBaseBarcodeInfo . getBarcodeAmount ( ) ; //要生成的条码数量
String poNo = StringUtils . isEmpty ( mesBaseBarcodeInfo . getPoNo ( ) ) ? "0" : mesBaseBarcodeInfo . getPoNo ( ) ;
String batchCode = this . getRawBatchCode ( poNo ) ;
if ( ! mesBaseMaterialInfo . getAlwaysFlag ( ) . equals ( MesConstants . MES_MATERIAL_ALWAYS_FLAG_YES ) ) {
// if (!mesBaseMaterialInfo.getAlwaysFlag().equals(MesConstants.MES_MATERIAL_ALWAYS_FLAG_YES)) {
Long orderBindId = mesBaseBarcodeInfo . getOrderBindId ( ) ;
if ( orderBindId = = null ) {
throw new ServiceException ( "请选择绑定销售订单信息的采购订单" ) ;
@ -217,16 +221,16 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
mesOrderBindMapper . updateMesOrderBind ( mesOrderBind ) ;
} else {
MesBaseBarcodeInfo toInsertedBarcodeInfo ;
for ( long i = 0 ; i < barcodeAmount . intValue ( ) ; i + + ) {
// 生成条码数量的不同条码内容
toInsertedBarcodeInfo = getInsertedBarcodeInfo ( mesBaseBarcodeInfo , Seq . getId ( Seq . mesBarcodeSeqType , Seq . mesBarcodeCode ) , batchCode , userName , currentDate ) ;
toInsertedBarcodeInfo . setSaleOrderId ( 0 L ) ;
toInsertedBarcodeInfo . setSafeFlag ( MesConstants . MES_ORDER_BIND_SAFE_FLAG_YES ) ;
mesBaseBarcodeInfoMapper . insertMesBaseBarcodeInfo ( toInsertedBarcodeInfo ) ;
}
}
// } else {
// MesBaseBarcodeInfo toInsertedBarcodeInfo;
// for (long i = 0; i < barcodeAmount.intValue(); i++) {
// // 生成条码数量的不同条码内容
// toInsertedBarcodeInfo = getInsertedBarcodeInfo(mesBaseBarcodeInfo, Seq.getId(Seq.mesBarcodeSeqType, Seq.mesBarcodeCode), batchCode, userName, currentDate);
// toInsertedBarcodeInfo.setSaleOrderId(0L);
// toInsertedBarcodeInfo.setSafeFlag(MesConstants.MES_ORDER_BIND_SAFE_FLAG_YES);
// mesBaseBarcodeInfoMapper.insertMesBaseBarcodeInfo(toInsertedBarcodeInfo);
// }
// }
}
@ -623,184 +627,132 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
* @return
* /
@Override
@Transactional
@Transactional ( rollbackFor = Exception . class )
public int printBarcodes ( Long [ ] barcodeIds , String printType , boolean reprintFlag , Integer printNumber ) {
//获取条码List
// List<List<PrintContentVo>> printContents = new ArrayList<>();
// List<MesBaseBarcodeInfo> toUpdatedBaseBarcodeInfos = new ArrayList<>();
JSONArray pintBarcodeJsonArr = new JSONArray ( ) ;
JSONObject printContentJson = new JSONObject ( ) ;
String barcodeType = "" ;
for ( Long barcodeId : barcodeIds ) {
MesBaseBarcodeInfo mesBaseBarcodeInfo = mesBaseBarcodeInfoMapper . selectMesBaseBarcodeInfoByBarcodeId ( barcodeId ) ;
if ( StringUtils . isEmpty ( barcodeType ) ) {
barcodeType = mesBaseBarcodeInfo . getBarcodeType ( ) ;
}
this . updateBaseBarcodePrintFlag ( mesBaseBarcodeInfo , reprintFlag ) ;
if ( printNumber ! = null & & printNumber > 1 ) {
for ( int i = 0 ; i < printNumber ; i + + ) {
printBarcodesByBarcodeId ( barcodeId , printType , reprintFlag ) ;
JSONObject printBarcodeJson = getBarcodeJsonByBarcode ( mesBaseBarcodeInfo , printType ) ;
pintBarcodeJsonArr . add ( printBarcodeJson ) ;
}
} else {
printBarcodesByBarcodeId ( barcodeId , printType , reprintFlag ) ;
JSONObject printBarcodeJson = getBarcodeJsonByBarcode ( mesBaseBarcodeInfo , printType ) ;
pintBarcodeJsonArr . add ( printBarcodeJson ) ;
}
}
// for (MesBaseBarcodeInfo toUpdateMesBaseBarcodeInfo : toUpdatedBaseBarcodeInfos) {
// toUpdateMesBaseBarcodeInfo.setPrintTime(DateUtils.getNowDate());
// toUpdateMesBaseBarcodeInfo.setPrintPerson(SecurityUtils.getUsername());
// toUpdateMesBaseBarcodeInfo.setPrintFlag(MesConstants.MES_BARCODE_PRINT_FLAG_YES);
// toUpdateMesBaseBarcodeInfo.setPrintNumber(1L);
// toUpdateMesBaseBarcodeInfo.setAcceptedDate(DateUtils.getNowDate());
// this.updateMesBaseBarcodeInfo(toUpdateMesBaseBarcodeInfo);
// }
//
// PrinterVo printerVo = new PrinterVo();
// printerVo.setPrintType(printType);
// printerVo.setPrintContents(printContents);
//
// //调用的打印接口
// R<?> printResultR = remotePrinterService.printBarcodes(printerVo, SecurityConstants.INNER);
// if (printResultR.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
// throw new RuntimeException(printResultR.getMsg());
// }
String printTemplate = "" ;
if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_RAW ) ) {
printTemplate = PrintContentVo . PRINT_TEMPLATE_RAW ;
} else if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_PRODUCT ) ) {
printTemplate = PrintContentVo . PRINT_TEMPLATE_PRODUCT ;
} else if ( barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_BIND ) ) {
printTemplate = PrintContentVo . PRINT_TEMPLATE_BIND ;
}
printContentJson . put ( "template" , printTemplate ) ;
printContentJson . put ( "printContent" , pintBarcodeJsonArr . toString ( ) ) ;
System . out . println ( printContentJson . toString ( ) ) ;
try {
String hostIp = IpUtils . getIpAddr ( ) ;
String printKey = "print_" + hostIp ;
redisTemplate . opsForList ( ) . rightPush ( printKey , printContentJson . toString ( ) ) ;
// redisTemplate.convertAndSend("print_10.10.3.119", printContentJson.toString());
} catch ( Exception e ) {
throw new ServiceException ( "打印失败:" + e . getMessage ( ) ) ;
}
return 1 ;
}
@Transactional ( propagation = Propagation . REQUIRES_NEW )
public void printBarcodesByBarcodeId ( Long barcodeId , String printType , boolean reprintFlag ) {
MesBaseBarcodeInfo mesBaseBarcodeInfo = mesBaseBarcodeInfoMapper . selectMesBaseBarcodeInfoJoinByBarcodeId ( barcodeId ) ;
if ( ! reprintFlag ) {
public void updateBaseBarcodePrintFlag ( MesBaseBarcodeInfo mesBaseBarcodeInfo , boolean reprintFlag ) {
String barcodeType = mesBaseBarcodeInfo . getBarcodeType ( ) ;
if ( ! reprintFlag & & ! barcodeType . equals ( MesConstants . MES_BARCODE_TYPE_BIND ) ) {
String printFlag = mesBaseBarcodeInfo . getPrintFlag ( ) ;
if ( printFlag . equals ( MesConstants . MES_BARCODE_PRINT_FLAG_YES ) ) {
throw new ServiceException ( "此物料条码[" + mesBaseBarcodeInfo . getBarcodeInfo ( ) + "]已经打印过,不能重复打印" ) ;
}
}
String materialName = mesBaseBarcodeInfo . getMaterialName ( ) ;
List < PrintContentVo > printContentVos = new ArrayList < > ( ) ;
PrintContentVo printMaterialCode = new PrintContentVo ( ) ;
printMaterialCode . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_CODE ) ;
printMaterialCode . setValue ( mesBaseBarcodeInfo . getMaterialCode ( ) ) ;
printMaterialCode . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printPreMaterial = new PrintContentVo ( ) ;
// if (mesBaseBarcodeInfo.getBindFlag() == null) {
//
// }
PrintContentVo printSaleOrderCode = new PrintContentVo ( ) ;
printSaleOrderCode . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_SALE_ORDER_CODE ) ;
printSaleOrderCode . setValue ( mesBaseBarcodeInfo . getSaleorderCode ( ) ) ;
printSaleOrderCode . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printBarCode = new PrintContentVo ( ) ;
printBarCode . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QRCODE ) ;
printBarCode . setValue ( mesBaseBarcodeInfo . getBarcodeInfo ( ) ) ;
printBarCode . setType ( PrintContentVo . TYPE_QRCODE ) ;
if ( printType . equals ( PrinterVo . PRINT_TYPE_RAW_LABEL ) ) {
PrintContentVo printMaterialName = new PrintContentVo ( ) ;
printMaterialName . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_NAME ) ;
materialName = materialName . length ( ) < = 10 ? "\n" + materialName : materialName ;
printMaterialName . setValue ( materialName . replaceAll ( "[\\x00-\\x1F\\x7F-\\x9F]" , "" ) ) ;
printMaterialName . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printBatchCode = new PrintContentVo ( ) ;
printBatchCode . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_BATCH_CODE ) ;
printBatchCode . setValue ( mesBaseBarcodeInfo . getBatchCode ( ) ) ;
printBatchCode . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printPoNo = new PrintContentVo ( ) ;
printPoNo . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_PO_NO ) ;
printPoNo . setValue ( mesBaseBarcodeInfo . getPoNo ( ) ) ;
printPoNo . setType ( PrintContentVo . TYPE_TEXT ) ;
//常备物料为安全库存
String printPreMaterialKey = mesBaseBarcodeInfo . getAlwaysFlag ( ) ! = null & & mesBaseBarcodeInfo . getAlwaysFlag ( ) . equals ( MesConstants . MES_MATERIAL_ALWAYS_FLAG_YES )
? PrintContentVo . RAW_MATERIAL_LABEL_KEY_PRE_MATERIAL_YES : PrintContentVo . RAW_MATERIAL_LABEL_KEY_PRE_MATERIAL_NO ;
printPreMaterial . setKey ( printPreMaterialKey ) ;
printPreMaterial . setType ( PrintContentVo . TYPE_CHECKBOX ) ;
PrintContentVo printMaterialSpec = new PrintContentVo ( ) ;
printMaterialSpec . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_SPEC ) ;
if ( StringUtils . isNotEmpty ( mesBaseBarcodeInfo . getBarcodeSpec ( ) ) ) {
printMaterialSpec . setValue ( mesBaseBarcodeInfo . getBarcodeSpec ( ) . replaceAll ( "[\\x00-\\x1F\\x7F-\\x9F]" , "" ) ) ;
}
printMaterialSpec . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printQty = new PrintContentVo ( ) ;
printQty . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QTY ) ;
DecimalFormat df = new DecimalFormat ( "#.##" ) ;
String formattedNumber = df . format ( mesBaseBarcodeInfo . getAmount ( ) = = null ? BigDecimal . ZERO : mesBaseBarcodeInfo . getAmount ( ) ) ;
printQty . setValue ( formattedNumber ) ;
printQty . setType ( PrintContentVo . TYPE_TEXT ) ;
printContentVos . add ( printMaterialName ) ;
printContentVos . add ( printBatchCode ) ;
printContentVos . add ( printPoNo ) ;
printContentVos . add ( printMaterialSpec ) ;
printContentVos . add ( printQty ) ;
} else if ( printType . equals ( PrinterVo . PRINT_TYPE_PRODUCT_LABEL ) ) {
PrintContentVo printMaterialName = new PrintContentVo ( ) ;
materialName = materialName . length ( ) < = 8 ? "\n" + materialName : materialName ;
printMaterialName . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_NAME ) ;
printMaterialName . setValue ( materialName ) ;
printMaterialName . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printQty = new PrintContentVo ( ) ;
printQty . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QTY ) ;
printQty . setValue ( "1" ) ;
printQty . setType ( PrintContentVo . TYPE_TEXT ) ;
PrintContentVo printPlanCode = new PrintContentVo ( ) ;
printPlanCode . setKey ( PrintContentVo . PRODUCT_PLAN_CODE ) ;
printPlanCode . setValue ( mesBaseBarcodeInfo . getPlanCode ( ) ) ;
printPlanCode . setType ( PrintContentVo . TYPE_TEXT ) ;
printContentVos . add ( printMaterialName ) ;
printContentVos . add ( printQty ) ;
printContentVos . add ( printPlanCode ) ;
}
printContentVos . add ( printMaterialCode ) ;
printContentVos . add ( printPreMaterial ) ;
printContentVos . add ( printSaleOrderCode ) ;
printContentVos . add ( printBarCode ) ;
String checkStatus = mesBaseBarcodeInfo . getCheckStatus ( ) = = null ? "" : mesBaseBarcodeInfo . getCheckStatus ( ) ;
if ( checkStatus . equals ( QmsConstants . QMS_CHECK_RESULT_CHECK_STATUS_PASS ) ) {
PrintContentVo printQcResult = new PrintContentVo ( ) ;
printQcResult . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QC_RESULT_YES ) ;
printQcResult . setType ( PrintContentVo . TYPE_CHECKBOX ) ;
printContentVos . add ( printQcResult ) ;
} else if ( checkStatus . equals ( QmsConstants . QMS_CHECK_RESULT_CHECK_STATUS_FAIL ) ) {
PrintContentVo printQcResult = new PrintContentVo ( ) ;
printQcResult . setKey ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QC_RESULT_NO ) ;
printQcResult . setType ( PrintContentVo . TYPE_CHECKBOX ) ;
printContentVos . add ( printQcResult ) ;
}
// printContents.add(printContentVos);
// toUpdatedBaseBarcodeInfos.add(mesBaseBarcodeInfo);
Date currentDate = new Date ( ) ;
mesBaseBarcodeInfo . setUpdateTime ( currentDate ) ;
mesBaseBarcodeInfo . setUpdateBy ( SecurityUtils . getUsername ( ) ) ;
mesBaseBarcodeInfo . setPrintTime ( DateUtils . getNowDate ( ) ) ;
mesBaseBarcodeInfo . setPrintPerson ( SecurityUtils . getUsername ( ) ) ;
mesBaseBarcodeInfo . setPrintFlag ( MesConstants . MES_BARCODE_PRINT_FLAG_YES ) ;
mesBaseBarcodeInfo . setPrintNumber ( mesBaseBarcodeInfo . getPrintNumber ( ) = = null ? 1L : mesBaseBarcodeInfo . getPrintNumber ( ) + 1 ) ;
mesBaseBarcodeInfo . setAcceptedDate ( DateUtils . getNowDate ( ) ) ;
this . updateMesBaseBarcodeInfo ( mesBaseBarcodeInfo ) ;
mesBaseBarcodeInfo . setAcceptedDate ( currentDate ) ;
mesBaseBarcodeInfoMapper . updateMesBaseBarcodeInfo ( mesBaseBarcodeInfo ) ;
}
PrinterVo printerVo = new PrinterVo ( ) ;
printerVo . setPrintType ( printType ) ;
printerVo . setPrintContentVos ( printContentVos ) ;
// @Transactional(propagation = Propagation.REQUIRES_NEW)
public JSONObject getBarcodeJsonByBarcode ( MesBaseBarcodeInfo mesBaseBarcodeInfo , String printType ) {
String materialName = mesBaseBarcodeInfo . getMaterialName ( ) ;
JSONObject printInfoObject = new JSONObject ( ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_CODE , mesBaseBarcodeInfo . getMaterialCode ( ) ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_SALE_ORDER_CODE , mesBaseBarcodeInfo . getSaleorderCode ( ) ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QRCODE , mesBaseBarcodeInfo . getBarcodeInfo ( ) ) ;
if ( printType . equals ( PrinterVo . PRINT_TYPE_RAW_LABEL ) ) {
// materialName = materialName.length() <= 10 ? "\n" + materialName : materialName;
// printMaterialName.setValue(materialName.replaceAll("[\\x00-\\x1F\\x7F-\\x9F]", ""));
// printMaterialName.setType(PrintContentVo.TYPE_TEXT);
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_NAME , materialName ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_BARCODE , mesBaseBarcodeInfo . getBarcodeInfo ( ) ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_BATCH_CODE , mesBaseBarcodeInfo . getBatchCode ( ) ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_PO_NO , mesBaseBarcodeInfo . getPoNo ( ) ) ;
//常备物料为安全库存
// String printPreMaterialKey = mesBaseBarcodeInfo.getAlwaysFlag() != null && mesBaseBarcodeInfo.getAlwaysFlag().equals(MesConstants.MES_MATERIAL_ALWAYS_FLAG_YES)
// ? PrintContentVo.RAW_MATERIAL_LABEL_KEY_PRE_MATERIAL_YES : PrintContentVo.RAW_MATERIAL_LABEL_KEY_PRE_MATERIAL_NO;
// printPreMaterial.setKey(printPreMaterialKey);
// printPreMaterial.setType(PrintContentVo.TYPE_CHECKBOX);
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_SPEC , mesBaseBarcodeInfo . getBarcodeSpec ( ) = = null ? ""
: mesBaseBarcodeInfo . getBarcodeSpec ( ) . replaceAll ( "[\\x00-\\x1F\\x7F-\\x9F]" , "" ) ) ;
// PrintContentVo printQty = new PrintContentVo();
// printQty.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_QTY);
// DecimalFormat df = new DecimalFormat("#.##");
// String formattedNumber = df.format(mesBaseBarcodeInfo.getAmount() == null ? BigDecimal.ZERO : mesBaseBarcodeInfo.getAmount());
// printQty.setValue(formattedNumber);
// printQty.setType(PrintContentVo.TYPE_TEXT);
} else if ( printType . equals ( PrinterVo . PRINT_TYPE_PRODUCT_LABEL ) ) {
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_NAME , materialName ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_MATERIAL_SPEC , mesBaseBarcodeInfo . getBarcodeSpec ( ) = = null ? ""
: mesBaseBarcodeInfo . getBarcodeSpec ( ) . replaceAll ( "[\\x00-\\x1F\\x7F-\\x9F]" , "" ) ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_BARCODE , mesBaseBarcodeInfo . getBarcodeInfo ( ) ) ;
printInfoObject . put ( PrintContentVo . PRODUCT_PLAN_CODE , mesBaseBarcodeInfo . getPlanCode ( ) ) ;
printInfoObject . put ( PrintContentVo . RAW_MATERIAL_LABEL_KEY_QTY , "1" ) ;
//调用的打印接口
R < ? > printResultR = remotePrinterService . printBarcodes ( printerVo , SecurityConstants . INNER ) ;
if ( printResultR . getCode ( ) ! = Constants . SUCCESS ) {
throw new RuntimeException ( printResultR . getMsg ( ) ) ;
}
return printInfoObject ;
}
@ -1434,7 +1386,7 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
Long materialId = this . insertNewVirtualMaterial ( barcodeInfo , userName , currentDate ) ;
//创建虚拟销售订单,保存对应的销售订单列表
MesSaleOrder virtualSaleOrder = this . insertNewVirtualSaleOrder ( materialId , barcodeInfo , mes SaleOrderRelateList, userName , currentDate ) ;
MesSaleOrder virtualSaleOrder = this . insertNewVirtualSaleOrder ( materialId , barcodeInfo , mes BaseBarcodeInfo. getSaleorderCode ( ) , mes SaleOrderRelateList, userName , currentDate ) ;
//创建虚拟bom, 并合并销售订单的bom信息
this . insertVirtualMaterialBom ( materialId , barcodeInfo , toUpdatedMaterialBoms , userName , currentDate ) ;
@ -1448,7 +1400,7 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
toInsertedBarcodeInfo . setPurchaseOrderId ( - 1L ) ;
toInsertedBarcodeInfo . setMaterialId ( materialId ) ;
toInsertedBarcodeInfo . setSaleOrderId ( virtualSaleOrder . getSaleOrderId ( ) ) ;
toInsertedBarcodeInfo . setSaleorderCode ( virtualSaleOrder . getSaleorderCode ( ) ) ;
toInsertedBarcodeInfo . setSaleorderCode ( mesBaseBarcodeInfo . getSaleorderCode ( ) ) ;
toInsertedBarcodeInfo . setSafeFlag ( MesConstants . MES_ORDER_BIND_SAFE_FLAG_NO ) ;
toInsertedBarcodeInfo . setSingleFlag ( MesConstants . MES_BARCODE_SINGLE_FLAG_MERGE ) ;
// toInsertedBarcodeInfo.setBarcodeSpec(materialCodes.toString());
@ -1490,7 +1442,7 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
}
public MesSaleOrder insertNewVirtualSaleOrder ( Long materialId , String barcodeInfo ,
public MesSaleOrder insertNewVirtualSaleOrder ( Long materialId , String barcodeInfo , String saleOrderCode ,
List < MesSaleOrderRelate > mesSaleOrderRelates , String userName , Date currentDate ) {
@ -1504,7 +1456,7 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
mesSaleOrder . setMaterialCode ( barcodeInfo ) ;
mesSaleOrder . setMaterialName ( barcodeInfo ) ;
mesSaleOrder . setOrderAmount ( BigDecimal . ONE ) ;
mesSaleOrder . setSaleorderCode ( Seq. getId ( Seq . me sVirtualSaleOrderSeqType, Seq . mesVirtualS aleOrderCode) ) ;
mesSaleOrder . setSaleorderCode ( saleOrderCode) ;
mesSaleOrder . setIsRelease ( MesConstants . MES_SALE_ORDER_IS_RELEASE_TO_PUBLISH ) ;
// mesSaleOrder.setPlanDeliveryDate();
mesSaleOrder . setSaleOrderClassfication ( MesConstants . MES_SALE_ORDER_CLASSFICATION_VIRTUAL ) ;
@ -1667,13 +1619,31 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
userName , currentDate ) ;
//新增的绑定信息
StringBuilder errorMsgBuilder = this . handleInsertSaleOrderRelates ( mesSaleOrderRelateList , mesBaseBarcodeInfo , virtualMaterialBom , userName , currentDate ) ;
StringBuilder errorMsgBuilder = this . handleInsertSaleOrderRelates ( mesSaleOrderRelateList , mesBaseBarcodeInfo , virtualMaterialBom , userName , currentDate ) ;
if ( errorMsgBuilder . length ( ) > 0 ) {
throw new ServiceException ( errorMsgBuilder . toString ( ) ) ;
}
// 判断是否要更新虚拟订单的销售订单号
if ( dbMesSaleOrderRelateList ! = null & & ! dbMesSaleOrderRelateList . isEmpty ( )
& & mesSaleOrderRelateList ! = null & & ! mesSaleOrderRelateList . isEmpty ( ) ) {
MesSaleOrderRelate toDeletedMesSaleOrderRelate = dbMesSaleOrderRelateList . get ( 0 ) ;
String oldSaleOrderCode = toDeletedMesSaleOrderRelate . getRelateSaleOrderCode ( ) ;
MesSaleOrderRelate toInsertedMesSaleOrder = mesSaleOrderRelateList . get ( 0 ) ;
String newSaleOrderCode = toInsertedMesSaleOrder . getRelateSaleOrderCode ( ) ;
if ( ! oldSaleOrderCode . equals ( newSaleOrderCode ) ) {
MesSaleOrder virtualSaleOrder = mesSaleOrderMapper . selectMesSaleOrderBySaleOrderId ( toDeletedMesSaleOrderRelate . getSaleOrderId ( ) ) ;
virtualSaleOrder . setSaleorderCode ( newSaleOrderCode ) ;
virtualSaleOrder . setUpdateTime ( currentDate ) ;
virtualSaleOrder . setUpdateBy ( userName ) ;
mesSaleOrderMapper . updateMesSaleOrder ( virtualSaleOrder ) ;
}
}
//生成条码
mesBaseBarcodeInfo . setUpdateBy ( userName ) ;
@ -1727,7 +1697,7 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
}
public StringBuilder handleInsertSaleOrderRelates ( List < MesSaleOrderRelate > toInsertedSaleOrderRelateList , MesBaseBarcodeInfo baseBarcodeInfo ,
public StringBuilder handleInsertSaleOrderRelates ( List < MesSaleOrderRelate > toInsertedSaleOrderRelateList , MesBaseBarcodeInfo baseBarcodeInfo ,
MesMaterialBom virtualMaterialBom , String userName , Date currentDate ) {
StringBuilder errorMsgBuilder = new StringBuilder ( ) ;
List < MesMaterialBom > toUpdatedMaterialBoms = new ArrayList < > ( ) ;
@ -2066,4 +2036,194 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
// return 1;
// }
// /**
// * 打印物料条码
// *
// * @param barcodeIds
// * @param printType 打印类型( 1原材料 3成品)
// * @param reprintFlag 重新打印标识(1重新打印)
// * @param printNumber 打印数量
// * @return
// */
// @Override
// @Transactional
// public int printBarcodes(Long[] barcodeIds, String printType, boolean reprintFlag, Integer printNumber) {
// //获取条码List
//// List<List<PrintContentVo>> printContents = new ArrayList<>();
//// List<MesBaseBarcodeInfo> toUpdatedBaseBarcodeInfos = new ArrayList<>();
//
// for (Long barcodeId : barcodeIds) {
// if (printNumber != null && printNumber > 1) {
// for (int i = 0; i < printNumber; i++) {
// printBarcodesByBarcodeId(barcodeId, printType, reprintFlag);
// }
// } else {
// printBarcodesByBarcodeId(barcodeId, printType, reprintFlag);
// }
//
// }
//
//// for (MesBaseBarcodeInfo toUpdateMesBaseBarcodeInfo : toUpdatedBaseBarcodeInfos) {
//// toUpdateMesBaseBarcodeInfo.setPrintTime(DateUtils.getNowDate());
//// toUpdateMesBaseBarcodeInfo.setPrintPerson(SecurityUtils.getUsername());
//// toUpdateMesBaseBarcodeInfo.setPrintFlag(MesConstants.MES_BARCODE_PRINT_FLAG_YES);
//// toUpdateMesBaseBarcodeInfo.setPrintNumber(1L);
//// toUpdateMesBaseBarcodeInfo.setAcceptedDate(DateUtils.getNowDate());
//// this.updateMesBaseBarcodeInfo(toUpdateMesBaseBarcodeInfo);
//// }
////
//// PrinterVo printerVo = new PrinterVo();
//// printerVo.setPrintType(printType);
//// printerVo.setPrintContents(printContents);
////
//// //调用的打印接口
//// R<?> printResultR = remotePrinterService.printBarcodes(printerVo, SecurityConstants.INNER);
//// if (printResultR.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
//// throw new RuntimeException(printResultR.getMsg());
//// }
//
// return 1;
//
// }
// @Transactional(propagation = Propagation.REQUIRES_NEW)
// public void printBarcodesByBarcodeId(Long barcodeId, String printType, boolean reprintFlag) {
// MesBaseBarcodeInfo mesBaseBarcodeInfo = mesBaseBarcodeInfoMapper.selectMesBaseBarcodeInfoJoinByBarcodeId(barcodeId);
// if (!reprintFlag) {
// String printFlag = mesBaseBarcodeInfo.getPrintFlag();
// if (printFlag.equals(MesConstants.MES_BARCODE_PRINT_FLAG_YES)) {
// throw new ServiceException("此物料条码[" + mesBaseBarcodeInfo.getBarcodeInfo() + "]已经打印过,不能重复打印");
// }
// }
//
// String materialName = mesBaseBarcodeInfo.getMaterialName();
// List<PrintContentVo> printContentVos = new ArrayList<>();
//
// PrintContentVo printMaterialCode = new PrintContentVo();
// printMaterialCode.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_MATERIAL_CODE);
// printMaterialCode.setValue(mesBaseBarcodeInfo.getMaterialCode());
// printMaterialCode.setType(PrintContentVo.TYPE_TEXT);
//
// PrintContentVo printPreMaterial = new PrintContentVo();
//// if (mesBaseBarcodeInfo.getBindFlag() == null) {
////
//// }
//
// PrintContentVo printSaleOrderCode = new PrintContentVo();
// printSaleOrderCode.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_SALE_ORDER_CODE);
// printSaleOrderCode.setValue(mesBaseBarcodeInfo.getSaleorderCode());
// printSaleOrderCode.setType(PrintContentVo.TYPE_TEXT);
//
//
// PrintContentVo printBarCode = new PrintContentVo();
// printBarCode.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_QRCODE);
// printBarCode.setValue(mesBaseBarcodeInfo.getBarcodeInfo());
// printBarCode.setType(PrintContentVo.TYPE_QRCODE);
//
// if (printType.equals(PrinterVo.PRINT_TYPE_RAW_LABEL)) {
// PrintContentVo printMaterialName = new PrintContentVo();
// printMaterialName.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_MATERIAL_NAME);
// materialName = materialName.length() <= 10 ? "\n" + materialName : materialName;
// printMaterialName.setValue(materialName.replaceAll("[\\x00-\\x1F\\x7F-\\x9F]", ""));
// printMaterialName.setType(PrintContentVo.TYPE_TEXT);
//
// PrintContentVo printBatchCode = new PrintContentVo();
// printBatchCode.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_BATCH_CODE);
// printBatchCode.setValue(mesBaseBarcodeInfo.getBatchCode());
// printBatchCode.setType(PrintContentVo.TYPE_TEXT);
//
// PrintContentVo printPoNo = new PrintContentVo();
// printPoNo.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_PO_NO);
// printPoNo.setValue(mesBaseBarcodeInfo.getPoNo());
// printPoNo.setType(PrintContentVo.TYPE_TEXT);
//
// //常备物料为安全库存
// String printPreMaterialKey = mesBaseBarcodeInfo.getAlwaysFlag() != null && mesBaseBarcodeInfo.getAlwaysFlag().equals(MesConstants.MES_MATERIAL_ALWAYS_FLAG_YES)
// ? PrintContentVo.RAW_MATERIAL_LABEL_KEY_PRE_MATERIAL_YES : PrintContentVo.RAW_MATERIAL_LABEL_KEY_PRE_MATERIAL_NO;
// printPreMaterial.setKey(printPreMaterialKey);
// printPreMaterial.setType(PrintContentVo.TYPE_CHECKBOX);
//
// PrintContentVo printMaterialSpec = new PrintContentVo();
// printMaterialSpec.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_MATERIAL_SPEC);
// if (StringUtils.isNotEmpty(mesBaseBarcodeInfo.getBarcodeSpec())) {
// printMaterialSpec.setValue(mesBaseBarcodeInfo.getBarcodeSpec().replaceAll("[\\x00-\\x1F\\x7F-\\x9F]", ""));
// }
// printMaterialSpec.setType(PrintContentVo.TYPE_TEXT);
//
// PrintContentVo printQty = new PrintContentVo();
// printQty.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_QTY);
// DecimalFormat df = new DecimalFormat("#.##");
// String formattedNumber = df.format(mesBaseBarcodeInfo.getAmount() == null ? BigDecimal.ZERO : mesBaseBarcodeInfo.getAmount());
// printQty.setValue(formattedNumber);
// printQty.setType(PrintContentVo.TYPE_TEXT);
//
// printContentVos.add(printMaterialName);
// printContentVos.add(printBatchCode);
// printContentVos.add(printPoNo);
// printContentVos.add(printMaterialSpec);
// printContentVos.add(printQty);
//
// } else if (printType.equals(PrinterVo.PRINT_TYPE_PRODUCT_LABEL)) {
// PrintContentVo printMaterialName = new PrintContentVo();
// materialName = materialName.length() <= 8 ? "\n" + materialName : materialName;
// printMaterialName.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_MATERIAL_NAME);
// printMaterialName.setValue(materialName);
// printMaterialName.setType(PrintContentVo.TYPE_TEXT);
//
// PrintContentVo printQty = new PrintContentVo();
// printQty.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_QTY);
// printQty.setValue("1");
// printQty.setType(PrintContentVo.TYPE_TEXT);
//
// PrintContentVo printPlanCode = new PrintContentVo();
// printPlanCode.setKey(PrintContentVo.PRODUCT_PLAN_CODE);
// printPlanCode.setValue(mesBaseBarcodeInfo.getPlanCode());
// printPlanCode.setType(PrintContentVo.TYPE_TEXT);
// printContentVos.add(printMaterialName);
// printContentVos.add(printQty);
// printContentVos.add(printPlanCode);
// }
//
// printContentVos.add(printMaterialCode);
// printContentVos.add(printPreMaterial);
// printContentVos.add(printSaleOrderCode);
// printContentVos.add(printBarCode);
//
// String checkStatus = mesBaseBarcodeInfo.getCheckStatus() == null ? "" : mesBaseBarcodeInfo.getCheckStatus();
// if (checkStatus.equals(QmsConstants.QMS_CHECK_RESULT_CHECK_STATUS_PASS)) {
// PrintContentVo printQcResult = new PrintContentVo();
// printQcResult.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_QC_RESULT_YES);
// printQcResult.setType(PrintContentVo.TYPE_CHECKBOX);
// printContentVos.add(printQcResult);
// } else if (checkStatus.equals(QmsConstants.QMS_CHECK_RESULT_CHECK_STATUS_FAIL)) {
// PrintContentVo printQcResult = new PrintContentVo();
// printQcResult.setKey(PrintContentVo.RAW_MATERIAL_LABEL_KEY_QC_RESULT_NO);
// printQcResult.setType(PrintContentVo.TYPE_CHECKBOX);
// printContentVos.add(printQcResult);
// }
//
//// printContents.add(printContentVos);
//// toUpdatedBaseBarcodeInfos.add(mesBaseBarcodeInfo);
//
// mesBaseBarcodeInfo.setPrintTime(DateUtils.getNowDate());
// mesBaseBarcodeInfo.setPrintPerson(SecurityUtils.getUsername());
// mesBaseBarcodeInfo.setPrintFlag(MesConstants.MES_BARCODE_PRINT_FLAG_YES);
// mesBaseBarcodeInfo.setPrintNumber(mesBaseBarcodeInfo.getPrintNumber() == null ? 1L : mesBaseBarcodeInfo.getPrintNumber() + 1);
// mesBaseBarcodeInfo.setAcceptedDate(DateUtils.getNowDate());
// this.updateMesBaseBarcodeInfo(mesBaseBarcodeInfo);
//
//
// PrinterVo printerVo = new PrinterVo();
// printerVo.setPrintType(printType);
// printerVo.setPrintContentVos(printContentVos);
//
// //调用的打印接口
// R<?> printResultR = remotePrinterService.printBarcodes(printerVo, SecurityConstants.INNER);
// if (printResultR.getCode() != Constants.SUCCESS) {
// throw new RuntimeException(printResultR.getMsg());
// }
//
// }
}