From da15785661f7832cdcb78fb6504752c0cb385e63 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期三, 11 二月 2026 09:59:13 +0800
Subject: [PATCH] 入库数量变更

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |  122 ++++++++++++++++++++++++++++++++--------
 1 files changed, 97 insertions(+), 25 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
index cdfc073..8450c7e 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -873,6 +873,9 @@
             }
             if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                 locWorking.setAnfme(taskItem.getAnfme());
+            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) && taskItem.getQty() != null && taskItem.getQty().compareTo(0.0) > 0) {
+                // 鎷f枡鍐嶅叆搴擄細鍏ュ簱鏁伴噺涓烘湰娆℃嫞鏂欐暟閲�(taskItem.qty)锛屼繚璇佷笌鍑哄簱鎵e噺涓�鑷�
+                locWorking.setAnfme(taskItem.getQty());
             }
             BeanUtils.copyProperties(locWorking, locItem);
             locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
@@ -960,11 +963,19 @@
         // 濡傛灉鏈変换鍔″凡涓嬪彂鍒癛CS锛屽厛璋冪敤RCS鍙栨秷鎺ュ彛
         boolean rcsCancelSuccess = false;
         if (!rcsTaskCodes.isEmpty()) {
-            try {
-                log.info("========== 寮�濮嬪彇娑圧CS浠诲姟 ==========");
-                log.info("闇�瑕佸彇娑堢殑RCS浠诲姟缂栧彿锛歿}", rcsTaskCodes);
-                String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
-                log.info("RCS鍙栨秷浠诲姟璇锋眰鍦板潃锛歿}", rcsUrl);
+            // 妫�鏌� RCS API 閰嶇疆鏄惁鏈夋晥
+            if (rcsApi == null || StringUtils.isBlank(rcsApi.getHost()) || StringUtils.isBlank(rcsApi.getPort())) {
+                log.error("========== RCS浠诲姟鍙栨秷澶辫触 ==========");
+                log.error("RCS API 閰嶇疆鏃犳晥锛乭ost: {}, port: {}", 
+                        rcsApi != null ? rcsApi.getHost() : "null", 
+                        rcsApi != null ? rcsApi.getPort() : "null");
+                // 鍗充娇閰嶇疆鏃犳晥锛屼篃缁х画鎵ц浠诲姟鍒犻櫎鎿嶄綔
+            } else {
+                try {
+                    log.info("========== 寮�濮嬪彇娑圧CS浠诲姟 ==========");
+                    log.info("闇�瑕佸彇娑堢殑RCS浠诲姟缂栧彿锛歿}", rcsTaskCodes);
+                    String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
+                    log.info("RCS鍙栨秷浠诲姟璇锋眰鍦板潃锛歿}", rcsUrl);
                 
                 // 濡傛灉娌℃湁鎵规缂栧彿锛屼娇鐢ㄧ涓�涓换鍔$紪鍙蜂綔涓烘壒娆$紪鍙�
                 if (StringUtils.isBlank(batchNo) && !rcsTaskCodes.isEmpty()) {
@@ -1010,12 +1021,13 @@
                     log.error("RCS鍙栨秷浠诲姟澶辫触锛歿}", result.getMsg());
                     throw new CoolException("RCS鍙栨秷浠诲姟澶辫触锛�" + result.getMsg());
                 }
-            } catch (JsonProcessingException e) {
-                log.error("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛歿}", e.getMessage(), e);
-                throw new CoolException("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛�" + e.getMessage());
-            } catch (Exception e) {
-                log.error("RCS鍙栨秷浠诲姟寮傚父锛歿}", e.getMessage(), e);
-                throw new CoolException("RCS鍙栨秷浠诲姟寮傚父锛�" + e.getMessage());
+                } catch (JsonProcessingException e) {
+                    log.error("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛歿}", e.getMessage(), e);
+                    throw new CoolException("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛�" + e.getMessage());
+                } catch (Exception e) {
+                    log.error("RCS鍙栨秷浠诲姟寮傚父锛歿}", e.getMessage(), e);
+                    throw new CoolException("RCS鍙栨秷浠诲姟寮傚父锛�" + e.getMessage());
+                }
             }
         }
         
@@ -1295,6 +1307,11 @@
             throw new CoolException("鏁版嵁閿欒锛氫换鍔℃槑缁嗕负绌猴紒锛�");
         }
 
