hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java
@@ -5,6 +5,7 @@
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;
@@ -14,10 +15,7 @@
import com.mes.base.entity.BigStorageCageBaseInfo;
import com.mes.bigstorage.entity.BigStorageCage;
import com.mes.bigstorage.entity.BigStorageCageDetails;
import com.mes.bigstorage.entity.dto.BigStorageDTO;
import com.mes.bigstorage.entity.dto.BigStorageRelationDTO;
import com.mes.bigstorage.entity.dto.BigStorageSequenceDTO;
import com.mes.bigstorage.entity.dto.TemperingLayoutDTO;
import com.mes.bigstorage.entity.dto.*;
import com.mes.bigstorage.service.BigStorageCageDetailsService;
import com.mes.bigstorage.service.BigStorageCageService;
import com.mes.bigstorage.service.BigStorageGlassInfoService;
@@ -107,6 +105,8 @@
    private static final String ALARM_TYPE = "钢化大理片";
    private static final String ALARM_CODE_SIZE = "sizeSame";
    private static final String ALARM_CODE_ID = "idSame";
    private static final String ALARM_CODE_SLOT = "slotLess";
    private static final String ALARM_CODE_OVER = "overSize";
    @Resource
    private RedisUtil redisUtil;
@@ -143,16 +143,17 @@
        String fromOpcUa = s7DataDLPOne.getFrom1().toString();
        List<String> ids = s7DataDLPOne.getIds();
        log.info("获取到进片任务 玻璃id:{}", ids);
        List<String> glassIdList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            String requestWord = ids.get(i);
            if (null != requestWord && !requestWord.isEmpty()) {
            if (StringUtils.isNotBlank(requestWord)) {
                log.info("玻璃id{}加入进片任务", requestWord);
                BigStorageCageTask task = new BigStorageCageTask();
                task.setGlassId(requestWord);
                task.setStartSlot(Integer.parseInt(fromOpcUa));
                inTaskList.add(task);
                glassIdList.add(requestWord);
                continue;
            }
        }
        if (CollectionUtil.isEmpty(inTaskList)) {
@@ -160,9 +161,9 @@
            return;
        }
        log.info("获取任务的玻璃id:{}", glassIdList);
        String countEntity = s7DataDLPOne.getGlassCount().toString();
        if (null == countEntity || Integer.parseInt(countEntity) != glassIdList.size()) {
            log.info("当前大车进片玻璃数量{}与mes读取到的数量{}不匹配,结束进片任务", countEntity, glassIdList.size());
        Integer glassCount = s7DataDLPOne.getGlassCount();
        if (glassCount != glassIdList.size()) {
            log.info("当前大车进片玻璃数量{}与mes读取到的数量{}不匹配,结束进片任务", glassCount, glassIdList.size());
            //向plc发送报警:当前大车进片玻璃数量与mes读取到的数量不匹配
            s7DataDLPOne = new S7DataDLPOne();
            s7DataDLPOne.setAlarmSignal(1);
@@ -219,19 +220,27 @@
            return;
        }
        Integer glassGap = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_GLASS_GAP);
        Integer slotMaxthickness = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_MAX_THICKNESS);
        Integer slotMaxThickness = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_MAX_THICKNESS);
        Integer slotWidth = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_WIDTH);
        Integer slotMaxHeight = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_MAX_HEIGHT);
        //按照玻璃厚度分组,判断剩余格子是否可以存放
        Map<Double, Long> thickCountMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getThickness, Collectors.counting()));
        if (glassInfoList.get(0).getThickness() < slotMaxthickness) {
        if (glassInfoList.get(0).getThickness() < slotMaxThickness) {
            for (Map.Entry<Double, Long> entry : thickCountMap.entrySet()) {
                int count = bigStorageCageService.count(new LambdaQueryWrapper<BigStorageCage>()
                        .eq(BigStorageCage::getEnableState, Const.SLOT_ON).eq(BigStorageCage::getRemainWidth, slotWidth)
                        .le(BigStorageCage::getDeviceId, 4)
                        .le(BigStorageCage::getMinThickness, entry.getKey())
                        .ge(BigStorageCage::getMaxThickness, entry.getKey()));
                if (count < entry.getValue()) {
                    log.info("笼内格子剩余数量不足,结束本次进片");
                    ProductAlarmInfo alarmInfo = new ProductAlarmInfo();
                    alarmInfo.setState(Const.LOAD_RAW_GLASS_NEW);
                    alarmInfo.setAlarmModule(ALARM_MODULE);
                    alarmInfo.setAlarmType(ALARM_TYPE);
                    alarmInfo.setAlarmCode(ALARM_CODE_SLOT);
                    alarmInfo.setAlarmMessage(count + "");
                    productAlarmInfoService.save(alarmInfo);
                    //向plc发送报警:笼内格子剩余数量不足
//                    miloService.writeToOpcWord(generateReadWriteEntity("DLP1A.DLP1A.alarmSignal", 16));
                    s7DataDLPOne = new S7DataDLPOne();
@@ -242,12 +251,19 @@
            }
        }
        //超大尺寸
        if (slotMaxHeight < Math.min(glassInfoList.get(0).getWidth(), glassInfoList.get(0).getHeight()) || glassInfoList.get(0).getThickness() >= slotMaxthickness) {
        if (slotMaxHeight < Math.min(glassInfoList.get(0).getWidth(), glassInfoList.get(0).getHeight()) || glassInfoList.get(0).getThickness() >= slotMaxThickness) {
            int count = bigStorageCageDetailsService.count(new LambdaQueryWrapper<BigStorageCageDetails>()
                    .eq(BigStorageCageDetails::getSlot, THROUGH_SLOT)
                    .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL));
            if (count > 0) {
                log.info("直通片台存在玻璃,结束本次进片");
                ProductAlarmInfo alarmInfo = new ProductAlarmInfo();
                alarmInfo.setState(Const.LOAD_RAW_GLASS_NEW);
                alarmInfo.setAlarmModule(ALARM_MODULE);
                alarmInfo.setAlarmType(ALARM_TYPE);
                alarmInfo.setAlarmCode(ALARM_CODE_OVER);
                alarmInfo.setAlarmMessage("");
                productAlarmInfoService.save(alarmInfo);
                //向plc发送报警:直通片台存在玻璃,无法继续直通
//                miloService.writeToOpcWord(generateReadWriteEntity("DLP1A.DLP1A.alarmSignal", 64));
                s7DataDLPOne = new S7DataDLPOne();
@@ -262,14 +278,15 @@
                .set(EdgGlassTaskInfo::getState, Const.EDG_GLASS_SUCCESS).in(EdgGlassTaskInfo::getGlassId, glassIdList));
        //报工
        for (String glass : glassIdList) {
            damageService.autoSubmitReport(glass, inTaskList.get(0).getStartSlot(), "磨边", "进大理片笼", 1);
            damageService.autoSubmitReport(glass, inTaskList.get(0).getStartSlot(),
                    "磨边", "进大理片笼", 1);
        }
        Map<String, List<GlassInfo>> glassListMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getGlassId));
        //计算目标格子
        List<BigStorageCageHistoryTask> historyTasks = new ArrayList<>();
        //超大尺寸与正常尺寸玻璃计算方式不一样
        if (slotMaxHeight > Math.min(glassInfoList.get(0).getWidth(), glassInfoList.get(0).getHeight()) && glassInfoList.get(0).getThickness() < slotMaxthickness) {
        if (slotMaxHeight > Math.min(glassInfoList.get(0).getWidth(), glassInfoList.get(0).getHeight()) && glassInfoList.get(0).getThickness() < slotMaxThickness) {
            for (BigStorageCageTask task : inTaskList) {
                GlassInfo info = glassListMap.get(task.getGlassId()).get(0);
                BigStorageDTO bigStorageDTO = bigStorageGlassInfoService.queryBigStorageTargetSlot(info.getEngineerId(), info.getTemperingLayoutId(), info.getTemperingFeedSequence());
@@ -301,27 +318,29 @@
                bigStorageCageDetailsService.save(cageDetails);
            }
        } else {
            BigStorageCageTask task = inTaskList.get(0);
            task.setTargetSlot(THROUGH_SLOT);
            //存放历史任务
            BigStorageCageHistoryTask historyTask = new BigStorageCageHistoryTask();
            BeanUtils.copyProperties(task, historyTask);
            historyTask.setTaskType(Const.BIG_STORAGE_BEFORE_IN);
            historyTask.setGlassCount(glassInfoList.size());
            historyTask.setTaskState(Const.ENGINEERING_NEW);
            historyTasks.add(historyTask);
            GlassInfo info = glassInfoList.get(0);
            BigStorageCageDetails cageDetails = new BigStorageCageDetails();
            BeanUtils.copyProperties(info, cageDetails);
            cageDetails.setSlot(THROUGH_SLOT);
            cageDetails.setState(Const.GLASS_STATE_NEW);
            cageDetails.setDeviceId(0);
            cageDetails.setSequence(0);
            cageDetails.setGap(glassGap);
            cageDetails.setAngle((int) info.getAngle());
            cageDetails.setFilmsId(info.getFilmsid());
            cageDetails.setId(null);
            bigStorageCageDetailsService.save(cageDetails);
            for (BigStorageCageTask task : inTaskList) {
                task.setTargetSlot(THROUGH_SLOT);
                //存放历史任务
                BigStorageCageHistoryTask historyTask = new BigStorageCageHistoryTask();
                BeanUtils.copyProperties(task, historyTask);
                historyTask.setTaskType(Const.BIG_STORAGE_BEFORE_IN);
                historyTask.setGlassCount(glassInfoList.size());
                historyTask.setTaskState(Const.ENGINEERING_NEW);
                historyTasks.add(historyTask);
                GlassInfo info = glassListMap.get(task.getGlassId()).get(0);
                BigStorageCageDetails cageDetails = new BigStorageCageDetails();
                BeanUtils.copyProperties(info, cageDetails);
                cageDetails.setSlot(THROUGH_SLOT);
                cageDetails.setState(Const.GLASS_STATE_NEW);
                cageDetails.setDeviceId(0);
                cageDetails.setSequence(0);
                cageDetails.setGap(glassGap);
                cageDetails.setAngle((int) info.getAngle());
                cageDetails.setFilmsId(info.getFilmsid());
                cageDetails.setId(null);
                bigStorageCageDetailsService.save(cageDetails);
            }
        }
        //历史数据入库
        bigStorageCageHistoryTaskService.saveBatch(historyTasks);
@@ -377,6 +396,72 @@
            log.info("有正在执行的出片任务,结束本次出片任务");
            return;
        }
        Integer glassGap = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_GLASS_GAP);
        Integer slotWidth = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_WIDTH);
        Integer slotMaxThickness = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_MAX_THICKNESS);
        Integer slotMaxHeight = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_SLOT_MAX_HEIGHT);
        List<BigStorageCageDetails> detailsList = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                .eq(BigStorageCageDetails::getSlot, THROUGH_SLOT)
                .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL).orderByAsc(BigStorageCageDetails::getId));
        if (CollectionUtil.isNotEmpty(detailsList)) {
            List<BigStorageCageHistoryTask> historyTasks = new ArrayList<>();
            List<BigStorageCageTask> taskList = new ArrayList<>();
            for (BigStorageCageDetails info : detailsList) {
                BigStorageCageTask task = new BigStorageCageTask();
                task.setGlassId(info.getGlassId());
                task.setStartSlot(THROUGH_SLOT);
                task.setTaskState(Const.ENGINEERING_NEW);
                LambdaQueryWrapper<BigStorageCage> queryWrapper = new LambdaQueryWrapper<BigStorageCage>()
                        .eq(BigStorageCage::getRemainWidth, slotWidth)
                        .eq(BigStorageCage::getEnableState, Const.SLOT_ON)
                        .orderByAsc(BigStorageCage::getDeviceId).orderByAsc(BigStorageCage::getSlot)
                        .last("limit 1");
                if (slotMaxHeight > Math.min(info.getWidth(), info.getHeight())) {
                    queryWrapper.in(BigStorageCage::getDeviceId, Arrays.asList(5, 6));
                } else {
                    queryWrapper.eq(BigStorageCage::getDeviceId, 6);
                }
                BigStorageCage bigStorageCage = bigStorageCageService.getOne(queryWrapper);
                //获取目标格子信息
//            临时更新格子的剩余尺寸:防止相邻玻璃进同一格子造成剩余尺寸不足,玻璃越界的情况,任务完成后再次更新大理片笼表剩余宽度(按照笼内玻璃数量更新大理片笼剩余尺寸)
                bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>()
                        .set(BigStorageCage::getRemainWidth, bigStorageCage.getRemainWidth() - Math.max(info.getWidth(), info.getHeight()) - glassGap)
                        .eq(BigStorageCage::getSlot, bigStorageCage.getSlot()));
                task.setTargetSlot(bigStorageCage.getSlot());
                taskList.add(task);
                //存放历史任务
                BigStorageCageHistoryTask historyTask = new BigStorageCageHistoryTask();
                BeanUtils.copyProperties(task, historyTask);
                historyTask.setTaskType(Const.BIG_STORAGE_BEFORE_DISPATCH);
                historyTask.setGlassCount(detailsList.size());
                historyTask.setTaskState(Const.ENGINEERING_NEW);
                historyTasks.add(historyTask);
                BigStorageCageDetails cageDetails = new BigStorageCageDetails();
                BeanUtils.copyProperties(info, cageDetails);
                cageDetails.setSlot(bigStorageCage.getSlot());
                cageDetails.setState(Const.GLASS_STATE_NEW);
                cageDetails.setDeviceId(bigStorageCage.getDeviceId());
                cageDetails.setSequence(0);
                cageDetails.setAngle(info.getAngle());
                cageDetails.setGap(glassGap);
                cageDetails.setFilmsId(info.getFilmsId());
                cageDetails.setId(null);
                bigStorageCageDetailsService.save(cageDetails);
                info.setState(Const.GLASS_STATE_OUT);
                bigStorageCageDetailsService.updateById(info);
            }
            //历史数据入库
            bigStorageCageHistoryTaskService.saveBatch(historyTasks);
            extracted(taskList);
            S7DataDLPTwo s7DataDLPTwo = new S7DataDLPTwo();
            s7DataDLPTwo.setMesReply(1);
            s7SerializerDLPTwo.write(s7DataDLPTwo);
            return;
        }
        Integer temperingOutTargetPosition = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_TEMPERING_OUT_TARGET_POSITION);
        if (redisUtil.getCacheObject("temperingSwitch")) {
            //是否允许钢化
@@ -392,26 +477,32 @@
                return;
            }
            BigStorageCageDetails details = bigStorageCageDetailsService.getOne(new LambdaQueryWrapper<BigStorageCageDetails>()
                    .eq(BigStorageCageDetails::getSlot, THROUGH_SLOT)
                    .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL).last("limit 1"));
            if (details != null) {
                TemperingGlassInfo temperingGlassInfo = new TemperingGlassInfo();
                BeanUtils.copyProperties(details, temperingGlassInfo);
                temperingGlassInfo.setState(-1);
                temperingGlassInfoService.save(temperingGlassInfo);
                computeOutGlassInfoByVirtualSlot(Arrays.asList(temperingGlassInfo), "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT);
                return;
            }
            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)) {
@@ -447,7 +538,8 @@
        Integer outCarMaxSize = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_OUT_CAR_SIZE);
        List<BigStorageCageDetails> artificialList = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_ARTIFICIAL)
                .orderByAsc(BigStorageCageDetails::getSlot)
                .orderByAsc(BigStorageCageDetails::getDeviceId)
                .orderByAsc(BigStorageCageDetails::getId)
                .orderByAsc(BigStorageCageDetails::getId).last("limit " + outCarMaxSize));
        if (CollectionUtil.isNotEmpty(artificialList)) {
            computeOutGlassInfoByVirtualSlot(artificialList, "big_storage_cage_out_one_task", artificialOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT);
@@ -469,42 +561,105 @@
                log.info("有正在执行的进片任务,结束调度任务");
                return;
            }
            //todo:获取笼内单格已经到齐的玻璃格子信息
            List<BigStorageRelationDTO> virtualList = bigStorageCageDetailsService.queryIsAllNeedDispatchVirtualSlot();
            if (CollectionUtil.isEmpty(virtualList)) {
                log.info("没有需要调度的格子");
                return;
            }
