Przeglądaj źródła

入库回库-ABC三个货架均匀任务

k 2 lat temu
rodzic
commit
b3f8db6d2d

+ 10 - 0
ruoyi-admin/src/main/java/com/ruoyi/init/StartService.java

@@ -7,6 +7,8 @@ import com.ruoyi.ams.agv.ndc.thread.AutoTaskThread;
 import com.ruoyi.ams.business.IBusinessService;
 import com.ruoyi.ams.erp.service.ISyncService;
 import com.ruoyi.ams.erp.service.impl.SyncServiceImpl;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.core.redis.RedisKey;
 import com.ruoyi.common.utils.http.HttpRequest;
 import com.ruoyi.common.utils.http.HttpUtils;
 import com.ruoyi.system.service.ISysConfigService;
@@ -28,6 +30,8 @@ public class StartService implements CommandLineRunner {
     private AciService aciService;
     @Autowired
     private ISyncService iSyncService;
+    @Autowired
+    private RedisCache redisCache;
 
 
     @Override
@@ -76,4 +80,10 @@ public class StartService implements CommandLineRunner {
         iSyncService.callBackOrder();
     }
 
+    // 清除AGV任务数量
+    public void clearAgvTaskNum(){
+        redisCache.deleteObject(RedisKey.AGV01_TASK_NUM);
+        redisCache.deleteObject(RedisKey.AGV02_TASK_NUM);
+    }
+
 }

+ 3 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisKey.java

@@ -3,4 +3,7 @@ package com.ruoyi.common.core.redis;
 public class RedisKey {
     public static final String LOCK_LIST = "lock_List_";
     public static final String LOCK_LOCATION = "lock_location_";
+
+    public static final String AGV01_TASK_NUM = "AGV01_TASK_NUM";
+    public static final String AGV02_TASK_NUM = "AGV02_TASK_NUM";
 }

+ 93 - 1
warewms-ams/src/main/java/com/ruoyi/ams/business/BusinessServiceImpl.java