+        // 鎷f枡鍏ュ簱锛氬湪鐢熸垚鎷f枡鍏ュ簱鍗曟椂鎵e噺鍘熷簱浣嶆暟閲忥紝涓嶄緷璧栧嚭搴撳畬鎴愭椂搴撲綅鐘舵�佷负R
+        if (TaskType.TASK_TYPE_PICK_IN.type.equals(type)) {
+            subtractLocItemByTaskItems(loc, taskItems, SystemAuthUtils.getLoginUserId());
+        }
+
         tempLocs.forEach(working -> {
             taskItems.forEach(taskItem -> {
                 if (Objects.equals(taskItem.getFieldsIndex(), working.getFieldsIndex())) {
@@ -1367,6 +1384,10 @@
                     .setQty(0.0)
                     .setLocId(loc1.getId())
                     .setLocCode(loc1.getCode());
+            // 鎷f枡鍐嶅叆搴擄細鐩爣搴撲綅鏁伴噺搴斾负鏈鎷f枡鏁伴噺(taskItem.qty)锛屼笉鏄師搴撲綅鍓╀綑鏁伴噺(taskItem.anfme)
+            if (TaskType.TASK_TYPE_PICK_IN.type.equals(task.getTaskType()) && taskItem.getQty() != null && taskItem.getQty().compareTo(0.0) > 0) {
+                itemWorking.setAnfme(taskItem.getQty());
+            }
             workings.add(itemWorking);
         });
 
@@ -1399,16 +1420,36 @@
         if (Objects.isNull(loc)) {
             throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
         }
-        if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)) {
-            throw new CoolException("搴撲綅鐘舵�佷笉澶勭悊浜嶳.鍑哄簱棰勭害锛侊紒");
-        }
-
+        
         List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
         if (taskItems.isEmpty()) {
             throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦紒锛�");
         }
 
         List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
+        
+        // 濡傛灉搴撲綅鐘舵�佷笉鏄疪锛屾鏌ユ槸鍚﹀凡缁忓鐞嗚繃
+        if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type)) {
+            // 濡傛灉搴撲綅鏄庣粏涓虹┖锛岃鏄庡凡缁忓鐞嗚繃浜嗭紝鐩存帴鏇存柊浠诲姟鐘舵�佷负199
+            if (locItems.isEmpty()) {
+                logger.warn("浠诲姟{}鐨勫簱浣峽}鐘舵�佷负{}锛屼絾搴撲綅鏄庣粏涓虹┖锛屽彲鑳藉凡缁忓鐞嗚繃锛岀洿鎺ユ洿鏂颁换鍔$姸鎬佷负199", 
+                        task.getId(), loc.getCode(), loc.getUseStatus());
+                if (!this.update(new LambdaUpdateWrapper<Task>()
+                        .eq(Task::getId, task.getId())
+                        .set(Task::getUpdateBy, loginUserId)
+                        .set(Task::getUpdateTime, new Date())
+                        .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
+                    throw new CoolException("浠诲姟鐘舵�佹洿鏂板け璐ワ紒锛�");
+                }
+                return; // 璺宠繃鍚庣画澶勭悊
+            } else {
+                // 搴撲綅鏄庣粏涓嶄负绌轰絾鐘舵�佷笉鏄疪锛岃烦杩囧鐞�
+                logger.error("浠诲姟{}鐨勫簱浣峽}鐘舵�佷负{}锛屼笉鏄疪.鍑哄簱棰勭害鐘舵�侊紝浣嗗簱浣嶆槑缁嗕笉涓虹┖锛岃烦杩囧鐞嗐�備换鍔$紪鐮侊細{}锛屽簱浣嶇紪鐮侊細{}", 
+                        task.getId(), loc.getCode(), loc.getUseStatus(), task.getTaskCode(), loc.getCode());
+                return;
+            }
+        }
+        
         // 濡傛灉搴撲綅鏄庣粏涓虹┖锛屽彲鑳芥槸宸茬粡琚鐞嗚繃浜嗭紝鍏佽缁х画鎵ц
         if (!locItems.isEmpty()) {
             List<LocItemWorking> workings = new ArrayList<>();
@@ -1430,10 +1471,10 @@
             try {
                 // 鏍规嵁浠诲姟绫诲瀷鏇存柊搴撲綅鏄庣粏
                 if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
-                    // 鍏ㄧ増鍑哄簱锛氬垹闄ゆ墍鏈夊簱浣嶆槑缁�
-                    subtractLocItem(loc);
-                } else {
-                    // 閮ㄥ垎鍑哄簱锛堝鎷f枡鍑哄簱锛夛細鏍规嵁TaskItem鏁伴噺鎵e噺搴撲綅鏄庣粏
+                    // 鍏ㄧ増鍑哄簱锛氫笉鍒犻櫎搴撲綅鏄庣粏锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶅垹闄�
+                    // subtractLocItem(loc); // 宸茬Щ闄わ紝鏀逛负鍦╟ompleteFullOutStock涓垹闄�
+                } else if (!TaskType.TASK_TYPE_PICK_AGAIN_OUT.type.equals(task.getTaskType())) {
+                    // 閮ㄥ垎鍑哄簱锛堝鐩樼偣鍑哄簱锛夛細鏍规嵁TaskItem鏁伴噺鎵e噺搴撲綅鏄庣粏锛涙嫞鏂欏嚭搴撳湪鐢熸垚鎷f枡鍏ュ簱鍗曟椂鎵e噺
                     subtractLocItemByTaskItems(loc, taskItems, loginUserId);
                 }
             } catch (Exception e) {
@@ -1493,6 +1534,8 @@
                 throw new CoolException(e.getMessage());
             }
         }
