diff --git a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationService.java b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationService.java
index 9399d60..54cab90 100644
--- a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationService.java
+++ b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationService.java
@@ -8,6 +8,6 @@ public interface LocationAllocationService {
 
    
    String allocation(int locationRule, List<String> locationTypeCodeList, int high, String area,
-                     List<String> roadWay, String warehouseCode, String containerCode, String materialAreaCode);
+                     List<String> roadWays, String warehouseCode, String containerCode, String materialAreaCode);
 
 }
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 f8266d1..3489dc3 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
@@ -1,6 +1,7 @@
 package com.huaheng.api.wcs.service.warecellAllocation;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.huaheng.common.constant.Constants;
 import com.huaheng.common.constant.QuantityConstant;
@@ -16,6 +17,7 @@ import com.huaheng.pc.config.locationType.domain.LocationType;
 import com.huaheng.pc.config.locationType.service.LocationTypeService;
 import com.huaheng.pc.config.zone.domain.Zone;
 import com.huaheng.pc.config.zone.service.ZoneService;
+import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
 import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
 import org.springframework.stereotype.Service;
 
@@ -44,7 +46,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
 
     @Override
     public String allocation(int locationRule, List<String> locationTypeCodeList,
-             int high, String area, List<String> raodWays, String warehouseCode,
+             int high, String area, List<String> roadWays, String warehouseCode,
              String containerCode, String materialAreaCode) {
         LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
         containerLambdaQueryWrapper.eq(Container::getCode, containerCode)
@@ -84,9 +86,9 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
         List<String> mergelocationTypeCodeList = locationTypeCodeList.stream().filter(item -> locationTypeCodes.contains(item)).collect(toList());
         switch (locationRule) {
             case QuantityConstant.DOUBLE_FORK:
- 				return doubleRk(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
+ 				return doubleRk(area, roadWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
             case QuantityConstant.SINGLE_FORK:
-               return singleRk(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
+               return singleRk(area, roadWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
         }
         return null;
     }
@@ -97,71 +99,50 @@ public class LocationAllocationServiceImpl implements LocationAllocationService 
     private String doubleRk(String area, List<String> roadWays, int high, String warehouseCode,
                             List<String> locationTypeCodeList, String materialAreaCode) {
 
-        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
-        locationLambdaQueryWrapper.eq(Location::getArea, area).
-                eq(Location::getWarehouseCode, warehouseCode)
-                .in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
-                .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
-                .eq(Location::getHigh, high)
-                .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
-                .in(Location::getLocationType, locationTypeCodeList)
-                .eq(Location::getContainerCode, "");
-        List<Location> totalLocationList = locationService.list(locationLambdaQueryWrapper);
-        if(totalLocationList.size() <= 4) {
+        if(CollectionUtils.isEmpty(roadWays)){
             return null;
         }
-
-        LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
-        locationLambda.eq(Location::getArea, area).
-                eq(Location::getWarehouseCode, warehouseCode)
- 				.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
-                .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
-                .eq(Location::getHigh, high)
-                .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
-                .eq(Location::getRowFlag, QuantityConstant.ROW_OUT)
-                .in(Location::getLocationType, locationTypeCodeList)
-                .eq(Location::getContainerCode, "");
-        List<Location> locationList = locationService.list(locationLambda);
-        List<Location> removeLocaationList = new ArrayList<>();
-        if(locationList != null && locationList.size() > 0) {
-            for (Location location1 : locationList) {
-                if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
-                    removeLocaationList.add(location1);
-                }
-            }
-        }
-        locationList.removeAll(removeLocaationList);
-
-
-
-        if (locationList == null || locationList.size() == 0) {
-            locationLambda = Wrappers.lambdaQuery();
-            locationLambda.eq(Location::getArea, area).
-                    eq(Location::getWarehouseCode, warehouseCode)
-					.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
-                    .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
+        for (String roadWay : roadWays) {
+            List<Location> roadwaylist=null;
+            List<String> locationss=new ArrayList<>();
+            LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
+            locationLambda
+                    .eq(Location::getArea, area)
+                    .eq(Location::getWarehouseCode, warehouseCode)
                     .eq(Location::getHigh, high)
-                    .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
-                    .eq(Location::getRowFlag, QuantityConstant.ROW_IN)
+                    .eq(Location::getRoadway,roadWay)
+                    .eq(Location::getContainerCode,"")
                     .in(Location::getLocationType, locationTypeCodeList)
-                    .eq(Location::getContainerCode, "");
-            locationList = locationService.list(locationLambda);
-            removeLocaationList = new ArrayList<>();
-            if(locationList != null && locationList.size() > 0) {
-                for (Location location1 : locationList) {
-                    if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
-                        removeLocaationList.add(location1);
+                    .eq(Location::getStatus,QuantityConstant.STATUS_LOCATION_EMPTY);
+            roadwaylist = locationService.list(locationLambda);
+            if(CollectionUtils.isEmpty(roadwaylist)||roadwaylist.size()<11){
+                 return null;
+            }
+            //查出外侧有货或者锁住(即有任务),内测无货的库位
+            List<String> locationlist =locationService.selectlistEnpty(roadWay);
+            if(!locationlist.isEmpty()){
+                locationss.addAll(locationlist);
+            }
+
+            //查出内侧有任务的库位
+            List<Location> locations = locationService.selectCode(roadWay);
+            if(!locations.isEmpty()) {
+                //筛选内部库位
+                for(Location item :locations){
+                    Location condition = locationService.getInsideNear(item);
+                    if(condition!=null) {
+                        locationss.add(condition.getCode());
                     }
                 }
+
             }
-            locationList.removeAll(removeLocaationList);
-        }
-        if (locationList == null || locationList.size() == 0) {
-            return null;
+            Location location = locationService.getEmptyLocationOne(roadWay, Integer.valueOf(high).toString(), locationss);
+            if(StringUtils.isNull(location)){
+                continue;
+            }
+            return location.getCode();
         }
-        Location location = locationList.stream().findFirst().orElse(null);
-        String locationCode = location.getCode();
-        return locationCode;
+        return null;
     }
 
     /**
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 8b5efe9..6f2bc88 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
@@ -49,6 +49,7 @@ import com.huaheng.api.wcs.domain.WcsTask;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -124,6 +125,9 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
         if (StringUtils.isNull(wcsTask.getHeight())) {
             return AjaxResult.error("高为空");
         }
+        if(StringUtils.isEmpty(wcsTask.getRoadWay())){
+            return AjaxResult.error("巷道为空");
+        }
         return verticalWarehouseAllocation(wcsTask);
     }
 
@@ -132,6 +136,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
         String area = wcsTask.getArea();
         String locationCode = null;
         String height =  wcsTask.getHeight();
+        List<String> roadWay = Arrays.asList(wcsTask.getRoadWay().split(","));
         if(height == null) {
             return AjaxResult.error("分配库位时,高度为空");
         }
@@ -197,7 +202,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService 
         }
         //1、双升位:值1   2、库位类型:值L   3、高低库位:值0   4、库区:值L   5、巷道:值null  6、仓库  7、托盘号  8、物料分区
         locationCode = locationAllocationService.allocation(allocationRule,
-             locationTypeCodeList, high, area, null, warehouseCode, containerCode, materialAreaCode);
+             locationTypeCodeList, high, area, roadWay, warehouseCode, containerCode, materialAreaCode);
         if (StringUtils.isEmpty(locationCode)) {
             return AjaxResult.error("没有库位可分配");
         }
diff --git a/src/main/java/com/huaheng/pc/config/location/mapper/LocationMapper.java b/src/main/java/com/huaheng/pc/config/location/mapper/LocationMapper.java
index c8f5dcf..d7e5539 100644
--- a/src/main/java/com/huaheng/pc/config/location/mapper/LocationMapper.java
+++ b/src/main/java/com/huaheng/pc/config/location/mapper/LocationMapper.java
@@ -31,4 +31,15 @@ public interface LocationMapper extends BaseMapper<Location> {
     int getFirstRowOfZone(@Param("warehouseCode") String warehouseCode, @Param("locationType") String locationType);
 
     int getLastRowOfZone(@Param("warehouseCode") String warehouseCode, @Param("locationType") String locationType);
+
+    //查出外侧有货,内测无货的库位
+    List<String> selectlistEnpty(@Param("roadWay")String roadWay);
+
+
+    List<Location> selectCode(@Param("roadWay")String roadWay);
+
+    Location selectModelByHg(@Param("roadWay")String roadWay, @Param("heght")String heght);
+
+    Location selectModelByOld(@Param("roadWay")String roadWay, @Param("heght")String heght,@Param("codes")List<String> codes);
+
 }
\ No newline at end of file
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 5d8a267..d067e0a 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
@@ -114,4 +114,14 @@ public interface LocationService extends IService<Location>{
     public List<Location> remoteList(String type);
 
     void upstatus(String code);
+
+    List<String> selectlistEnpty(String roadWay);
+
+    List<Location> selectCode(String roadWay);
+
+    Location getEmptyLocationOne(String roadWay,String heght,List<String> codes);
+
+    Location selectModelByHg(String roadWay, String heght);
+
+    Location selectModelByOld(String roadWay, String heght,List<String> codes);
 }
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 a572220..613a622 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
@@ -659,4 +659,37 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i
         int update = locationMapper.update(user, userUpdateWrapper);
         System.out.println(update);
     }
+
+    @Override
+    public List<String> selectlistEnpty(String roadWay) {
+        return locationMapper.selectlistEnpty(roadWay);
+    }
+
+    @Override
+    public List<Location> selectCode(String roadWay) {
+        return locationMapper.selectCode(roadWay);
+    }
+
+    @Override
+    public Location getEmptyLocationOne(String roadWay,  String heght, List<String> codes) {
+        Location location = new Location();
+        if(codes.isEmpty()){
+            location =
+                    locationService.selectModelByHg(roadWay,heght);
+        }else {
+            location =
+                    locationService.selectModelByOld(roadWay, heght,codes);
+        }
+        return location;
+    }
+
+    @Override
+    public Location selectModelByHg(String roadWay, String heght) {
+        return locationMapper.selectModelByHg(roadWay,heght);
+    }
+
+    @Override
+    public Location selectModelByOld(String roadWay, String heght, List<String> codes) {
+        return locationMapper.selectModelByOld(roadWay, heght,codes);
+    }
 }
diff --git a/src/main/resources/mybatis/config/LocationMapper.xml b/src/main/resources/mybatis/config/LocationMapper.xml
index d610495..f871684 100644
--- a/src/main/resources/mybatis/config/LocationMapper.xml
+++ b/src/main/resources/mybatis/config/LocationMapper.xml
@@ -161,5 +161,32 @@
         select max(iRow) from location where warehouseCode=#{warehouseCode} and locationType = #{locationType}
     </select>
 
+    <select id="selectlistEnpty" resultType="java.lang.String">
+        SELECT a.code from (SELECT * from location where rowFlag=1 and containerCode='' and zoneCode='L' and roadWay =#{roadWay}) a
+                               INNER JOIN (SELECT * from location where rowFlag=0 and (containerCode != '' or `status`='lock') and zoneCode='L' and roadWay =#{roadWay}) b on a.iColumn=b.iColumn and a.iLayer=b.iLayer
+    </select>
+
+
+    <select id="selectCode" resultType="com.huaheng.pc.config.location.domain.Location">
+        select l.* from location l inner join task_header t on t.status !=100 and l.roadWay=#{roadWay} and l.zoneCode='L' and l.rowFlag=1 and (t.fromLocation = l.code or t.toLocation =l.code)
+    </select>
+
+    <select id="selectModelByHg" resultType="com.huaheng.pc.config.location.domain.Location">
+        select * from location where locationType='L' and containerCode ='' and status='empty'
+        and roadWay = #{roadWay} and high=#{heght}
+        order by rowFlag desc,iColumn desc,iLayer asc limit 1
+
+    </select>
+
+
+    <select id="selectModelByOld" resultType="com.huaheng.pc.config.location.domain.Location">
+        select * from location where locationType='L' and containerCode ='' and status='empty'
+        and roadWay = #{roadWay} and high=#{heght}
+        and code not in
+        <foreach item="item" index="index" collection="codes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        order by rowFlag desc,iColumn desc,iLayer asc limit 1
+    </select>
 
 </mapper>
\ No newline at end of file