wu
2024-12-23 b9b44b51b201e2f5a9a1f3665c7fb76b5690f9af
hangzhoumesParent/moduleService/howllowGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageHollowTask.java
@@ -4,10 +4,11 @@
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.base.entity.BigStorageCageBaseInfo;
import com.mes.base.entity.HollowBigStorageCageBaseInfo;
import com.mes.bigstoragecagetask.entity.BigStorageCageTask;
import com.mes.bigstoragecagetask.service.BigStorageCageTaskService;
import com.mes.common.config.Const;
@@ -19,7 +20,10 @@
import com.mes.hollow.entity.HollowBigStorageCageDetails;
import com.mes.hollow.entity.HollowGlassOutRelationInfo;
import com.mes.hollow.entity.HollowGlassRelationInfo;
import com.mes.hollow.entity.dto.*;
import com.mes.hollow.entity.dto.BigStorageSequenceDTO;
import com.mes.hollow.entity.dto.FlowCardVirtualSlotDTO;
import com.mes.hollow.entity.dto.HollowBigStorageDTO;
import com.mes.hollow.entity.dto.UpdateHollowBigStorageCageDTO;
import com.mes.hollow.service.HollowBigStorageCageDetailsService;
import com.mes.hollow.service.HollowBigStorageCageService;
import com.mes.hollow.service.HollowGlassOutRelationInfoService;
@@ -71,6 +75,13 @@
    private HollowGlassQueueInfoService hollowGlassQueueInfoService;
    @Resource
    private HollowGlassOutRelationInfoService hollowGlassOutRelationInfoService;
    private static final String BIG_STORAGE_CAGE_IN_TWO_TASK = "big_storage_cage_in_two_task";
    private static final String BIG_STORAGE_CAGE_OUT_TWO_TASK = "big_storage_cage_out_two_task";
    /**
     * 直通格子
     */
    private static final Integer THROUGH_SLOT = 920;
    @Autowired(required = false)
    MiloService miloService;
    @Resource
