|
|
|
@ -13,18 +13,16 @@ import com.hw.common.core.utils.StringUtils;
|
|
|
|
|
import com.hw.common.core.utils.uuid.Seq;
|
|
|
|
|
import com.hw.common.security.utils.SecurityUtils;
|
|
|
|
|
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
|
|
|
|
|
import com.hw.mes.api.domain.MesBaseMaterialInfo;
|
|
|
|
|
import com.hw.mes.domain.MesBasePalletInfo;
|
|
|
|
|
import com.hw.mes.domain.MesOrderBind;
|
|
|
|
|
import com.hw.mes.domain.MesProductOrder;
|
|
|
|
|
import com.hw.mes.domain.vo.MesBindBarcodeVo;
|
|
|
|
|
import com.hw.mes.mapper.MesBasePalletInfoMapper;
|
|
|
|
|
import com.hw.mes.mapper.MesOrderBindMapper;
|
|
|
|
|
import com.hw.mes.mapper.MesProductOrderMapper;
|
|
|
|
|
import com.hw.mes.mapper.*;
|
|
|
|
|
import com.hw.mes.service.IMesOrderBindService;
|
|
|
|
|
import com.hw.printer.api.RemotePrinterService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.hw.mes.mapper.MesBaseBarcodeInfoMapper;
|
|
|
|
|
import com.hw.mes.service.IMesBaseBarcodeInfoService;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
@ -51,6 +49,9 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesBasePalletInfoMapper mesBasePalletInfoMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesBaseMaterialInfoMapper mesBaseMaterialInfoMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询条码信息
|
|
|
|
|
*
|
|
|
|
@ -95,6 +96,34 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int insertMesBaseBarcodeInfo(MesBaseBarcodeInfo mesBaseBarcodeInfo) {
|
|
|
|
|
// 生成原材料条码
|
|
|
|
|
if (mesBaseBarcodeInfo.getBarcodeType().equals(MesConstants.MES_BARCODE_TYPE_RAW)) {
|
|
|
|
|
generateRawBarcode(mesBaseBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成成品条码
|
|
|
|
|
else if (mesBaseBarcodeInfo.getBarcodeType().equals(MesConstants.MES_BARCODE_TYPE_PRODUCT)) {
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
String userName = SecurityUtils.getUsername();
|
|
|
|
|
// 批次代码 == 条码内容
|
|
|
|
|
int frequency = mesBaseBarcodeInfo.getAmount().intValue();
|
|
|
|
|
for (int i = 0; i < frequency; i++) {
|
|
|
|
|
String code = Seq.getId(Seq.mesCompBarcodeSeqType, Seq.mesCompBarcodeCode);
|
|
|
|
|
mesBaseBarcodeInfo.setBatchCode(code);
|
|
|
|
|
mesBaseBarcodeInfo.setBarcodeInfo(code);
|
|
|
|
|
mesBaseBarcodeInfo.setAmount(new BigDecimal(1));
|
|
|
|
|
mesBaseBarcodeInfo.setCreateTime(currentDate);
|
|
|
|
|
mesBaseBarcodeInfo.setCreateBy(userName);
|
|
|
|
|
mesBaseBarcodeInfoMapper.insertMesBaseBarcodeInfo(mesBaseBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void generateRawBarcode(MesBaseBarcodeInfo mesBaseBarcodeInfo) {
|
|
|
|
|
Date currentDate = new Date();
|
|
|
|
|
String userName = SecurityUtils.getUsername();
|
|
|
|
|
Long purchaseOrderId = mesBaseBarcodeInfo.getPurchaseOrderId();
|
|
|
|
|
MesBaseBarcodeInfo queryBaseBarcodeInfo = new MesBaseBarcodeInfo();
|
|
|
|
|
queryBaseBarcodeInfo.setPurchaseOrderId(purchaseOrderId);
|
|
|
|
@ -103,22 +132,31 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
|
|
|
|
|
throw new ServiceException("此采购订单已经生成条码,无需重复生成");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal barcodeAmount = mesBaseBarcodeInfo.getBarcodeAmount();
|
|
|
|
|
MesOrderBind queryOrderBind = new MesOrderBind();
|
|
|
|
|
queryOrderBind.setPurchaseOrderId(purchaseOrderId);
|
|
|
|
|
List<MesOrderBind> mesOrderBinds = mesOrderBindMapper.selectMesOrderBindList(queryOrderBind);
|
|
|
|
|
if (mesOrderBinds == null || mesOrderBinds.isEmpty()) {
|
|
|
|
|
throw new ServiceException("此采购订单还未绑定销售订单,不能生成条码");
|
|
|
|
|
Long materialId = mesBaseBarcodeInfo.getMaterialId();
|
|
|
|
|
MesBaseMaterialInfo mesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByMaterialId(materialId);
|
|
|
|
|
if (mesBaseMaterialInfo == null) {
|
|
|
|
|
throw new ServiceException("物料信息不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal totalBindAmount = mesOrderBinds.stream().map(MesOrderBind::getBindAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
if (barcodeAmount.compareTo(totalBindAmount) != 0) {
|
|
|
|
|
throw new ServiceException("采购订单还未完全绑定到销售订单");
|
|
|
|
|
if (mesBaseMaterialInfo.getBindFlag() == null) {
|
|
|
|
|
throw new ServiceException("请先设置此物料信息[物料编码:" + mesBaseBarcodeInfo.getMaterialCode()
|
|
|
|
|
+ ",物料名称:" + mesBaseBarcodeInfo.getMaterialName() + "]的绑定标识");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mesBaseBarcodeInfo.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
// 生成原材料条码
|
|
|
|
|
if (mesBaseBarcodeInfo.getBarcodeType().equals(MesConstants.MES_BARCODE_TYPE_RAW)) {
|
|
|
|
|
//如果物料信息需要绑定,则判断是否有绑定的信息
|
|
|
|
|
BigDecimal barcodeAmount = mesBaseBarcodeInfo.getBarcodeAmount();
|
|
|
|
|
if (mesBaseMaterialInfo.getBindFlag().equals(MesConstants.MES_MATERIAL_BIND_FLAG_YES)) {
|
|
|
|
|
MesOrderBind queryOrderBind = new MesOrderBind();
|
|
|
|
|
queryOrderBind.setPurchaseOrderId(purchaseOrderId);
|
|
|
|
|
List<MesOrderBind> mesOrderBinds = mesOrderBindMapper.selectMesOrderBindList(queryOrderBind);
|
|
|
|
|
if (mesOrderBinds == null || mesOrderBinds.isEmpty()) {
|
|
|
|
|
throw new ServiceException("此采购订单还未绑定销售订单,不能生成条码");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BigDecimal totalBindAmount = mesOrderBinds.stream().map(MesOrderBind::getBindAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
if (barcodeAmount.compareTo(totalBindAmount) != 0) {
|
|
|
|
|
throw new ServiceException("采购订单还未完全绑定到销售订单");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String batchCode = Seq.getId(Seq.mesBatchCodeSeqType, Seq.mesBatchCodeCode);
|
|
|
|
|
MesBaseBarcodeInfo toInsertedBarcodeInfo;
|
|
|
|
|
|
|
|
|
@ -126,51 +164,55 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
|
|
|
|
|
BigDecimal bindAmount = mesOrderBind.getBindAmount();
|
|
|
|
|
for (int i = 0; i < bindAmount.intValue(); i++) {
|
|
|
|
|
// 生成数量条的不同条码内容
|
|
|
|
|
toInsertedBarcodeInfo = new MesBaseBarcodeInfo();
|
|
|
|
|
//同一批次的批次代码相同
|
|
|
|
|
toInsertedBarcodeInfo.setBatchCode(batchCode);
|
|
|
|
|
toInsertedBarcodeInfo.setPurchaseOrderId(purchaseOrderId);
|
|
|
|
|
toInsertedBarcodeInfo.setPoNo(mesBaseBarcodeInfo.getPoNo());
|
|
|
|
|
toInsertedBarcodeInfo.setBarcodeType(MesConstants.MES_BARCODE_TYPE_RAW);
|
|
|
|
|
toInsertedBarcodeInfo.setBarcodeInfo(Seq.getId(Seq.mesBarcodeSeqType, Seq.mesBarcodeCode));
|
|
|
|
|
toInsertedBarcodeInfo.setMaterialId(mesBaseBarcodeInfo.getMaterialId());
|
|
|
|
|
toInsertedBarcodeInfo.setProductionDate(mesBaseBarcodeInfo.getProductionDate());
|
|
|
|
|
toInsertedBarcodeInfo.setLastOutstockDate(mesBaseBarcodeInfo.getLastOutstockDate());
|
|
|
|
|
toInsertedBarcodeInfo.setProjectNo(mesBaseBarcodeInfo.getProjectNo());
|
|
|
|
|
toInsertedBarcodeInfo.setBatchFlag(mesBaseBarcodeInfo.getBatchFlag());
|
|
|
|
|
toInsertedBarcodeInfo = getInsertedBarcodeInfo(mesBaseBarcodeInfo, batchCode, userName, currentDate);
|
|
|
|
|
|
|
|
|
|
toInsertedBarcodeInfo.setSaleOrderId(mesOrderBind.getSaleOrderId());
|
|
|
|
|
toInsertedBarcodeInfo.setSaleorderCode(mesOrderBind.getSaleOrderCode());
|
|
|
|
|
toInsertedBarcodeInfo.setSafeFlag(mesOrderBind.getSafeFlag());
|
|
|
|
|
|
|
|
|
|
if (mesBaseBarcodeInfo.getBatchFlag().equals(MesConstants.NOT_IS_BATCH)) {
|
|
|
|
|
toInsertedBarcodeInfo.setAmount(new BigDecimal(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mesBaseBarcodeInfo.getBatchFlag().equals(MesConstants.IS_BATCH)) {
|
|
|
|
|
toInsertedBarcodeInfo.setAmount(mesBaseBarcodeInfo.getAmount());
|
|
|
|
|
}
|
|
|
|
|
mesBaseBarcodeInfoMapper.insertMesBaseBarcodeInfo(toInsertedBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MesBaseBarcodeInfo toInsertedBarcodeInfo;
|
|
|
|
|
String batchCode = Seq.getId(Seq.mesBatchCodeSeqType, Seq.mesBatchCodeCode);
|
|
|
|
|
for (long i = 0; i < barcodeAmount.intValue(); i++) {
|
|
|
|
|
// 生成数量条的不同条码内容
|
|
|
|
|
toInsertedBarcodeInfo = getInsertedBarcodeInfo(mesBaseBarcodeInfo, batchCode, userName, currentDate);
|
|
|
|
|
toInsertedBarcodeInfo.setSafeFlag(MesConstants.MES_ORDER_BIND_SAFE_FLAG_YES);
|
|
|
|
|
mesBaseBarcodeInfoMapper.insertMesBaseBarcodeInfo(toInsertedBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MesBaseBarcodeInfo getInsertedBarcodeInfo(MesBaseBarcodeInfo mesBaseBarcodeInfo, String batchCode, String userName, Date currentDate) {
|
|
|
|
|
MesBaseBarcodeInfo toInsertedBarcodeInfo = new MesBaseBarcodeInfo();
|
|
|
|
|
//同一批次的批次代码相同
|
|
|
|
|
toInsertedBarcodeInfo.setBatchCode(batchCode);
|
|
|
|
|
toInsertedBarcodeInfo.setPurchaseOrderId(mesBaseBarcodeInfo.getPurchaseOrderId());
|
|
|
|
|
toInsertedBarcodeInfo.setPoNo(mesBaseBarcodeInfo.getPoNo());
|
|
|
|
|
toInsertedBarcodeInfo.setBarcodeType(MesConstants.MES_BARCODE_TYPE_RAW);
|
|
|
|
|
toInsertedBarcodeInfo.setBarcodeInfo(Seq.getId(Seq.mesBarcodeSeqType, Seq.mesBarcodeCode));
|
|
|
|
|
toInsertedBarcodeInfo.setMaterialId(mesBaseBarcodeInfo.getMaterialId());
|
|
|
|
|
toInsertedBarcodeInfo.setProductionDate(mesBaseBarcodeInfo.getProductionDate());
|
|
|
|
|
toInsertedBarcodeInfo.setLastOutstockDate(mesBaseBarcodeInfo.getLastOutstockDate());
|
|
|
|
|
toInsertedBarcodeInfo.setProjectNo(mesBaseBarcodeInfo.getProjectNo());
|
|
|
|
|
toInsertedBarcodeInfo.setBatchFlag(mesBaseBarcodeInfo.getBatchFlag());
|
|
|
|
|
if (mesBaseBarcodeInfo.getBatchFlag().equals(MesConstants.NOT_IS_BATCH)) {
|
|
|
|
|
toInsertedBarcodeInfo.setAmount(new BigDecimal(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成成品条码
|
|
|
|
|
else if (mesBaseBarcodeInfo.getBarcodeType().equals(MesConstants.MES_BARCODE_TYPE_PRODUCT)) {
|
|
|
|
|
// 批次代码 == 条码内容
|
|
|
|
|
int frequency = mesBaseBarcodeInfo.getAmount().intValue();
|
|
|
|
|
for (int i = 0; i < frequency; i++) {
|
|
|
|
|
String code = Seq.getId(Seq.mesCompBarcodeSeqType, Seq.mesCompBarcodeCode);
|
|
|
|
|
mesBaseBarcodeInfo.setBatchCode(code);
|
|
|
|
|
mesBaseBarcodeInfo.setBarcodeInfo(code);
|
|
|
|
|
mesBaseBarcodeInfo.setAmount(new BigDecimal(1));
|
|
|
|
|
mesBaseBarcodeInfoMapper.insertMesBaseBarcodeInfo(mesBaseBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
if (mesBaseBarcodeInfo.getBatchFlag().equals(MesConstants.IS_BATCH)) {
|
|
|
|
|
toInsertedBarcodeInfo.setAmount(mesBaseBarcodeInfo.getAmount());
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
toInsertedBarcodeInfo.setCreateBy(userName);
|
|
|
|
|
toInsertedBarcodeInfo.setCreateTime(currentDate);
|
|
|
|
|
|
|
|
|
|
return toInsertedBarcodeInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改条码信息
|
|
|
|
|
*
|
|
|
|
@ -371,7 +413,7 @@ public class MesBaseBarcodeInfoServiceImpl implements IMesBaseBarcodeInfoService
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MesBaseBarcodeInfo productBarcodeInfo = mesBaseBarcodeInfoMapper.selectMesBaseBarcodeInfoByBarcodeInfo(productBarcode);
|
|
|
|
|
if(productBarcodeInfo==null){
|
|
|
|
|
if (productBarcodeInfo == null) {
|
|
|
|
|
throw new ServiceException("成品条码不存在");
|
|
|
|
|
}
|
|
|
|
|
productBarcodeInfo.setPalletInfoCode("");
|
|
|
|
|