zouyu
2026-01-19 c29edce627dc82103612e2e29494c14230b1e039
检验任务提交:表格列宽度设置问题修复
已修改1个文件
131 ■■■■■ 文件已修改
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java 131 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -2544,26 +2544,27 @@
                    newTableRenderData.setRows(new ArrayList<>(firstTwoRows));
                    //设置样式
                    TableStyle tableStyle = new TableStyle();
                    for (int i = 1; i <= max; i++) {
                        // 根据减压那结果个数修改长度
                        switch (i) {
                            case 1:
                                tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
                                break;
                            case 2:
                                tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
                                break;
                            case 3:
                                tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
                                break;
                            case 4:
                                tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
                                break;
                            case 5:
                                tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
                                break;
                        }
                    }
//                    for (int i = 1; i <= max; i++) {
//                    }
                    // 根据检验结果个数修改长度
                    tableStyle.setColWidths(calcTableColWidths(max));
//                    switch (max) {
//                        case 1:
//                            tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
//                            break;
//                        case 2:
//                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
//                            break;
//                        case 3:
//                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
//                            break;
//                        case 4:
//                            tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
//                            break;
//                        case 5:
//                            tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
//                            break;
//                    }
                    tableStyle.setWidth("10000");
                    tableStyle.setAlign(TableRowAlign.CENTER);
                    BorderStyle borderStyle = new BorderStyle();
@@ -2586,28 +2587,30 @@
                }
                tableRenderData.getRows().add(row);
            }
            if (!tableRenderData.getRows().isEmpty() && tableRenderData.getRows().size() != 3) {
                //设置样式
                TableStyle tableStyle = new TableStyle();
                for (int i = 1; i <= max; i++) {
                    // 根据减压那结果个数修改长度
                    switch (i) {
                        case 1:
                            tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
                            break;
                        case 2:
                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
                            break;
                        case 3:
                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
                            break;
                        case 4:
                            tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
                            break;
                        case 5:
                            tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
                            break;
                    }
            if (tableRenderData.getRows().size() != 3) {
                //设置样式
//                for (int i = 1; i <= max; i++) {
//                }
                // 根据检验结果个数修改长度
                tableStyle.setColWidths(calcTableColWidths(max));
//                switch (max) {
//                    case 1:
//                        tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
//                        break;
//                    case 2:
//                        tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
//                        break;
//                    case 3:
//                        tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
//                        break;
//                    case 4:
//                        tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
//                        break;
//                    case 5:
//                        tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
//                        break;
//                }
                }
                tableStyle.setWidth("10000");
                tableStyle.setAlign(TableRowAlign.CENTER);
@@ -2621,7 +2624,6 @@
                tableStyle.setBottomBorder(borderStyle);
                tableRenderData.setTableStyle(tableStyle);
                tables1.add(tableRenderData);
            }
            tables1.forEach(table -> {
                Map<String, Object> tableMap = new HashMap<>();
                tableMap.put("table", table);
@@ -2830,6 +2832,45 @@
    }
    /**
     * 计算表格列宽度
     * @param max 最大检验个数
     * @return
     */
    private static int[] calcTableColWidths(int max){
        int[] colWidths = null;
        switch (max) {
            case 1:
                colWidths = new int[]{650, 2000, 2000, 850, 2200, 2100, 1200};
                break;
            case 2:
                colWidths = new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200};
                break;
            case 3:
                colWidths = new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200};
                break;
            case 4:
                colWidths = new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200};
                break;
            case 5:
                colWidths = new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200};
                break;
        }
        if(ObjectUtils.isNull(colWidths)){
            List<Integer> defaultColWidths = new ArrayList<>(Arrays.asList(650, 1100, 1100, 850, 1350));
            int totalWidth = 3000;//总宽度
            int byOneWidth = totalWidth/max;//每一个的宽度
            int realWidth = 0;//实际宽度
            for (int i = 0; i < max; i++) {
                realWidth+=byOneWidth;
                defaultColWidths.add(byOneWidth);
            }
            defaultColWidths.add(1200+(totalWidth-realWidth));
            return defaultColWidths.stream().mapToInt(Integer::intValue).toArray();
        }
        return colWidths;
    }
    /**
     * 调整高度
     * @param row
     * @param rowHeight
@@ -2844,9 +2885,9 @@
        // 获取检测内容判断是否超出
        if (StringUtils.isNotBlank(dataText) && dataText.contains("@")) {
            double number = 1;
            double chinaLength = 0;
            double englishLength = 0;
            double valueLength = 0;
            double chinaLength = 14;
            double englishLength = 28;
            double valueLength = 6;
            // 根据线芯个数判断距离
            switch (max) {
                case 1: