changhaoning 2 лет назад
Родитель
Сommit
b397f98a29

+ 12 - 0
src/main/java/com/dk/mdm/controller/pur/PurchaseController.java

@@ -94,6 +94,18 @@ public class PurchaseController{
     public ResponseResultVO<Boolean> update(@RequestBody  PurchaseVO Purchasevo) {
         return purchaseService.update(Purchasevo);
     }
+
+    /**
+     * @desc : 作废
+     * @author : 常皓宁
+     * @date : 2024-03-08 16:36
+     */
+    @ApiOperation(value = "作废", notes = "作废")
+    @PostMapping({"invalid/{id}"})
+    public ResponseResultVO<?> invalid(@PathVariable String id) {
+        return purchaseService.invalid(id);
+    }
+
     /**
      * @desc   : 采购订单 转 采购入库   (目前废弃)
      * @author : 王英杰

+ 28 - 2
src/main/java/com/dk/mdm/service/pur/PurchaseService.java

@@ -18,6 +18,7 @@ import com.dk.mdm.mapper.pur.PurchaseMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.pojo.pur.PurchaseItem;
+import com.dk.mdm.model.pojo.sale.Order;
 import com.dk.mdm.model.query.pur.PurchaseItemQuery;
 import com.dk.mdm.model.query.pur.PurchaseQuery;
 import com.dk.mdm.model.response.pur.PurchaseItemResponse;
@@ -33,6 +34,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.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
@@ -236,8 +238,8 @@ public class PurchaseService extends BaseService<Purchase> {
         // 编辑的
         List<PurchaseItemVO> editPurchaseItemVOList = purchasevo.getEditPurchaseItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
         for (PurchaseItemVO purchaseItemVO : editPurchaseItemVOList) {
-            // 商品数量不能小于入库中数量
-            if (purchaseItemVO.getItemQty().compareTo(purchaseItemVO.getIntoQty()) == -1) {
+            // 商品数量不能小于可转入库数量数量(入库中+已入库)
+            if (purchaseItemVO.getItemQty().compareTo(purchaseItemVO.getIntoQty().add(purchaseItemVO.getIntoingQty())) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_INTOQTY.getMessage());
             } else {
                 PurchaseItem purchaseItem = purchaseItemConvert.convertToPo(purchaseItemVO);
@@ -249,6 +251,30 @@ public class PurchaseService extends BaseService<Purchase> {
     }
 
     /**
+     * @desc : 作废
+     * @author : 常皓宁
+     * @date : 2024-03-08 16:38
+     */
+    public ResponseResultVO<?> invalid(String id) {
+        Purchase purForUpdate = purchaseMapper.selectByIdForUpdate(id);
+        // 并发校验
+        if (!purForUpdate.getFlgValid()) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+        }
+
+        // 如果入库中数量或已入库数量不是0,不能作废
+        if (purForUpdate.getIntoQty().compareTo(BigDecimal.ZERO) != 0 || purForUpdate.getIntoingQty().compareTo(BigDecimal.ZERO) != 0) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
+        }
+        // 作废
+        Purchase purUpdate = new Purchase();
+        purUpdate.setFlgValid(false).setPurId(id);
+        super.update(purUpdate, new UpdateWrapper<Purchase>().lambda().eq(Purchase::getPurId,
+                UUID.fromString(purUpdate.getPurId ())));
+        return ResponseResultUtil.success();
+    }
+
+    /**
      * @desc : 采购订单 转 采购入库   (目前废弃)
      * @author : 王英杰
      * @date : 2024年3月11日