From 450320f28d8db37264d7fc448c01fb32f64610b2 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 13 十一月 2025 16:53:06 +0800
Subject: [PATCH] 波次出库修改

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/utils/LocManageUtil.java |  110 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 80 insertions(+), 30 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 ed0b31d..f16250a 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
@@ -2,15 +2,19 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.vincent.rsf.framework.common.SpringUtils;
+import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.server.api.utils.LocUtils;
 import com.vincent.rsf.server.manager.controller.dto.ExistDto;
 import com.vincent.rsf.server.manager.controller.dto.OrderOutItemDto;
 import com.vincent.rsf.server.manager.controller.params.WaveToLocParams;
 import com.vincent.rsf.server.manager.entity.*;
+import com.vincent.rsf.server.manager.enums.ContainerType;
 import com.vincent.rsf.server.manager.enums.TaskType;
 import com.vincent.rsf.server.manager.enums.WaveRuleType;
 import com.vincent.rsf.server.manager.service.*;
 import com.vincent.rsf.server.manager.enums.LocStsType;
+
+import org.apache.commons.lang3.StringUtils;
 
 import javax.swing.*;
 import java.math.BigDecimal;
@@ -20,22 +24,48 @@
 public class LocManageUtil {
 
     /**
-     * @author Ryan
-     * @description  鑾峰彇鐩爣搴撲綅, 鍖呭惈搴撲綅鑾峰彇绛栫暐
      * @param
      * @return
+     * @author Ryan
+     * @description 鑾峰彇鐩爣搴撲綅, 鍖呭惈搴撲綅鑾峰彇绛栫暐
      * @time 2025/3/31 08:50
      */
     public static String getTargetLoc(Long areaId) {
         //TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
-        LocService locService = SpringUtils.getBean(LocService.class);
 
+        return getTargetLoc(areaId, null);
+    }
+
+    public static String getTargetLoc(Long areaId, Long containerType) {
+        Long locType = null;
+        if (!Objects.isNull(containerType)) {
+            LocTypeService locService = SpringUtils.getBean(LocTypeService.class);
+            if (containerType.equals(ContainerType.CONTAINER_TYPE_NORMAL.val)) {
+                LocType low = locService.getOne(new LambdaQueryWrapper<LocType>()
+                        .eq(LocType::getCode, "L"));
+                if (Objects.isNull(low)) {
+                    throw new CoolException("搴綅椤炲瀷涓嶅瓨鍦紒锛�");
+                }
+                locType = low.getId();
+            } else {
+                LocType low = locService.getOne(new LambdaQueryWrapper<LocType>()
+                        .eq(LocType::getCode, "H"));
+                if (Objects.isNull(low)) {
+                    throw new CoolException("搴綅椤炲瀷涓嶅瓨鍦紒锛�");
+                }
+                locType = low.getId();
+            }
+        }
+        //TODO 搴撲綅绛栫暐鍚庣画鎺掓湡
+        LocService locService = SpringUtils.getBean(LocService.class);
         Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>()
+                .eq(!Objects.isNull(locType), Loc::getType, locType)
                 .eq(Loc::getAreaId, areaId)
+                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                 .orderByAsc(Loc::getLev)
                 .orderByAsc(Loc::getCol)
                 .orderByAsc(Loc::getRow)
-                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type), false
+                .last("LIMIT 1")
         );
 
         return !Objects.isNull(loc) ? loc.getCode() : null;
