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 b1a9226..eccccb2 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 @@ -176,27 +176,28 @@ public class MesPurchaseOrderController extends BaseController /** * 保存销售订单绑定采购订单 - * @param saleOrderId - * @param purchaseOrderIds + * @param purchaseOrderList * @return */ @RequiresPermissions("mes:purchaseOrder:bind") @Log(title = "采购订单信息", businessType = BusinessType.ALLOCATE) @PutMapping("/saveSalesBindPurchase") - public AjaxResult saveSalesBindPurchase(Long saleOrderId, Long[] purchaseOrderIds) { - return success(mesPurchaseOrderService.saveSalesBindPurchase(saleOrderId, purchaseOrderIds)); + public AjaxResult saveSalesBindPurchase(@RequestBody List purchaseOrderList) { + return success(mesPurchaseOrderService.saveSalesBindPurchase(purchaseOrderList)); } /** * 删除销售订单绑定采购订单 - * @param orderBindIds + * + * @param saleOrderId + * @param purchaseOrderIds * @return */ @RequiresPermissions("mes:purchaseOrder:bind") @Log(title = "采购订单信息", businessType = BusinessType.UNALLOCATE) @PostMapping("/removeSalesBindPurchase") - public AjaxResult removeSalesBindPurchase(Long[] orderBindIds) { - return toAjax(mesPurchaseOrderService.removeSalesBindPurchase(orderBindIds)); + public AjaxResult removeSalesBindPurchase(Long saleOrderId, Long[] purchaseOrderIds) { + return toAjax(mesPurchaseOrderService.removeSalesBindPurchase(saleOrderId, purchaseOrderIds)); } } 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 c509156..7b29b4c 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 @@ -146,6 +146,50 @@ public class MesPurchaseOrder extends BaseEntity { /**采购销售订单绑定主键*/ private Long orderBindId; + /** 已绑定数 */ + private BigDecimal boundAmount; + + /** 销售订单已绑定数 */ + private BigDecimal saleBindAmount; + + /** 安全库存数 */ + private BigDecimal safeAmount; + + /** 条码数 */ + private BigDecimal barcodeAmount; + + public BigDecimal getBoundAmount() { + return boundAmount; + } + + public void setBoundAmount(BigDecimal boundAmount) { + this.boundAmount = boundAmount; + } + + public BigDecimal getSaleBindAmount() { + return saleBindAmount; + } + + public void setSaleBindAmount(BigDecimal saleBindAmount) { + this.saleBindAmount = saleBindAmount; + } + + public BigDecimal getSafeAmount() { + return safeAmount; + } + + public void setSafeAmount(BigDecimal safeAmount) { + this.safeAmount = safeAmount; + } + + public BigDecimal getBarcodeAmount() { + return barcodeAmount; + } + + public void setBarcodeAmount(BigDecimal barcodeAmount) { + this.barcodeAmount = barcodeAmount; + } + public Long getSaleOrderId() { return saleOrderId; } 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 e700e8d..a77d0c5 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 @@ -92,16 +92,17 @@ public interface IMesPurchaseOrderService /** * 保存销售订单绑定采购订单 - * @param saleOrderId - * @param purchaseOrderIds + * @param purchaseOrderList * @return */ - public int saveSalesBindPurchase(Long saleOrderId, Long[] purchaseOrderIds); + public int saveSalesBindPurchase(List purchaseOrderList); /** * 删除销售订单绑定采购订单 - * @param orderBindIds + * + * @param saleOrderId + * @param purchaseOrderIds * @return */ - public int removeSalesBindPurchase(Long[] orderBindIds); + public int removeSalesBindPurchase(Long saleOrderId, Long[] purchaseOrderIds); } 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 ee9e553..4ba207e 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 @@ -14,13 +14,9 @@ import com.hw.mes.api.domain.MesBaseBarcodeInfo; import com.hw.mes.api.domain.MesBaseMaterialInfo; import com.hw.mes.domain.MesOrderBind; import com.hw.mes.domain.MesSaleOrder; -import com.hw.mes.mapper.MesBaseBarcodeInfoMapper; -import com.hw.mes.mapper.MesBaseMaterialInfoMapper; -import com.hw.mes.mapper.MesSaleOrderMapper; -import com.hw.mes.service.IMesBaseMaterialInfoService; +import com.hw.mes.mapper.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.hw.mes.mapper.MesPurchaseOrderMapper; import com.hw.mes.domain.MesPurchaseOrder; import com.hw.mes.service.IMesPurchaseOrderService; import org.springframework.transaction.annotation.Transactional; @@ -45,6 +41,9 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService { @Autowired private MesSaleOrderMapper mesSaleOrderMapper; + @Autowired + private MesOrderBindMapper mesOrderBindMapper; + /** * 查询采购订单信息 * @@ -237,13 +236,13 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService { /** * 保存销售订单绑定采购订单 - * @param saleOrderId - * @param purchaseOrderIds + * @param purchaseOrderList * @return */ @Override - public int saveSalesBindPurchase(Long saleOrderId, Long[] purchaseOrderIds) { - List orderBindList = new ArrayList<>(); + @Transactional(rollbackFor = ServiceException.class) + public int saveSalesBindPurchase(List purchaseOrderList) { + Long saleOrderId = purchaseOrderList.get(0).getSaleOrderId(); if (StringUtils.isNull(saleOrderId)){ return 0; } @@ -254,41 +253,69 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService { String productName = mesSaleOrder.getMaterialName(); Date currentDate = new Date(); String userName = SecurityUtils.getUsername(); - for (Long purchaseOrderId : purchaseOrderIds) { - MesOrderBind orderBind = new MesOrderBind(); - MesPurchaseOrder mesPurchaseOrder = mesPurchaseOrderMapper.selectMesPurchaseOrderByPurchaseOrderId(purchaseOrderId); - Long materialId = mesPurchaseOrder.getMaterialId(); - String materialCode = mesPurchaseOrder.getMaterialCode(); - String materialName = mesPurchaseOrder.getMaterialName(); - String poNo = mesPurchaseOrder.getPoNo(); - BigDecimal orderAmount = mesPurchaseOrder.getOrderAmount(); - - orderBind.setSafeFlag(MesConstants.MES_ORDER_BIND_SAFE_FLAG_NO); - orderBind.setSaleOrderId(saleOrderId); - orderBind.setSaleOrderCode(saleorderCode); - orderBind.setProductId(productId); - orderBind.setProductCode(productCode); - orderBind.setProductName(productName); - orderBind.setPurchaseOrderId(purchaseOrderId); - orderBind.setMaterialId(materialId); - orderBind.setMaterialCode(materialCode); - orderBind.setMaterialName(materialName); - orderBind.setBindAmount(orderAmount); - orderBind.setPoNo(poNo); - orderBind.setCreateTime(currentDate); - orderBind.setCreateBy(userName); - orderBindList.add(orderBind); + for (MesPurchaseOrder purchaseOrder : purchaseOrderList) { + Long purchaseOrderId = purchaseOrder.getPurchaseOrderId(); + MesOrderBind selectOrderBind = new MesOrderBind(); + selectOrderBind.setSafeFlag(MesConstants.MES_ORDER_BIND_SAFE_FLAG_NO); + selectOrderBind.setSaleOrderId(saleOrderId); + selectOrderBind.setPurchaseOrderId(purchaseOrderId); + List bindList = mesOrderBindMapper.selectMesOrderBindList(selectOrderBind); + if (bindList.size() == 0){ + MesOrderBind orderBind = new MesOrderBind(); + MesPurchaseOrder mesPurchaseOrder = mesPurchaseOrderMapper.selectMesPurchaseOrderByPurchaseOrderId(purchaseOrderId); + Long materialId = mesPurchaseOrder.getMaterialId(); + String materialCode = mesPurchaseOrder.getMaterialCode(); + String materialName = mesPurchaseOrder.getMaterialName(); + String poNo = mesPurchaseOrder.getPoNo(); + BigDecimal orderAmount = mesPurchaseOrder.getOrderAmount(); + orderBind.setSafeFlag(MesConstants.MES_ORDER_BIND_SAFE_FLAG_NO); + orderBind.setSaleOrderId(saleOrderId); + orderBind.setSaleOrderCode(saleorderCode); + orderBind.setProductId(productId); + orderBind.setProductCode(productCode); + orderBind.setProductName(productName); + orderBind.setPurchaseOrderId(purchaseOrderId); + orderBind.setMaterialId(materialId); + orderBind.setMaterialCode(materialCode); + orderBind.setMaterialName(materialName); + orderBind.setBindAmount(purchaseOrder.getSaleBindAmount()); + orderBind.setPoNo(poNo); + orderBind.setCreateTime(currentDate); + orderBind.setCreateBy(userName); + mesOrderBindMapper.insertMesOrderBind(orderBind); + } else { + MesOrderBind bind = bindList.get(0); + bind.setBindAmount(purchaseOrder.getSaleBindAmount()); + bind.setUpdateBy(SecurityUtils.getUsername()); + bind.setUpdateTime(DateUtils.getNowDate()); + mesOrderBindMapper.updateMesOrderBind(bind); + } } - return mesPurchaseOrderMapper.batchMesOrderBind(orderBindList); + return 1; } /** * 删除销售订单绑定采购订单 - * @param orderBindIds + * + * @param saleOrderId + * @param purchaseOrderIds * @return */ @Override - public int removeSalesBindPurchase(Long[] orderBindIds) { + @Transactional(rollbackFor = ServiceException.class) + public int removeSalesBindPurchase(Long saleOrderId, Long[] purchaseOrderIds) { + List list = new ArrayList<>(); + for (Long purchaseOrderId : purchaseOrderIds) { + MesOrderBind selectOrderBind = new MesOrderBind(); + selectOrderBind.setSafeFlag(MesConstants.MES_ORDER_BIND_SAFE_FLAG_NO); + selectOrderBind.setSaleOrderId(saleOrderId); + selectOrderBind.setPurchaseOrderId(purchaseOrderId); + List bindList = mesOrderBindMapper.selectMesOrderBindList(selectOrderBind); + if (bindList.size() > 0){ + list.add(bindList.get(0).getOrderBindId()); + } + } + Long[] orderBindIds = list.toArray(new Long[0]); return mesPurchaseOrderMapper.deleteMesOrderBindByOrderBindIds(orderBindIds); } diff --git a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesPurchaseOrderMapper.xml b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesPurchaseOrderMapper.xml index a501c59..248d35f 100644 --- a/hw-modules/hw-mes/src/main/resources/mapper/mes/MesPurchaseOrderMapper.xml +++ b/hw-modules/hw-mes/src/main/resources/mapper/mes/MesPurchaseOrderMapper.xml @@ -39,6 +39,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + @@ -221,25 +225,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"