@@ -88,13 +99,10 @@
    @Value("${mes.outCarMaxSize}")
    private Integer outCarMaxSize;
    @Value("${mes.sequence.order}")
    private boolean sequenceOrder;
    @Value("${mes.temperingOutTargetPosition}")
    private Integer temperingOutTargetPosition;
    @Value("${mes.artificialOutTargetPosition}")
    private Integer artificialOutTargetPosition;
    @Value("${mes.slotMaxHeight}")
    private Integer slotMaxHeight;
    @Value("${mes.slotMaxthickness}")
    private Integer slotMaxthickness;
    @Scheduled(fixedDelay = 1000)
    public void inBigStorageTask() throws Exception {
@@ -142,7 +150,7 @@
            }
        }
        List<HollowBigStorageCageDetails> detailsList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>().in(HollowBigStorageCageDetails::getGlassId, glassIdList)
                .in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL));
                .in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL_ZERO));
        if (CollectionUtil.isNotEmpty(detailsList)) {
            log.info("理片笼存在相同的进片玻璃{},结束本次任务", detailsList);
            //todo:向plc发送报警
@@ -155,51 +163,94 @@
            //todo:向plc发送报警
            return;
        }
        //按照玻璃厚度分组,判断剩余格子是否可以存放
        Map<Double, Long> thickCountMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getThickness, Collectors.counting()));
        for (Map.Entry<Double, Long> entry : thickCountMap.entrySet()) {
            int count = hollowBigStorageCageService.count(new LambdaQueryWrapper<HollowBigStorageCage>()
                    .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON).eq(HollowBigStorageCage::getRemainWidth, slotWidth)
                    .le(HollowBigStorageCage::getMinThickness, entry.getKey())
                    .ge(HollowBigStorageCage::getMaxThickness, entry.getKey()));
            if (count < entry.getValue()) {
                log.info("笼内格子剩余数量不足,结束本次进片");
                //todo:向plc发送报警
                return;
            }
        }
        //todo:超大尺寸
        if (slotMaxHeight < Math.min(glassInfoList.get(0).getWidth(), glassInfoList.get(0).getHeight()) || glassInfoList.get(0).getThickness() > slotMaxthickness) {
            int count = hollowBigStorageCageDetailsService.count(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                    .eq(HollowBigStorageCageDetails::getSlot, THROUGH_SLOT)
                    .in(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL));
            if (count > 0) {
                log.info("直通片台存在玻璃,结束本次进片");
                //todo:向plc发送报警
                return;
            }
        }
        log.info("将钢化小片表内的状态改为钢化结束,玻璃id有:{}", glassIdList);
        //修改钢化任务表中的状态
        temperingGlassInfoService.update(new LambdaUpdateWrapper<TemperingGlassInfo>()
                .set(TemperingGlassInfo::getState, Const.TEMPERING_END).in(TemperingGlassInfo::getGlassId, glassIdList));
        //报工
        log.info("将接收到的玻璃进行钢化自动报工,玻璃id有:{}", glassIdList);
        for (String glass : glassIdList) {
            damageService.autoSubmitReport(glass, inTaskList.get(0).getStartSlot(), "钢化", "进中空理片笼");
        }
        Map<String, List<GlassInfo>> glassListMap = glassInfoList.stream().collect(Collectors.groupingBy(GlassInfo::getGlassId));
        //计算目标格子
        List<HollowBigStorageCageHistoryTask> historyTasks = new ArrayList<>();
        for (BigStorageCageTask task : inTaskList) {
            GlassInfo info = glassListMap.get(task.getGlassId()).get(0);
            HollowBigStorageDTO bigStorageDTO = hollowGlassRelationInfoService.queryHollowTargetSlot(info.getFlowCardId(),
                    info.getWidth(), info.getHeight(), info.getTotalLayer(), info.getLayer());
        try {
            for (BigStorageCageTask task : inTaskList) {
                GlassInfo info = glassListMap.get(task.getGlassId()).get(0);
                HollowBigStorageDTO bigStorageDTO = hollowGlassRelationInfoService.queryHollowTargetSlot(info.getFlowCardId(),
                        info.getWidth(), info.getHeight(), info.getTotalLayer(), info.getLayer());
//            临时更新格子的剩余尺寸:防止相邻玻璃进同一格子造成剩余尺寸不足,玻璃越界的情况,任务完成后再次更新大理片笼表剩余宽度(按照笼内玻璃数量更新大理片笼剩余尺寸)
            hollowBigStorageCageService.update(new LambdaUpdateWrapper<HollowBigStorageCage>()
                    .set(HollowBigStorageCage::getRemainWidth, bigStorageDTO.getRemainWidth() - Math.max(info.getWidth(), info.getHeight()) - glassGap)
                    .eq(HollowBigStorageCage::getSlot, bigStorageDTO.getSlot()));
            task.setTargetSlot(bigStorageDTO.getSlot());
            task.setGlassId(info.getGlassId());
            bigStorageCageTaskService.updateTaskMessage("big_storage_cage_in_two_task", task);
            //存放历史任务
            HollowBigStorageCageHistoryTask historyTask = new HollowBigStorageCageHistoryTask();
            BeanUtils.copyProperties(task, historyTask);
            historyTask.setTaskType(Const.BIG_STORAGE_AFTER_IN);
            historyTask.setGlassCount(glassInfoList.size());
            historyTask.setTaskState(Const.ENGINEERING_NEW);
            historyTasks.add(historyTask);
            //存放详情数据
            HollowBigStorageCageDetails cageDetails = new HollowBigStorageCageDetails();
            BeanUtils.copyProperties(bigStorageDTO, cageDetails);
            BeanUtils.copyProperties(info, cageDetails);
            cageDetails.setState(Const.GLASS_STATE_NEW);
            cageDetails.setSequence(bigStorageDTO.getSlotSequence());
            cageDetails.setGap(glassGap);
            cageDetails.setId(null);
            hollowBigStorageCageDetailsService.save(cageDetails);
                hollowBigStorageCageService.update(new LambdaUpdateWrapper<HollowBigStorageCage>()
                        .set(HollowBigStorageCage::getRemainWidth, bigStorageDTO.getRemainWidth() - Math.max(info.getWidth(), info.getHeight()) - glassGap)
                        .eq(HollowBigStorageCage::getSlot, bigStorageDTO.getSlot()));
                task.setTargetSlot(bigStorageDTO.getSlot());
                task.setGlassId(info.getGlassId());
                bigStorageCageTaskService.updateTaskMessage(BIG_STORAGE_CAGE_IN_TWO_TASK, task);
                //存放历史任务
                HollowBigStorageCageHistoryTask historyTask = new HollowBigStorageCageHistoryTask();
                BeanUtils.copyProperties(task, historyTask);
                historyTask.setTaskType(Const.BIG_STORAGE_AFTER_IN);
                historyTask.setGlassCount(glassInfoList.size());
                historyTask.setTaskState(Const.ENGINEERING_NEW);
                historyTasks.add(historyTask);
                //存放详情数据
                HollowBigStorageCageDetails cageDetails = new HollowBigStorageCageDetails();
                BeanUtils.copyProperties(bigStorageDTO, cageDetails);
                BeanUtils.copyProperties(info, cageDetails);
                cageDetails.setState(Const.GLASS_STATE_NEW);
                cageDetails.setSequence(bigStorageDTO.getSlotSequence());
                cageDetails.setGap(glassGap);
                cageDetails.setId(null);
                hollowBigStorageCageDetailsService.save(cageDetails);
                hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                        .set(HollowGlassRelationInfo::getGlassId, cageDetails.getGlassId())
                        .set(HollowGlassRelationInfo::getTemperingLayoutId, cageDetails.getTemperingLayoutId())
                        .set(HollowGlassRelationInfo::getTemperingFeedSequence, cageDetails.getTemperingFeedSequence())
                        .set(HollowGlassRelationInfo::getEngineerId, cageDetails.getEngineerId())
                        .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_OCCUPY)
                        .eq(HollowGlassRelationInfo::getFlowCardId, bigStorageDTO.getFlowCardId())
                        .eq(HollowGlassRelationInfo::getLayer, bigStorageDTO.getLayer())
                        .eq(HollowGlassRelationInfo::getVirtualSlot, bigStorageDTO.getVirtualSlot())
                        .eq(HollowGlassRelationInfo::getSlotSequence, bigStorageDTO.getSlotSequence())
                        .eq(HollowGlassRelationInfo::getHollowSequence, bigStorageDTO.getHollowSequence())
                );
            }
        } catch (Exception exception) {
            log.info("进片任务执行中发生异常:{}", exception);
            hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                    .set(HollowGlassRelationInfo::getGlassId, cageDetails.getGlassId())
                    .set(HollowGlassRelationInfo::getTemperingLayoutId, cageDetails.getTemperingLayoutId())
                    .set(HollowGlassRelationInfo::getTemperingFeedSequence, cageDetails.getTemperingFeedSequence())
                    .set(HollowGlassRelationInfo::getEngineerId, cageDetails.getEngineerId())
                    .eq(HollowGlassRelationInfo::getFlowCardId, bigStorageDTO.getFlowCardId())
                    .eq(HollowGlassRelationInfo::getLayer, bigStorageDTO.getLayer())
                    .eq(HollowGlassRelationInfo::getVirtualSlot, bigStorageDTO.getVirtualSlot())
                    .eq(HollowGlassRelationInfo::getSlotSequence, bigStorageDTO.getSlotSequence())
                    .eq(HollowGlassRelationInfo::getHollowSequence, bigStorageDTO.getHollowSequence())
                    .set(HollowGlassRelationInfo::getGlassId, null)
                    .set(HollowGlassRelationInfo::getTemperingLayoutId, null)
                    .set(HollowGlassRelationInfo::getTemperingFeedSequence, null)
                    .set(HollowGlassRelationInfo::getEngineerId, null)
                    .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
                    .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_OCCUPY)
            );
        }
        //历史数据入库
