hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java
@@ -28,6 +28,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -57,6 +58,12 @@
    @Value("${mes.threshold}")
    private Integer threshold;
    @Value("${mes.throughWidth}")
    private Integer throughWidth;
    @Value("${mes.throughHeight}")
    private Integer throughHeight;
    @Value("${mes.maxWidth}")
    private Integer maxWidth;
@@ -95,26 +102,26 @@
        }
        if ("1".equals(requestWord)) {
            log.info("2、进片请求,且确认字为0,执行进片任务");
            inTo(glassIdeValue, confirmationWrodAddress, currentSlot);
            inTo(glassIdeValue, requestWord, confirmationWrodAddress, currentSlot);
        } else if ("2".equals(requestWord)) {
            //09空闲 :1      10空闲 :2        都空闲:3    其他0
            log.info("2、出片请求,且确认字为0,执行进片任务");
            outTo(Integer.parseInt(out08Glassstate),
                    Integer.parseInt(out10Glassstate), confirmationWrodAddress, "", 0);
//            outTo(Integer.parseInt(out08Glassstate),
//                    Integer.parseInt(out10Glassstate), confirmationWrodAddress, "", 0);
        } else if ("3".equals(requestWord)) {
            log.info("2、进片和出片都空闲,执行出片任务");
            //加笼子里面是否有玻璃,有先出,无玻璃先进
            boolean outFlase = outTo(Integer.parseInt(out08Glassstate),
                    Integer.parseInt(out10Glassstate), confirmationWrodAddress, glassIdeValue, Integer.parseInt(currentSlot));
            boolean outFlase = false;
//                    outTo(Integer.parseInt(out08Glassstate),
//                    Integer.parseInt(out10Glassstate), confirmationWrodAddress, glassIdeValue, Integer.parseInt(currentSlot));
            log.info("出片任务是否完成:{},失败且玻璃id:{}不为空则执行进片任务", outFlase, glassIdeValue);
            if (!outFlase && StringUtils.isNotBlank(glassIdeValue)) {
                inTo(glassIdeValue, confirmationWrodAddress, currentSlot);
                inTo(glassIdeValue, requestWord, confirmationWrodAddress, currentSlot);
            }
        }
    }
    private void inTo(String glassId, String confirmationWrodAddress, String currentSlot) {
    private void inTo(String glassId, String requestWord, String confirmationWrodAddress, String currentSlot) {
        log.info("1、按照玻璃id:{}获取玻璃小片信息,当前格子为:{}", glassId, currentSlot);
        //添加进片任务  查找空格
        DownStorageCage nearestEmpty = downStorageCageService.selectCacheEmpty(Integer.parseInt(currentSlot), Boolean.FALSE);
@@ -122,8 +129,12 @@
        log.info("2、查询卧式理片笼里面的空格:{}", nearestEmpty);
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId));
        Assert.isFalse(null == glassInfo, "玻璃信息不存在");
        if ("1".equals(requestWord) && (glassInfo.getWidth() > throughWidth || glassInfo.getHeight() > throughHeight)) {
            log.info("玻璃当前尺寸宽:{},高:{}只能直通,当前进片任务需等待", glassInfo.getWidth(), glassInfo.getHeight());
            return;
        }
        Boolean checkFlag = Boolean.FALSE;
        //todo:玻璃尺寸是否走人工下片
        //玻璃尺寸是否走人工下片
        if (glassInfo.getWidth() > maxWidth || glassInfo.getHeight() > maxHeight) {
            log.info("该玻璃尺寸走人工下片,直接进片");
        } else {
@@ -162,7 +173,7 @@
                    for (GlassInfo item : glassInfoList) {
                        if (item.getWidth().equals(glassInfo.getWidth()) && item.getHeight().equals(glassInfo.getHeight())
                                && item.getThickness().equals(glassInfo.getThickness()) && item.getFilmsid().equals(glassInfo.getFilmsid())) {
                            //todo:玻璃是否为多层
                            //玻璃是否为多层
                            checkFlag = multilayerCheck(item);
                            if (checkFlag) {
                                //玻璃替换 仅替换流程卡id及层数
@@ -191,42 +202,90 @@
        downStorageCageDetails.setState(Const.GLASS_STATE_IN);
        downStorageCageDetailsService.save(downStorageCageDetails);
//        生成进片任务
        initDownGlassTask(glassInfo, nearestEmpty.getSlot() + "", null, Const.GLASS_CACHE_TYPE_IN);
        initDownGlassTask(glassInfo, nearestEmpty.getSlot(), null, Const.GLASS_CACHE_TYPE_IN);
        //log.info("5、生成进片任务信息存入任务表是否完成:{}", taskCache);
//        S7object.getinstance().plccontrol.writeWord(confirmationWrodAddress, (short) 1);
//        log.info("6、发送确认字完成");
    }
    private Boolean outTo(int parseInt, int parseInt1, String confirmationWrodAddress, String s, int i) {
        //定义笼内无法出片玻璃数量
        int glassCount = 0;
        String glassId = null;
        Boolean isBind = Boolean.FALSE;
        List<DownStorageCageDetails> list = downStorageCageDetailsService.list(new LambdaQueryWrapper<DownStorageCageDetails>()
    private Boolean outTo(String glassStatus06, String glassStatus11, String glassStatus13, String glassId) {
        if ("2".equals(glassStatus06) && "2".equals(glassStatus11) && "2".equals(glassStatus13)) {
            log.info("G06、G11、G13分别为{},{}、{}非自动状态,无法出片", glassStatus06, glassStatus11, glassStatus13);
            return Boolean.FALSE;
        }
        List<DownStorageCageDetails> tempList = downStorageCageDetailsService.list(new LambdaQueryWrapper<DownStorageCageDetails>()
                .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN));
        log.info("笼内玻璃的数据有:{}", list);
        if (CollectionUtils.isEmpty(list)) {
        log.info("笼内玻璃的数据有:{}", tempList);
        if (CollectionUtils.isEmpty(tempList)) {
            log.info("笼内没有玻璃,无法执行出片");
            return Boolean.FALSE;
        }
        //获取2个机械臂范围内的架子绑定的流程卡信息
        List<Integer> workList = new ArrayList();
        if (!"2".equals(glassStatus06)) {
            workList.addAll(Const.G06_WORK_STATION);
        }
        if (!"2".equals(glassStatus11)) {
            workList.addAll(Const.G11_WORK_STATION);
        }
        List<DownStorageCageDetails> list = new ArrayList();
        Boolean isEmptyShelf = Boolean.FALSE;
        //对笼内玻璃进行过滤,仅出符合逻辑的玻璃
        if (CollectionUtils.isNotEmpty(workList)) {
            List<DownWorkstation> downWorkstationList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                    .eq(DownWorkstation::getEnableState, 0).in(DownWorkstation::getWorkstationId, workList));
            log.info("架子被禁用,无法出片落架");
            if (CollectionUtils.isEmpty(downWorkstationList)) {
                log.info("笼子被禁用,无法走机械臂下片");
                //走人工下片
                if (!"2".equals(glassStatus13)) {
                    list = tempList.stream().filter(item -> item.getWidth() > maxWidth || item.getHeight() > maxHeight).collect(Collectors.toList());
                }
            } else {
                List<DownWorkstation> workstationsIsNotBind = downWorkstationList.stream().filter(item -> null == (item.getFlowCardId())).collect(Collectors.toList());
                Map<String, List<DownWorkstation>> listMap = downWorkstationList.stream().collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer()));
                if (CollectionUtils.isEmpty(workstationsIsNotBind)) {
                    log.info("不存在未绑定流程卡架子");
                    //筛选出对应架子已绑定流程卡可下片的玻璃
                    list = tempList.stream().filter(item -> listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
                } else {
                    log.info("存在未绑定流程卡架子,直接获取笼内所有玻璃");
                    isEmptyShelf = Boolean.TRUE;
                    //todo:如果禁用架子已绑定流程卡,因为时间不确定,笼子内的玻璃可重新绑定新架子
//                    list = tempList.stream().filter(item -> !listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
                    list = tempList;
                }
            }
        } else {
            //直接走人工下片
            list = tempList.stream().filter(item -> item.getWidth() > maxWidth || item.getHeight() > maxHeight).collect(Collectors.toList());
        }
        if (CollectionUtils.isEmpty(list)) {
            log.info("笼内玻璃无法执行出片");
            return Boolean.FALSE;
        }
        //定义笼内无法出片玻璃数量
        int glassCount = tempList.size() - list.size();
        String tempGlassId = null;
        Boolean isBind = Boolean.FALSE;
        for (DownStorageCageDetails item : list) {
            if (item.getWidth() > maxWidth || item.getHeight() > maxHeight) {
                log.info("玻璃宽度或高度超出阈值,执行人工下片");
                glassId = item.getGlassId();
                tempGlassId = item.getGlassId();
                break;
            }
        }
        loop:
        if (glassId == null) {
            //获取正在落架的绑定流程卡的信息
        if (tempGlassId == null) {
            //获取正在落架的绑定流程卡的信息(流程卡、层数、落架数量)
            List<DownGlassInfoDTO> downGlassInfoDTOList = downGlassInfoService.queryWorkStationIsIn(Boolean.TRUE);
            List<String> downGlassFlowList = downGlassInfoDTOList.stream().map(item -> item.getFlowCardId() + ":" + item.getLayer()).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(downGlassFlowList)) {
                //获取架子玻璃都为空,出笼内子数量最多尺寸最大的玻璃
                //架子玻璃都为空,出笼内子数量最多尺寸最大的玻璃
                DownStorageCageDetails downStorageCageDetails = downStorageCageDetailsService.getGlassInfoMaxCount();
                //绑定流程卡,更新玻璃状态,生成出片任务,
                glassId = downStorageCageDetails.getGlassId();
                tempGlassId = downStorageCageDetails.getGlassId();
                isBind = Boolean.TRUE;
                break loop;
            }
@@ -234,19 +293,19 @@
            List<DownStorageCageDetails> noDownLoadList = list.stream().filter(item -> !downGlassFlowList.contains(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(noDownLoadList)) {
                //是否有空架子
                List<DownWorkstation> emptyShelfList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                        .isNull(DownWorkstation::getFlowCardId));
                if (CollectionUtils.isNotEmpty(emptyShelfList)) {
//                List<DownWorkstation> emptyShelfList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
//                        .isNull(DownWorkstation::getFlowCardId));
                if (isEmptyShelf) {
                    DownStorageCageDetails downStorageCageDetails = downStorageCageDetailsService.getGlassInfoMaxCount();
                    //绑定流程卡,更新玻璃状态,生成出片任务
                    glassId = downStorageCageDetails.getGlassId();
                    tempGlassId = downStorageCageDetails.getGlassId();
                    isBind = Boolean.TRUE;
                    break loop;
                }
                glassCount = noDownLoadList.size();
                if (glassCount > threshold) {
                    //更新玻璃状态,生成出片人工下片任务
                    glassId = noDownLoadList.get(0).getGlassId();
                    tempGlassId = noDownLoadList.get(0).getGlassId();
                    isBind = Boolean.FALSE;
                    break loop;
                }
@@ -271,7 +330,7 @@
                    if (downGlassInfoDTO.getLayer().equals(downGlassInfoDTO.getLayer())) {
                        log.info("当前玻璃的流程在架子上落架最多,直接出片");
                        //更新玻璃状态,生成出片任务
                        glassId = noDownLoadList.get(0).getGlassId();
                        tempGlassId = noDownLoadList.get(0).getGlassId();
                        isBind = Boolean.FALSE;
                        break loop;
                    }
@@ -283,14 +342,14 @@
                    if (null != downGlassInfoDTO && downGlassInfo.getWidth().equals(item.getWidth()) && downGlassInfo.getHeight().equals(item.getHeight())) {
                        log.info("相同次序玻璃对应上,可执行进片任务");
                        //更新玻璃状态,生成出片任务
                        glassId = noDownLoadList.get(0).getGlassId();
                        tempGlassId = noDownLoadList.get(0).getGlassId();
                        isBind = Boolean.FALSE;
                        break loop;
                    } else {
                        log.info("同次序玻璃对应不上,需执行替换玻璃的操作");
                        glassCount += 1;
                        if (glassCount > threshold) {
                            glassId = noDownLoadList.get(0).getGlassId();
                            tempGlassId = noDownLoadList.get(0).getGlassId();
                            isBind = Boolean.FALSE;
                            break loop;
                        }
@@ -301,13 +360,13 @@
            Map<String, List<DownStorageCageDetails>> singleLayerMap = list.stream().filter(item -> item.getTotalLayer() == 1)
                    .collect(Collectors.groupingBy(item -> item.getFlowCardId() + item.getLayer(), Collectors.toList()));
            if (glassId == null) {
            if (tempGlassId == null) {
                if (CollectionUtils.isNotEmpty(singleLayerMap)) {
                    //获取已落架流程卡信息,按落架数量排序
                    for (DownGlassInfoDTO e : downGlassInfoDTOList) {
                        List<DownStorageCageDetails> downStorageCageDetails = singleLayerMap.get(e.getFlowCardId() + e.getLayer());
                        if (CollectionUtils.isNotEmpty(downStorageCageDetails)) {
                            glassId = downStorageCageDetails.get(0).getGlassId();
                            tempGlassId = downStorageCageDetails.get(0).getGlassId();
                            isBind = Boolean.FALSE;
                            break;
                        }
@@ -315,12 +374,12 @@
                }
            }
        }
        if (glassId == null) {
        if (tempGlassId == null) {
            log.info("没有找到可以下片的的玻璃,结束任务");
            return Boolean.FALSE;
        } else {
            //todo:按照出片的玻璃id更新笼内的玻璃状态为已出片
            return generateDownGlassOutTask(glassId, Const.GLASS_CACHE_TYPE_OUT, isBind);
            //按照出片的玻璃id更新笼内的玻璃状态为已出片
            return generateDownGlassOutTask(tempGlassId, Const.GLASS_CACHE_TYPE_OUT, isBind);
        }
    }
@@ -360,7 +419,7 @@
        //按玻璃id获取玻璃信息
        DownStorageCageDetails downStorageCageDetails = downStorageCageDetailsService.getOne(new LambdaQueryWrapper<DownStorageCageDetails>()
                .eq(DownStorageCageDetails::getGlassId, glassId));
        String endCell = null;
        Integer endCell = null;
        if (isBind) {
            //获取空架子信息,将空架子信息绑定流程卡
            DownWorkstation emptyDownWorkstation = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>()
@@ -370,7 +429,7 @@
                emptyDownWorkstation.setFlowCardId(downStorageCageDetails.getFlowCardId());
                emptyDownWorkstation.setLayer(downStorageCageDetails.getLayer());
                downWorkstationService.updateById(emptyDownWorkstation);
                endCell = emptyDownWorkstation.getWorkstationId() + "";
                endCell = emptyDownWorkstation.getWorkstationId();
            } else {
                log.info("没有空架子信息,无法绑定流程卡");
                return Boolean.FALSE;
@@ -378,7 +437,7 @@
        } else {
            DownWorkstation workstation = downWorkstationService.getOne(new LambdaUpdateWrapper<DownWorkstation>()
                    .eq(DownWorkstation::getFlowCardId, downStorageCageDetails.getFlowCardId()).eq(DownWorkstation::getLayer, downStorageCageDetails.getLayer()));
            endCell = workstation.getWorkstationId() + "";
            endCell = workstation.getWorkstationId();
        }
        //更新详情表内的状态
        if (downStorageCageDetailsService.update(new LambdaUpdateWrapper<DownStorageCageDetails>()
@@ -391,10 +450,10 @@
        //生成任务信息
        GlassInfo glassInfo = new GlassInfo();
        BeanUtils.copyProperties(downStorageCageDetails, glassInfo);
        return initDownGlassTask(glassInfo, downStorageCageDetails.getSlot() + "", endCell, taskType);
        return initDownGlassTask(glassInfo, downStorageCageDetails.getSlot(), endCell, taskType);
    }
    private Boolean initDownGlassTask(GlassInfo glassInfo, String startCell, String endCell, Integer taskType) {
    private Boolean initDownGlassTask(GlassInfo glassInfo, Integer startCell, Integer endCell, Integer taskType) {
        log.info("玻璃{}生成进片任务", glassInfo.getGlassId());
        DownGlassTask downGlassTask = new DownGlassTask();
        BeanUtils.copyProperties(glassInfo, downGlassTask);