|  |  |  | @ -1,17 +1,20 @@ | 
			
		
	
		
			
				
					|  |  |  |  | package net.educoder.ecsonar.task; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import cn.hutool.core.util.ZipUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import net.educoder.ecsonar.model.api.Person; | 
			
		
	
		
			
				
					|  |  |  |  | import net.educoder.ecsonar.model.api.SonarRequest; | 
			
		
	
		
			
				
					|  |  |  |  | import net.educoder.ecsonar.services.SonarService; | 
			
		
	
		
			
				
					|  |  |  |  | import net.educoder.ecsonar.utils.UrlUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import org.slf4j.Logger; | 
			
		
	
		
			
				
					|  |  |  |  | import org.slf4j.LoggerFactory; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.BufferedInputStream; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.File; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.FileOutputStream; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.IOException; | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.*; | 
			
		
	
		
			
				
					|  |  |  |  | import java.net.URL; | 
			
		
	
		
			
				
					|  |  |  |  | import java.net.URLConnection; | 
			
		
	
		
			
				
					|  |  |  |  | import java.nio.charset.Charset; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.zip.ZipEntry; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.zip.ZipInputStream; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | /** | 
			
		
	
		
			
				
					|  |  |  |  |  * @Author: youys | 
			
		
	
	
		
			
				
					|  |  |  | @ -83,4 +86,77 @@ public class ReadExcelRunnable implements Runnable{ | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     public static void main(String[] args) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //        unzip();
 | 
			
		
	
		
			
				
					|  |  |  |  |             valid("/tmp/20230102"); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     public static void unzip(){ | 
			
		
	
		
			
				
					|  |  |  |  |         String sourceDir = "/tmp/20230101"; | 
			
		
	
		
			
				
					|  |  |  |  |         String targetDir = "/tmp/20230102"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         File directory = new File(sourceDir); | 
			
		
	
		
			
				
					|  |  |  |  |         File[] studentDirs = directory.listFiles(); | 
			
		
	
		
			
				
					|  |  |  |  |         if (studentDirs == null) { | 
			
		
	
		
			
				
					|  |  |  |  |             System.out.println("No student directories found."); | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         int i=0; | 
			
		
	
		
			
				
					|  |  |  |  |         for (File studentDir : studentDirs) { | 
			
		
	
		
			
				
					|  |  |  |  |             if (!studentDir.isDirectory()) { | 
			
		
	
		
			
				
					|  |  |  |  |                 continue; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             String studentId = studentDir.getName(); | 
			
		
	
		
			
				
					|  |  |  |  |             String studentTargetDir = targetDir + "/" + studentId; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             File[] zipFiles = studentDir.listFiles((dir, name) -> name.endsWith(".zip")); | 
			
		
	
		
			
				
					|  |  |  |  |             if (zipFiles == null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 System.out.println("No zip files found for student: " + studentId); | 
			
		
	
		
			
				
					|  |  |  |  |                 continue; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //            if(i++ < 82){
 | 
			
		
	
		
			
				
					|  |  |  |  | //                continue;
 | 
			
		
	
		
			
				
					|  |  |  |  | //            }
 | 
			
		
	
		
			
				
					|  |  |  |  |             for (File zipFile : zipFiles) { | 
			
		
	
		
			
				
					|  |  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |  |                     unzip(zipFile.getAbsolutePath(), studentTargetDir); | 
			
		
	
		
			
				
					|  |  |  |  |                 } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |  |                     System.out.println("Error occurred while unzipping file: " + zipFile.getName()); | 
			
		
	
		
			
				
					|  |  |  |  |                     e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private static void unzip(String zipFilePath, String targetDir) throws IOException { | 
			
		
	
		
			
				
					|  |  |  |  |         System.out.println(zipFilePath + " to " + targetDir); | 
			
		
	
		
			
				
					|  |  |  |  |         ZipUtil.unzip(zipFilePath,targetDir,Charset.forName("GBK")); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     public static void valid(String path){ | 
			
		
	
		
			
				
					|  |  |  |  |         File directory = new File(path); | 
			
		
	
		
			
				
					|  |  |  |  |         File[] studentDirs = directory.listFiles(); | 
			
		
	
		
			
				
					|  |  |  |  |         if (studentDirs == null) { | 
			
		
	
		
			
				
					|  |  |  |  |             System.out.println("No student directories found."); | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         for (File studentDir : studentDirs) { | 
			
		
	
		
			
				
					|  |  |  |  |             if (studentDir.isDirectory()) { | 
			
		
	
		
			
				
					|  |  |  |  |                 for (File file : studentDir.listFiles()) { | 
			
		
	
		
			
				
					|  |  |  |  |                     System.out.println(studentDir.getName()+" ->" + file.getName()); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |