fubin 2 rokov pred
rodič
commit
9c2bf216f5

+ 21 - 10
src/main/java/com/dk/mdm/controller/ivt/OutboundController.java

@@ -60,24 +60,35 @@ public class OutboundController{
     }
 
     /**
-     * @desc   : 获取出库单信息(编辑用)
+     * @desc : 编辑出库单
      * @author : 付斌
-     * @date   : 2024-03-03 9:28
+     * @date : 2023/1/9 10:49
      */
     @ApiOperation(value = "编辑出库单", notes = "编辑出库单")
-    @PostMapping({"get_outbound_for_update/{id}"})
-    public ResponseResultVO<?> getOutboundForUpdate(@PathVariable String id) {
-        return outboundService.getOutboundForUpdate(id);
+    @PostMapping({"update"})
+    public ResponseResultVO<Boolean> update(@RequestBody OutboundVO outboundVO) {
+        return outboundService.update(outboundVO);
     }
 
     /**
-     * @desc : 编辑出库单
+     * @desc : 作废
      * @author : 付斌
-     * @date : 2023/1/9 10:49
+     * @date : 2024-03-08 16:36
+     */
+    @ApiOperation(value = "作废", notes = "作废")
+    @PostMapping({"invalid/{id}"})
+    public ResponseResultVO<?> invalid(@PathVariable String id) {
+        return outboundService.invalid(id);
+    }
+
+    /**
+     * @desc   : 获取出库单信息(编辑用)
+     * @author : 付斌
+     * @date   : 2024-03-03 9:28
      */
     @ApiOperation(value = "编辑出库单", notes = "编辑出库单")
-    @PostMapping({"update"})
-    public ResponseResultVO<Boolean> update(@RequestBody OutboundVO outboundVO) {
-        return outboundService.update(outboundVO);
+    @PostMapping({"get_outbound_for_update/{id}"})
+    public ResponseResultVO<?> getOutboundForUpdate(@PathVariable String id) {
+        return outboundService.getOutboundForUpdate(id);
     }
 }

+ 7 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundItemMapper.java

@@ -26,5 +26,12 @@ public interface OutboundItemMapper extends BaseMapper<OutboundItem>{
      * @date   : 2024-02-28 10:19
      */
     Long countByCond(OutboundItemQuery outboundItemQuery);
+
+    /**
+     * @desc   : 根据主表主键锁定表t_psi_outbound_item的多行数据
+     * @author : 付斌
+     * @date   : 2024-03-09 11:36
+     */
+    List<OutboundItem> selectByZIdForUpdate(String id);
 }
 

+ 10 - 1
src/main/java/com/dk/mdm/mapper/ivt/OutboundItemMapper.xml

@@ -212,7 +212,7 @@
         SELECT
         <include refid="Base_Column_List"/>
         FROM t_psi_outbound_item
-        WHERE item_id = #{itemId}
+        WHERE item_id = #{id}::uuid
         for update
     </select>
 
@@ -225,6 +225,15 @@
         for update
     </select>
 
+    <!-- 根据主表主键锁定表t_psi_outbound_item的多行数据 -->
+    <select id="selectByZIdForUpdate" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_psi_outbound_item
+        WHERE outId = #{id}::uuid
+        for update
+    </select>
+
     <insert id="insertBatch">
         insert into t_psi_outbound_item
         (

+ 73 - 6
src/main/java/com/dk/mdm/service/ivt/OutboundService.java

@@ -26,8 +26,6 @@ import com.dk.mdm.model.query.ivt.OutboundItemQuery;
 import com.dk.mdm.model.query.ivt.OutboundQuery;
 import com.dk.mdm.model.response.ivt.OutboundItemResponse;
 import com.dk.mdm.model.response.ivt.OutboundResponse;
-import com.dk.mdm.model.response.pur.PurchaseItemResponse;
-import com.dk.mdm.model.response.sale.OrderResponse;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -187,21 +185,49 @@ public class OutboundService extends BaseService<Outbound> {
             rollbackFor = {Exception.class}
     )
     public ResponseResultVO<Boolean> update(OutboundVO outboundVO) {
+        // 订单明细实体
+        OrderItem orderItemForUpdate;
+        // 订单明细实体
+        OutboundItem outboundItemForUpdate;
         // 转化实体
         Outbound outbound = outboundConvert.convertToPo(outboundVO);
 
-        // 编辑的
+        // 编辑出库明细
         List<OutboundItemVO> editOutboundItemVOList = outboundVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
         for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
             // 出库中数量不能小于出库数量
             if (outboundItemVO.getOutingQty().compareTo(outboundItemVO.getOutQty()) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTINGQTY_NO_LESS_OUTQTY.getMessage());
-            } else {
-                OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
-                outboundItemService.updateByUuid(outboundItem);
             }
+
+            outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getItemId());
+            orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemVO.getFromItemId());
+
+            // 订单的商品数量不能小于(订单之前的出库中数量 - 出库明细之前的出库中数量 + 出库明细现在的出库中数量)
+            if (orderItemForUpdate.getItemQty().compareTo(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty())) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
+            }
+            // 更新订单明细出库中数量
+            OrderItem orderItemUpdate = new OrderItem();
+            orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty()))
+                    .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()).add(outboundItemVO.getOutingAmt()))
+                    .setItemId(orderItemForUpdate.getItemId());
+            orderItemService.updateByUuid(orderItemUpdate);
+            // 更新出库明细
+            OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
+            outboundItemService.updateByUuid(outboundItem);
         }
 
