From 6c3cc6842009f3897c3fb18bef8a6634fe653818 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期三, 04 三月 2026 19:59:11 +0800
Subject: [PATCH] lsh#

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java |  157 ++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 104 insertions(+), 53 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
index b202115..da7af21 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java
@@ -1,6 +1,7 @@
 package com.vincent.rsf.server.manager.utils;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.vincent.rsf.framework.common.Cools;
 import com.vincent.rsf.framework.common.SpringUtils;
 import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.server.api.utils.LocUtils;
@@ -175,7 +176,9 @@
         LocService locService = SpringUtils.getBean(LocService.class);
         LocItemService locItemService = SpringUtils.getBean(LocItemService.class);
         DeviceSiteService deviceSiteService = SpringUtils.getBean(DeviceSiteService.class);
-
+        BasStationAreaService basStationAreaService = SpringUtils.getBean(BasStationAreaService.class);
+//        List<BasStationArea> basStationAreas = basStationAreaService.list(new LambdaQueryWrapper<>());//
+        List<Loc> locList = new  ArrayList<>();
         List<OrderOutItemDto> list = new ArrayList<>();
         //涓嶈绔欑偣閲嶅浣跨敤闂
         List<BasStation> stations = new ArrayList<>();
@@ -198,10 +201,27 @@
                     locItems = LocManageUtil.getFirstInFirstOutItemList(item.getMatnrCode(), item.getBatch(), item.getAnfme());
                 }
             }
+
             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.doubleValue() > 0) {
+                List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
+
+                if (issued.doubleValue() > 0 && locList.contains(loc)) {
+                    for (OrderOutItemDto itemDto : list) {
+                        if (itemDto.getLoc().equals(loc)) {
+                            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())
+                                        .setSourceId(item.getWaveId())//娉㈡ID
+                                        .setSource(item.getItemId());//娉㈡鏄庣粏ID
+                                itemDto.getLocItemList().add(locItem);
+                                issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+                            }
+                            break;
+                        }
+                    }
+                } else if (issued.doubleValue() > 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());
@@ -209,65 +229,96 @@
                                 .setSourceId(item.getWaveId())//娉㈡ID
                                 .setSource(item.getItemId());//娉㈡鏄庣粏ID
                         OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
-                        orderOutItemDto.setLocItem(locItem);
-
-                        List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>()
-                                .eq(!Objects.isNull(loc.getChannel()), 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);
-                            //鑾峰彇婊¤冻鏉′欢绔欑偣
-                            Set<String> stationSet = deviceSites.stream().map(DeviceSite::getSite).collect(Collectors.toSet());
-                            //宸蹭娇鐢ㄧ珯鐐�
-                            Set<String> stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
-                            BasStationService basStationService = SpringUtils.getBean(BasStationService.class);
-                            BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
-                                    .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
-                                    .in(BasStation::getStationName, stationSet)
-                                    .notIn(!stas.isEmpty(), BasStation::getStationName, stas)
-                                    .last("LIMIT 1"));
-                            stations.add(basStation);
-
-                            if (Objects.isNull(basStation)) {
-                                throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
-                            }
-                            orderOutItemDto.setSitesNo(basStation.getStationName());
+//                        orderOutItemDto.setLocItem(locItem);
+                        orderOutItemDto.setLoc(loc);
+                        orderOutItemDto.getLocItemList().add(locItem);
+                        BasContainer containerType = getContainerType(loc.getBarcode());
+                        List<BasStationArea> basStationAreas = basStationAreaService.list(new LambdaQueryWrapper<BasStationArea>()
+                                .apply("JSON_CONTAINS(cross_zone_area, '{0}') = 1", loc.getAreaId())//鍙墽琛屽簱鍖哄尯鍖哄煙id
+                                .apply("JSON_CONTAINS(container_type, '{0}') = 1", containerType)//瀹瑰櫒绫诲瀷
+//                                .apply("JSON_CONTAINS(station_alias, '\"{0}\"') = 1", null)//鍖哄煙鍖呭惈绔欑偣闆�
+                                .eq(BasStationArea::getDeleted, 0));// 閫氬父闇�瑕佸姞涓婃湭鍒犻櫎鏉′欢
+                        List<String> targSiteAreaList = new ArrayList<>();
+                        for (BasStationArea basStationArea : basStationAreas) {
+                            targSiteAreaList.add(basStationArea.getStationAreaId());
                         }