@@ -227,7 +278,7 @@
            return;
        }
        //获取出片任务表
        List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_out_two_task");
        List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage(BIG_STORAGE_CAGE_OUT_TWO_TASK);
        if (CollectionUtil.isNotEmpty(outTaskList)) {
            log.info("有正在执行的出片任务,结束本次出片任务");
            return;
@@ -270,10 +321,12 @@
            List<HollowGlassQueueInfo> unFinishHollowQueueList = hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>()
                    .eq(HollowGlassQueueInfo::getFlowCardId, hollowGlassOutRelationInfo.getFlowCardId())
                    .eq(HollowGlassQueueInfo::getCell, cell)
                    .eq(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW));
                    .eq(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW)
                    .orderByAsc(HollowGlassQueueInfo::getHollowSequence));
            if (CollectionUtil.isNotEmpty(unFinishHollowQueueList)) {
                log.info("有正在出片的中空任务");
                computeOutGlassInfo(unFinishHollowQueueList, "big_storage_cage_out_two_task", hollowGlassOutRelationInfo.getCell(), Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_AFTER_OUT);
                Integer isPair = unFinishHollowQueueList.get(0).getIsPair();
                hollowOutGlassByIsPair(unFinishHollowQueueList, hollowGlassOutRelationInfo.getCell(), isPair, hollowGlassOutRelationInfo.getTotalLayer(), hollowGlassOutRelationInfo.getIsForce());
                Date endDate = new Date();
                log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                return;
@@ -284,62 +337,65 @@
                        .eq(HollowGlassOutRelationInfo::getCell, hollowGlassOutRelationInfo.getCell())
                        .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_SUCCESS));
            }
            if (redisUtil.getCacheObject("hollowSwitch")) {
                List<HollowGlassOutRelationInfo> HollowGlassOutRelationInfoList = hollowGlassOutRelationInfoService
                        .list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
                                .eq(HollowGlassOutRelationInfo::getCell, cell)
                                .eq(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW));
                for (HollowGlassOutRelationInfo e : HollowGlassOutRelationInfoList) {
                    //中空优先:获取理片笼  玻璃小片  破损表 数量   判断笼内版图是否到齐
                    List<FlowCardGlassInfoDTO> flowCardGlassInfoDTO = hollowBigStorageCageDetailsService.hollowIsAll(e.getFlowCardId(), e.getTotalLayer(), Boolean.TRUE);
                    if (CollectionUtil.isNotEmpty(flowCardGlassInfoDTO)) {
                        //玻璃到齐包括已出片的
                        //到齐,将玻璃小片数据存入中空小片表,逻辑生成出片任务  结束
                        for (FlowCardGlassInfoDTO item : flowCardGlassInfoDTO) {
                            List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                                    .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                                    .eq(HollowBigStorageCageDetails::getFlowCardId, item.getFlowCardId())
                                    .orderByAsc(HollowBigStorageCageDetails::getHollowSequence)
                                    .orderBy(Boolean.TRUE, cell != 931, HollowBigStorageCageDetails::getLayer)
                            );
                            int finalCell = cell;
                            List<HollowGlassQueueInfo> hollowQueues = hollowBigStorageCageDetailsList.stream().map(queue -> {
                                HollowGlassQueueInfo queueInfo = new HollowGlassQueueInfo();
                                BeanUtils.copyProperties(queue, queueInfo);
                                queueInfo.setState(Const.TEMPERING_NEW);
                                queueInfo.setCell(finalCell);
                                return queueInfo;
                            }).collect(Collectors.toList());
                            if (CollectionUtil.isNotEmpty(hollowQueues)) {
                                hollowGlassQueueInfoService.saveBatch(hollowQueues);
                                computeOutGlassInfo(hollowQueues, "big_storage_cage_out_two_task", cell, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_AFTER_OUT);
                                //将中空任务状态改为开始
                                hollowGlassOutRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>()
                                        .eq(HollowGlassOutRelationInfo::getFlowCardId, e.getFlowCardId())
                                        .eq(HollowGlassOutRelationInfo::getCell, cell)
                                        .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START));
                                Date endDate = new Date();
                                log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                                return;
                            }
                        }
                    }
                }
            }
            //是否有人工下片任务   有直接出
            List<HollowBigStorageCageDetails> artificialList = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                    .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_ARTIFICIAL)
                    .orderByAsc(HollowBigStorageCageDetails::getSlot)
                    .orderByAsc(HollowBigStorageCageDetails::getId).last("limit " + outCarMaxSize));
            if (CollectionUtil.isNotEmpty(artificialList)) {
                computeOutGlassInfo(artificialList, "big_storage_cage_out_two_task", artificialOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_AFTER_OUT);
                Date endDate = new Date();
                log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                return;
            }
