From e08c30f6a36a15be4e019b5e0d631f32f6d06029 Mon Sep 17 00:00:00 2001
From: wangfei <3597712270@qq.com>
Date: 星期一, 24 十一月 2025 14:51:09 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10105/r/YiWuProject

---
 hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java |   55 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java
index 07c694b..442fbb7 100644
--- a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java
+++ b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java
@@ -3,8 +3,8 @@
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
 import com.github.yulichang.toolkit.JoinWrappers;
 import com.kangaroohy.milo.model.ReadWriteEntity;
@@ -414,6 +414,8 @@
                 LambdaQueryWrapper<BigStorageCage> queryWrapper = new LambdaQueryWrapper<BigStorageCage>()
                         .eq(BigStorageCage::getRemainWidth, slotWidth)
                         .eq(BigStorageCage::getEnableState, Const.SLOT_ON)
+                        .le(BigStorageCage::getMinThickness, info.getThickness())
+                        .ge(BigStorageCage::getMaxThickness, info.getThickness())
                         .orderByAsc(BigStorageCage::getDeviceId).orderByAsc(BigStorageCage::getSlot)
                         .last("limit 1");
 
@@ -478,13 +480,30 @@
 
             String temperingEngineerId = redisUtil.getCacheObject("temperingEngineerId");
             if (StringUtils.isNotBlank(temperingEngineerId)) {
-                TemperingGlassInfo temperingGlassInfo = temperingGlassInfoService.getOne(new QueryWrapper<TemperingGlassInfo>()
-                        .select("Top 1 *")
-                        .eq("engineer_id", temperingEngineerId)
-                        .orderByDesc("tempering_layout_id"));
+                List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.list(
+                        new LambdaQueryWrapper<TemperingGlassInfo>()
+                                .eq(TemperingGlassInfo::getEngineerId, temperingEngineerId)
+                                .orderByAsc(TemperingGlassInfo::getId)
+                );
                 int temperingLayoutId = 1;
-                if (temperingGlassInfo != null) {
-                    temperingLayoutId = temperingGlassInfo.getTemperingLayoutId() + 1;
+                if (CollectionUtils.isEmpty(temperingGlassInfoList)) {
+                    temperingLayoutId = 1;
+                } else {
+                    List<Integer> tempIds = temperingGlassInfoList.stream()
+                            .map(TemperingGlassInfo::getTemperingLayoutId)
+                            .distinct()
+                            .sorted()
+                            .collect(Collectors.toList());
+
+                    int expected = 1;
+                    for (int current : tempIds) {
+                        if (current > expected) {
+                            break; // 鎵惧埌绗竴涓己澶卞�硷紝璺冲嚭寰幆
+                        } else if (current == expected) {
+                            expected++; // 杩炵画鍒欓�掑鏈熸湜鐨勫��
+                        }
+                    }
+                    temperingLayoutId = expected; // 缂哄け鍒欎负expected锛岃繛缁垯涓簃ax+1
                 }
                 List<GlassInfo> glassInfos = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getEngineerId, temperingEngineerId).eq(GlassInfo::getTemperingLayoutId, temperingLayoutId));
                 if (CollectionUtil.isEmpty(glassInfos)) {
@@ -575,6 +594,7 @@
                     .eq(BigStorageCage::getEnableState, Const.SLOT_ON));
             //瀹氫箟10涓牸瀛愪负闃堝��
             if (count <= 10) {
+                log.info("绗煎瓙瓒呰繃闃堝�硷紝鎵ц4鍙风瀛愯皟搴﹂�昏緫");
                 //鑾峰彇搴忓彿涓�1鐨勬牸瀛� 灏嗘牸瀛愬唴鐨勬墍鏈夌幓鐠冮�佸埌瀵瑰簲鐨勭瀛�
                 BigStorageCage bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
                         .eq(BigStorageCage::getRemainWidth, slotWidth)
@@ -582,15 +602,18 @@
                         .in(BigStorageCage::getDeviceId, Arrays.asList(5, 6))
                         .orderByAsc(BigStorageCage::getDeviceId).orderByAsc(BigStorageCage::getSlot)
                         .last("limit 1"));
-
-                list = bigStorageCageDetailsService.queryNeedDispatch();
-                computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task",
-                        bigStorageCage.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH);
-                List<Integer> slotList = new ArrayList<>();
-                slotList.add(bigStorageCage.getSlot());
-                slotList.add(list.get(0).getSlot());
-                updateSlotRemainBySlots(slotList);
-                return;
+                if (null != bigStorageCage) {
+                    list = bigStorageCageDetailsService.queryNeedDispatch();
+                    if (CollectionUtil.isNotEmpty(list)) {
+                        computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task",
+                                bigStorageCage.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH);
+                        List<Integer> slotList = new ArrayList<>();
+                        slotList.add(bigStorageCage.getSlot());
+                        slotList.add(list.get(0).getSlot());
+                        updateSlotRemainBySlots(slotList);
+                        return;
+                    }
+                }
             }
             //鐢熸垚璋冨害浠诲姟鎸夌収缁勫彿缁勫簭鐢�1寮�濮嬩緷娆″線5鍙风瀛愰�佸皬鐗�
             BigStorageSlotDTO slotDTO = bigStorageCageDetailsService.queryNeedDispatchSlotBySequence();

--
Gitblit v1.8.0