소스 검색

导出文件提交

小么熊🐻 1 년 전
부모
커밋
7e1a194644
2개의 변경된 파일33개의 추가작업 그리고 50개의 파일을 삭제
  1. 10 38
      nbjk-admin/src/test/java/com/miaxis/test/ReadFileNameTest.java
  2. 23 12
      nbjk-admin/src/test/java/com/miaxis/test/ReadFileNameTest2.java

+ 10 - 38
nbjk-admin/src/test/java/com/miaxis/test/ReadFileNameTest.java

@@ -38,8 +38,8 @@ public class ReadFileNameTest {
      */
     @Test
     public void test() {
-        String folderPath = "H:/河南省"; // 替换为你的文件夹路径
-        String excelFilePath = "H:/file.xlsx"; // 替换为你的Excel文件路径
+        String folderPath = "H:/广东省"; // 替换为你的文件夹路径
+        String excelFilePath = "H:/vip_exam_video.xlsx"; // 替换为你的Excel文件路径
 
         try {
             Workbook workbook = new XSSFWorkbook();
@@ -88,7 +88,7 @@ public class ReadFileNameTest {
 
     private void traverseFolders(File folder, Sheet sheet, int rowIndex) {
         String province = folder.getName();
-        String provinceId = "41";
+        String provinceId = "44";
         String city = null;
         String cityId = null;
         String county = null;
@@ -105,7 +105,7 @@ public class ReadFileNameTest {
 
                 for (int j = 0; j < dictCityList.size(); j++) {
                     cityId = dictCityList.get(j).getCode();
-                    if (cityId.startsWith("41")) {
+                    if (cityId.startsWith(provinceId)) {
                         break;
                     }
                 }
@@ -204,49 +204,21 @@ public class ReadFileNameTest {
                                         }
 
 
-                                            System.out.println(province+"   "+city+"    "+county+"  "+exam+"    "+video);
-                                            rowIndex++;
-                                        }
+                                        System.out.println(province + "   " + city + "    " + county + "  " + exam + "    " + video);
+                                        rowIndex++;
                                     }
+                                }
 
 
-                                }
                             }
                         }
                     }
                 }
-//                if (files != null) {
-//                    for (File file : files) {
-//                        if (file.isDirectory()) {
-//                            // 获取文件夹路径
-//                            String folderPath = file.getPath();
-//
-//                            // 分割文件夹路径
-//                            String[] folderNames = folderPath.split("\\\\");
-//                            int numLevels = folderNames.length;
-//
-//                            // 创建新行
-//                            Row row = sheet.createRow(rowIndex);
-//                            for (int i = 0; i < numLevels; i++) {
-//                                row.createCell(i).setCellValue(folderNames[i]);
-//                            }
-//
-//                            // 获取mp4文件
-//                            File[] mp4Files = file.listFiles((dir, name) -> name.toLowerCase().endsWith(".mp4"));
-//                            if (mp4Files != null && mp4Files.length > 0) {
-//                                String mp4FileName = mp4Files[0].getName();
-//                                row.createCell(numLevels).setCellValue(mp4FileName);
-//                            }
-//
-//                            rowIndex++;
-//
-//                            // 递归遍历下一级文件夹
-//                            traverseFolders(file, sheet, rowIndex);
-//                        }
-//                    }
-                }
             }
 
+        }
+    }
+
 }
 
 

+ 23 - 12
nbjk-admin/src/test/java/com/miaxis/test/ReadFileNameTest2.java

@@ -5,6 +5,7 @@ import com.miaxis.dict.domain.DictCity;
 import com.miaxis.dict.service.IDictCityService;
 import com.miaxis.exam.domain.ExamInfo;
 import com.miaxis.exam.service.IExamInfoService;
+import net.sourceforge.pinyin4j.PinyinHelper;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -40,8 +41,8 @@ public class ReadFileNameTest2 {
      */
     @Test
     public void test() {
-        String folderPath = "F:/河南省"; // 替换为你的文件夹路径
-        String excelFilePath = "F:/exam_info.xlsx"; // 替换为你的Excel文件路径
+        String folderPath = "H:/广东省"; // 替换为你的文件夹路径
+        String excelFilePath = "H:/exam_info.xlsx"; // 替换为你的Excel文件路径
 
         try {
             Workbook workbook = new XSSFWorkbook();
@@ -81,7 +82,7 @@ public class ReadFileNameTest2 {
 
     private void traverseFolders(File folder, Sheet sheet, int rowIndex) {
         String province = folder.getName();
-        String provinceId = "41";
+        String provinceId = "44";
         String city = null;
         String cityId = null;
         String county = null;
@@ -98,7 +99,7 @@ public class ReadFileNameTest2 {
 
                 for (int j = 0; j < dictCityList.size(); j++) {
                     cityId = dictCityList.get(j).getCode();
-                    if (cityId.startsWith("41")) {
+                    if (cityId.startsWith("44")) {
                         break;
                     }
                 }
@@ -152,20 +153,30 @@ public class ReadFileNameTest2 {
     }
 
 
-    public File[] sortFiles(File[] files) {
-
+    public static File[] sortFiles(File[] files) {
         if (files != null) {
-            // 使用Collator类创建一个特定语言环境的排序器(这里使用中文)
             Collator collator = Collator.getInstance(Locale.CHINA);
             // 使用Comparator.comparing方法结合Lambda表达式按文件名的拼音首字母排序
-            Arrays.sort(files, Comparator.comparing(file -> file.getName(), collator));
+            //Arrays.sort(files, Comparator.comparing(file -> file.getName(), collator));
+            // 使用Pinyin4j将汉字转换为拼音,并按拼音进行排序
+            Arrays.sort(files, Comparator.comparing(file -> getPinyin(file.getName()), collator));
+        }
+        return files;
+    }
 
-            // 输出排序后的文件名
-            for (File file : files) {
-                System.out.println(file.getName());
+    // 使用Pinyin4j将汉字转换为拼音
+    private static String getPinyin(String hanzi) {
+        StringBuilder pinyin = new StringBuilder();
+        for (char ch : hanzi.toCharArray()) {
+            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(ch);
+            if (pinyinArray != null && pinyinArray.length > 0) {
+                pinyin.append(pinyinArray[0]);
+            } else {
+                // 如果无法获取拼音,则原样输出汉字
+                pinyin.append(ch);
             }
         }
-        return files;
+        return pinyin.toString();
     }