+        
+        // 鏍规嵁浠诲姟绫诲瀷鏇存柊搴撲綅鐘舵��
         if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
             /**淇敼涓哄簱浣嶇姸鎬佷负S.棰勭害鍏ュ簱锛屼繚鐣欏師鏈夊簱浣�*/
             if (!locService.update(new LambdaUpdateWrapper<Loc>()
@@ -1503,6 +1546,9 @@
                     .eq(Loc::getId, loc.getId()))) {
                 throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
             }
+        } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
+            // 鍏ㄧ増鍑哄簱锛氫笉鏇存柊搴撲綅鐘舵�佷负O锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶆洿鏂�
+            // 搴撲綅鐘舵�佷繚鎸佸師鏍凤紙R.鍑哄簱棰勭害鐘舵�侊級
         } else {
             /**淇敼涓哄簱浣嶇姸鎬佷负O.绌哄簱*/
             if (!locService.update(new LambdaUpdateWrapper<Loc>()
@@ -1667,6 +1713,15 @@
     @Transactional(rollbackFor = Exception.class)
     public void pubTaskToWcs(List<Task> tasks) {
         /**浠诲姟涓嬪彂鎺ュ彛*/
+        // 妫�鏌� RCS API 閰嶇疆鏄惁鏈夋晥
+        if (rcsApi == null || StringUtils.isBlank(rcsApi.getHost()) || StringUtils.isBlank(rcsApi.getPort())) {
+            log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+            log.error("RCS API 閰嶇疆鏃犳晥锛乭ost: {}, port: {}", 
+                    rcsApi != null ? rcsApi.getHost() : "null", 
+                    rcsApi != null ? rcsApi.getPort() : "null");
+            return;
+        }
+        
         String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
         
         for (Task task : tasks) {
@@ -1761,7 +1816,10 @@
                     // 涓烘瘡涓笉鍚岀殑搴撲綅鍒涘缓涓�涓猅askItemParam
                     for (String locCode : locCodes) {
                         TaskItemParam outItemParam = new TaskItemParam();
-                        outItemParam.setTaskNo(task.getTaskCode());
+                        String taskNo = locCodes.size() > 1
+                                ? task.getTaskCode() + "_" + locCode 
+                                : task.getTaskCode();
+                        outItemParam.setTaskNo(taskNo);
                         outItemParam.setPriority(1);
                         outItemParam.setOriLoc(locCode);
                         outItemParam.setDestSta(task.getTargSite());
@@ -2161,12 +2219,26 @@
                 throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
             }
             LocItem item = new LocItem();
-            LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
+            // 鏋勫缓鏌ヨ鏉′欢锛氶渶瑕佸悓鏃跺尮閰嶇墿鏂橧D銆佸簱浣岻D銆佹壒娆″拰绁ㄥ彿
+            LambdaQueryWrapper<LocItem> locItemWrapper = new LambdaQueryWrapper<LocItem>()
                     .eq(LocItem::getMatnrId, taskItem.getMatnrId())
-                    .eq(LocItem::getLocId, loc.getId())
-                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
-                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex())
-            );
+                    .eq(LocItem::getLocId, loc.getId());
+            
+            // 鎵规鍖归厤锛氬鏋渢askItem鏈夋壒娆★紝鍒欏繀椤诲尮閰嶏紱濡傛灉taskItem娌℃湁鎵规锛屽垯鏌ヨ鎵规涓簄ull鎴栫┖瀛楃涓茬殑璁板綍
+            if (StringUtils.isNotBlank(taskItem.getBatch())) {
+                locItemWrapper.eq(LocItem::getBatch, taskItem.getBatch());
+            } else {
+                locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, ""));
+            }
+            
+            // 绁ㄥ彿鍖归厤锛氬鏋渢askItem鏈夌エ鍙凤紝鍒欏繀椤诲尮閰嶏紱濡傛灉taskItem娌℃湁绁ㄥ彿锛屽垯鏌ヨ绁ㄥ彿涓簄ull鎴栫┖瀛楃涓茬殑璁板綍
+            if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) {
+                locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex());
+            } else {
+                locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, ""));
+            }
+            
+            LocItem locItem = locItemService.getOne(locItemWrapper);
             if (Objects.isNull(locItem)) {
                 // 搴撲綅鏄庣粏涓嶅瓨鍦紝鍒涘缓鏂扮殑搴撲綅鏄庣粏
                 BeanUtils.copyProperties(taskItem, item);

--
Gitblit v1.9.1