@@ -330,11 +330,39 @@ public class BusinessServiceImpl implements IBusinessService {
                     if (!canPut) {
                         continue;
                     }
+                    // AGV均匀任务
+                    int agvNo;
+                    // 推荐几号车做
+                    agvNo = recommendedWarehousingCarNumber();
+                    // 校验当前库位绑定的车号
+                    boolean iscan = checkCurrentLocationCarNumber(agvNo, b);
+                    if (!iscan) {
+                        continue;
+                    }
+
                     locationInfo = b;
                     break;
                 }
                 if (locationInfo == null) {
-                    throw new ServiceException("入库目标点没有可以分配的库位", token);
+                    // 如果没有可用库位,去掉AGV均匀任务判断
+                    for (BaseLocationInfo b : locationInfoList) {
+                        if (!b.getStockStatus().equals("00") || !b.getIsEmpty().equals("Y") || redisCache.checkIsLock(RedisKey.LOCK_LOCATION + b.getId())) {
+                            continue;
+                        }
+                        if (!redisCache.lockCacheObject(RedisKey.LOCK_LOCATION + b.getId(), b.getId().toString(), token)) {
+                            continue;
+                        }
+                        // 根据起始库位判断目标是否可放
+                        Boolean canPut = checkLocCanPut(locationFrom, b);
+                        if (!canPut) {
+                            continue;
+                        }
+                        locationInfo = b;
+                        break;
+                    }
+                    if(locationInfo == null) {
+                        throw new ServiceException("入库目标点没有可以分配的库位", token);
+                    }
                 }
             }
         } else if (type.equals("SO")) {
@@ -419,6 +447,52 @@ public class BusinessServiceImpl implements IBusinessService {
         return locationInfo;
     }
 
+    /**
+     * 校验当前库位车号
+     *
+     * @param agvNo
+     * @param b
+     * @return
+     */
+    private boolean checkCurrentLocationCarNumber(int agvNo,BaseLocationInfo b) {
+        if (agvNo == 1) {
+            if (!b.getFoldedTag().equals("1")) {
+                return false;
+            }
+        } else if (agvNo == 2) {
+            if (!b.getFoldedTag().equals("2")) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 推荐入库车号
+     *
+     * @return
+     */
+    private int recommendedWarehousingCarNumber() {
+        if (redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) == null
+                && redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) == null) {
+            return  0;
+        } else if (redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) == null
+                && redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) != null
+                && (int) redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) != 0) {
+            return  1;
+        } else if (redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) == null
+                && redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) != null
+                && (int) redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) != 0) {
+            return  2;
+        } else if (redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) != null
+                && redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) != null) {
+            int agv01 = redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM);
+            int agv02 = redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM);
+            return agv01 > agv02 ? 2 : 1;
+        }
+        return 0;
+    }
+
     public Boolean checkLocCanPut(BaseLocationInfo locationFrom, BaseLocationInfo locationTo) {
         boolean con = false;
         // 永湖仓储区一层高度为1600,其他为2300
@@ -499,6 +573,24 @@ public class BusinessServiceImpl implements IBusinessService {
             wcsTask.setExtParam(agvCallDTO.getExtParam());
             wcsTaskList.add(wcsTask);
             businessService.addTask(wcsTask);
+            // 入库任务,统计两辆车分别发了多少任务
+            if (locationTo.getZoneId().equals(Constant.ZONE_TYPE.ZONE_INV.getValue())) {
+                if (locationTo.getFoldedTag().equals("1")) {
+                    if (redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) == null) {
+                        redisCache.setCacheObject(RedisKey.AGV01_TASK_NUM, 1);
+                    } else {
+                        int num = redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM);
+                        redisCache.setCacheObject(RedisKey.AGV01_TASK_NUM, 1 + num);
+                    }
+                } else if (locationTo.getFoldedTag().equals("2")) {
+                    if (redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) == null) {
+                        redisCache.setCacheObject(RedisKey.AGV02_TASK_NUM, 1);
+                    } else {
+                        int num = redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM);
+                        redisCache.setCacheObject(RedisKey.AGV02_TASK_NUM, 1 + num);
+                    }
+                }
+            }
         } else {
             /*//获取对应的流程
             List<FlowConfigHeader> headerVOList = flowConfigHeaderService.sortFlowConfigHeader(Long.parseLong(flowConfigHeaderVO.getRootFlow()));

+ 35 - 0
warewms-ams/src/main/java/com/ruoyi/ams/task/service/impl/WcsTaskServiceImpl.java

@@ -25,6 +25,7 @@ import com.ruoyi.base.domain.BaseLocationInfo;
 import com.ruoyi.base.service.IBaseLocationInfoService;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.core.redis.RedisKey;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
@@ -371,6 +372,8 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
                             if (!StringUtils.isEmpty(wcsTask.getExt8())) {
                                 redisCache.unlockCacheObject(Long.parseLong(wcsTask.getExt8()));
                             }
+                            // 如果是入库任务,任务结束,减去当前AGV任务数量
+                            subtractTheNumberOfTasks(wcsTask.getLocationTo());
                             // 任务完成回调
                             callBackTaskComplete(wcsTask);
                         }
@@ -413,6 +416,8 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
                             if (!StringUtils.isEmpty(wcsTask.getExt8())) {
                                 redisCache.unlockCacheObject(Long.parseLong(wcsTask.getExt8()));
                             }
+                            // 如果是入库任务,任务结束,减去当前AGV任务数量
+                            subtractTheNumberOfTasks(wcsTask.getLocationTo());
                             // 任务完成回调
                             callBackTaskComplete(wcsTask);
                         }
@@ -433,6 +438,8 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
                         if (!StringUtils.isEmpty(wcsTask.getExt8())) {
                             redisCache.unlockCacheObject(Long.parseLong(wcsTask.getExt8()));
                         }
+                        // 如果是入库任务,任务结束,减去当前AGV任务数量
+                        subtractTheNumberOfTasks(wcsTask.getLocationTo());
                         // 取消任务删除中间缓存库存
 //                        cancelTaskDelMiddleCache(wcsTask);
                         break;
@@ -459,6 +466,34 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
         wcsTaskService.updateWcsTask(wcsTask);
     }
 
+    /**
+     * 如果是入库任务,任务结束,减去当前AGV任务数量
+     *
+     * @param locationTo
+     */
+    private void subtractTheNumberOfTasks(String locationTo) {
+        BaseLocationInfo baseLocationInfo = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(locationTo, Constant.WAREHOUSE_ID);
+        if (!baseLocationInfo.getZoneId().equals(Constant.ZONE_TYPE.ZONE_INV.getValue())) {
+            return;
+        }
+        if (baseLocationInfo.getFoldedTag().equals("1")) {
+            if (redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM) == null) {
+
+            } else {
+                int num = redisCache.getCacheObject(RedisKey.AGV01_TASK_NUM);
+                redisCache.setCacheObject(RedisKey.AGV01_TASK_NUM, num - 1);
+            }
+        } else if (baseLocationInfo.getFoldedTag().equals("2")) {
+            if (redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM) == null) {
+
+            } else {
+                int num = redisCache.getCacheObject(RedisKey.AGV02_TASK_NUM);
+                redisCache.setCacheObject(RedisKey.AGV02_TASK_NUM, num -1);
+            }
+        }
+
+    }
+
     /**
      * 将起点库存放到中间缓存位置
      *