chenlu
2025-10-31 9b3bd81d2531a82e5729ee8d6252b40ac0add600
north-glass-erp/src/main/java/com/example/erp/service/pp/ReportService.java
@@ -666,70 +666,166 @@
        return map;
    }
    public Map<String, Object> productionScheduleSv(String orderId, List<Integer> columns) {
    public Map<String, Object> productionScheduleSv(String orderId, List<String> columns) {
        Map<String, Object> map = new HashMap<>();
        //获取表格内容数据
        map.put("data", reportMapper.productionScheduleMp(orderId));
        List<Map<String, String>> dataList = reportMapper.productionScheduleMp(orderId);
        //获取表头工序筛选数据
        List<Map<String, String>> processFilterList = orderProcessDetailMapper.filterOrderProcess(orderId);
        List<Map<String, String>> processList = processFilterList;
        List<Map<String, String>> uniqueList = orderProcessDetailMapper.filterOrderProcess(orderId);
        List<String> filterList = new ArrayList<>();
        //循环遍历数组,判断此序号当前的工序
        for (int i = 1; i < processFilterList.size(); i++) {
            filterList.add(processFilterList.get(i).get("process"));
            List<Map<String, String>> lastProcessList =
                    orderProcessDetailMapper.filterLastProcess(
                            orderId,
                            String.valueOf(processFilterList.get(i).get("order_number")),
                            String.valueOf(processFilterList.get(i).get("technology_number")),
                            String.valueOf(processFilterList.get(i).get("id"))
                    );
            if (!lastProcessList.isEmpty()) {
                int finalI = i;
                lastProcessList.forEach(lastProcess -> {
                    if (filterList.contains(lastProcess.get("process"))) {
                        processList.add(lastProcess);
                    }
                });
            }
        }
        // 使用HashSet来记录已经遇到的value值
        Set<String> seenValues = new HashSet<>();
        // 创建一个新的List来存储结果
        List<Map<String, String>> uniqueList = new ArrayList<>();
        // 反向遍历原始List
        for (int i = processList.size() - 1; i >= 0; i--) {
            Map<String, String> maps = processList.get(i);
            String value = maps.values().iterator().next(); // 假设每个Map只有一个value
            // 如果value还没有被看到过,就添加到结果List和HashSet中
            if (!seenValues.contains(value)) {
                uniqueList.add(0, maps); // 添加到结果List的开头,以保持原顺序
                seenValues.add(value);
            }
        }
        map.put("title", uniqueList);
        Map<String,Integer> clos = new HashMap<>();
        HashMap<String,HashMap<String,Map<String, Integer>>> rowCount = new HashMap<String,HashMap<String,Map<String, Integer>>>();
        for (int i=0;i<uniqueList.size();i++){
            //根据流程查询基础数据
            BasicData basicData =  basicDataMapper.selectOne(
                    new QueryWrapper<BasicData>()
                            .eq("basic_category","process")
                            .eq("basic_name",uniqueList.get(i).get("process"))
                            .last("limit 1")
            );
            //判断夹胶和夹胶后工序
            //Objects.equals(basicData.getNickname(), "stepA") || Objects.equals(basicData.getNickname(), "stepC")
            if(Objects.equals(basicData.getNickname(), "stepA") || Objects.equals(basicData.getNickname(), "stepC")){
                clos.put(uniqueList.get(i).get("process"), 14+i);
            }
            //判断中空和中空后工序
            //Objects.equals(basicData.getNickname(), "stepB") || Objects.equals(basicData.getNickname(), "stepD")
            if(Objects.equals(basicData.getNickname(), "stepB") || Objects.equals(basicData.getNickname(), "stepD")){
                columns.add("reportWorkQuantity."+uniqueList.get(i).get("process"));
            }
        }
        List<Map<String, Object>> getRowCount = orderProcessDetailMapper.getGlassLRow(orderId);
        List<Map<String, Integer>> rowCount = new ArrayList<>();
        columns.forEach(col -> {
            getRowCount.forEach(row -> {
                Map<String, Integer> getRow = new HashMap<>();
                // { row: 0, col: 1, rowspan: 3, colspan: 0},
                getRow.put("row", ((Number) row.get("RowNum")).intValue());
                getRow.put("col", col);
                getRow.put("rowspan", ((Number) row.get("rowCount")).intValue());
                getRow.put("colspan", 0);
                rowCount.add(getRow);
            });
        HashMap<Integer,Map<String, Object>> getRowCountMap = new HashMap<>();
        getRowCount.forEach(col -> {
            Integer getRowCountOrderNumber = ((Number) col.get("order_number")).intValue();
            getRowCountMap.put(getRowCountOrderNumber, col);
        });
        //循环结果
        for (int i=0;i<dataList.size();i++ ) {
            Integer orderNumber = Integer.parseInt(String.valueOf(dataList.get(i).get("order_number")));
            Integer technologyNumber = Integer.parseInt(String.valueOf(dataList.get(i).get("technology_number")));
            int finalI1 = i;
            columns.forEach(col -> {
                if(rowCount.get(col) == null){
                    rowCount.put(col, new HashMap<String,Map<String,Integer>>());
                }
                if(getRowCountMap.get(orderNumber) != null){
                    Map<String,Object> row = getRowCountMap.get(orderNumber);
                    Map<String, Integer> getRow = new HashMap<>();
                    //判断当前此次 是否为第一行 并且相同序号
                    if(technologyNumber==1){
                        getRow.put("rowspan", ((Number) row.get("rowCount")).intValue());
                        getRow.put("colspan", 1);
                    }else{
                        getRow.put("rowspan", 0);
                        getRow.put("colspan", 0);
                    }
                    rowCount.get(col).put(finalI1+"_"+col, getRow);
                }
            });
            Map<String, String> data = JSON.parseObject(dataList.get(i).get("reportWorkQuantity"),
                    new TypeReference<Map<String, String>>() {
                    });
            Map<String, String> dataShow = JSON.parseObject(dataList.get(i).get("reportWorkQuantityShow"),
                    new TypeReference<Map<String, String>>() {
                    });
            //判断后工序此流程卡号是否有次破
            List<DamageDetails> hasBreak = damageDetailsMapper
                    .getNotReview(dataList.get(i).get("processId"),
                            String.valueOf(dataList.get(i).get("order_number")),
                            String.valueOf(dataList.get(i).get("technology_number"))
                    );
            if(!hasBreak.isEmpty()){
                int finalI = i;
                data.forEach((thisProcess, index)->{
                    String behindProcess = orderProcessDetailMapper.getBehindProcess(
                            dataList.get(finalI).get("processId"),
                            String.valueOf(dataList.get(finalI).get("order_number")),
                            String.valueOf(dataList.get(finalI).get("technology_number")),
                            thisProcess,
                            orderId
                    );
                    if(behindProcess!=null &&!behindProcess.isEmpty()){
                        Integer behindDamageSum = damageDetailsMapper.getBehindDamageSum(
                                dataList.get(finalI).get("processId"),
                                String.valueOf(dataList.get(finalI).get("order_number")),
                                String.valueOf(dataList.get(finalI).get("technology_number")),
                                behindProcess,1
                        );
                        if(behindDamageSum>0){
                            data.put(thisProcess, String.valueOf(Integer.parseInt(data.get(thisProcess) )- behindDamageSum));
                            dataShow.put(thisProcess, String.valueOf(Integer.parseInt(dataShow.get(thisProcess) )- behindDamageSum));
                        }
                    }
                });
            }
            //夹胶工序判断合并行数
            if(!clos.isEmpty()){
                Integer max = orderGlassDetailMapper
                        .getMaxTechnologyNumberByGroup(dataList.get(i).get("order_id"),
                                String.valueOf(dataList.get(i).get("order_number")),
                                String.valueOf(dataList.get(i).get("group"))
                        );
                Integer min = orderGlassDetailMapper
                        .getMinTechnologyNumberByGroup(dataList.get(i).get("order_id"),
                                String.valueOf(dataList.get(i).get("order_number")),
                                String.valueOf(dataList.get(i).get("group"))
                        );
                for (String key : clos.keySet()) {
                    if(data.get(key) != null){
                        if (rowCount.get("reportWorkQuantity."+key)==null){
                            rowCount.put("reportWorkQuantity."+key, new HashMap<String,Map<String,Integer>>());
                        }
                        Map<String, Integer> getRow = new HashMap<>();
                        if(min == Integer.parseInt(String.valueOf(dataList.get(i).get("technology_number")))  ){
                            // { row: 0, col: 1, rowspan: 3, colspan: 0},
                            //getRow.put("row", i );
                            getRow.put("rowspan", max-min+1);
                            getRow.put("colspan", 1);
                        }else{
                            getRow.put("rowspan", 0);
                            getRow.put("colspan", 0);
                            data.put(key,"0");
                        }
                        rowCount.get("reportWorkQuantity."+key).put(i+"_reportWorkQuantity."+key, getRow);
                    }
                }
            }
            dataList.get(i).put("reportWorkQuantity",JSON.toJSONString(data));
            dataList.get(i).put("reportWorkQuantityShow",JSON.toJSONString(dataShow));
        }
        map.put("data",dataList );
        map.put("mergeCells", rowCount);
        return map;