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 |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 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 778076d..23754df 100644
--- a/src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/CheckOrderServiceImpl.java
@@ -1,18 +1,25 @@
 package com.zy.asrs.service.impl;
 
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
 import com.core.common.Cools;
+import com.core.common.R;
 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;
 import com.zy.common.model.LocDto;
 import org.springframework.beans.factory.annotation.Autowired;
 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")
@@ -29,6 +36,12 @@
 
     @Autowired
     private StaDescService staDescService;
+
+    @Autowired
+    private WrkMastService wrkMastService;
+
+    @Autowired
+    private WrkDetlService wrkDetlService;
 
     @Override
     public void remove(Long orderId) {
@@ -51,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());
@@ -67,4 +86,107 @@
         return locDtos;
 
     }
+
+    @Override
+    public List<CheckOrderDetl> getTaskList(String barcode) {
+        List<CheckOrderDetl> checkOrderDetls = new ArrayList<>();
+
+        WrkMast wrkMast = wrkMastService.selectByBarcode(barcode);
+        if (Cools.isEmpty(wrkMast)) {
+            throw new CoolException("鏈壘鍒颁换鍔�");
+        }
+
+        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
+        if (Cools.isEmpty(wrkDetls)) {
+            throw new CoolException("鏈壘鍒颁换鍔℃槑缁�");
+        }
+
+        for (WrkDetl wrkDetl : wrkDetls) {
+            if(Cools.isEmpty(wrkDetl.getOrderNo())){
+                throw new CoolException("鏄庣粏鏁版嵁鏈夎锛屾棤璁㈠崟鍙锋暟鎹�");
+            }
+            CheckOrderDetl checkOrderDetl = checkOrderDetlService.selectById(wrkDetl.getOrderId());
+            if(Cools.isEmpty(checkOrderDetl)){
+                throw new CoolException("鏄庣粏鏁版嵁鏈夎锛屾湭鎵惧埌鐩樼偣鍗曟暟鎹�");
+            }
+            if (checkOrderDetl.getStatus().equals(2)){
+                checkOrderDetls.add(checkOrderDetl);
+            }
+
+        }
+        if (Cools.isEmpty(checkOrderDetls)) {
+            throw new CoolException("璇ュ鍣ㄥ凡瀹屾垚鐩樼偣");
+        }
+
+        return checkOrderDetls;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R pdaComplete(CheckTaskListParam checkTaskListParam) {
+
+        WrkMast wrkMast = wrkMastService.selectByBarcode(checkTaskListParam.getBarcode());
+        if (Cools.isEmpty(wrkMast)) {
+            throw new CoolException("鏈壘鍒颁换鍔�");
+        }
+
+        for (CheckOrderDetl checkOrderDetl: checkTaskListParam.getCheckOrderDetlList()){
+            checkOrderDetl.setDiffQty(checkOrderDetl.getWorkQty().subtract(checkOrderDetl.getAnfme()));
+            checkOrderDetl.setStatus(3);
+            if (!checkOrderDetlService.updateById(checkOrderDetl)){
+                throw new CoolException("鏇存柊鐩樼偣鐘舵�佸け璐�");
+            }
+        }
+        CheckOrder checkOrder = this.selectOne(new EntityWrapper<CheckOrder>().eq("order_no", checkTaskListParam.getCheckOrderDetlList().get(0).getOrderNo()));
+        List<CheckOrderDetl> checkOrderDetls = checkOrderDetlService.selectList(new EntityWrapper<CheckOrderDetl>().eq("order_id", checkOrder.getId()));
+        boolean is = checkOrderDetls.stream().allMatch(item -> item.getStatus().equals(3));
+        if (is){
+            checkOrder.setSettle(4L);
+            if (!this.updateById(checkOrder)){
+                throw new CoolException("鏇存柊鐩樼偣涓诲崟鐘舵�佸け璐�");
+            }
+
+        }
+
+
+        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