From b06233aa71b70f7a30ff382ae1ba19c29b134d7c Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期五, 28 十一月 2025 15:41:51 +0800
Subject: [PATCH] #库存调整完成

---
 src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java |   54 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java
index 1380b77..23754df 100644
--- a/src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java
@@ -7,6 +7,7 @@
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.CheckTaskListParam;
+import com.zy.asrs.enums.CheckStatusEnum;
 import com.zy.asrs.mapper.CheckOrderMapper;
 import com.zy.asrs.service.*;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
@@ -15,8 +16,10 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 @Service("checkOrderService")
@@ -61,9 +64,15 @@
         }
         List<LocDto> locDtos = new ArrayList<>();
         for (CheckOrderDetl checkOrderDetl : checkOrderDetls) {
+            if (!checkOrderDetl.getStatus().equals(1)){
+                continue;
+            }
             LocDto locDto = new LocDto(checkOrderDetl.getLocNo(), checkOrderDetl.getMatnr(), checkOrderDetl.getMaktx(), checkOrderDetl.getBatch(), checkOrderDetl.getOrderNo(),
                     checkOrderDetl.getAnfme().doubleValue());
             LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", checkOrderDetl.getLocNo()));
+            if (!locMast.getLocSts().equals("F")){
+                continue;
+            }
             LocDetl locDetl = locDetlService.selectById(checkOrderDetl.getLocDetlId());
             locDto.setFrozen(locDetl.getFrozen());
             locDto.setFrozenLoc(locMast.getFrozen());
@@ -96,11 +105,7 @@
             if(Cools.isEmpty(wrkDetl.getOrderNo())){
                 throw new CoolException("鏄庣粏鏁版嵁鏈夎锛屾棤璁㈠崟鍙锋暟鎹�");
             }
-            CheckOrderDetl checkOrderDetl = checkOrderDetlService.selectOne(new EntityWrapper<CheckOrderDetl>()
-                    .eq("loc_no", wrkMast.getSourceLocNo())
-                    .eq("matnr", wrkDetl.getMatnr())
-                    .eq("batch", wrkDetl.getBatch())
-                    .eq("order_no", wrkDetl.getOrderNo()));
+            CheckOrderDetl checkOrderDetl = checkOrderDetlService.selectById(wrkDetl.getOrderId());
             if(Cools.isEmpty(checkOrderDetl)){
                 throw new CoolException("鏄庣粏鏁版嵁鏈夎锛屾湭鎵惧埌鐩樼偣鍗曟暟鎹�");
             }
@@ -126,6 +131,7 @@
         }
 
         for (CheckOrderDetl checkOrderDetl: checkTaskListParam.getCheckOrderDetlList()){
+            checkOrderDetl.setDiffQty(checkOrderDetl.getWorkQty().subtract(checkOrderDetl.getAnfme()));
             checkOrderDetl.setStatus(3);
             if (!checkOrderDetlService.updateById(checkOrderDetl)){
                 throw new CoolException("鏇存柊鐩樼偣鐘舵�佸け璐�");
@@ -145,4 +151,42 @@
 
         return R.ok();
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void adjustOrderComplete(Long orderId, Long userId) {
+        CheckOrder checkOrder = this.selectById(orderId);
+        if (Cools.isEmpty(checkOrder)) {
+            throw new CoolException("鏁版嵁閿欒");
+        }
+        List<CheckOrderDetl> selectList = checkOrderDetlService.selectList(new EntityWrapper<CheckOrderDetl>().eq("order_id", orderId));
+        for (CheckOrderDetl checkOrderDetl : selectList) {
+
+            LocDetl locDetl = locDetlService.selectById(checkOrderDetl.getLocDetlId());
+            if (Cools.isEmpty(locDetl)) {
+                throw new CoolException("鏈壘鍒板簱瀛樻暟鎹�,鏁版嵁閿欒");
+            }
+            if (checkOrderDetl.getStatus().equals(CheckStatusEnum.ALLOW.type)) {
+                BigDecimal decimal = locDetl.getBookQty().add(checkOrderDetl.getDiffQty());
+                locDetl.setAnfme(decimal.doubleValue());
+            }else if (checkOrderDetl.getStatus().equals(CheckStatusEnum.FORBID.type)) {
+                if (locDetl.getDiffQty().compareTo(BigDecimal.ZERO) < 0) {
+                    BigDecimal subtract = new BigDecimal(locDetl.getAnfme().toString()).subtract(locDetl.getDiffQty());
+                    locDetl.setAnfme(subtract.doubleValue());
+                }
+            }
+
+            locDetl.setDiffQty(BigDecimal.ZERO);
+            locDetl.setModiTime(new Date());
+            if (!locDetlService.updateById(locDetl)){
+                throw new CoolException("鏇存柊搴撳瓨鏁版嵁澶辫触");
+            }
+        }
+
+        checkOrder.setSettle(4L);
+        checkOrder.setUpdateTime(new Date());
+        if (!this.updateById(checkOrder)){
+            throw new CoolException("鏇存柊璋冩暣鍗曠姸鎬佸け璐�");
+        }
+    }
 }

--
Gitblit v1.9.1