//4号获取笼内单格已经到齐的玻璃格子信息
            List<BigStorageCageDetails> list = new ArrayList<>();
            loop:
            List<BigStorageRelationDTO> virtualList = bigStorageCageDetailsService.queryIsAllNeedDispatchVirtualSlot(Arrays.asList(4));
            for (BigStorageRelationDTO dto : virtualList) {
                List<BigStorageSequenceDTO> sequenceDTOList = bigStorageCageDetailsService.dispatchBigStorageGlassInfo(dto);
                if (CollectionUtil.isEmpty(sequenceDTOList) || sequenceDTOList.size() == 1) {
                    continue;
                }
                int sequence = -1;
                int targetSlot = -1;
                for (BigStorageSequenceDTO item : sequenceDTOList) {
                    if (item.getMaxSequence() == sequence - 1) {
                        //生成调度任务
                        int startSlot = item.getSlot();
                        list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                                .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN).eq(BigStorageCageDetails::getSlot, startSlot));
                        computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task",
                                targetSlot, Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH);
                        List<Integer> slotList = new ArrayList<>();
                        slotList.add(targetSlot);
                        updateSlotRemainBySlots(slotList);
                        break loop;
                BigStorageCage bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
                        .eq(BigStorageCage::getRemainWidth, slotWidth)
                        .eq(BigStorageCage::getEnableState, Const.SLOT_ON)
                        .in(BigStorageCage::getDeviceId, Arrays.asList(5, 6))
                        .orderByAsc(BigStorageCage::getDeviceId).orderByAsc(BigStorageCage::getSlot)
                        .last("limit 1"));
                List<Integer> slotList = sequenceDTOList.stream().map(BigStorageSequenceDTO::getSlot).collect(Collectors.toList());
                list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                        .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                        .in(BigStorageCageDetails::getSlot, slotList)
                        .orderByAsc(BigStorageCageDetails::getTemperingFeedSequence)
                );
                computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task",
                        bigStorageCage.getSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH);
                slotList.add(bigStorageCage.getSlot());
                updateSlotRemainBySlots(slotList);
                return;
            }
            //有:统一往5号笼子送
