From 2b67f0d6bafb35b0ec5cc297e474aff903db0c07 Mon Sep 17 00:00:00 2001
From: yiwenpeng <ywp303@163.com>
Date: Wed, 10 Jan 2024 19:25:15 +0800
Subject: [PATCH] feat:自建库位移库只能移到自建库位中

---
 src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java          |  12 ++++++------
 src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java | 125 ++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------
 src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java |   3 ++-
 src/main/java/com/huaheng/common/constant/QuantityConstant.java                                 |   8 ++++++--
 src/main/java/com/huaheng/pc/config/location/service/LocationService.java                       |   6 +++---
 src/main/java/com/huaheng/pc/config/location/service/LocationServiceImpl.java                   |  20 +++++++++-----------
 6 files changed, 64 insertions(+), 110 deletions(-)

diff --git a/src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java b/src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java
index b135e48..d2a0c66 100644
--- a/src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java
+++ b/src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java
@@ -157,13 +157,13 @@ public class TaskAssignServiceImpl implements TaskAssignService {
                     if (taskHeader2 != null) {
                         preTaskNo = taskHeader2.getId();
                     } else {
+                        //是否自建单据库位
+                        int isSelfCreated = 0;
+                        if (insideLocation.getSelfCreated()) {
+                            isSelfCreated = 1;
+                        }
                         Location destinationLocation;
                         if (insideLocation.getRoadway().equals("5")) {
-                            //是否自建单据库位
-                            int isSelfCreated = 0;
-                            if (insideLocation.getSelfCreated()) {
-                                isSelfCreated = 1;
-                            }
                             boolean isFlammable = true;
                             if (insideLocation.getILayer() > 3) {
                                 isFlammable = false;
@@ -179,7 +179,7 @@ public class TaskAssignServiceImpl implements TaskAssignService {
                             destinationLocation = locationService.getLocationByCode(destinationLocationCode);
                         } else {
                             //获取一个最近的空闲库位(优先找外侧)
-                            destinationLocation = locationService.getEmptyLocation(insideLocation);
+                            destinationLocation = locationService.getEmptyLocation(insideLocation, isSelfCreated);
                         }
                         AjaxResult ajaxResult = transferTaskService.createTransferTask(insideLocation.getCode(), destinationLocation.getCode(), warehouseCode);
                         if (ajaxResult.getCode() == 400) {
diff --git a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
index 17d6a4f..1734719 100644
--- a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
+++ b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
@@ -61,7 +61,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         //二期5号巷道
         if (roadWay.equals(DYNAMIC_ROADWAY)) {
             return locationAllocationService.fiveStacker(high, containerCode, isFlammable, transfer);
-        } else if (isSelfCreated == 1) { //自建单据
+        } else if (isSelfCreated == 1) { //二厂的自建单据库位
             return locationAllocationService.isSelfCreated(roadWay, high, frequencyLocation, isFlammable);
         } else {
             return locationAllocationService.doubleRk(area, roadWay, high, frequencyLocation, emptyContainerTask, isFlammable);
@@ -237,32 +237,36 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
 
 
     /**
-     * 双伸位库位入库分配库位
+     * 双伸位库位分配库位
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String doubleRk(String area, String roadWay, int high, Integer frequencyLocation, Integer emptyContainerTask, boolean isFlammable) {
-        // 获取双伸位预留库位数
-        int reserveNumber = getReserveNumber();
+        //如果是二厂的空托盘入库任务,优先分配空托盘库位,没有了再分配其他的库位
+        if (emptyContainerTask == 1) {
+            LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery();
+            wrapper.eq(Location::getRoadway, roadWay)
+                    .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
+                    .eq(Location::getHigh, high)
+                    .eq(Location::getContainerCode, "")
+                    .eq(Location::getOnlyEmptyContainer, EMPTY_CONTAINER_LOCATION);
+            List<Location> list = locationService.list(wrapper);
+            if (!list.isEmpty()) {
+                return list.get(0).getCode();
+            }
+        }
+
+        int reserveNumber = getReserveNumber();// 获取双伸位预留库位数
         // 移除掉可用库位数小于预留库位数的巷道
         LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery();
-        wrapper.eq(Location::getArea, area)
-                .eq(Location::getRoadway, roadWay)
+        wrapper.eq(Location::getRoadway, roadWay)
                 .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
                 .eq(Location::getHigh, high)
                 .eq(Location::getContainerCode, "")
-                .orderByAsc(Location::getILayer)
-                .eq(Location::getSelfCreated, NOTSELFCREATED)
+                .eq(Location::getSelfCreated, NO_TSELFCREATED)
+                .eq(Location::getOnlyEmptyContainer, NO_EMPTY_CONTAINER_LOCATION)
                 .last(" limit 20");
 
-        // emptyContainerTask=1表示是空托盘任务
-        // 如果是空托盘,onlyEmptyContainer大于等于0,并排序,只限空托盘的库位优先分配,不是不是空托盘任务,只能分配分配onlyEmptyContainer为0的库位
-        if (emptyContainerTask == 1) {
-            wrapper.ge(Location::getOnlyEmptyContainer, 0);//大于等于0
-            wrapper.orderByDesc(Location::getFrequencyLocation);
-        } else {
-            wrapper.eq(Location::getOnlyEmptyContainer, 0);
-        }
         List<Location> totalLocationList = locationService.list(wrapper);
         //双伸位预留库位数不够了就排除掉该巷道
         if (totalLocationList.size() <= reserveNumber) {
@@ -271,22 +275,15 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
 
         // 查找外侧的库位
         LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
-        locationLambda.eq(Location::getArea, area)
-                .eq(Location::getRoadway, roadWay)
+        locationLambda.eq(Location::getRoadway, roadWay)
                 .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
                 .eq(Location::getHigh, high)
                 .eq(Location::getRowFlag, ROW_OUT)//外侧
                 .eq(Location::getContainerCode, "")
-                .eq(Location::getSelfCreated, NOTSELFCREATED)
+                .eq(Location::getSelfCreated, NO_TSELFCREATED)
+                .eq(Location::getOnlyEmptyContainer, NO_EMPTY_CONTAINER_LOCATION)
                 .last(" limit 20");
 
-        //空托盘
-        if (emptyContainerTask == 1) {
-            locationLambda.ge(Location::getOnlyEmptyContainer, 0);//大于等于0
-            locationLambda.orderByDesc(Location::getOnlyEmptyContainer);
-        } else {
-            locationLambda.eq(Location::getOnlyEmptyContainer, 0);
-        }
         //频繁库位
         String str;
         if (frequencyLocation == 1) {
@@ -303,15 +300,12 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
             //locationLambda.orderByDesc(Location::getFrequencyLocation);//倒序
         }
 
-        //可燃物料(空托盘不用进来判断)
-        if (emptyContainerTask != 1) {
-            if (isFlammable) {
-                locationLambda.orderByAsc(Location::getILayer);
-            } else {
-                locationLambda.last("ORDER BY " + str + ", (CASE WHEN iLayer > 2 THEN iLayer ELSE iLayer + 20 END) ASC");
-            }
+        //可燃物料
+        if (isFlammable) {
+            locationLambda.orderByAsc(Location::getILayer);
+        } else {
+            locationLambda.last("ORDER BY " + str + ", (CASE WHEN iLayer > 2 THEN iLayer ELSE iLayer + 20 END) ASC");
         }
-
         List<Location> locationList = locationService.list(locationLambda);
         List<Location> removeLocaationList = new ArrayList<>();
         if (locationList != null && !locationList.isEmpty()) {
@@ -322,7 +316,6 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
                 }
             }
         }
-
         if (locationList != null) {
             locationList.removeAll(removeLocaationList);
         }
@@ -330,22 +323,15 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         // 如果没有外侧库位可分配了,再查内侧的库位
         if (locationList == null || locationList.isEmpty()) {
             locationLambda = Wrappers.lambdaQuery();
-            locationLambda.eq(Location::getArea, area)
-                    .eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
+            locationLambda.eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
                     .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
                     .eq(Location::getHigh, high)
                     .eq(Location::getRowFlag, ROW_IN)
                     .eq(Location::getContainerCode, "")
-                    .eq(Location::getSelfCreated, NOTSELFCREATED)
+                    .eq(Location::getSelfCreated, NO_TSELFCREATED)
+                    .eq(Location::getOnlyEmptyContainer, NO_EMPTY_CONTAINER_LOCATION)
                     .last(" limit 20");
 
-            if (emptyContainerTask == 1) {
-                locationLambda.ge(Location::getOnlyEmptyContainer, 0);//大于等于0
-                locationLambda.orderByDesc(Location::getOnlyEmptyContainer);
-            } else {
-                locationLambda.eq(Location::getOnlyEmptyContainer, 0);
-            }
-
             //频繁库位
             //if (frequencyLocation == 1) {
             //    locationLambda.orderByAsc(Location::getFrequencyLocation); //升序
@@ -358,15 +344,12 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
             //    locationLambda.orderByDesc(Location::getFrequencyLocation);//倒序
             //}
             //可燃物料(空托盘不用进来判断)
-            if (emptyContainerTask != 1) {
-                if (isFlammable) {
-                    locationLambda.orderByAsc(Location::getILayer);
-                } else {
-                    locationLambda.last("ORDER BY " + str + ", (CASE WHEN iLayer > 2 THEN iLayer ELSE iLayer + 20 END) ASC");
-                }
+            if (isFlammable) {
+                locationLambda.orderByAsc(Location::getILayer);
+            } else {
+                locationLambda.last("ORDER BY " + str + ", (CASE WHEN iLayer > 2 THEN iLayer ELSE iLayer + 20 END) ASC");
             }
             locationList = locationService.list(locationLambda);
-
             removeLocaationList = new ArrayList<>();
             if (locationList != null && !locationList.isEmpty()) {
                 for (Location location1 : locationList) {
@@ -394,13 +377,11 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         int reserveNumber = getReserveNumber();
         // 移除掉可用库位数小于预留库位数的巷道
         LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery();
-        wrapper.eq(Location::getArea, AREA)
-                .eq(Location::getRoadway, roadWay)
+        wrapper.eq(Location::getRoadway, roadWay)
                 .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
                 .eq(Location::getHigh, high)
                 .eq(Location::getSelfCreated, SELFCREATED)
                 .eq(Location::getContainerCode, "")
-                .orderByAsc(Location::getILayer)
                 .last(" limit 20");
 
         List<Location> totalLocationList = locationService.list(wrapper);
@@ -411,36 +392,13 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
 
         // 查找外侧的库位
         LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
-        locationLambda.eq(Location::getArea, AREA)
-                .eq(Location::getRoadway, roadWay)
+        locationLambda.eq(Location::getRoadway, roadWay)
                 .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
                 .eq(Location::getHigh, high)
                 .eq(Location::getSelfCreated, SELFCREATED)
                 .eq(Location::getRowFlag, ROW_OUT)//外侧
                 .eq(Location::getContainerCode, "")
                 .last(" limit 20");
-
-        //频繁库位
-        String str;
-        if (frequencyLocation == 1) {
-            str = "frequencyLocation asc";
-        } else if (frequencyLocation == 2) {
-            //常用
-            locationLambda.ge(Location::getFrequencyLocation, 2);//大于等于2
-            str = "frequencyLocation asc";
-        } else {
-            //不常用
-            str = "frequencyLocation desc";
-        }
-
-        //可燃物料
-        if (isFlammable) {
-            locationLambda.orderByAsc(Location::getILayer);
-        } else {
-            locationLambda.last("ORDER BY " + str + ", (CASE WHEN iLayer > 2 THEN iLayer ELSE iLayer + 20 END) ASC");
-        }
-
-
         List<Location> locationList = locationService.list(locationLambda);
         List<Location> removeLocaationList = new ArrayList<>();
         if (locationList != null && !locationList.isEmpty()) {
@@ -458,7 +416,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         // 如果没有外侧库位可分配了,再查内侧的库位
         if (locationList == null || locationList.isEmpty()) {
             locationLambda = Wrappers.lambdaQuery();
-            locationLambda.eq(Location::getArea, AREA)
+            locationLambda
                     .eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
                     .eq(Location::getStatus, STATUS_LOCATION_EMPTY)
                     .eq(Location::getHigh, high)
@@ -466,13 +424,6 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
                     .eq(Location::getRowFlag, ROW_IN)
                     .eq(Location::getContainerCode, "")
                     .last(" limit 20");
-
-            //可燃物料(空托盘不用进来判断)
-            if (isFlammable) {
-                locationLambda.orderByAsc(Location::getILayer);
-            } else {
-                locationLambda.last("ORDER BY " + str + ", (CASE WHEN iLayer > 2 THEN iLayer ELSE iLayer + 20 END) ASC");
-            }
             locationList = locationService.list(locationLambda);
 
             removeLocaationList = new ArrayList<>();
diff --git a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
index d8332bf..801f7da 100644
--- a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
+++ b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
@@ -252,6 +252,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
         if (rowFlag == QuantityConstant.ROW_OUT) {
             //拿到该库位的内侧库位
             Location insideLocation = locationService.getInsideNear(location);
+
             //如果内侧库位上有托盘的话
             if (StringUtils.isNotEmpty(insideLocation.getContainerCode())) {
                 Location destinationLocation;
@@ -266,7 +267,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
                     destinationLocation = locationService.getLocationByCode(destinationLocationCode);
                 } else {
                     //获取一个最近的空闲库位(优先找外侧)
-                    destinationLocation = locationService.getEmptyLocation(insideLocation);
+                    destinationLocation = locationService.getEmptyLocation(insideLocation, isSelfCreated);
                 }
 
                 //创建移库任务
diff --git a/src/main/java/com/huaheng/common/constant/QuantityConstant.java b/src/main/java/com/huaheng/common/constant/QuantityConstant.java
index f35cc7a..cca852b 100644
--- a/src/main/java/com/huaheng/common/constant/QuantityConstant.java
+++ b/src/main/java/com/huaheng/common/constant/QuantityConstant.java
@@ -571,6 +571,10 @@ public class QuantityConstant {
     public static final String BIG_CONTAINER_TYPE = "2";
 
     public static final String AREA = "1";
-    public static final String SELFCREATED = "1";
-    public static final String NOTSELFCREATED = "0";
+    public static final String SELFCREATED = "1";//自建单据库位
+    public static final String NO_TSELFCREATED = "0";//非建单据库位
+
+    public static final String EMPTY_CONTAINER_LOCATION = "1";//空托盘库位
+    public static final String NO_EMPTY_CONTAINER_LOCATION = "0";//不是空托盘库位
+
 }
diff --git a/src/main/java/com/huaheng/pc/config/location/service/LocationService.java b/src/main/java/com/huaheng/pc/config/location/service/LocationService.java
index b68558c..4a8d2e8 100644
--- a/src/main/java/com/huaheng/pc/config/location/service/LocationService.java
+++ b/src/main/java/com/huaheng/pc/config/location/service/LocationService.java
@@ -111,11 +111,11 @@ public interface LocationService extends IService<Location> {
 
     Location getNear(Location location);
 
-    Location getEmptyInsideLocation(Location location);
+    Location getEmptyInsideLocation(Location location, int isSelfCreated);
 
-    Location getEmptyOutSideLocation(Location location);
+    Location getEmptyOutSideLocation(Location location, int isSelfCreated);
 
-    Location getEmptyLocation(Location location);
+    Location getEmptyLocation(Location location, int isSelfCreated);
 
     int getFirstRowOfZone(String warehouseCode, String zoneCode);
 
diff --git a/src/main/java/com/huaheng/pc/config/location/service/LocationServiceImpl.java b/src/main/java/com/huaheng/pc/config/location/service/LocationServiceImpl.java
index 09e3017..aadd323 100644
--- a/src/main/java/com/huaheng/pc/config/location/service/LocationServiceImpl.java
+++ b/src/main/java/com/huaheng/pc/config/location/service/LocationServiceImpl.java
@@ -551,11 +551,10 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i
     }
 
     @Override
-    public Location getEmptyOutSideLocation(Location location) {
+    public Location getEmptyOutSideLocation(Location location, int isSelfCreated) {
         LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(Location::getSelfCreated, false);
-        queryWrapper.ne(Location::getOnlyEmptyContainer, 1);
-        queryWrapper.eq(Location::getWarehouseCode, location.getWarehouseCode());
+        queryWrapper.eq(Location::getSelfCreated, isSelfCreated);
+        queryWrapper.eq(Location::getOnlyEmptyContainer, NO_EMPTY_CONTAINER_LOCATION);
         queryWrapper.eq(Location::getRoadway, location.getRoadway());
         queryWrapper.eq(Location::getHigh, location.getHigh());
         queryWrapper.eq(Location::getRowFlag, QuantityConstant.ROW_OUT);//外侧
@@ -596,11 +595,10 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i
 
 
     @Override
-    public Location getEmptyInsideLocation(Location location) {
+    public Location getEmptyInsideLocation(Location location, int isSelfCreated) {
         LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.eq(Location::getSelfCreated, false);
-        queryWrapper.ne(Location::getOnlyEmptyContainer, 1);
-        queryWrapper.eq(Location::getWarehouseCode, location.getWarehouseCode());
+        queryWrapper.eq(Location::getSelfCreated, isSelfCreated);
+        queryWrapper.eq(Location::getOnlyEmptyContainer, NO_EMPTY_CONTAINER_LOCATION);
         queryWrapper.eq(Location::getRoadway, location.getRoadway());
         queryWrapper.eq(Location::getRowFlag, QuantityConstant.ROW_IN);//内侧
         queryWrapper.eq(Location::getHigh, location.getHigh());
@@ -638,10 +636,10 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i
     }
 
     @Override
-    public Location getEmptyLocation(Location location) {
-        Location location1 = getEmptyOutSideLocation(location);
+    public Location getEmptyLocation(Location location, int isSelfCreated) {
+        Location location1 = getEmptyOutSideLocation(location, isSelfCreated);
         if (location1 == null) {
-            location1 = getEmptyInsideLocation(location);
+            location1 = getEmptyInsideLocation(location, isSelfCreated);
         }
         return location1;
     }
--
libgit2 0.22.2