//            if (redisUtil.getCacheObject("hollowSwitch")) {
//                List<HollowGlassOutRelationInfo> HollowGlassOutRelationInfoList = hollowGlassOutRelationInfoService
//                        .list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
//                                .eq(HollowGlassOutRelationInfo::getCell, cell)
//                                .eq(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW));
//                for (HollowGlassOutRelationInfo e : HollowGlassOutRelationInfoList) {
//                    //中空优先:获取理片笼  玻璃小片  破损表 数量   判断笼内版图是否到齐
//                    List<FlowCardGlassInfoDTO> flowCardGlassInfoDTO = hollowBigStorageCageDetailsService.hollowIsAll(e.getFlowCardId(), e.getTotalLayer(), Boolean.TRUE);
//                    if (CollectionUtil.isNotEmpty(flowCardGlassInfoDTO)) {
//                        //玻璃到齐包括已出片的
//                        //到齐,将玻璃小片数据存入中空小片表,逻辑生成出片任务  结束
//                        for (FlowCardGlassInfoDTO item : flowCardGlassInfoDTO) {
//                            List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService.queryOutGlassList(item.getFlowCardId(), cell);
//                            int finalCell = cell;
//                            List<HollowGlassQueueInfo> hollowQueues = hollowBigStorageCageDetailsList.stream().map(queue -> {
//                                HollowGlassQueueInfo queueInfo = new HollowGlassQueueInfo();
//                                BeanUtils.copyProperties(queue, queueInfo);
//                                queueInfo.setState(Const.TEMPERING_NEW);
//                                queueInfo.setCell(finalCell);
//                                return queueInfo;
//                            }).collect(Collectors.toList());
//
//                            List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService.queryOutGlassList(flowCardId, cell);
//                            int isPairCount = glassInfo.getTotalLayer() * e.getTotalLayer();
//                            List<HollowGlassQueueInfo> hollowQueues = new ArrayList<>();
//                            loop:
//                            for (HollowBigStorageCageDetails queue : hollowBigStorageCageDetailsList) {
//                                HollowGlassQueueInfo queueInfo = new HollowGlassQueueInfo();
//                                BeanUtils.copyProperties(queue, queueInfo);
//                                queueInfo.setState(Const.TEMPERING_NEW);
//                                queueInfo.setCell(cell);
//                                hollowQueues.add(queueInfo);
//                                if (queue.getIsPair() == 1){
//                                    isPairCount -=1;
//                                    if (isPairCount == 0){
//                                        break loop;
//                                    }
//                                }
//                            }
//
//                            if (CollectionUtil.isNotEmpty(hollowQueues)) {
//                                hollowGlassQueueInfoService.saveBatch(hollowQueues);
//                                Integer isPair = hollowQueues.get(0).getIsPair();
//                                hollowOutGlassByIsPair(hollowQueues, cell, isPair, e.getTotalLayer());
//                                //将中空任务状态改为开始
//                                hollowGlassOutRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>()
//                                        .eq(HollowGlassOutRelationInfo::getFlowCardId, e.getFlowCardId())
//                                        .eq(HollowGlassOutRelationInfo::getCell, cell)
//                                        .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START));
//                                Date endDate = new Date();
//                                log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
//                                return;
//                            }
//                        }
//                    }
//                }
//            }
        }