//            无 4号笼子使用数量是否超过阈值 有 生成调度任务按照组号组序由1开始依次往5号笼子送小片
            int count = bigStorageCageService.count(new LambdaQueryWrapper<BigStorageCage>().eq(BigStorageCage::getDeviceId, 4).eq(BigStorageCage::getRemainWidth, slotWidth)
                    .eq(BigStorageCage::getEnableState, Const.SLOT_ON));
            //定义10个格子为阈值
            if (count <= 10) {
                //获取序号为1的格子 将格子内的所有玻璃送到对应的笼子
                BigStorageCage bigStorageCage = bigStorageCageService.getOne(new LambdaQueryWrapper<BigStorageCage>()
                        .eq(BigStorageCage::getRemainWidth, slotWidth)
                        .eq(BigStorageCage::getEnableState, Const.SLOT_ON)
                        .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;
            }
            //生成调度任务按照组号组序由1开始依次往5号笼子送小片
            BigStorageSlotDTO slotDTO = bigStorageCageDetailsService.queryNeedDispatchSlotBySequence();
            if (null != slotDTO) {
                list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                        .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                        .in(BigStorageCageDetails::getSlot, slotDTO.getStartSlot())
                        .orderByAsc(BigStorageCageDetails::getTemperingFeedSequence)
                );
                computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task",
                        slotDTO.getTargetSlot(), Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH);
                List<Integer> slotList = new ArrayList<>();
                slotList.add(slotDTO.getStartSlot());
                slotList.add(slotDTO.getTargetSlot());
                updateSlotRemainBySlots(slotList);
                return;
            }
            //1-3号获取笼内单格已经到齐的玻璃格子信息
            virtualList = bigStorageCageDetailsService.queryIsAllNeedDispatchVirtualSlot(Arrays.asList(1, 2, 3));
            if (CollectionUtil.isNotEmpty(virtualList)) {
                loop:
                for (BigStorageRelationDTO dto : virtualList) {
                    List<BigStorageSequenceDTO> sequenceDTOList = bigStorageCageDetailsService.dispatchBigStorageGlassInfo(dto);
                    if (CollectionUtil.isEmpty(sequenceDTOList) || sequenceDTOList.size() == 1) {
                        continue;
                    }
                    sequence = item.getMinSequence();
                    targetSlot = item.getSlot();
                    int sequence = -1;
                    int targetSlot = -1;
                    for (BigStorageSequenceDTO item : sequenceDTOList) {
                        if (item.getMaxSequence() == sequence - 1) {
                            //生成调度任务
                            int startSlot = item.getSlot();
                            list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                                    .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN).eq(BigStorageCageDetails::getSlot, startSlot));
                            computeOutGlassInfoByVirtualSlot(list, "big_storage_cage_out_one_task",
                                    targetSlot, Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_BEFORE_DISPATCH);
                            List<Integer> slotList = new ArrayList<>();
                            slotList.add(targetSlot);
                            updateSlotRemainBySlots(slotList);
                            break loop;
                        }
                        sequence = item.getMinSequence();
                        targetSlot = item.getSlot();
                    }
                }
                Date endDate = new Date();
                log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                return;
            }
        }
        Date endDate = new Date();
        log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
        return;
    }
    @Scheduled(fixedDelay = 1000)
