ZengTao
2025-09-11 61cae17b15d6a7d256e25ce42f0a4ef4163fd088
hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/job/DownLoadCacheGlassTask.java
@@ -36,6 +36,7 @@
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * @Author : zhoush
@@ -94,6 +95,15 @@
        String confirmationWrodAddress = plcParameterObject.getPlcParameter("confirmationWord").getAddress();
        String currentSlot = plcParameterObject.getPlcParameter("currentCell").getValue();
        requestWord = "2";
        glassIdeValue = "";
        out06Glassstate = "1";
        out08Glassstate = "1";
        out11Glassstate = "1";
        out13Glassstate = "1";
        currentSlot = "1";
        confirmationWrodValue = "0";
        log.info("1、获取到的请求字为:{},获取到的扫描ID为:{},获取到的确认字为:{},获取到的出片状态分别为:g06:{}、g08:{}、g11:{}、g13:{},当前格子号为:{}",
                requestWord, glassIdeValue, confirmationWrodValue, out06Glassstate, out08Glassstate, out11Glassstate, out13Glassstate, currentSlot);
@@ -135,7 +145,7 @@
        PlcParameterObject plcMesObject = S7object.getinstance().PlcMesObject;
        if (CollectionUtils.isNotEmpty(list)) {
            s7control.writeWord(plcMesObject.getPlcParameter("alarm_signal").getAddress(), 1);
        }else{
        } else {
            s7control.writeWord(plcMesObject.getPlcParameter("alarm_signal").getAddress(), 0);
        }
    }