+                        int count = 0;
+                        for (BasStationArea basStationArea : basStationAreas) {
+                            count++;
+                            if (!basStationArea.getStationAlias().isEmpty()) {
+                                List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
+                                for (String site : basStationArea.getStationAlias()) {
+                                    OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
+                                    staListDto.setStaNo(site);
+                                    staListDto.setStaName(site);
+                                    maps.add(staListDto);
+                                }
+                                orderOutItemDto.setStaNos(maps);
+                                //鑾峰彇婊¤冻鏉′欢绔欑偣
+                                Set<String> stationSet = new HashSet<>(basStationArea.getStationAlias());
+//                                Set<String> stationSet = basStationArea.getStationAlias().stream().collect(Collectors.toSet());
+//                                Set<String> stationSet = deviceSites.stream().map(DeviceSite::getSite).collect(Collectors.toSet());
+                                //宸蹭娇鐢ㄧ珯鐐�
+                                Set<String> stas = stations.stream().map(BasStation::getStationName).collect(Collectors.toSet());
+                                BasStationService basStationService = SpringUtils.getBean(BasStationService.class);
+                                BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+                                        .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+                                        .in(BasStation::getStationName, stationSet)
+                                        .notIn(!stas.isEmpty(), BasStation::getStationName, stas)
+                                        .last("LIMIT 1"));
+                                if (!Objects.isNull(basStation)) {
+                                    stations.add(basStation);
+                                }
 
-                        orderOutItemDto.setSource(item.getItemId())
-                                .setSourceId(item.getWaveId());
-                        list.add(orderOutItemDto);
+                                if (count == basStationAreas.size()) {
+                                    if (!Objects.isNull(basStation)) {
+                                        orderOutItemDto.setSiteNo(basStation.getStationName());
+//                                        throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
+                                    }
+                                } else {
+                                    if (Objects.isNull(basStation)) {
+                                        continue;
+//                                        throw new CoolException("绔欓粸涓嶅瓨鍦紒锛�");
+                                    }
+                                    orderOutItemDto.setSiteNo(basStation.getStationName());
+                                }
 
-                        issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+                            }
+
+                            orderOutItemDto.setSource(item.getItemId().toString())
+                                    .setTargSiteAreaList(targSiteAreaList)
+                                    .setSourceId(item.getWaveId().toString());
+                            list.add(orderOutItemDto);
+                            locList.add(loc);
+
+                            issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+                            break;
+                        }
                     }
                 }
             }
-//            if (issued.doubleValue() > 0) {
-//                LocItem locItem = new LocItem()
-//                        .setId(new Random().nextLong())
-//                        .setMatnrCode(item.getMatnrCode())
-//                        .setMaktx(item.getMaktx())
-//                        .setAnfme(0.00)
-//                        .setWorkQty(issued.doubleValue())
-//                        .setOutQty(issued.doubleValue())
-//                        .setUnit(item.getUnit())
-//                        .setBatch(item.getBatch());
-//                OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
-//                orderOutItemDto.setLocItem(locItem);
-//                list.add(orderOutItemDto);
-//            }
         }
 
         return list;
     }
 
+
+
+
+    //鏍规嵁鏉$爜鑾峰彇瑙勫垯
+    private static BasContainer getContainerType(String barcode) {
+        BasContainerService basContainerService = SpringUtils.getBean(BasContainerService.class);
+        if (Cools.isEmpty(barcode)) {
+            throw new CoolException("瀹瑰櫒鐮佷笉鑳戒负绌�");
+        }
+        List<BasContainer> containers = basContainerService.list(new LambdaQueryWrapper<>());
+        for (BasContainer container : containers) {
+            String codeType = container.getCodeType();  // 鑾峰彇姝e垯琛ㄨ揪寮�
+            if (barcode.matches(codeType)) {  // 鍒ゆ柇鏉$爜鏄惁绗﹀悎杩欎釜姝e垯
+                return container;
+            }
+        }
+        return null;
+    }
+
 }

--
Gitblit v1.9.1