Commit d95b2d9e5751d7a96902ac42150ecea3f2d102db

Authored by 肖超群
1 parent 5ba8a834

分配巷道 优先分配到物料少的巷道

huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationService.java
... ... @@ -8,18 +8,20 @@ public interface LocationAllocationService {
8 8 * 获得库位分配的库位
9 9 */
10 10 String allocation(int locationRule, List<String> locationTypeCodeList, int high, String zoneCode, List<Integer> raodWays, String warehouseCode,
11   - String containerCode, String materialAreaCode);
  11 + String containerCode, String materialAreaCode, String materialCode);
12 12  
13   - String doubleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode);
  13 + String doubleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode,
  14 + String materialCode);
14 15  
15   - String singleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode);
  16 + String singleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode,
  17 + String materialCode);
16 18  
17 19 /**
18 20 * 获取可用巷道
19 21 * @param roadWays
20 22 * @return
21 23 */
22   - Integer getRoadWay(List<Integer> roadWays, String warehouseCode);
  24 + Integer getRoadWay(List<Integer> roadWays, String materialCode, String zoneCode, String warehouseCode);
23 25  
24 26 /**
25 27 * 获取巷道,选取空闲库位最多作为巷道
... ... @@ -36,11 +38,11 @@ public interface LocationAllocationService {
36 38 */
37 39 List<Integer> removeRoadWaysByPreLocations(List<Integer> roadWays, String warehouseCode);
38 40  
39   -// /**
40   -// * 获取巷道,根据入库物料均分原则,选取物料最少的巷道
41   -// * @param roadWays
42   -// * @return
43   -// */
44   -// Integer getRoadWayByMinMaterial(List<Integer> roadWays, String warehouseCode);
  41 + /**
  42 + * 获取巷道,根据入库物料均分原则,选取物料最少的巷道
  43 + * @param roadWays
  44 + * @return
  45 + */
  46 + Integer getRoadWayByMinMaterial(List<Integer> roadWays, String materialCode, String zoneCode, String warehouseCode);
45 47  
46 48 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationServiceImpl.java
... ... @@ -20,6 +20,8 @@ import org.jeecg.modules.wms.config.locationType.entity.LocationType;
20 20 import org.jeecg.modules.wms.config.locationType.service.ILocationTypeService;
21 21 import org.jeecg.modules.wms.config.parameterConfiguration.service.IParameterConfigurationService;
22 22 import org.jeecg.modules.wms.config.zone.service.IZoneService;
  23 +import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryDetail;
  24 +import org.jeecg.modules.wms.inventory.inventoryHeader.service.IInventoryDetailService;
23 25 import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader;
24 26 import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService;
25 27 import org.jeecg.utils.StringUtils;
... ... @@ -56,11 +58,13 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
56 58 private IParameterConfigurationService parameterConfigurationService;
57 59 @Resource
58 60 private LocationAllocationService locationAllocationService;
  61 + @Resource
  62 + private IInventoryDetailService inventoryDetailService;