@@ -844,20 +999,21 @@
     * @param <T>
     * @return
     */
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfoByVirtualSlot(List<T> list, String tableName, int targetSlot, int state, int taskType) {
    private <T extends BigStorageCageBaseInfo> Boolean
    computeOutGlassInfoByVirtualSlot(List<T> list, String tableName, int targetSlot, int state, int taskType) {
        //任务数据:获取车子存放玻璃最大数量,玻璃间隔
        List<T> outGlassList = list;
        if (!THROUGH_SLOT.equals(list.get(0).getSlot())) {
            //todo:临时解决方案:出片时考虑玻璃碰撞,改为一片一出
            // 界面关闭调度开关 !Const.BIG_STORAGE_BEFORE_DISPATCH.equals(taskType)
            if (list.get(0).getThickness() >= 8) {
                outGlassList = list.subList(0, 1);
            } else {
                List<String> glassIdList = bigStorageGlassRelationInfoService.queryNeedOutGlassId(
                        list.get(0).getEngineerId(), list.get(0).getTemperingLayoutId(), list.get(0).getTemperingFeedSequence());
                outGlassList = list.stream().filter(e -> glassIdList.contains(e.getGlassId())).collect(Collectors.toList());
            }
//        if (!THROUGH_SLOT.equals(list.get(0).getSlot())) {
//            临时解决方案:出片时考虑玻璃碰撞,改为一片一出
        // 界面关闭调度开关 !Const.BIG_STORAGE_BEFORE_DISPATCH.equals(taskType)
        if (list.get(0).getSlot() >= 500 && list.get(0).getThickness() > 8) {
            outGlassList = list.subList(0, 1);
        } else {
            List<String> glassIdList = bigStorageGlassRelationInfoService.queryNeedOutGlassId(
                    list.get(0).getEngineerId(), list.get(0).getTemperingLayoutId(), list.get(0).getTemperingFeedSequence());
            outGlassList = list.stream().filter(e -> glassIdList.contains(e.getGlassId())).collect(Collectors.toList());
        }
//        }
        Assert.isFalse(CollectionUtil.isEmpty(outGlassList), "未获取出片数据,结束出片任务");
        log.info("获取出片任务数据{}条,执行保存", outGlassList.size());
        List<BigStorageCageTask> bigStorageCageTaskList = outGlassList.stream()
@@ -865,12 +1021,43 @@
        List<String> glassIds = bigStorageCageTaskList.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList());
        int glassCount = bigStorageCageTaskList.size();
        //生成出片任务条数不足6补全
//        while (bigStorageCageTaskList.size() < 6) {
//            bigStorageCageTaskList.add(new BigStorageCageTask("", 0, 0, 0));
//        }
        //清空任务表数据
        resetOutTask();
        extracted(bigStorageCageTaskList);
        S7DataDLPTwo s7DataDLPTwo;
        List<BigStorageCageHistoryTask> historyList = bigStorageCageTaskList.stream().filter(e -> StringUtils.isNotBlank(e.getGlassId())).map(e -> {
            BigStorageCageHistoryTask history = new BigStorageCageHistoryTask();
            BeanUtils.copyProperties(e, history);
            history.setGlassCount(glassCount);
            history.setTaskType(taskType);
            return history;
        }).collect(Collectors.toList());
        bigStorageCageHistoryTaskService.saveBatch(historyList);
        log.info("将出片玻璃{}玻璃状态改为出片中", glassIds);
        bigStorageCageDetailsService.update(new LambdaUpdateWrapper<BigStorageCageDetails>()
                .set(BigStorageCageDetails::getState, state)
                .set(Const.BIG_STORAGE_BEFORE_DISPATCH.equals(taskType), BigStorageCageBaseInfo::getSlot, targetSlot)
                .ne(BigStorageCageDetails::getState, Const.GLASS_STATE_OUT)
                .in(BigStorageCageDetails::getGlassId, glassIds));
        try {
//            miloService.writeToOpcWord(generateReadWriteEntity("DLP1B.DLP1B.MesReply", 1));
            s7DataDLPTwo = new S7DataDLPTwo();
            s7DataDLPTwo.setMesReply(1);
            s7SerializerDLPTwo.write(s7DataDLPTwo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Boolean.TRUE;
    }
    /**
     * 按照任务生成出片任务
     *
     * @param bigStorageCageTaskList
     * @return
     */
    private Boolean extracted(List<BigStorageCageTask> bigStorageCageTaskList) {
//        resetOutTask();
        S7DataDLPTwo s7DataDLPTwo = new S7DataDLPTwo();
        for (int i = 0; i < bigStorageCageTaskList.size() && i < 6; i++) {
            String glassId = bigStorageCageTaskList.get(i).getGlassId();
@@ -912,29 +1099,6 @@
            }
        }
        s7SerializerDLPTwo.write(s7DataDLPTwo);
        List<BigStorageCageHistoryTask> historyList = bigStorageCageTaskList.stream().filter(e -> StringUtils.isNotBlank(e.getGlassId())).map(e -> {
            BigStorageCageHistoryTask history = new BigStorageCageHistoryTask();
            BeanUtils.copyProperties(e, history);
            history.setGlassCount(glassCount);
            history.setTaskType(taskType);
            return history;
        }).collect(Collectors.toList());
        bigStorageCageHistoryTaskService.saveBatch(historyList);
        log.info("将出片玻璃{}玻璃状态改为出片中", glassIds);
        bigStorageCageDetailsService.update(new LambdaUpdateWrapper<BigStorageCageDetails>()
                .set(BigStorageCageDetails::getState, state)
                .set(Const.BIG_STORAGE_BEFORE_DISPATCH.equals(taskType), BigStorageCageBaseInfo::getSlot, targetSlot)
                .ne(BigStorageCageDetails::getState, Const.GLASS_STATE_OUT)
                .in(BigStorageCageDetails::getGlassId, glassIds));
        try {
//            miloService.writeToOpcWord(generateReadWriteEntity("DLP1B.DLP1B.MesReply", 1));
            s7DataDLPTwo = new S7DataDLPTwo();
            s7DataDLPTwo.setMesReply(1);
            s7SerializerDLPTwo.write(s7DataDLPTwo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Boolean.TRUE;
    }
@@ -945,7 +1109,8 @@
//     * @param <T>
//     * @return
//     */
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, String tableName, int targetSlot, int state, int taskType) {
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, String tableName,
                                                                           int targetSlot, int state, int taskType) {
        //任务数据:获取车子存放玻璃最大数量,玻璃间隔
        List<BigStorageCageTask> bigStorageCageTaskList = new ArrayList<>();
        //打车剩余尺寸