@@ -43,12 +73,12 @@
 
 
     /**
-    * @author Ryan
-    * @description 鑾峰彇鐩爣绔欑偣
-    * @param
-    * @return
-    * @time 2025/3/31 09:49
-    */
+     * @param
+     * @return
+     * @author Ryan
+     * @description 鑾峰彇鐩爣绔欑偣
+     * @time 2025/3/31 09:49
+     */
     public static String getTargetSite() {
         //TODO 绔欑偣绛栫暐鍚庣画鎺掓湡
         DeviceSiteService deviceSite = SpringUtils.getBean(DeviceSiteService.class);
@@ -58,6 +88,7 @@
 
     /**
      * 鍑哄簱绛栫暐锛�--銆堟晥鐜囦紭鍖栥��
+     *
      * @param matnrCode
      * @param splrBatch
      * @param anfme
@@ -66,7 +97,7 @@
     public static List<LocItem> getEfficiencyFirstItemList(String matnrCode, String splrBatch, Double anfme) {
         LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>();
         locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode);
-        locItemQueryWrapper.eq(LocItem::getBatch, splrBatch);
+        locItemQueryWrapper.eq(StringUtils.isNotBlank(splrBatch), LocItem::getBatch, splrBatch);
         String applySql = String.format(
                 "EXISTS (SELECT 1 FROM man_loc ml " +
                         "WHERE ml.use_status = '%s'" +
@@ -88,6 +119,7 @@
 
     /**
      * 鍑哄簱绛栫暐锛�--<鍏堣繘鍏堝嚭>
+     *
      * @param matnrCode
      * @param splrBatch
      * @param anfme
@@ -96,7 +128,7 @@
     public static List<LocItem> getFirstInFirstOutItemList(String matnrCode, String splrBatch, Double anfme) {
         LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>();
         locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode);
-        locItemQueryWrapper.eq(LocItem::getBatch, splrBatch);
+        locItemQueryWrapper.eq(StringUtils.isNotEmpty(splrBatch), LocItem::getBatch, splrBatch);
         locItemQueryWrapper.orderByAsc(LocItem::getCreateTime);
         String applySql = String.format(
                 "EXISTS (SELECT 1 FROM man_loc ml " +
@@ -113,6 +145,7 @@
 
     /**
      * 鑾峰彇鍑哄簱搴撲綅淇℃伅
+     *
      * @param params
      * @param waveRule
      * @return
@@ -123,7 +156,10 @@
         DeviceSiteService deviceSiteService = SpringUtils.getBean(DeviceSiteService.class);
 
         List<OrderOutItemDto> list = new ArrayList<>();
-        Set<ExistDto> existDtos = new HashSet<>();
+        //涓嶈绔欑偣閲嶅浣跨敤闂
+        List<BasStation> stations = new ArrayList<>();
+        List<ExistDto> existDtos = new ArrayList<>();
+        Set<Loc> locs = new HashSet<>();
         for (WaveToLocParams item : params) {
             BigDecimal issued = new BigDecimal(item.getAnfme().toString())
                     .subtract(new BigDecimal(item.getWorkQty().toString()));
@@ -142,7 +178,6 @@
                     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()));
@@ -151,31 +186,46 @@
                     if (existDtos.add(existDto)) {
                         locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue());
                         locItem.setBarcode(loc.getBarcode())
-                                .setSourceId(item.getWaveId())
-                                .setSource(item.getItemId());
+                                .setSourceId(item.getWaveId())//娉㈡ID
+                                .setSource(item.getItemId());//娉㈡鏄庣粏ID
                         OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
                         orderOutItemDto.setLocItem(locItem);
-
+                        orderOutItemDto.setSource(item.getItemId())
+                                .setSourceId(item.getWaveId());
                         List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>()
-                                .eq(DeviceSite::getChannel, loc.getChannel())
+                                .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);
+                        if (locs.add(loc)) {
+                            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.setStaNos(maps);
-                            //榛樿鑾峰彇绗竴绔欑偣
-                            DeviceSite deviceSite = deviceSites.stream().findFirst().get();
-                            orderOutItemDto.setSiteNo(deviceSite.getSite());
                         }
 
-                        orderOutItemDto.setSource(item.getItemId()).setSource(item.getWaveId());
 
                         list.add(orderOutItemDto);
 

--
Gitblit v1.9.1