zhoushihao
2025-11-15 43f70d713bdf1095db2231b1be0e82ee29c64d9f
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;
@@ -478,13 +478,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,连续则为max+1
                }
                List<GlassInfo> glassInfos = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getEngineerId, temperingEngineerId).eq(GlassInfo::getTemperingLayoutId, temperingLayoutId));
                if (CollectionUtil.isEmpty(glassInfos)) {
@@ -575,6 +592,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 +600,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();