hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java
@@ -134,13 +134,15 @@
        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());
        double glassWidth = Math.max(glassInfo.getWidth(), glassInfo.getHeight());
        double glassHeight = Math.min(glassInfo.getWidth(), glassInfo.getHeight());
        if ("1".equals(requestWord) && (glassWidth > throughWidth || glassHeight > throughHeight)) {
            log.info("玻璃当前尺寸宽:{},高:{}只能直通,当前进片任务需等待", glassWidth, glassHeight);
            return;
        }
        Boolean checkFlag = Boolean.FALSE;
        //玻璃尺寸是否走人工下片
        if (glassInfo.getWidth() > maxWidth || glassInfo.getHeight() > maxHeight || glassInfo.getWidth() < minWidth || glassInfo.getHeight() < minHeight) {
        if (glassWidth > maxWidth || glassHeight > maxHeight || glassWidth < minWidth || glassHeight < minHeight) {
            log.info("该玻璃尺寸不符合要求,需要走人工下片直接进片");
        } else {
            log.info("该玻璃尺寸非人工下片");
@@ -148,6 +150,7 @@
            DownWorkstation one = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>()
                    .eq(DownWorkstation::getLayer, glassInfo.getLayer())
                    .eq(DownWorkstation::getFlowCardId, glassInfo.getFlowCardId()));
            //是否已经绑定   true:已绑定    false:未绑定
            Boolean isBind = Boolean.FALSE;
            if (null != one) {
                log.info("该流程卡已绑定架子");
@@ -157,7 +160,7 @@
            if (!checkFlag && !isBind) {
                log.info("该玻璃的流程卡未绑定架子,获取是否有空架子");
                List<DownWorkstation> list = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                        .isNull(DownWorkstation::getFlowCardId).orderByDesc(DownWorkstation::getWorkstationId));
                        .and(on -> on.isNull(DownWorkstation::getFlowCardId).or().eq(DownWorkstation::getFlowCardId, "")).orderByDesc(DownWorkstation::getWorkstationId));
                if (CollectionUtils.isNotEmpty(list)) {
                    log.info("有空架子,将流程卡与架子好绑定,执行进片任务 结束");
                    //绑定流程卡
@@ -176,28 +179,31 @@
                    endLoop:
                    for (DownGlassInfoDTO e : downGlassInfoDTOList) {
                        List<GlassInfo> glassInfoList = e.getGlassInfoList();
                        Optional<GlassInfo> glassInfoTempOptional = glassInfoList.stream().filter(item -> item.getWidth() == glassInfo.getWidth() && item.getHeight() == glassInfo.getHeight()
                                && item.getThickness() == glassInfo.getThickness() && item.getFilmsid().equals(glassInfo.getFilmsid()))
                                .findFirst();
                        if (glassInfoTempOptional.isPresent()) {
                            GlassInfo item = glassInfoTempOptional.get();
                            //玻璃是否为多层
                            checkFlag = multilayerCheck(item, Boolean.FALSE);
                            if (checkFlag) {
                                //玻璃替换 仅替换流程卡id及层数
                                String tempFlowCardId = item.getFlowCardId();
                                Integer tempLayer = item.getLayer();
                                String flowCardId = glassInfo.getFlowCardId();
                                Integer layer = glassInfo.getLayer();
                                log.info("替换流程卡信息,当前玻璃信息:{}的流程卡号{}及层数{},替换后玻璃信息:{}的流程卡号{}及层数{}",
                                        item, glassInfo, flowCardId, layer, tempFlowCardId, tempLayer);
                                glassInfo.setFlowCardId(tempFlowCardId);
                                glassInfo.setLayer(tempLayer);
                                glassInfoService.updateById(glassInfo);
                                item.setFlowCardId(flowCardId);
                                item.setLayer(layer);
                                glassInfoService.updateById(item);
                                break endLoop;
                        List<GlassInfo> glassInfoTempList = glassInfoList.stream().filter(item -> item.getWidth() == glassInfo.getWidth() && item.getHeight() == glassInfo.getHeight()
                                && item.getThickness() == glassInfo.getThickness() && item.getFilmsid().equals(glassInfo.getFilmsid())).collect(Collectors.toList());
                        if (CollectionUtils.isNotEmpty(glassInfoTempList)) {
                            for (GlassInfo item : glassInfoTempList) {
                                //玻璃是否为多层:1、先获取当前流程卡落架最多的层数,如果为空,表明未绑定流程卡,未落架,然后按照是否可绑定架子决定是否替换。(可忽略不计,本校验仅在前一次调用起作用)
//                                          2、判断落架最多的层数是否为当前替换玻璃的层数,是  则走替换逻辑返回true
//                                          3、不是最多的层数,获取落架最多层数的相同次序的玻璃尺寸与当前替换玻璃的尺寸比较,相同走替换,否则继续循环
//                                          4、单层玻璃直接走替换
                                checkFlag = multilayerCheck(item, Boolean.FALSE);
                                if (checkFlag) {
                                    //玻璃替换 仅替换流程卡id及层数
                                    String tempFlowCardId = item.getFlowCardId();
                                    Integer tempLayer = item.getLayer();
                                    String flowCardId = glassInfo.getFlowCardId();
                                    Integer layer = glassInfo.getLayer();
                                    log.info("替换流程卡信息,当前玻璃信息:{}的流程卡号{}及层数{},替换后玻璃信息:{}的流程卡号{}及层数{}",
                                            item, glassInfo, flowCardId, layer, tempFlowCardId, tempLayer);
                                    glassInfo.setFlowCardId(tempFlowCardId);
                                    glassInfo.setLayer(tempLayer);
                                    glassInfoService.updateById(glassInfo);
                                    item.setFlowCardId(flowCardId);
                                    item.setLayer(layer);
                                    glassInfoService.updateById(item);
                                    break endLoop;
                                }
                            }
                        }
                    }
@@ -210,7 +216,6 @@
        downStorageCageDetails.setState(Const.GLASS_STATE_IN);
        downStorageCageDetails.setSlot(nearestEmpty.getSlot());
        downStorageCageDetailsService.save(downStorageCageDetails);
        //        生成进片任务
        initDownGlassTask(glassInfo, 0, nearestEmpty.getSlot(), Const.GLASS_CACHE_TYPE_IN);
    }
@@ -221,9 +226,9 @@
            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("出片1、笼内的玻璃信息有:{}", tempList);
        //获取待进片玻璃
        DownStorageCageDetails cageDetails = new DownStorageCageDetails();
        if (StringUtils.isNotBlank(glassId)) {
@@ -234,12 +239,15 @@
            cageDetails.setSlot(empty.getSlot());
            tempList.add(cageDetails);
        }
        log.info("笼内玻璃的数据有:{}", tempList);
        log.info("出片2:笼内玻璃的数据(包括待进片)有:{}", tempList);
        if (CollectionUtils.isEmpty(tempList)) {
            log.info("笼内没有玻璃,无法执行出片");
            return Boolean.FALSE;
        }
        //优先走08片台的玻璃:走人工下片或者2号机械臂
        //1、08台忙碌,仅走1号机械臂
        //2、08台空闲,先走扔工下片或2号机械臂,无玻璃出片 在走1号机械臂
        //机械臂被禁用的情况下不能继续向禁用的机械臂放玻璃
        Boolean flag08 = "1".equals(out08Glassstate) ? Boolean.TRUE : Boolean.FALSE;
        if (!flag08) {
            generateTaskByShelf(glassStatus06, glassStatus11, flag08, glassStatus13, tempList, cageDetails, glassId);
@@ -248,7 +256,6 @@
                return generateTaskByShelf(glassStatus06, glassStatus11, !flag08, glassStatus13, tempList, cageDetails, glassId);
            }
        }
        return Boolean.TRUE;
    }
@@ -264,7 +271,6 @@
                    log.info("架子已经占满,多层玻璃无法找到对应的格子,需执行替换玻璃的操作");
                    return Boolean.FALSE;
                }
            }
            if (downGlassInfoDTO.getLayer().equals(glassInfo.getLayer())) {
                log.info("当前玻璃的流程在架子上落架最多 直接进片");
@@ -293,7 +299,6 @@
            glassStatus13, List<DownStorageCageDetails> tempList, DownStorageCageDetails cageDetails, String glassId) {
        //获取2个机械臂范围内的架子绑定的流程卡信息
        List<Integer> workList = new ArrayList();
        if (flag08) {
            if (!"2".equals(glassStatus11)) {
                workList.addAll(Const.G11_WORK_STATION);
@@ -306,51 +311,59 @@
        List<Integer> workStationAll = Arrays.asList(1, 2, 3, 4, 5, 6);
        List<Integer> offWorkStationList = workStationAll.stream().filter(e -> !workList.contains(e)).collect(Collectors.toList());
        List<DownStorageCageDetails> list = new ArrayList();
        //是否有空架子 true:有   false:无
        Boolean isEmptyShelf = Boolean.FALSE;
        //对笼内玻璃进行过滤,仅出符合逻辑的玻璃
        if (CollectionUtils.isNotEmpty(workList)) {
            List<DownWorkstation> downWorkstationList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                    .eq(DownWorkstation::getEnableState, Const.SLOT_ON).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());
                if (flag08 && !"2".equals(glassStatus13)) {
                    list = tempList.stream().filter(item -> {
                        double firstLength = Math.max(item.getWidth(), item.getHeight());
                        double secondLength = Math.min(item.getWidth(), item.getHeight());
                        return firstLength > maxWidth || secondLength > maxHeight;
                    }).collect(Collectors.toList());
                }
            } else {
                //获取可落架的的架子信息(包括空架子)
                List<DownWorkstation> workstationsIsNotBind = downWorkstationList.stream().filter(item -> null == (item.getFlowCardId())).collect(Collectors.toList());
                //将架子的流程卡号及层数作为key
                //仅获取空架子信息
                List<DownWorkstation> workstationsIsNotBind = downWorkstationList.stream().filter(item -> StringUtils.isBlank(item.getFlowCardId())).collect(Collectors.toList());
                //将架子的流程卡号及层数作为key  不存在空架子的情况
                if (CollectionUtils.isEmpty(workstationsIsNotBind)) {
                    log.info("不存在未绑定流程卡架子");
                    //筛选出对应架子已绑定流程卡可下片的玻璃
                    Map<String, List<DownWorkstation>> listMap = downWorkstationList.stream()
                            .filter(item -> null != (item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer()));
                            .filter(item -> StringUtils.isNotBlank(item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer()));
                    //过滤筛选获取架子上对应流程卡+层数的笼子内的玻璃信息
                    list = tempList.stream().filter(item -> listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
                } else {
                    log.info("存在未绑定流程卡架子,直接获取笼内所有玻璃,且未绑定架子的玻璃信息");
                    //获取禁用架子的流程号,将笼内绑定架子且架子被禁用的流程卡信息
                    //获取禁用及非本机械臂的架子的流程号及层数对应的玻璃信息
                    List<DownWorkstation> downWorkstationOffList = downWorkstationService.list(new LambdaQueryWrapper<DownWorkstation>()
                            .and(i -> i.in(DownWorkstation::getWorkstationId, offWorkStationList).or().eq(DownWorkstation::getEnableState, Const.SLOT_OFF)));
                    //获取被禁用的流程卡信息
                    //获取被禁用的流程卡信息 为空:将返回笼内的所有玻璃信息
                    if (CollectionUtils.isEmpty(downWorkstationOffList)) {
                        list = tempList;
                    } else {
                        Map<String, List<DownWorkstation>> listOffMap = downWorkstationOffList.stream().filter(item -> null != (item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer()));
                        //笼内存在无法出片的玻璃信息,过滤无法出片的玻璃信息,仅获取可出片的玻璃信息   无法出片的玻璃为:未绑定架子、绑定架子被禁用、非本机械臂对应的架子
                        Map<String, List<DownWorkstation>> listOffMap = downWorkstationOffList.stream().filter(item -> StringUtils.isNotBlank(item.getFlowCardId())).collect(Collectors.groupingBy(item -> item.getFlowCardId() + ":" + item.getLayer()));
                        list = tempList.stream().filter(item -> !listOffMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
                    }
                    //空架子表示置为true
                    isEmptyShelf = Boolean.TRUE;
                    //todo:如果禁用架子已绑定流程卡,因为时间不确定,笼子内的玻璃可重新绑定新架子
//                    list = tempList.stream().filter(item -> !listMap.containsKey(item.getFlowCardId() + ":" + item.getLayer())).collect(Collectors.toList());
                }
            }
        } else {
            if (flag08 && !"2".equals(glassStatus13)) {
                //直接走人工下片
                list = tempList.stream().filter(item -> item.getWidth() > maxWidth || item.getHeight() > maxHeight).collect(Collectors.toList());
                list = tempList.stream().filter(item -> {
                    double firstLength = Math.max(item.getWidth(), item.getHeight());
                    double secondLength = Math.min(item.getWidth(), item.getHeight());
                    return firstLength > maxWidth || secondLength > maxHeight;
                }).collect(Collectors.toList());
            }
        }
        if (CollectionUtils.isEmpty(list)) {
@@ -358,10 +371,12 @@
            return Boolean.FALSE;
        }
        String tempGlassId = null;
        Boolean isBind = Boolean.FALSE;
        Boolean isNeedBind = Boolean.FALSE;
        for (DownStorageCageDetails item : list) {
            if (item.getWidth() > maxWidth || item.getHeight() > maxHeight) {
            double firstLength = Math.max(item.getWidth(), item.getHeight());
            double secondLength = Math.min(item.getWidth(), item.getHeight());
            if (firstLength > maxWidth || secondLength > maxHeight) {
                if (flag08 && !"2".equals(glassStatus13)) {
                    log.info("玻璃宽度或高度超出阈值,执行人工下片");
                    tempGlassId = item.getGlassId();
@@ -378,7 +393,7 @@
                //架子都未绑定流程卡,出笼内子数量最多尺寸最大的玻璃id,无  则返回扫描扫到的玻璃id进行出片
                tempGlassId = downStorageCageDetailsService.getGlassInfoMaxCount(glassId, offWorkStationList);
                isBind = Boolean.TRUE;
                isNeedBind = Boolean.TRUE;
                break loop;
            }
            //将笼子内的玻璃进行过滤,仅获取无法落架的流程卡玻璃
@@ -391,7 +406,7 @@
                if (isEmptyShelf) {
                    //架子都未绑定流程卡,出笼内子数量最多尺寸最大的玻璃id,无  则返回扫描扫到的玻璃id进行出片
                    tempGlassId = downStorageCageDetailsService.getGlassInfoMaxCount(glassId, offWorkStationList);
                    isBind = Boolean.TRUE;
                    isNeedBind = Boolean.TRUE;
                    break loop;
                }
            }
@@ -409,16 +424,13 @@
                    DownGlassInfoDTO downGlassInfoDTO = downGlassInfoService.queryDownGlassMaxLayer(item.getFlowCardId());
                    if (null == downGlassInfoDTO) {
//                    历史落架玻璃按照相关流程卡取数据库未找到最多玻璃信息,表明当前流程卡下的有层的玻璃均未落架,直接可出当前玻璃
                        log.info("");
                        isBind = Boolean.FALSE;
                        tempGlassId = item.getGlassId();
                        log.info("当前流程卡不存在落架的玻璃,可直接出片落架,玻璃id:{}", tempGlassId);
                        break loop;
                    }
                    if (downGlassInfoDTO.getLayer().equals(downGlassInfoDTO.getLayer())) {
                        log.info("当前玻璃的流程在架子上落架最多,直接出片");
                        //更新玻璃状态,生成出片任务
                        tempGlassId = item.getGlassId();
                        isBind = Boolean.FALSE;
                        log.info("当前玻璃的流程在架子上落架最多,直接出片,玻璃id:{}", tempGlassId);
                        break loop;
                    }
                    Integer sequence = downGlassInfoService.queryMaxSequence(item.getFlowCardId(), item.getLayer());
@@ -427,10 +439,8 @@
                            .eq(DownGlassInfo::getFlowCardId, downGlassInfoDTO.getFlowCardId())
                            .eq(DownGlassInfo::getLayer, downGlassInfoDTO.getLayer()).eq(DownGlassInfo::getSequence, sequence));
                    if (null != downGlassInfoDTO && downGlassInfo.getWidth() == item.getWidth() && downGlassInfo.getHeight() == item.getHeight()) {
                        log.info("相同次序玻璃对应上,可执行进片任务");
                        //更新玻璃状态,生成出片任务
                        tempGlassId = item.getGlassId();
                        isBind = Boolean.FALSE;
                        log.info("相同次序玻璃对应上,可执行进片任务,玻璃id:{}", tempGlassId);
                        break loop;
                    }
                }
@@ -445,7 +455,6 @@
                        List<DownStorageCageDetails> downStorageCageDetails = singleLayerMap.get(e.getFlowCardId() + e.getLayer());
                        if (CollectionUtils.isNotEmpty(downStorageCageDetails)) {
                            tempGlassId = downStorageCageDetails.get(0).getGlassId();
                            isBind = Boolean.FALSE;
                            break;
                        }
                    }
@@ -457,12 +466,12 @@
            return Boolean.FALSE;
        } else {
            //按照出片的玻璃id更新笼内的玻璃状态为已出片
            return generateDownGlassOutTask(tempGlassId, Const.GLASS_CACHE_TYPE_OUT, isBind, cageDetails, workList);
            return generateDownGlassOutTask(tempGlassId, Const.GLASS_CACHE_TYPE_OUT, isNeedBind, cageDetails, workList);
        }
    }
    public Boolean generateDownGlassOutTask(String glassId, Integer taskType, Boolean
            isBind, DownStorageCageDetails cageDetails, List<Integer> workList) {
            isNeedBind, DownStorageCageDetails cageDetails, List<Integer> workList) {
        //按玻璃id获取玻璃信息
        DownStorageCageDetails downStorageCageDetails = null;
        if (glassId.equals(cageDetails.getGlassId())) {
@@ -486,10 +495,10 @@
        }
        Integer endCell = null;
        if (isBind) {
        if (isNeedBind) {
            //获取空架子信息,将空架子信息绑定流程卡
            DownWorkstation emptyDownWorkstation = downWorkstationService.getOne(new LambdaQueryWrapper<DownWorkstation>()
                    .isNull(DownWorkstation::getFlowCardId).in(DownWorkstation::getWorkstationId, workList).orderByDesc(DownWorkstation::getWorkstationId).last("limit 1"));
                    .and(on -> on.isNull(DownWorkstation::getFlowCardId).or().eq(DownWorkstation::getFlowCardId, "")).in(DownWorkstation::getWorkstationId, workList).orderByDesc(DownWorkstation::getWorkstationId).last("limit 1"));
            if (null != emptyDownWorkstation) {
                log.info("获取到空架子信息,绑定流程卡");
                downWorkstationService.updateFlowCardIdAndCount(downStorageCageDetails.getFlowCardId(), emptyDownWorkstation.getWorkstationId(), downStorageCageDetails.getLayer());
@@ -515,7 +524,7 @@
        //生成任务信息
        DownGlassInfo downGlassInfo = new DownGlassInfo();
        BeanUtils.copyProperties(downStorageCageDetails, downGlassInfo);
        //todo:落架片序
        //落架片序
        downGlassInfo.setSequence(downGlassInfoService.queryMaxSequence(downGlassInfo.getFlowCardId(), downGlassInfo.getLayer()));
        downGlassInfoService.save(downGlassInfo);
        //生成任务信息