diff --git a/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/MesConstants.java b/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/MesConstants.java index 42dc5da..189905b 100644 --- a/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/MesConstants.java +++ b/hw-common/hw-common-core/src/main/java/com/hw/common/core/constant/MesConstants.java @@ -102,4 +102,8 @@ public class MesConstants { /**生产工单销售类型*/ public static final String MES_PRODUCT_ORDER_SALE = "1";//外部销售 public static final String MES_PRODUCT_ORDER_INTERNAL = "2";//对内生产 + + + /**物料信息绑定标识,是否需要采购订单明细绑定销售订单*/ + public static final String MES_MATERIAL_BIND_FLAG_YES = "1";//是 } diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesPurchaseOrderController.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesPurchaseOrderController.java index 888f7f3..437978f 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesPurchaseOrderController.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/controller/MesPurchaseOrderController.java @@ -134,4 +134,15 @@ public class MesPurchaseOrderController extends BaseController return toAjax(mesPurchaseOrderService.bindOrder(mesPurchaseOrder)); } + + + /** + * 获取采购订单信息详细信息,校验是否需要绑定 + */ + @RequiresPermissions("mes:purchaseOrder:query") + @GetMapping(value = "/getCheckedPurchaseOrder/{purchaseOrderId}") + public AjaxResult getCheckedPurchaseOrder(@PathVariable("purchaseOrderId") Long purchaseOrderId) + { + return success(mesPurchaseOrderService.selectCheckedPurchaseOrderByPurchaseOrderId(purchaseOrderId)); + } } diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesPurchaseOrder.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesPurchaseOrder.java index ce216e6..7900c54 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesPurchaseOrder.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/domain/MesPurchaseOrder.java @@ -131,6 +131,9 @@ public class MesPurchaseOrder extends BaseEntity { /** 采购销售订单绑定信息信息 */ private List mesOrderBindList; + /**判断是否需要绑定*/ + private String bindFlag; + public void setPurchaseOrderId(Long purchaseOrderId) { this.purchaseOrderId = purchaseOrderId; @@ -376,6 +379,14 @@ public class MesPurchaseOrder extends BaseEntity { this.mesOrderBindList = mesOrderBindList; } + public String getBindFlag() { + return bindFlag; + } + + public void setBindFlag(String bindFlag) { + this.bindFlag = bindFlag; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesPurchaseOrderService.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesPurchaseOrderService.java index c5ccebc..71c43ca 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesPurchaseOrderService.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/IMesPurchaseOrderService.java @@ -68,4 +68,12 @@ public interface IMesPurchaseOrderService */ public int bindOrder(MesPurchaseOrder mesPurchaseOrder); + /** + * 查询采购订单信息,校验是否需要绑定 + * + * @param purchaseOrderId 采购订单信息主键 + * @return 采购订单信息 + */ + public MesPurchaseOrder selectCheckedPurchaseOrderByPurchaseOrderId(Long purchaseOrderId); + } diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesBaseBarcodeInfoServiceImpl.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesBaseBarcodeInfoServiceImpl.java index 46420e0..50c57c4 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesBaseBarcodeInfoServiceImpl.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesBaseBarcodeInfoServiceImpl.java @@ -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 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 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(""); diff --git a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesPurchaseOrderServiceImpl.java b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesPurchaseOrderServiceImpl.java index 95ae136..07f861d 100644 --- a/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesPurchaseOrderServiceImpl.java +++ b/hw-modules/hw-mes/src/main/java/com/hw/mes/service/impl/MesPurchaseOrderServiceImpl.java @@ -9,7 +9,12 @@ 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.security.utils.SecurityUtils; +import com.hw.mes.api.domain.MesBaseBarcodeInfo; +import com.hw.mes.api.domain.MesBaseMaterialInfo; import com.hw.mes.domain.MesOrderBind; +import com.hw.mes.mapper.MesBaseBarcodeInfoMapper; +import com.hw.mes.mapper.MesBaseMaterialInfoMapper; +import com.hw.mes.service.IMesBaseMaterialInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.hw.mes.mapper.MesPurchaseOrderMapper; @@ -28,6 +33,12 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService { @Autowired private MesPurchaseOrderMapper mesPurchaseOrderMapper; + @Autowired + private MesBaseMaterialInfoMapper mesBaseMaterialInfoMapper; + + @Autowired + private MesBaseBarcodeInfoMapper mesBaseBarcodeInfoMapper; + /** * 查询采购订单信息 * @@ -106,13 +117,34 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService { @Override @Transactional public int bindOrder(MesPurchaseOrder mesPurchaseOrder) { - //TODO:绑定前看看有没有生成的物料条码,或者判断采购订单状态是否已完成 + Long erpMaterialId = mesPurchaseOrder.getMaterialId(); + MesBaseMaterialInfo mesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByErpId(erpMaterialId); + if (mesBaseMaterialInfo == null) { + throw new ServiceException("物料信息不存在"); + } + String bindFlag = mesBaseMaterialInfo.getBindFlag(); + if (bindFlag == null) { + throw new ServiceException("请先设置物料信息的绑定标识"); + } + + if (!bindFlag.equals(MesConstants.MES_MATERIAL_BIND_FLAG_YES)) { + throw new ServiceException("此物料绑定标识为否,不需要绑定"); + } + + Long purchaseOrderId = mesPurchaseOrder.getPurchaseOrderId(); + MesBaseBarcodeInfo queryBaseBarcodeInfo = new MesBaseBarcodeInfo(); + queryBaseBarcodeInfo.setPurchaseOrderId(purchaseOrderId); + int mesBaseBarcodeInfoCount = mesBaseBarcodeInfoMapper.selectMesBaseBarcodeInfoCount(queryBaseBarcodeInfo); + if (mesBaseBarcodeInfoCount > 0) { + throw new ServiceException("此采购订单已经生成条码,不能再绑定"); + } + + mesPurchaseOrderMapper.deleteMesOrderBindByPurchaseOrderId(mesPurchaseOrder.getPurchaseOrderId()); Date currentDate = new Date(); String userName = SecurityUtils.getUsername(); - Long purchaseOrderId = mesPurchaseOrder.getPurchaseOrderId(); - Long erpMaterialId = mesPurchaseOrder.getMaterialId(); + String materialCode = mesPurchaseOrder.getMaterialCode(); String materialName = mesPurchaseOrder.getMaterialName(); String poNo = mesPurchaseOrder.getPoNo(); @@ -157,4 +189,24 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService { } + /** + * 查询采购订单信息,校验是否需要绑定 + * + * @param purchaseOrderId 采购订单信息主键 + * @return 采购订单信息 + */ + @Override + public MesPurchaseOrder selectCheckedPurchaseOrderByPurchaseOrderId(Long purchaseOrderId) { + MesPurchaseOrder mesPurchaseOrder = mesPurchaseOrderMapper.selectMesPurchaseOrderByPurchaseOrderId(purchaseOrderId); + Long erpMaterialId = mesPurchaseOrder.getMaterialId(); + MesBaseMaterialInfo mesBaseMaterialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByErpId(erpMaterialId); + if (mesBaseMaterialInfo == null) { + throw new ServiceException("物料信息不存在"); + } + mesPurchaseOrder.setBindFlag(mesPurchaseOrder.getBindFlag()); + + return mesPurchaseOrder; + } + + } diff --git a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesBaseMaterialInfoMapper.xml b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesBaseMaterialInfoMapper.xml index 4c026a8..b5839d0 100644 --- a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesBaseMaterialInfoMapper.xml +++ b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesBaseMaterialInfoMapper.xml @@ -50,12 +50,14 @@ bmi.material_type_id, bmt.type_name material_type_name, bmi.batch_flag, + bmi.batch_amount, bmi.material_unit_id, bmi.material_unit, bmi.material_matkl, bmi.material_spec, bmi.net_weight, bmi.gross_weight, + bmi.bind_flag, bmi.factory_id, bmi.create_org_id, bmi.use_org_id, @@ -189,13 +191,15 @@ material_subclass = #{materialSubclass}, material_type_id = #{materialTypeId}, - batch_flag = #{batchFlag}, + batch_flag = #{batchFlag}, + batch_amount = #{batchAmount}, material_unit_id = #{materialUnitId}, material_unit = #{materialUnit}, material_matkl = #{materialMatkl}, material_spec = #{materialSpec}, net_weight = #{netWeight}, gross_weight = #{grossWeight}, + bind_flag = #{bindFlag}, factory_id = #{factoryId}, create_org_id = #{createOrgId}, use_org_id = #{useOrgId}, @@ -317,6 +321,7 @@ bmi.material_spec, bmi.net_weight, bmi.gross_weight, + bmi.bind_flag, bmi.factory_id, bmi.create_org_id, bmi.use_org_id, diff --git a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesProductPlanMapper.xml b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesProductPlanMapper.xml index 14e2d16..128a397 100644 --- a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesProductPlanMapper.xml +++ b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesProductPlanMapper.xml @@ -324,7 +324,7 @@