xyc
2024-11-07 769ba15e9071b01cb53a65e8fdf4c8f37ac005b9
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/basicInfo/service/XhProductModelService.java
@@ -451,23 +451,37 @@
            Workbook workbook = new XSSFWorkbook(inputStream);
            // 获取第一个工作表
            Sheet sheet = workbook.getSheetAt(0);
            List.sort((o1, o2) -> {
                String[] parentList1 = o1.getNamePath().split(",");
                String[] parentList2 = o2.getNamePath().split(",");
                String xt1 = parentList1.length > 0 ? parentList1[0] : "";
                String xt2 = parentList2.length > 0 ? parentList2[0] : "";
                // 首先比较xt值
                int xtCompare = xt1.compareTo(xt2);
                if (xtCompare != 0) {
                    return xtCompare;
                }
                // 如果xt相同,比较parentList的长度,确保parentList.length = 2的数据排在前面
                return Integer.compare(parentList1.length, parentList2.length);
            });
            int num = 0;
            String xt = "";
            String fxt = "";
            String sb = "";
            for (int i = 0; i < List.size(); i++) {
                if (List.get(i).getProductType() == 5) {
                    num = num + 1;
                    String[] parentList = List.get(i).getNamePath().split(",");
                    Row row = sheet.createRow(sheet.getLastRowNum() + 1); // 创建新行
                    Cell cell = row.createCell(0);
                    cell.setCellValue(num);
                    if (parentList.length > 2) {
                        if (!xt.equals(parentList[0])) {
                            xt = parentList[0];
                            cell = row.createCell(1);
                            cell.setCellValue(xt);
                        }
                    if (parentList.length > 2) {
                        if (!fxt.equals(parentList[1])) {
                            fxt = parentList[1];
                            cell = row.createCell(2);
@@ -479,12 +493,6 @@
                            cell.setCellValue(sb);
                        }
                    } else {
                        if (!xt.equals(parentList[0])) {
                            xt = parentList[0];
                            cell = row.createCell(1);
                            cell.setCellValue(xt);
                        }
                        if (!sb.equals(parentList[1])) {
                            sb = parentList[1];
                            cell = row.createCell(3);
@@ -561,7 +569,6 @@
                    cell = row.createCell(20);
                    if (List.get(i).getRepairMttcrOtherParams3() != null) {
                        cell.setCellValue(List.get(i).getRepairMttcrOtherParams3());
                    }
                }
            }
            response.setContentType("application/octet-stream;charset=UTF-8");