//        redisUtil.setCacheObject("dispatchHollowSwitch",true);
        //是否存在需要内部调度的格子:执行内部调度任务
        if (redisUtil.getCacheObject("dispatchHollowSwitch")) {
            //todo:获取笼内单格已经到齐的玻璃格子信息
@@ -363,7 +419,7 @@
                        int targetSlot = item.getSlot();
                        list = hollowBigStorageCageDetailsService.list(new LambdaQueryWrapper<HollowBigStorageCageDetails>()
                                .eq(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_IN).eq(HollowBigStorageCageDetails::getSlot, startSlot));
                        computeOutGlassInfo(list, "big_storage_cage_out_two_task", targetSlot, Const.GLASS_STATE_SCHEDULE_ING, Const.BIG_STORAGE_AFTER_DISPATCH);
                        hollowOutGlassByIsPair(list, targetSlot, 0, 0, 0);
                        List<Integer> slotList = new ArrayList<>();
                        slotList.add(targetSlot);
                        updateSlotRemainBySlots(slotList);
@@ -436,12 +492,38 @@
                hollowBigStorageCageDetailsService.updateBySlot(storageCageDTOList, Const.GLASS_STATE_IN);
                log.info("4、大理片笼进片状态已完成已完成的玻璃信息id:{}", v);
                updateSlotRemainBySlots(inSuccessGlassSlot);
                List<String> glassList = v.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList());
                hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                        .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_SUCCESS)
                        .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_OCCUPY)
                        .in(HollowGlassRelationInfo::getGlassId, glassList)
                );
            } else if (e1 == 3) {
                //破损处理
                dealDamageInTask(v);
                List<String> glassList = v.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList());
                hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                        .set(HollowGlassRelationInfo::getGlassId, null)
                        .set(HollowGlassRelationInfo::getTemperingLayoutId, null)
                        .set(HollowGlassRelationInfo::getTemperingFeedSequence, null)
                        .set(HollowGlassRelationInfo::getEngineerId, null)
                        .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
                        .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_OCCUPY)
                        .in(HollowGlassRelationInfo::getGlassId, glassList)
                );
            } else {
                //清空理片笼空数据
                noDealInTask(v);
                List<String> glassList = v.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList());
                hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                        .set(HollowGlassRelationInfo::getGlassId, null)
                        .set(HollowGlassRelationInfo::getTemperingLayoutId, null)
                        .set(HollowGlassRelationInfo::getTemperingFeedSequence, null)
                        .set(HollowGlassRelationInfo::getEngineerId, null)
                        .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
                        .eq(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_OCCUPY)
                        .in(HollowGlassRelationInfo::getGlassId, glassList)
                );
            }
        });
        for (BigStorageCageTask item : inTaskList) {
@@ -474,7 +556,7 @@
            return;
        }
        //获取进片任务表
        List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_out_one_task");
        List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage(BIG_STORAGE_CAGE_OUT_TWO_TASK);
        if (CollectionUtil.isEmpty(outTaskList)) {
            log.info("当前大车无进片玻璃,结束完成进片任务");
            return;
@@ -532,6 +614,7 @@
                noDealOutTask(v);
            }
        });
        for (BigStorageCageTask item : outTaskList) {
            //更新历史任务表中的任务状态
            hollowBigStorageCageHistoryTaskService.update(new LambdaUpdateWrapper<HollowBigStorageCageHistoryTask>()
@@ -552,8 +635,45 @@
//                空执行
            }
        }
        try {
            //更新数量
            //按照玻璃id获取需要出片对列表中的数据
            if (finalTaskType.equals(Const.BIG_STORAGE_AFTER_OUT)) {
                HollowGlassQueueInfo hollowGlassQueueInfo = hollowGlassQueueInfoService.getOne(new LambdaQueryWrapper<HollowGlassQueueInfo>()
                        .eq(HollowGlassQueueInfo::getGlassId, outTaskList.get(0).getGlassId())
                        .orderByDesc(HollowGlassQueueInfo::getUpdateTime).last("limit 1"));
                List<HollowGlassQueueInfo> list = hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>()
                                .eq(HollowGlassQueueInfo::getFlowCardId, hollowGlassQueueInfo.getFlowCardId())
                                .eq(HollowGlassQueueInfo::getCell, hollowGlassQueueInfo.getCell())
//                        .eq(HollowGlassQueueInfo::getIsPair, 1)
                                .eq(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW)
                );
                if (CollectionUtil.isEmpty(list)) {
//                任务更新为已完成
                    hollowGlassOutRelationInfoService.update(new UpdateWrapper<HollowGlassOutRelationInfo>()
                            .eq("flow_card_id", hollowGlassQueueInfo.getFlowCardId())
                            .eq("cell", hollowGlassQueueInfo.getCell())
                            .setSql("pair_quantity = total_pair_quantity")
                            .set("state", Const.HOLLOW_FLOW_CARD_SUCCESS)
                    );
                } else {
//               计算剩余玻璃对数,用任务总队数减剩余对数
                    int remainCount = list.size() / hollowGlassQueueInfo.getTotalLayer();
                    hollowGlassOutRelationInfoService.update(new UpdateWrapper<HollowGlassOutRelationInfo>()
                            .eq("flow_card_id", hollowGlassQueueInfo.getFlowCardId())
                            .eq("cell", hollowGlassQueueInfo.getCell())
                            .setSql("pair_quantity = total_pair_quantity -" + remainCount)
                    );
                }
            }
        } catch (Exception e) {
            log.info("计算玻璃数量过程中出现错误,错误信息{}", e.getMessage());
        }
