Browse Source

库位逻辑推荐优化

ChenYang 1 year ago
parent
commit
e972ab6365

+ 16 - 34
warewms-ams/src/main/java/com/ruoyi/ams/xuankuang/service/WmsDocOrderSubService.java

@@ -9,7 +9,6 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.ruoyi.ams.asn.domain.WmsDocAsnDetails;
 import com.ruoyi.ams.asn.service.IWmsDocAsnHeaderService;
 import com.ruoyi.ams.config.domain.dto.LotattDTO;
@@ -88,8 +87,6 @@ public class WmsDocOrderSubService {
     private ISysConfigService sysConfigService;
 
 
-
-
     @Transactional
     public AjaxResult initOrderDetails(@PathVariable("orderNo") String orderNo) {
 
@@ -107,13 +104,14 @@ public class WmsDocOrderSubService {
         //筛选库存 由于选矿项目出库单头只对应一个
         Boolean orderRule = getOrderRule();
         List<BaseLocationLotattDTO> filteredLocationLotattList = orderRule
-                ?   selectInventoriesByLocation(baseLocationLotattList, list.get(0)) : filterInv(baseLocationLotattList, orderNo);
+                ?  selectInventoriesByLocation(baseLocationLotattList, list.get(0)) : filterInv(baseLocationLotattList, orderNo);
         // 匹配库存(撇开先进先出)
 //        baseLocationLotattVOS = addConfirmAllocationAuto(orderNo);
 
         //重新筛选库存
 //        baseLocationLotattVOS1 = filterInv(baseLocationLotattVOS, orderNo);
 
+
         boolean con = true;
         //机械手应拆袋数
         int allocateQuantities = 0;
@@ -235,15 +233,13 @@ public class WmsDocOrderSubService {
                     .filter(item -> StringUtils.equals(NumberUtil.toStr(item.getId()), invLotLocId.getLocationId())).findFirst().orElse(null);
             if(ObjectUtil.isNull(locationInfo)) continue;
 
-            String floorAppendRowKey = locationInfo.getShiftNo() + "_" + locationInfo.getRowIndex();
-            Map<String, List<Long>> partitionRowNoListMapper = redisCache.getCacheObject(floorAppendRowKey);
-            Map<String, Object> warehouseAttrMapper = getWarehouseAttrConfig();
-            List<Integer> wayRowNoList = (List<Integer>) warehouseAttrMapper.get(Constants.WAY_ROW_NO_LIST);
-            //获取到这个库位命中的子列在两边还是中间
-            Integer firstWayNo = CollectionUtil.getFirst(wayRowNoList);
-            Integer lastWayNo = CollectionUtil.getLast(wayRowNoList);
-            String partitionRowKey = getPartitionRowKey(firstWayNo, lastWayNo, locationInfo.getRowNo());
-            List<Long> partitionLocationIdList = partitionRowNoListMapper.get(partitionRowKey);
+            Map<String, Object> subLocationIdListMapper = baseLocationInfoService.clacSubLocationIdList(locationInfo);
+            String partitionRowKey = (String) subLocationIdListMapper.get("partitionRowKey");
+            List<Long> partitionLocationIdList = (List<Long>) subLocationIdListMapper.get("partitionLocationIdList");
+            if(ObjectUtil.isNull(partitionRowKey) || CollectionUtil.isEmpty(partitionLocationIdList)){
+                log.info("partitionRowKey or partitionLocationIdList can not be found");
+                return Lists.newArrayList();
+            }
 
             int locationIndex = partitionLocationIdList.indexOf(locationInfo.getId());
             if(StringUtils.equals(partitionRowKey, Constants.FIRST)) {
@@ -314,7 +310,10 @@ public class WmsDocOrderSubService {
 
         List<Long> resultLocationIdList = checkLocationIdListOnBeside(locationId, sourceInvLotLocIdList, subList,
                 baseLocationLotattList, quantity);
-        if(CollectionUtil.isEmpty(resultLocationIdList)) return Maps.newHashMap();
+        if(CollectionUtil.isEmpty(resultLocationIdList)) {
+            return MapUtil.builder(new HashMap<String, Object>()).put("quantity", quantity)
+                    .put("baseLocationLotattList", baseLocationLotattList).map();
+        }
         BigDecimal firstRightCount = sourceInvLotLocIdList.stream()
                 .filter(item -> CollectionUtil.contains(resultLocationIdList, Long.parseLong(item.getLocationId()))
                         && ObjectUtil.isNotNull(item.getQty()))
@@ -372,14 +371,13 @@ public class WmsDocOrderSubService {
                 .filter(item -> CollectionUtil.contains(subList, Long.parseLong(item.getLocationId()))).collect(Collectors.toList());
         BigDecimal currentRowInvCount = currentRowInvList.stream().filter(item -> ObjectUtil.isNotNull(item.getQty()))
                 .map(item -> item.getQty()).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
-        List<InvLotLocId> exceptCurrentInvIdList = filterdInvLocIdList.stream()
-                .filter(item -> !StringUtils.equals(item.getLocationId(), NumberUtil.toStr(locationId))).collect(Collectors.toList());
-        BigDecimal exceptCurrentLocationInvCount = exceptCurrentInvIdList.stream().filter(item -> ObjectUtil.isNotNull(item.getQty()))
+        BigDecimal exceptCurrentLnvCount = currentRowInvList.stream()
+                .filter(item -> ObjectUtil.isNotNull(item.getQty()) && CollectionUtil.contains(filteredList, Long.parseLong(item.getLocationId())))
                 .map(item -> item.getQty()).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
         List<Long> invIdList = currentRowInvList.stream().map(item -> Long.parseLong(item.getLocationId())).collect(Collectors.toList());
 
         return CompareUtil.compare(currentRowInvCount, quantity) < 0
-                || CompareUtil.compare(exceptCurrentLocationInvCount, quantity) < 0
+                || (CompareUtil.compare(currentRowInvCount, quantity) > 0 && CompareUtil.compare(exceptCurrentLnvCount, quantity) < 0)
                 ? subList.stream().filter(item -> CollectionUtil.contains(invIdList, item)).collect(Collectors.toList())
                 : Lists.newArrayList();
     }
@@ -413,23 +411,7 @@ public class WmsDocOrderSubService {
     }
 
 
-    private String getPartitionRowKey(Integer first, Integer last, String rowIndex) {
-        if(CompareUtil.compare(Integer.parseInt(rowIndex), first) < 0) return Constants.FIRST;
-        if(CompareUtil.compare(Integer.parseInt(rowIndex), first) > 0
-                && CompareUtil.compare(Integer.parseInt(rowIndex), last) < 0) return Constants.MIDDLE;
-        if(CompareUtil.compare(Integer.parseInt(rowIndex), last) > 0) return Constants.LAST;
-        return StringUtils.EMPTY;
-    }
 
-    /**
-     * 获取库位的配置
-     * @return
-     */
-    private Map<String, Object> getWarehouseAttrConfig() {
-        String warehouseAttrInfo = sysConfigService.selectConfigByKey(SceneConstants.WAREHOUSE_ATTRIBUTE_SCENE_CONFIG);
-        Assert.isTrue(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(warehouseAttrInfo), "baseLocationInfoList is empty");
-        return JSONObject.parseObject(warehouseAttrInfo);
-    }
 
 
     /**

+ 7 - 0
warewms-base/src/main/java/com/ruoyi/base/service/IBaseLocationInfoService.java

@@ -373,4 +373,11 @@ public interface IBaseLocationInfoService {
      * @return
      */
     List<BaseLocationInfo> selectLocationInfoList(List<Long> locationIdList);
+
+    /**
+     * 计算在库位在哪一列
+     * @param locationInfo
+     * @return
+     */
+    Map<String, Object> clacSubLocationIdList(BaseLocationInfo locationInfo);
 }

+ 58 - 4
warewms-base/src/main/java/com/ruoyi/base/service/impl/BaseLocationInfoServiceImpl.java

@@ -1,6 +1,10 @@
 package com.ruoyi.base.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.comparator.CompareUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -14,14 +18,18 @@ import com.ruoyi.base.mapper.BaseLocationZoneMapper;
 import com.ruoyi.base.service.IBaseLocationInfoService;
 import com.ruoyi.base.utils.CommonUtils;
 import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.SceneConstants;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.service.ISysConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -40,6 +48,10 @@ public class BaseLocationInfoServiceImpl implements IBaseLocationInfoService {
     private BaseLocationInfoMapper baseLocationInfoMapper;
     @Autowired
     private BaseLocationZoneMapper baseLocationZoneMapper;
+    @Autowired
+    private RedisCache redisCache;
+    @Autowired
+    private ISysConfigService sysConfigService;
 
     /**
      * 入库校验同列任务任务状态和阻挡
@@ -60,10 +72,18 @@ public class BaseLocationInfoServiceImpl implements IBaseLocationInfoService {
                 //只有第一次判断同列任务占用和阻挡
                 if (i == 0 && isBlock) {
                     //同列是否有任务
-                    List<BaseLocationInfo> occupyByLocs = baseLocationInfoMapper.queryByListOccupyByLoc(location);
-                    if (occupyByLocs.size() > 0) {
-                        continue;
-                    }
+                    Map<String, Object> subLocationIdListMapper = clacSubLocationIdList(location);
+                    List<Long> partitionLocationIdList = (List<Long>) subLocationIdListMapper.get("partitionLocationIdList");
+                    List<Long> filteredList = partitionLocationIdList.stream()
+                            .filter(item -> !ObjectUtil.equal(item, location.getId())).collect(Collectors.toList());
+                    if(CollectionUtil.isEmpty(filteredList)) return location;//如果为空,同列只有一个,不会阻挡;
+
+                    List<BaseLocationInfo> locationInfoList = selectLocationInfoList(filteredList);
+                    List<BaseLocationInfo> asnTaskCheckList = locationInfoList.stream()
+                            .filter(item -> StringUtils.equals(item.getStockStatus(), Constant.STOCK_STATUS.STOCK10.getValue())).collect(Collectors.toList());
+                    if(CollectionUtil.isNotEmpty(asnTaskCheckList)) continue;// 如果不为空,证明同列有(出库或者入库)任务
+
+
                     //同列前方是否有阻挡
                     List<BaseLocationInfo> inStockByLocs = baseLocationInfoMapper.queryByListInStockByLoc(location);
                     if (inStockByLocs.size() > 0) {
@@ -562,4 +582,38 @@ public class BaseLocationInfoServiceImpl implements IBaseLocationInfoService {
         return baseLocationInfoMapper.selectList(queryWrapper);
     }
 
+    @Override
+    public Map<String, Object> clacSubLocationIdList(BaseLocationInfo locationInfo) {
+        String floorAppendRowKey = locationInfo.getShiftNo() + "_" + locationInfo.getRowIndex();
+        Map<String, List<Long>> partitionRowNoListMapper = redisCache.getCacheObject(floorAppendRowKey);
+        Map<String, Object> warehouseAttrMapper = getWarehouseAttrConfig();
+        List<Integer> wayRowNoList = (List<Integer>) warehouseAttrMapper.get(Constants.WAY_ROW_NO_LIST);
+        //获取到这个库位命中的子列在两边还是中间
+        Integer firstWayNo = CollectionUtil.getFirst(wayRowNoList);
+        Integer lastWayNo = CollectionUtil.getLast(wayRowNoList);
+        String partitionRowKey = getPartitionRowKey(firstWayNo, lastWayNo, locationInfo.getRowNo());
+        List<Long> partitionLocationIdList = partitionRowNoListMapper.get(partitionRowKey);
+        return MapUtil.builder(new HashMap<String, Object>()).put("partitionRowKey", partitionRowKey)
+                .put("partitionLocationIdList", partitionLocationIdList).map();
+    }
+
+    /**
+     * 获取库位的配置
+     * @return
+     */
+    private Map<String, Object> getWarehouseAttrConfig() {
+        String warehouseAttrInfo = sysConfigService.selectConfigByKey(SceneConstants.WAREHOUSE_ATTRIBUTE_SCENE_CONFIG);
+        Assert.isTrue(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(warehouseAttrInfo), "baseLocationInfoList is empty");
+        return JSONObject.parseObject(warehouseAttrInfo);
+    }
+
+
+    private String getPartitionRowKey(Integer first, Integer last, String rowIndex) {
+        if(CompareUtil.compare(Integer.parseInt(rowIndex), first) < 0) return Constants.FIRST;
+        if(CompareUtil.compare(Integer.parseInt(rowIndex), first) > 0
+                && CompareUtil.compare(Integer.parseInt(rowIndex), last) < 0) return Constants.MIDDLE;
+        if(CompareUtil.compare(Integer.parseInt(rowIndex), last) > 0) return Constants.LAST;
+        return StringUtils.EMPTY;
+    }
+
 }