59 63  
60 64 @Override
61 65 @Transactional(rollbackFor = Exception.class)
62 66 public String allocation(int locationRule, List<String> locationTypeCodeList, int high, String zoneCode, List<Integer> raodWays, String warehouseCode,
63   - String containerCode, String materialAreaCode) {
  67 + String containerCode, String materialAreaCode, String materialCode) {
64 68 Container container = containerService.getContainerByCode(containerCode, warehouseCode);
65 69 if (container == null) {
66 70 throw new JeecgBootException("分配库位时,容器为空");
... ... @@ -83,9 +87,9 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
83 87 List<String> mergelocationTypeCodeList = locationTypeCodeList.stream().filter(item -> locationTypeCodes.contains(item)).collect(toList());
84 88 switch (locationRule) {
85 89 case QuantityConstant.DOUBLE_FORK:
86   - return locationAllocationService.doubleRk(zoneCode, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
  90 + return locationAllocationService.doubleRk(zoneCode, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode, materialCode);
87 91 case QuantityConstant.SINGLE_FORK:
88   - return locationAllocationService.singleRk(zoneCode, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
  92 + return locationAllocationService.singleRk(zoneCode, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode, materialCode);
89 93 }
90 94 return null;
91 95 }
... ... @@ -95,7 +99,8 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
95 99 */
96 100 @Override
97 101 @Transactional(rollbackFor = Exception.class)
98   - public String doubleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode) {
  102 + public String doubleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode,
  103 + String materialCode) {
99 104 if (roadWays == null || roadWays.size() < 1) {
100 105 List<Location> locationList = locationService.getLocationListByZoneCode(zoneCode, warehouseCode);
101 106 roadWays = locationList.stream().map(Location::getRoadWay).distinct().collect(toList());
... ... @@ -131,7 +136,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
131 136 throw new JeecgBootException("分配库位时, 可用巷道为空");
132 137 }
133 138 Collections.shuffle(roadWays);
134   - Integer roadWay = locationAllocationService.getRoadWay(roadWays, warehouseCode);
  139 + Integer roadWay = locationAllocationService.getRoadWay(roadWays, materialCode, zoneCode, warehouseCode);
135 140 // 优先找外侧库位
136 141 LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
137 142 locationLambda.eq(Location::getZoneCode, zoneCode).eq(Location::getWarehouseCode, warehouseCode).eq(Location::getRoadWay, roadWay)
... ... @@ -184,7 +189,8 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
184 189 */
185 190 @Override
186 191 @Transactional(rollbackFor = Exception.class)
187   - public String singleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode) {
  192 + public String singleRk(String zoneCode, List<Integer> roadWays, int high, String warehouseCode, List<String> locationTypeCodeList, String materialAreaCode,
  193 + String materialCode) {
188 194 if (roadWays == null || roadWays.size() < 1) {
189 195 List<Location> locationList = locationService.getLocationListByZoneCode(zoneCode, warehouseCode);
190 196 roadWays = locationList.stream().map(Location::getRoadWay).distinct().collect(toList());
... ... @@ -210,7 +216,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
210 216 throw new JeecgBootException("分配库位时, 可用巷道为空");
211 217 }
212 218 Collections.shuffle(roadWays);
213   - Integer roadWay = locationAllocationService.getRoadWay(roadWays, warehouseCode);
  219 + Integer roadWay = locationAllocationService.getRoadWay(roadWays, materialCode, zoneCode, warehouseCode);
214 220 LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
215 221 locationLambdaQueryWrapper.eq(Location::getZoneCode, zoneCode).eq(Location::getWarehouseCode, warehouseCode).eq(Location::getRoadWay, roadWay)
216 222 .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY).ge(Location::getHigh, high)
... ... @@ -229,7 +235,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
229 235  
230 236 @Override
231 237 @Transactional(rollbackFor = Exception.class)
232   - public Integer getRoadWay(List<Integer> roadWays, String warehouseCode) {
  238 + public Integer getRoadWay(List<Integer> roadWays, String materialCode, String zoneCode, String warehouseCode) {
233 239 if (StringUtils.isEmpty(roadWays)) {
234 240 throw new JeecgBootException("分配库位错误,没有巷道");
235 241 }
... ... @@ -237,11 +243,15 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
237 243 if (roadWays.size() == 1) {
238 244 return roadWay;
239 245 }
  246 +
240 247 roadWays = locationAllocationService.removeRoadWaysByPreLocations(roadWays, warehouseCode);
241 248 if (StringUtils.isEmpty(roadWays)) {
242 249 return roadWay;
243 250 }
244   - roadWay = locationAllocationService.getRoadWayByMaxFreeLocation(roadWays, warehouseCode);
  251 + // 获取巷道,选取空闲库位最多作为巷道
  252 +// roadWay = locationAllocationService.getRoadWayByMaxFreeLocation(roadWays, warehouseCode);
  253 + // 获取巷道,根据入库物料均分原则,选取物料最少的巷道
  254 + roadWay = locationAllocationService.getRoadWayByMinMaterial(roadWays, materialCode, zoneCode, warehouseCode);
245 255 return roadWay;
246 256 }
247 257  
... ... @@ -303,4 +313,35 @@ public class LocationAllocationServiceImpl implements LocationAllocationService
303 313 return roadWays;
304 314 }
305 315  
  316 + @Override
  317 + public Integer getRoadWayByMinMaterial(List<Integer> roadWays, String materialCode, String zoneCode, String warehouseCode) {
  318 + if (roadWays == null || roadWays.size() == 0) {
  319 + throw new JeecgBootException("分配库位时, 巷道为空");
  320 + }
  321 + Collections.shuffle(roadWays);
  322 + int roadWay = roadWays.get(0);
  323 + if (roadWays.size() == 1) {
  324 + return roadWay;
  325 + }
  326 + int min = Integer.MAX_VALUE;
  327 + roadWays = locationAllocationService.removeRoadWaysByPreLocations(roadWays, warehouseCode);
  328 + if (roadWays.size() == 0) {
  329 + return roadWay;
  330 + }
  331 + List<InventoryDetail> inventoryDetailList = inventoryDetailService.getInventoryDetailListByMaterialCodeAndZoneCode(materialCode, zoneCode, warehouseCode);
  332 + if (inventoryDetailList.size() != 0) {
  333 + List<Integer> roadWayList = inventoryDetailList.stream().map(InventoryDetail::getRoadWay).collect(toList());
  334 + roadWayList.removeAll(Collections.singleton(null));
  335 + for (Integer road : roadWays) {
  336 + // i是查出现次数 这里速度很快返回次数
  337 + int i = Collections.frequency(roadWayList, road);
  338 + if (min > i) {
  339 + min = i;
  340 + roadWay = road;
  341 + }
  342 + }
  343 + }
  344 + return roadWay;
  345 + }
  346 +
306 347 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java
1 1 package org.jeecg.modules.wms.api.wcs.service;
2 2  
3   -import java.net.SocketException;
4   -
5 3 import org.jeecg.common.api.vo.Result;
6 4 import org.jeecg.modules.wms.api.wcs.entity.MaterialInfoEntity;
7 5 import org.jeecg.modules.wms.api.wcs.entity.WarecellDomain;
... ... @@ -13,8 +11,9 @@ import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader;
13 11 */
14 12 public interface WcsService {
15 13  
16   - /** 仓位分配
17   - * @throws SocketException */
  14 + /**
  15 + * 仓位分配
  16 + */
18 17 Result warecellAllocation(WarecellDomain warecellDomain);
19 18  
20 19 /**
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java
... ... @@ -184,8 +184,9 @@ public class WcsServiceImpl implements WcsService {
184 184 String materialAreaCode = null;
185 185 // 查询任务明细
186 186 List<TaskDetail> taskDetailList = taskDetailService.getTaskDetailListByTaskId(Integer.parseInt(taskNo));
  187 + String materialCode = null;
187 188 if (taskDetailList.size() > 0) {
188   - String materialCode = taskDetailList.get(0).getMaterialCode();
  189 + materialCode = taskDetailList.get(0).getMaterialCode();
189 190 if (StringUtils.isNotEmpty(materialCode)) {
190 191 Material material = materialService.getMaterialByCode(materialCode);
191 192 if (material != null) {
... ... @@ -194,8 +195,8 @@ public class WcsServiceImpl implements WcsService {
194 195 }
195 196 }
196 197  
197   - locationCode =
198   - locationAllocationService.allocation(allocationRule, locationTypeCodeList, high, zoneCode, roadWays, warehouseCode, containerCode, materialAreaCode);
  198 + locationCode = locationAllocationService.allocation(allocationRule, locationTypeCodeList, high, zoneCode, roadWays, warehouseCode, containerCode,
  199 + materialAreaCode, materialCode);
199 200 if (StringUtils.isEmpty(locationCode)) {
200 201 return Result.error("分配库位时,没有库位可分配");
201 202 }
... ... @@ -614,8 +615,8 @@ public class WcsServiceImpl implements WcsService {
614 615 materialAreaCode = material.getMaterialareaCode();
615 616 }
616 617 // 4. WMS重新分配库位编码
617   - String locationCode =
618   - locationAllocationService.allocation(allocationRule, locationTypeCodeList, high, zoneCode, roadWays, warehouseCode, containerCode, materialAreaCode);
  618 + String locationCode = locationAllocationService.allocation(allocationRule, locationTypeCodeList, high, zoneCode, roadWays, warehouseCode, containerCode,
  619 + materialAreaCode, null);
619 620 if (StringUtils.isEmpty(locationCode)) {
620 621 return Result.error("重入处理失败, 没有库位可分配");
621 622 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/inventory/inventoryHeader/service/IInventoryDetailService.java
... ... @@ -29,6 +29,8 @@ public interface IInventoryDetailService extends IService&lt;InventoryDetail&gt; {
29 29  
30 30 List<InventoryDetail> getInventoryDetailListByMaterialCode(String materialCode, String warehouseCode);
31 31  
  32 + List<InventoryDetail> getInventoryDetailListByMaterialCodeAndZoneCode(String materialCode, String zoneCode, String warehouseCode);
  33 +
32 34 List<InventoryDetail> getInventoryDetailListByMaterialCodeToShipment(String materialCode, BigDecimal qty, String warehouseCode);
33 35  
34 36 InventoryDetail getInventoryDetailByMaterialCodeToShipment(String containerCode, String materialCode, BigDecimal qty, String warehouseCode);
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/inventory/inventoryHeader/service/impl/InventoryDetailServiceImpl.java
... ... @@ -98,6 +98,15 @@ public class InventoryDetailServiceImpl extends ServiceImpl&lt;InventoryDetailMappe
98 98 }
99 99  
100 100 @Override
  101 + public List<InventoryDetail> getInventoryDetailListByMaterialCodeAndZoneCode(String materialCode, String zoneCode, String warehouseCode) {
  102 + LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
  103 + inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode).eq(InventoryDetail::getZoneCode, zoneCode)
  104 + .eq(InventoryDetail::getWarehouseCode, warehouseCode);
  105 + List<InventoryDetail> inventoryDetailList = list(inventoryDetailLambdaQueryWrapper);
  106 + return inventoryDetailList;
  107 + }
  108 +
  109 + @Override
101 110 public List<InventoryDetail> getInventoryDetailListByMaterialCodeToShipment(String materialCode, BigDecimal qty, String warehouseCode) {
102 111 LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
103 112 inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode).ge(InventoryDetail::getQty, qty)
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java
... ... @@ -452,7 +452,7 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
452 452 return Result.error("创建空托盘组入库任务时,没有找到容器");
453 453 }
454 454 if (StringUtils.isNotEmpty(container.getLocationCode())) {
455   - return Result.error("容器已在库位" + container.getLocationCode() + "上");
  455 + return Result.error("创建空托盘组入库任务时, 容器已在库位" + container.getLocationCode() + "上");
456 456 }
457 457 List<Integer> roadWays = new ArrayList<>();
458 458 String[] strList = roadWay.split(",");
... ... @@ -461,7 +461,7 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
461 461 }
462 462 String value = parameterConfigurationService.getValueByCode(QuantityConstant.RULE_ALLOCATION);
463 463 if (StringUtils.isEmpty(value)) {
464   - return Result.error("未绑定定位规则");
  464 + return Result.error("创建空托盘组入库任务时, 未绑定定位规则");
465 465 }
466 466 int allocationRule = Integer.parseInt(value);
467 467 Zone zone = zoneService.getZoneByCode(zoneCode, warehouseCode);
... ... @@ -483,7 +483,8 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
483 483 return Result.error("创建空托盘组入库任务时,没有获取到库位高度");
484 484 }
485 485 int high = locationHigh.getHigh();
486   - String toLocationCode = allocationService.allocation(allocationRule, locationTypeCodeList, high, zoneCode, roadWays, warehouseCode, containerCode, null);
  486 + String toLocationCode =
  487 + allocationService.allocation(allocationRule, locationTypeCodeList, high, zoneCode, roadWays, warehouseCode, containerCode, null, null);
487 488 if (StringUtils.isEmpty(toLocationCode)) {
488 489 throw new JeecgBootException("创建空托盘组入库任务时,目标库位为空");
489 490 }
... ... @@ -1962,11 +1963,15 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
1962 1963 }
1963 1964 String warehouseCode = taskHeader.getWarehouseCode();
1964 1965 String fromLocationCode = taskHeader.getFromLocationCode();
  1966 + String toLocationCode = taskHeader.getToLocationCode();
1965 1967 String toPortCode = taskHeader.getToPortCode();
1966 1968 Location fromLocation = locationService.getLocationByCode(fromLocationCode, warehouseCode);
1967 1969 if (fromLocation == null) {
1968 1970 return Result.error("切换任务失败, 没有找到起始库位:" + fromLocationCode);
1969 1971 }
  1972 + if (StringUtils.isNotEmpty(toLocationCode)) {
  1973 + return Result.error("切换任务失败, 目标库位不为空");
  1974 + }
1970 1975 Integer roadWay = fromLocation.getRoadWay();
1971 1976 List<String> allContainerCodeList = new ArrayList<>();
1972 1977 List<ShipmentDetail> shipmentDetailList = new ArrayList<>();
... ...