//        hollowGlassOutRelationInfoService.update
//       重置任务表数据
        bigStorageCageTaskService.updateOutTaskMessage("big_storage_cage_out_one_task");
        bigStorageCageTaskService.updateOutTaskMessage(BIG_STORAGE_CAGE_OUT_TWO_TASK);
        //清空启动状态
        //向opc发送启动信号
        miloService.writeToOpcWord(generateReadWriteEntity("DLP2B.DLP2B.MesReply", 0));
@@ -660,29 +780,83 @@
        log.info("出片任务-无动作执行完成");
    }
    private <T extends HollowBigStorageCageBaseInfo> Boolean hollowOutGlassByIsPair(List<T> list, int targetSlot, int isPair, int totalLayer, int isForce) {
        List<T> resultList = new ArrayList<>();
        List<T> tempList = new ArrayList<>();
        int taskType = Const.BIG_STORAGE_AFTER_OUT;
        int taskState = Const.GLASS_STATE_OUT_ING;
        for (T t : list) {
            if (isPair == (t.getIsPair() == null ? 0 : t.getIsPair())) {
                tempList.add(t);
            } else {
                break;
            }
        }
        if (isPair == 0 && isForce != 1) {
            taskType = Const.BIG_STORAGE_AFTER_DISPATCH;
            taskState = Const.GLASS_STATE_SCHEDULE_ING;
            //目前调度任务totalLayer为0  出片调度任务有层号,用于区分调度方式
            // 因为出片存在调度,如果为调度,提前占用格子,更新格子剩余尺寸,避免被进片玻璃占用
            if (totalLayer != 0) {
                resultList.add(list.get(0));
                HollowBigStorageCage storageCage = hollowBigStorageCageService.getOne(new LambdaQueryWrapper<HollowBigStorageCage>()
                        .eq(HollowBigStorageCage::getEnableState, Const.SLOT_ON)
                        .le(HollowBigStorageCage::getMinThickness, list.get(0).getThickness())
                        .ge(HollowBigStorageCage::getMaxThickness, list.get(0).getThickness())
                        .eq(HollowBigStorageCage::getRemainWidth, slotWidth)
                        .orderByAsc(HollowBigStorageCage::getMaxThickness).last("limit 1"));
                targetSlot = storageCage.getSlot();
                hollowBigStorageCageService.update(new LambdaUpdateWrapper<HollowBigStorageCage>()
                        .set(HollowBigStorageCage::getRemainWidth, 0).eq(HollowBigStorageCage::getSlot, targetSlot));
            } else {
                resultList = tempList;
            }
            totalLayer = 0;
        } else {
            resultList = tempList;
        }
        return computeOutGlassInfo(resultList, BIG_STORAGE_CAGE_OUT_TWO_TASK, targetSlot, taskState, taskType, totalLayer, isForce);
    }
    /**
     * 出片一次仅生成一车玻璃
     *
     * @param list
     * @param <T>
     * @param list
     * @param totalLayer
     * @return
     */
    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, String tableName, int targetSlot, int state, int taskType) {
    private <T extends HollowBigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, String tableName, int targetSlot, int state, int taskType, int totalLayer, int isForce) {
        //任务数据:获取车子存放玻璃最大数量,玻璃间隔
        List<BigStorageCageTask> bigStorageCageTaskList = new ArrayList<>();
        List<BigStorageCageTask> tempList = new ArrayList<>();
        List<T> tempTList = new ArrayList<>();
        //打车剩余尺寸
        Integer remainWidth = carWidth;
        for (T e : list) {
            if (bigStorageCageTaskList.size() >= outCarMaxSize || Math.max((int) e.getWidth(), (int) e.getHeight()) > remainWidth) {
            if (tempList.size() >= outCarMaxSize || Math.max((int) e.getWidth(), (int) e.getHeight()) > remainWidth) {
                break;
            }
            //计算当前出片车剩尺寸
            remainWidth = remainWidth - Math.max((int) e.getWidth(), (int) e.getHeight()) - glassGap;
            bigStorageCageTaskList.add(new BigStorageCageTask(e.getGlassId(), e.getSlot(), targetSlot,
            tempTList.add(e);
            tempList.add(new BigStorageCageTask(e.getGlassId(), e.getSlot(), targetSlot,
                    0));
        }
        Assert.isFalse(CollectionUtil.isEmpty(bigStorageCageTaskList), "未获取出片数据,结束出片任务");
        log.info("获取出片任务数据{}条,执行保存", bigStorageCageTaskList.size());
        Assert.isFalse(CollectionUtil.isEmpty(tempList), "未获取出片数据,结束出片任务");
        log.info("获取出片任务数据{}条,执行保存", tempList.size());
        List<BigStorageCageTask> bigStorageCageTaskList = tempList;
        if (1 != isForce) {
            if (taskType == Const.BIG_STORAGE_AFTER_OUT) {
                if (tempList.size() <= totalLayer) {
                    bigStorageCageTaskList = tempList;
                } else {
                    int remainCount = tempList.size() % totalLayer;
                    bigStorageCageTaskList = tempList.subList(0, tempList.size() - remainCount);
                }
            }
        }
        List<String> glassIds = bigStorageCageTaskList.stream().map(BigStorageCageTask::getGlassId).collect(Collectors.toList());
        int glassCount = bigStorageCageTaskList.size();
        //生成出片任务条数不足6补全
@@ -704,7 +878,7 @@
        log.info("将出片玻璃{}玻璃状态改为出片中", glassIds);
        hollowBigStorageCageDetailsService.update(new LambdaUpdateWrapper<HollowBigStorageCageDetails>()
                .set(HollowBigStorageCageDetails::getState, state)
                .set(Const.RAW_GLASS_TASK_TYPE_DISPATCH.equals(taskType), BigStorageCageBaseInfo::getSlot, targetSlot)
                .set(Const.BIG_STORAGE_AFTER_DISPATCH.equals(taskType), HollowBigStorageCageDetails::getSlot, targetSlot)
                .ne(HollowBigStorageCageDetails::getState, Const.GLASS_STATE_OUT)
                .in(HollowBigStorageCageDetails::getGlassId, glassIds));
        try {
@@ -723,6 +897,9 @@
        //是否存在有格子非空的玻璃
        if (CollectionUtils.isNotEmpty(inSlotGlassList)) {
            //存在  将格子内的玻璃分别进行更新
//            List<HollowBigStorageCage> hollowBigStorageCageList = hollowBigStorageCageService.list(new LambdaQueryWrapper<HollowBigStorageCage>()
//                    .lt(HollowBigStorageCage::getRemainWidth, 0).in(HollowBigStorageCage::getSlot, slotList));
//            List<Integer> resultSlotList = hollowBigStorageCageList.stream().map(HollowBigStorageCage::getSlot).collect(Collectors.toList());
            slotRemainMap = inSlotGlassList.stream()
                    .collect(Collectors.groupingBy(HollowBigStorageCageDetails::getSlot, Collectors.summingDouble(item -> Math.max(item.getWidth(), item.getHeight()) + glassGap)));
            slotRemainMap.forEach((e, v) -> {
@@ -747,4 +924,10 @@
                .value(value)
                .build();
    }
//
//    private List<BigStorageCageTask> computeOutTaskList(List<BigStorageCageTask> taskList, int totalLayer, int target) {
////        if (target == 931){}
//        if (taskList.get(0).get)
//            return null;
//    }
}