+        Outbound outboundForUpdate = outboundMapper.selectByIdForUpdate(outboundVO.getOutId());
+
+        // 更新订单上的退货数量,金额
+        Order orderForUpdate = orderMapper.selectByIdForUpdate(outboundVO.getFromId());
+        Order orderUpdate = new Order();
+        orderUpdate.setOutingQty(orderForUpdate.getOutingQty().subtract(outboundForUpdate.getOutingQty()).add(outboundForUpdate.getOutingQty()))
+                .setOutingAmt(orderForUpdate.getOutingAmt().subtract(outboundForUpdate.getOutingAmt()).add(outboundForUpdate.getOutingAmt()))
+                .setOrderId(outboundVO.getFromId());
+        orderService.updateByUuid(orderUpdate);
+
         return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
                 UUID.fromString(outbound.getOutId()))));
     }
@@ -212,6 +238,47 @@ public class OutboundService extends BaseService<Outbound> {
      * @date : 2024-03-08 16:38
      */
     public ResponseResultVO<?> invalid(String id) {
+        Outbound outbound = outboundMapper.selectByIdForUpdate(id);
+        // 如果退货数量不是0,不能作废
+        if (!outbound.getReturnQty().equals(new BigDecimal(0))) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
+        }
+
+        double sumOutingQty = 0;    // 合计出库中数量
+        double sumOutingAmt = 0;    // 合计出库中金额
+        List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(id);
+        OrderItem orderItemForUpdate;
+        for (OutboundItem outboundItemForUpdate : outboundItemList) {
+            orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemForUpdate.getFromItemId());
+            // 更新订单明细出库中数量
+            OrderItem orderItemUpdate = new OrderItem();
+            orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()))
+                    .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()))
+                    .setItemId(orderItemForUpdate.getItemId());
+            orderItemService.updateByUuid(orderItemUpdate);
+
+            // 累加出库中数量,金额
+            sumOutingQty += outboundItemForUpdate.getOutingQty().doubleValue();
+            sumOutingAmt += outboundItemForUpdate.getOutingAmt().doubleValue();
+        }
+
+        // 更新订单上的出库中数量,金额,状态
+        Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
+        Order orderUpdate = new Order();
+        orderUpdate.setOutingQty(orderForUpdate.getOutingQty().subtract(new BigDecimal(sumOutingQty)))
+                .setOutingAmt(orderForUpdate.getOutingAmt().subtract(new BigDecimal(sumOutingAmt)))
+                .setOrderId(outbound.getFromId());
+        // 如果出库中数量为0了,更新状态为待出库
+        if(orderUpdate.getOutingQty().equals(new BigDecimal(0))){
+            orderUpdate.setOutStatus(Constant.OutStatus.DAICHUKU.getName());
+        }
+        orderService.updateByUuid(orderUpdate);
+
+        // 作废
+        Outbound outboundUpdate = new Outbound();
+        outboundUpdate.setFlgValid(false).setOutId(id);
+        super.update(outboundUpdate, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
+                UUID.fromString(outboundUpdate.getOutId())));
         return ResponseResultUtil.success();
     }
 

+ 9 - 9
src/main/java/com/dk/mdm/service/sale/OrderService.java

@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -194,10 +195,9 @@ public class OrderService extends BaseService<Order> {
             // 商品数量不能小于出库中数量
             if (orderItemVO.getItemQty().compareTo(orderItemForUpdate.getOutingQty()) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
-            } else {
-                OrderItem orderItem = orderItemConvert.convertToPo(orderItemVO);
-                orderItemService.updateByUuid(orderItem);
             }
+            OrderItem orderItem = orderItemConvert.convertToPo(orderItemVO);
+            orderItemService.updateByUuid(orderItem);
         }
 
         return ResponseResultUtil.success(super.update(order, new UpdateWrapper<Order>().lambda().eq(Order::getOrderId,
@@ -211,15 +211,15 @@ public class OrderService extends BaseService<Order> {
      */
     public ResponseResultVO<?> invalid(String id) {
         Order order = orderMapper.selectByIdForUpdate(id);
-        // 如果状态不是待出库,不能作废
-        if (!order.getOutStatus().equals(Constant.OutStatus.DAICHUKU.getName())) {
+        // 如果状态不是待出库,出库中数量不是0,不能作废
+        if (!order.getOutStatus().equals(Constant.OutStatus.DAICHUKU.getName()) || !order.getOutingQty().equals(new BigDecimal(0)) ) {
             throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
         }
         // 作废
-        Order orderForUpdate = new Order();
-        orderForUpdate.setFlgValid(false).setOrderId(id);
-        super.update(orderForUpdate, new UpdateWrapper<Order>().lambda().eq(Order::getOrderId,
-                UUID.fromString(orderForUpdate.getOrderId())));
+        Order orderUpdate = new Order();
+        orderUpdate.setFlgValid(false).setOrderId(id);
+        super.update(orderUpdate, new UpdateWrapper<Order>().lambda().eq(Order::getOrderId,
+                UUID.fromString(orderUpdate.getOrderId())));
         return ResponseResultUtil.success();
     }