From 9d06821cbe3e9e7bd693ba745167dd3f620677ad Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期三, 11 二月 2026 13:24:51 +0800
Subject: [PATCH] 修改库口

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java |   74 ++++++++++++++++++++++--------------
 1 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
index 2bc9667..0d00940 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
@@ -520,7 +520,12 @@
                 if (StringUtils.isNotBlank(locItem.getFieldsIndex())) {
                     orderItemWrapper.eq(WkOrderItem::getFieldsIndex, locItem.getFieldsIndex());
                 }
-                WkOrderItem orderItem = outStockItemService.getOne(orderItemWrapper);
+                // 鍚屼竴鍑哄簱鍗曚笅鍚屼竴鐗╂枡鍙兘鏈夊鏉℃槑缁嗭紙濡傚琛屽悎骞讹級锛岀敤 list 鍙栦粛鏈夊墿浣欐暟閲忕殑绗竴鏉★紝閬垮厤 getOne 杩斿洖澶氭潯鎶� TooManyResultsException
+                List<WkOrderItem> orderItemCandidates = outStockItemService.list(orderItemWrapper);
+                WkOrderItem orderItem = orderItemCandidates.stream()
+                        .filter(o -> o.getAnfme() != null && o.getWorkQty() != null && o.getAnfme().compareTo(o.getWorkQty()) > 0)
+                        .findFirst()
+                        .orElse(null);
 
                 // 濡傛灉鎵句笉鍒板崟鎹槑缁嗭紝涓擫ocItem鏉ヨ嚜搴撳瓨璋冩暣锛屽垯鑷姩鍒涘缓WkOrderItem
                 if (Objects.isNull(orderItem)) {
@@ -631,7 +636,12 @@
                 TaskType.TASK_TYPE_OUT.type,
                 TaskType.TASK_TYPE_MERGE_OUT.type,
                 TaskType.TASK_TYPE_PICK_AGAIN_OUT.type);
-        List<DeviceSite> sites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>().in(DeviceSite::getType, list).groupBy(DeviceSite::getSite));
+        // 鍏堟煡鍏ㄩ儴鍐嶆寜 site 鍘婚噸锛岄伩鍏� GROUP BY 涓� only_full_group_by 鍐茬獊
+        List<DeviceSite> all = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>().in(DeviceSite::getType, list));
+        List<DeviceSite> sites = all.stream()
+                .collect(Collectors.toMap(DeviceSite::getSite, d -> d, (a, b) -> a))
+                .values().stream()
+                .collect(Collectors.toList());
         return R.ok(sites);
     }
 
@@ -699,37 +709,43 @@
             for (LocItem locItem : locItems) {
                 Loc loc = locService.getById(locItem.getLocId());
                 List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, locItem.getLocCode()));
-                if (issued.compareTo(ISSUED_TOLERANCE) > 0) {
-                    ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
-                    if (existDtos.add(existDto)) {
-                        locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue());
-                        locItem.setBarcode(loc.getBarcode());
-                        OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
-                        orderOutItemDto.setLocItem(locItem);
+                if (issued.compareTo(ISSUED_TOLERANCE) <= 0) {
+                    break;
+                }
+                // 璇ュ簱浣嶅彲鍒嗛厤鏁伴噺锛氬彇鏈寰呭垎閰嶄笌搴撲綅搴撳瓨鐨勮緝灏忓��
+                double allocatable = Math.min(issued.doubleValue(), locItem.getAnfme() != null ? locItem.getAnfme() : 0);
+                ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
+                if (existDtos.add(existDto)) {
+                    // 棣栨浣跨敤璇ュ簱浣嶏細鍔犲叆鍒楄〃骞舵墸鍑� issued
+                    locItem.setOutQty(allocatable);
+                    locItem.setBarcode(loc.getBarcode());
+                    OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
+                    orderOutItemDto.setLocItem(locItem);
 
-                        List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>()
-                                .eq(DeviceSite::getChannel, loc.getChannel())
-                                .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
-                        );
+                    List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>()
+                            .eq(DeviceSite::getChannel, loc.getChannel())
+                            .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
+                    );
 
-                        if (!deviceSites.isEmpty()) {
-                            List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
-                            for (DeviceSite sta : deviceSites) {
-                                OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
-                                staListDto.setStaNo(sta.getSite());
-                                staListDto.setStaName(sta.getSite());
-                                maps.add(staListDto);
-                            }
-                            orderOutItemDto.setStaNos(maps);
-                            //榛樿鑾峰彇绗竴绔欑偣
-                            DeviceSite deviceSite = deviceSites.stream().findFirst().get();
-                            orderOutItemDto.setSiteNo(deviceSite.getSite());
+                    if (!deviceSites.isEmpty()) {
+                        List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
+                        for (DeviceSite sta : deviceSites) {
+                            OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
+                            staListDto.setStaNo(sta.getSite());
+                            staListDto.setStaName(sta.getSite());
+                            maps.add(staListDto);
                         }
-
-                        list.add(orderOutItemDto);
-
-                        issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+                        orderOutItemDto.setStaNos(maps);
+                        //榛樿鑾峰彇绗竴绔欑偣
+                        DeviceSite deviceSite = deviceSites.stream().findFirst().get();
+                        orderOutItemDto.setSiteNo(deviceSite.getSite());
                     }
+
+                    list.add(orderOutItemDto);
+                    issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+                } else {
+                    // 璇ュ簱浣嶅凡琚墠搴忚鍗曡鍗犵敤锛氬彧鎵e噺 issued锛屼笉閲嶅鍔犲叆鍒楄〃锛岄伩鍏嶄骇鐢熲�滃簱瀛樹笉瓒斥�濊剰鏁版嵁
+                    issued = issued.subtract(new BigDecimal(String.valueOf(allocatable)));
                 }
             }
             if (issued.compareTo(ISSUED_TOLERANCE) > 0) {

--
Gitblit v1.9.1