@@ -156,7 +166,7 @@
            //下片数量-1
            for (DownGlassTask downGlassTask : downGlassTaskList
            ) {
                if (Const.GLASS_CACHE_TYPE_OUT_ALL.equals(downGlassTask.getTaskType())) {
                if (Const.GLASS_CACHE_TYPE_OUT_ALL.contains(downGlassTask.getTaskType())) {
                    downWorkstationService.update(
                            new LambdaUpdateWrapper<DownWorkstation>()
                                    .setSql("racks_number = racks_number-1")
@@ -171,7 +181,7 @@
                damage.setLine(Const.TEMPERING_OUT_TARGET_POSITION);
                damage.setWorkingProcedure("下片");
                damage.setRemark("下片");
                damage.setStatus(0);
                damage.setStatus(1);
                damage.setType(e.getTaskStatus());
                return damage;
            }).collect(Collectors.toList());
@@ -197,7 +207,10 @@
            //更新工位其他玻璃信息的数量
            QueryWrapper<Damage> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("process_id", downWorkstation.getFlowCardId());
            queryWrapper.eq("technology_number", downWorkstation.getLayer());
            queryWrapper.gt("type", 3);
            if (downWorkstation.getLayer() != 0) {
                queryWrapper.eq("technology_number", downWorkstation.getLayer());
            }
            int otherNumber = damageService.count(queryWrapper);
            downWorkstationService.update(new LambdaUpdateWrapper<DownWorkstation>().set(DownWorkstation::getOtherNumber, otherNumber)
                    .eq(DownWorkstation::getWorkstationId, downWorkstation.getWorkstationId()));
@@ -224,6 +237,7 @@
        //玻璃尺寸是否走人工下片
        if (glassWidth > maxWidth || glassHeight > maxHeight || glassWidth < minWidth || glassHeight < minHeight) {
            log.info("该玻璃尺寸不符合要求,需要走人工下片直接进片");
            return;
        } else {
            log.info("该玻璃尺寸非人工下片");
            //获取该玻璃的流程卡是否已绑定架子
@@ -272,7 +286,8 @@
                    for (DownGlassInfoDTO e : downGlassInfoDTOList) {
                        List<GlassInfo> glassInfoList = e.getGlassInfoList();
                        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());
                                && item.getThickness() == glassInfo.getThickness() && item.getMarkIcon().equals(glassInfo.getMarkIcon())
                                && item.getFilmsid().equals(glassInfo.getFilmsid())).collect(Collectors.toList());
                        if (CollectionUtils.isNotEmpty(glassInfoTempList)) {
                            for (GlassInfo item : glassInfoTempList) {
                                //玻璃是否为多层:1、先获取当前流程卡落架最多的层数,如果为空,表明未绑定流程卡,未落架,然后按照是否可绑定架子决定是否替换。(可忽略不计,本校验仅在前一次调用起作用)
@@ -348,6 +363,145 @@
            log.info("笼内没有玻璃,无法执行出片");
            return Boolean.FALSE;
        }
//        //获取最小工程与炉数
//        Map<String, List<DownStorageCageDetails>> groupedMap = tempList.stream()
//                .collect(Collectors.groupingBy(item -> item.getEngineerId() + "_" + item.getTemperingLayoutId()));
//        // 获取第一个 先进卧理那一炉的信息
//        List<DownStorageCageDetails> cageList =
//                new ArrayList<>(groupedMap.values().stream().findFirst().orElse(Collections.emptyList()));
//
//        if (groupedMap.size() > 1) {
//            //按流程卡进行分组
//            Map<String, List<DownStorageCageDetails>> getFlowCardIds = cageList.stream()
//                    .collect(Collectors.groupingBy(item -> item.getFlowCardId() + "_" + item.getLayer()));
//            // 按 短边 降序,长边 降序,炉内片序 降序
//            getFlowCardIds.forEach((key, list) -> {
//                list.sort(Comparator.comparingDouble((DownStorageCageDetails item) -> Math.min(item.getWidth(), item.getHeight()))
//                        .reversed()
//                        .thenComparingDouble(item -> Math.max(item.getWidth(), item.getHeight()))
//                        .reversed()
//                        .thenComparingInt(item -> item.getTemperingFeedSequence()));
//            });
//            //获取每个流程卡出片优先级最高的玻璃
//            tempList = getFlowCardIds.values().stream()
//                    .map(list -> list.isEmpty() ? null : list.get(0))
//                    .filter(Objects::nonNull)
//                    .collect(Collectors.toList());
//        } else {
//            //笼内加扫码位玻璃id
//            List<String> cageGlassIds = cageList.stream()
//                    .map(DownStorageCageDetails::getGlassId)
//                    .collect(Collectors.toList());
//            //获取破损拿走的玻璃并过滤调已经在笼内的,防止乱报破损
//            List<Damage> damageList = damageService.list(
//                    new LambdaQueryWrapper<Damage>()
//                            .eq(Damage::getEngineerId, cageList.get(0).getEngineerId())
//                            .eq(Damage::getTemperingLayoutId, cageList.get(0).getTemperingLayoutId())
//                            .and(item -> item.eq(Damage::getType, 8).or().eq(Damage::getType, 9))
//                            .lt(Damage::getStatus, 4)
//                            .notIn(Damage::getGlassId, cageGlassIds)
//            );
//            //获取破损/拿走玻璃id
//            List<String> damageGlassIds = damageList.stream()
//                    .map(Damage::getGlassId)
//                    .collect(Collectors.toList());
//            //获取已出片玻璃信息
//            List<DownStorageCageDetails> downStorageCageDetails = downStorageCageDetailsService.list(
//                    new LambdaQueryWrapper<DownStorageCageDetails>()
//                            .eq(DownStorageCageDetails::getEngineerId, cageList.get(0).getEngineerId())
//                            .eq(DownStorageCageDetails::getTemperingLayoutId, cageList.get(0).getTemperingLayoutId())
//            );
//            //获取已出片玻璃id
//            List<String> downGlassIds = downStorageCageDetails.stream()
//                    .map(DownStorageCageDetails::getGlassId)
//                    .collect(Collectors.toList());
//            //获取所有未下片的玻璃信息
//            List<GlassInfo> glassInfoList = glassInfoService.list(
//                    new LambdaQueryWrapper<GlassInfo>()
//                            .eq(GlassInfo::getEngineerId, cageList.get(0).getEngineerId())
//                            .eq(GlassInfo::getTemperingLayoutId, cageList.get(0).getTemperingLayoutId())
//                            .notIn(CollectionUtils.isNotEmpty(damageGlassIds), GlassInfo::getGlassId, damageGlassIds)
//                            .notIn(CollectionUtils.isNotEmpty(downGlassIds), GlassInfo::getGlassId, downGlassIds)
//            );
//            //按流程卡进行分组
//            Map<String, List<GlassInfo>> getFlowCardIds = glassInfoList.stream()
//                    .collect(Collectors.groupingBy(item -> item.getFlowCardId() + "_" + item.getLayer()));
//            // 按 短边 降序,长边 降序,炉内片序 降序
//            getFlowCardIds.forEach((key, list) -> {
//                list.sort(Comparator.comparingDouble((GlassInfo item) -> Math.min(item.getWidth(), item.getHeight()))
//                        .reversed()
//                        .thenComparingDouble(item -> Math.max(item.getWidth(), item.getHeight()))
//                        .reversed()
//                        .thenComparingInt(item -> item.getTemperingFeedSequence()));
//            });
//            //获取一炉所有未出片流程卡优先级最高的玻璃
//            List<GlassInfo> glassInfos = getFlowCardIds.values().stream()
//                    .map(list -> list.isEmpty() ? null : list.get(0))
//                    .filter(Objects::nonNull)
//                    .collect(Collectors.toList());
//            //获取一炉所有未出片流程卡优先级最高的玻璃id
//            List<String> noOutGlassIds = glassInfos.stream()
//                    .map(GlassInfo::getGlassId)
//                    .collect(Collectors.toList());
//            //获取匹配的玻璃信息
//            List<DownStorageCageDetails> filteredList = tempList.stream()
//                    .filter(item -> noOutGlassIds.contains(item.getGlassId()))
//                    .collect(Collectors.toList());
//            if (CollectionUtils.isNotEmpty(filteredList)) {
//                tempList = filteredList;
//            } else {
//                //是否满笼
//                if (tempList.size() == 9) {
//                    // 结果列表
//                    List<DownStorageCageDetails> resultList = new ArrayList<>();
//
//                    // 将 glassInfos 转换成 Map,以 flowCardId_layer 作为 key
//                    Map<String, GlassInfo> glassInfoMap = glassInfos.stream()
//                            .collect(Collectors.toMap(
//                                    item -> item.getFlowCardId() + "_" + item.getLayer(),
//                                    item -> item
//                            ));
//
//                    // 按 flowCardId 和 layer 进行分组
//                    Map<String, List<DownStorageCageDetails>> groupedByFlowCardLayer = tempList.stream()
//                            .collect(Collectors.groupingBy(item -> item.getFlowCardId() + "_" + item.getLayer()));
//
//                    // 遍历分组,找出每一组中误差最小的 DownStorageCageDetails
//                    for (Map.Entry<String, List<DownStorageCageDetails>> entry : groupedByFlowCardLayer.entrySet()) {
//                        String key = entry.getKey();
//                        List<DownStorageCageDetails> groupList = entry.getValue();
//
//                        // 只有当 glassInfoMap 里有相应的 key 时,才计算最接近的匹配项
//                        if (glassInfoMap.containsKey(key)) {
//                            GlassInfo glassInfo = glassInfoMap.get(key);
//                            double glassShortEdge = Math.min(glassInfo.getWidth(), glassInfo.getHeight());
//                            double glassLongEdge = Math.max(glassInfo.getWidth(), glassInfo.getHeight());
//
//                            // 找到误差最小的 DownStorageCageDetails
//                            Optional<DownStorageCageDetails> bestMatch = groupList.stream()
//                                    .min(Comparator.comparingDouble(item -> {
//                                        double itemShortEdge = Math.min(item.getWidth(), item.getHeight());
//                                        double itemLongEdge = Math.max(item.getWidth(), item.getHeight());
//
//                                        // 先比较短边误差
//                                        double shortEdgeDiff = Math.abs(itemShortEdge - glassShortEdge);
//                                        // 再比较长边误差(仅当短边误差相同时)
//                                        double longEdgeDiff = Math.abs(itemLongEdge - glassLongEdge);
//
//                                        return shortEdgeDiff * 1000 + longEdgeDiff; // 让短边误差优先级更高
//                                    }));
//
//                            bestMatch.ifPresent(resultList::add);
//                        }
//                    }
//                    tempList = resultList;
//                } else {
//                    return Boolean.FALSE;
//                }
//            }
//        }
        //优先走08片台的玻璃:走人工下片或者2号机械臂
        //1、08台忙碌,仅走1号机械臂
        //2、08台空闲,先走扔工下片或2号机械臂,无玻璃出片 在走1号机械臂
@@ -673,22 +827,28 @@
            wrapper.eq(DownGlassInfo::getLayer, downGlassInfo.getLayer());
        }
//        downGlassInfo.setSequence(downGlassInfoService.queryMaxSequence(downGlassInfo.getFlowCardId(), downGlassInfo.getLayer()));
        int k = 0;
        DownGlassInfo downGlassInfo1 = downGlassInfoService.getOne(wrapper);
        if (downGlassInfo1 != null) {
            k = 1;
        } else {
            k = 1;
        }
        int k = 1;
//        DownGlassInfo downGlassInfo1 = downGlassInfoService.getOne(wrapper);
//        if (downGlassInfo1 != null) {
//            k = 1;
//        } else {
//            k = 1;
//        }
        GlassInfo glassInfo = new GlassInfo();
        BeanUtils.copyProperties(downStorageCageDetails, glassInfo);
        GlassInfo glassInfo1 = glassInfoService.getOne(
                new LambdaUpdateWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassInfo.getGlassId())
        );
        downGlassInfo.setSequence(k);
        downGlassInfo.setWorkStationId(endCell);
        downGlassInfo.setGmtCreate(new Date());
        downGlassInfo.setLayer(glassInfo1.getLayer());
        downGlassInfoService.save(downGlassInfo);
        //生成任务信息
        GlassInfo glassInfo = new GlassInfo();
        downStorageCageDetails.setLayer(0);
        BeanUtils.copyProperties(downStorageCageDetails, glassInfo);
        //删除理片笼表拿走/破损数据数据
        glassInfo.setLayer(glassInfo1.getLayer());
        damageService.deleteByGlassId(glassInfo.getGlassId());
        return initDownGlassTask(glassInfo, downStorageCageDetails.getSlot(), endCell, taskType);
    }
@@ -708,7 +868,7 @@
        downGlassTask.setCreateTime(new Date());
        downGlassTaskService.save(downGlassTask);
        //添加报工数据
        Damage damage=new Damage();
        Damage damage = new Damage();
        damage.setGlassId(glassInfo.getGlassId());
        damage.setWorkingProcedure("钢化");
        damage.setLine(4001);