Forráskód Böngészése

出库逻辑优化

dfsfs 1 éve
szülő
commit
194057e917

+ 1 - 0
ruoyi-admin/src/main/java/com/ruoyi/nieyan/controller/pda/PdaAgvCallController.java

@@ -290,6 +290,7 @@ public class PdaAgvCallController {
     @ApiOperation("成品出库(硫酸镍)")
     @PostMapping("productsOutboundLSN")
     public AjaxResult productsOutboundLSN(@RequestBody AgvCallForm agvCallForm) {
+        log.info("productsOutboundLSN成品出库(硫酸镍)--请求参数--{}",agvCallForm);
         if (StringUtils.isEmpty(agvCallForm.getLocationFrom())) {
             return AjaxResult.error("起始库位为空!");
         }

+ 104 - 3
warewms-ams/src/main/java/com/ruoyi/ams/business/BusinessServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.ams.business;
 
+import cn.hutool.core.lang.Assert;
 import com.alibaba.fastjson.JSON;
 import com.ruoyi.ams.agv.ndc.common.ByteUtil;
 import com.ruoyi.ams.agv.ndc.common.CRC16Util;
@@ -147,7 +148,15 @@ public class BusinessServiceImpl implements IBusinessService {
                 }
 
                 if (flowConfigHeaderVO.getFlowType().equals("ASN")) {
+                    // 判断队列中是否有未完成的出库任务
+                    BaseLocationInfo baseLocInfo = baseLocationInfoMapper.selectBaseLocationInfoById(Long.parseLong(paramLocationFrom));
+                    boolean isFinish = checkWcsSameColumnNotFinish(baseLocInfo.getColNo(), baseLocInfo.getColIndex(), baseLocInfo.getZoneId(),"ASN");
+                    if (!isFinish){
+                        throw new ServiceException("当前列有未完成的出库任务");
+                    }
+
                     List<BaseLocationInfo> locationFromList = this.convertLocation(paramLocationFrom, agvCallDTO.getWarehouseId(), null);
+                    //
                     List<BaseLocationInfo> locationToList = this.convertLocation(paramLocationTo, agvCallDTO.getWarehouseId(), null);
                     locationFrom = this.zoneLocationAllocation(locationFromList, "locationFrom", "ASN", asnSoStrategy, token);
                     locationTo = this.zoneLocationAllocation(locationToList, "locationTo", "ASN", asnSoStrategy, token);
@@ -160,6 +169,14 @@ public class BusinessServiceImpl implements IBusinessService {
                     wcsTaskList.addAll(this.genTask(locationFrom, locationTo, flowConfigHeaderVO, agvCallDTO, token));
 
                 } else if (flowConfigHeaderVO.getFlowType().equals("SO")) {
+
+                    // 判断同列中是否有未完成的入库任务
+                    BaseLocationInfo baseLocInfo = baseLocationInfoMapper.selectBaseLocationInfoById(Long.parseLong(paramLocationFrom));
+                    boolean isFinish = checkWcsSameColumnNotFinish(baseLocInfo.getColNo(), baseLocInfo.getColIndex(), baseLocInfo.getZoneId(),"SO");
+                    if (!isFinish){
+                        throw new ServiceException("当前列有未完成的入库任务");
+                    }
+
                     List<BaseLocationInfo> locationFromListEnd = new ArrayList<>();
                     boolean isLocation = baseLocationInfoService.checkIsLocation(paramLocationFrom, Constant.WAREHOUSE_ID);
                     if (isLocation) {
@@ -201,6 +218,30 @@ public class BusinessServiceImpl implements IBusinessService {
         }
     }
 
+    /**
+     * 检查同列的未完成任务类型是否与当前任务类型一致
+     * @param colNo
+     * @param colIndex
+     * @param zoneId
+     * @param type 任务类型
+     * @return
+     */
+    public boolean checkWcsSameColumnNotFinish(String colNo, Long colIndex, Long zoneId,String type){
+        log.info("检查同列的未完成任务类型是否与当前任务类型一致============");
+        // 查询任务状态不为2(完成),6(卸货完成),7(取消)的同列任务
+        List<WcsTask> wcsTaskList = wcsTaskService.selectWcsSameColumnNotFinish(colNo, colIndex, zoneId,Constant.WAREHOUSE_ID);
+        if (wcsTaskList != null && wcsTaskList.size()>0){
+            for(WcsTask wcsTask : wcsTaskList){
+                FlowConfigHeaderVO flowConfigHeaderVO = flowConfigHeaderService.selectFlowConfigHeaderById(Long.valueOf(wcsTask.getExt7()));
+                if (Objects.nonNull(flowConfigHeaderVO) && !flowConfigHeaderVO.getFlowType().equals(type)){
+                    log.info("同列的未完成任务类型与当前任务类型不同{}====",wcsTask);
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
     @Transactional
     @Override
     public BaseLocationInfo inLocationAllocation(InWarehouseDTO inWarehouseDTO, Long token) {
@@ -313,7 +354,13 @@ public class BusinessServiceImpl implements IBusinessService {
         }
         if (locationType.equals("locationFrom")) {
 
-            locationInfo = checkTheSameColumnLocation(locationInfoList, token, false);
+            // 如果是出库 调用无需判断阻挡的方法
+            if (type.equals("SO")){
+                locationInfo = checkTheSameColumnLocationSO(locationInfoList, token);
+            }else {
+                locationInfo = checkTheSameColumnLocation(locationInfoList, token, false);
+            }
+
             if (locationInfo == null) {
                 if (type.equals("ASN")) { // 入库
                     fromMsg = "起始点没有可以分配的库存!";
@@ -365,21 +412,23 @@ public class BusinessServiceImpl implements IBusinessService {
                     //同列是否有任务
                     List<BaseLocationInfo> occupyByLocs = baseLocationInfoMapper.queryByListOccupyByLoc(location);
                     if (occupyByLocs.size() > 0) {
+                        log.info("同列有任务=========={}",occupyByLocs);
                         continue;
                     }
                     //同列前方是否有阻挡
                     List<BaseLocationInfo> inStockByLocs = baseLocationInfoMapper.queryByListInStockByLoc(location);
                     if (inStockByLocs.size() > 0) {
+                        log.info("同列有阻挡=========={}",inStockByLocs);
                         continue;
                     }
                 }
                 // 是否目标点
-                if (!isReleaseGoods) {
+                if (!isReleaseGoods) {  // 起始点位状态必须空闲且没有被锁住
                     if (!location.getStockStatus().equals(Constant.STOCK_STATUS.STOCK00.getValue())
                             || redisCache.checkIsLock(RedisKey.LOCK_LOCATION + location.getId())) {
                         continue;
                     }
-                } else {
+                } else { // 目标点状态为空闲、空、且没有被锁住
                     if (!location.getStockStatus().equals(Constant.STOCK_STATUS.STOCK00.getValue())
                             || !location.getIsEmpty().equals(Constant.IS_YES.Y.name())
                             || redisCache.checkIsLock(RedisKey.LOCK_LOCATION + location.getId())) {
@@ -398,6 +447,35 @@ public class BusinessServiceImpl implements IBusinessService {
         return basLocation;
     }
 
+    /**
+     * AGV出库任务生成时的起始位置不判断是否阻挡
+     * @param basLocationList
+     * @param token
+     * @return
+     */
+    public BaseLocationInfo checkTheSameColumnLocationSO(List<BaseLocationInfo> basLocationList, Long token) {
+        BaseLocationInfo basLocation = null;
+        //筛选2次 第2次去除同列占用和阻挡条件 todo 先筛选一次吧
+        for (int i = 0; i < 1 && basLocation == null; i++) {
+            for (BaseLocationInfo location : basLocationList) {
+
+                // 起始点位状态必须空闲且没有被锁住
+                if (!location.getStockStatus().equals(Constant.STOCK_STATUS.STOCK00.getValue())
+                        || redisCache.checkIsLock(RedisKey.LOCK_LOCATION + location.getId())) {
+                    continue;
+                }
+                if (!redisCache.lockCacheObject(RedisKey.LOCK_LOCATION + location.getId()
+                        , location.getId().toString()
+                        , token)) {
+                    continue;
+                }
+                basLocation = location;
+                break;
+            }
+        }
+        return basLocation;
+    }
+
 
     @Override
     public List<BaseLocationInfo> convertLocation(String locationNoOrZoneId, Long warehouseId, String orderBy) {
@@ -578,6 +656,7 @@ public class BusinessServiceImpl implements IBusinessService {
     public AjaxResult sendTask(WcsTask wcsTask) {
         BaseLocationInfo locFrom = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(wcsTask.getLocationFrom(), Constant.WAREHOUSE_ID);
         BaseLocationInfo locTo = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(wcsTask.getLocationTo(), Constant.WAREHOUSE_ID);
+        log.info("进入AMS任务下发=========={}",wcsTask);
         AmsTask amsTask = new AmsTask();
         amsTask.setTaskNo(wcsTask.getTaskNo());
         if (wcsTask.getBusinessType() == null || wcsTask.getBusinessType().equals("")) {
@@ -646,6 +725,28 @@ public class BusinessServiceImpl implements IBusinessService {
                 //转发任务
                 if (StringUtils.isNotEmpty(wcsTask.getTaskType())
                         && wcsTask.getTaskType().equals(Constant.TASK_TYPE.FORWARD.getValue())) {
+                    log.info("进入转发任务{}=={}========", wcsTask.getTaskType(),wcsTask.getExt7());
+                    // 判断如果是出库任务
+                    if (StringUtils.isNotEmpty(wcsTask.getExt7())
+                            && (wcsTask.getExt7().equals(String.valueOf(Constant.FLOW_CONFIG_ID.FOURTEEN.getValue()))
+                            || wcsTask.getExt7().equals(String.valueOf(Constant.FLOW_CONFIG_ID.FIFTEEN.getValue())))){
+                        log.info("出库任务下发AMS调用AGV{}", JSON.toJSONString(wcsTask));
+                        // 根据起始地查询库位信息
+                        BaseLocationInfo baseLocationInfo = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(wcsTask.getLocationFrom(), Constant.WAREHOUSE_ID);
+                        //同列是否有任务
+                        List<BaseLocationInfo> occupyByLocs = baseLocationInfoMapper.queryByListOccupyByLoc(baseLocationInfo);
+                        if (occupyByLocs.size() > 0) {
+                            log.info("同列有任务=========={}",occupyByLocs);
+                            continue;
+                        }
+                        //同列前方是否有阻挡
+                        List<BaseLocationInfo> inStockByLocs = baseLocationInfoMapper.queryByListInStockByLoc(baseLocationInfo);
+                        if (inStockByLocs.size() > 0) {
+                            log.info("同列有阻挡=========={}",inStockByLocs);
+                            continue;
+                        }
+                    }
+
                     sendTask(wcsTask);
                     wcsTask.setState(10L);
                     wcsTaskService.updateWcsTask(wcsTask);

+ 17 - 7
warewms-ams/src/main/java/com/ruoyi/ams/task/mapper/WcsTaskMapper.java

@@ -9,7 +9,7 @@ import java.util.List;
 
 /**
  * AGV任务Mapper接口
- * 
+ *
  * @author andy
  * @date 2022-03-10
  */
@@ -17,7 +17,7 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
 {
     /**
      * 查询AGV任务
-     * 
+     *
      * @param taskNo AGV任务主键
      * @return AGV任务
      */
@@ -25,7 +25,7 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
 
     /**
      * 查询AGV任务列表
-     * 
+     *
      * @param wcsTask AGV任务
      * @return AGV任务集合
      */
@@ -40,7 +40,7 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
 
     /**
      * 新增AGV任务
-     * 
+     *
      * @param wcsTask AGV任务
      * @return 结果
      */
@@ -48,7 +48,7 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
 
     /**
      * 修改AGV任务
-     * 
+     *
      * @param wcsTask AGV任务
      * @return 结果
      */
@@ -56,7 +56,7 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
 
     /**
      * 删除AGV任务
-     * 
+     *
      * @param taskNo AGV任务主键
      * @return 结果
      */
@@ -64,7 +64,7 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
 
     /**
      * 批量删除AGV任务
-     * 
+     *
      * @param taskNos 需要删除的数据主键集合
      * @return 结果
      */
@@ -109,4 +109,14 @@ public interface WcsTaskMapper extends BaseMapper<WcsTask>
      * @return
      */
      List<WcsTask> selectBeforeTask(@Param("taskNo") String taskNo);
+
+    /**
+     * 查询任务状态不为2(完成),6(卸货完成),7(取消)的同列任务
+     * @param colNo
+     * @param colIndex
+     * @param zoneId
+     * @param warehouseId
+     * @return
+     */
+     List<WcsTask> selectWcsSameColumnNotFinish(@Param("colNo") String colNo,@Param("colIndex") Long colIndex,@Param("zoneId") Long zoneId,@Param("warehouseId") Long warehouseId);
 }

+ 3 - 0
warewms-ams/src/main/java/com/ruoyi/ams/task/service/IWcsTaskService.java

@@ -183,4 +183,7 @@ public interface IWcsTaskService {
      * @return
      */
     AjaxResult moveStartingPointToDestination(WcsTask wcsTask);
+
+
+    List<WcsTask> selectWcsSameColumnNotFinish(String colNo, Long colIndex, Long zoneId,Long warehouseId);
 }

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

@@ -599,6 +599,12 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
         return AjaxResult.success();
     }
 
+    @Override
+    public List<WcsTask> selectWcsSameColumnNotFinish(String colNo, Long colIndex, Long zoneId, Long warehouseId) {
+        return wcsTaskMapper.selectWcsSameColumnNotFinish(colNo, colIndex, zoneId, warehouseId);
+    }
+
+
     /**
      * 修改库存出入库标记
      *

+ 15 - 0
warewms-ams/src/main/resources/mapper/ams/WcsTaskMapper.xml

@@ -314,6 +314,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by priority
     </select>
 
+    <select id="selectWcsSameColumnNotFinish" resultMap="WcsTaskDTOResult">
+        select w.* from wcs_task w left join base_location_info i on w.location_from = i.id
+        where w.state not in (2,6,7)
+        <if test="colNo != null  and colNo != ''">
+            and i.col_no = #{colNo}
+        </if>
+        <if test=" warehouseId!= null  and warehouseId != ''">
+            and w.shop_id = #{warehouseId}
+        </if>
+        <if test="zoneId != null  and zoneId != ''">
+            and i.zone_id = #{zoneId}
+        </if>
+    </select>
+
     <select id="selectTaskByColNoAfter" resultMap="WcsTaskDTOResult">
         select w.*,i.col_no,i.col_index from wcs_task w left join base_location_info i on w.location_to = i.id
         where w.state = 9
@@ -337,4 +351,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select * from wcs_task
         where task_no = #{taskNo} and state not in (2,7,4,11,12)
     </select>
+
 </mapper>