From 4b971be282ac5563e898da8781491c2c359083d8 Mon Sep 17 00:00:00 2001
From: youys <1272586223@qq.com>
Date: Thu, 18 May 2023 14:42:03 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E8=B4=A8=E9=87=8F=E5=88=86?=
=?UTF-8?q?=E6=9E=90=EF=BC=8C=E6=9C=AC=E5=9C=B0=E8=BF=90=E8=A1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 6 +-
.../ecsonar/services/SonarService.java | 5 +-
.../ecsonar/task/ReadExcelRunnable.java | 84 ++++++++++++++++++-
src/main/resources/application.properties | 14 ++--
.../ecsonar/EcsonarApplicationTests.java | 12 +--
5 files changed, 101 insertions(+), 20 deletions(-)
diff --git a/pom.xml b/pom.xml
index 1fce790..b30a9b6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,7 +108,11 @@
2.6.10
-
+
+ com.github.junrar
+ junrar
+ 4.0.0
+
diff --git a/src/main/java/net/educoder/ecsonar/services/SonarService.java b/src/main/java/net/educoder/ecsonar/services/SonarService.java
index bc66a31..1141db2 100644
--- a/src/main/java/net/educoder/ecsonar/services/SonarService.java
+++ b/src/main/java/net/educoder/ecsonar/services/SonarService.java
@@ -192,7 +192,8 @@ public class SonarService {
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);
- SystemUtil.executeAndGetExitStatus(command);
+ SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
+ log.info("projectPath:{},key:{}, result: {}", projectPath, key, executeResp.getOutput());
}
/**
@@ -257,7 +258,7 @@ public class SonarService {
*/
public void scanExcel(String excelPath) {
- int homeworkId = 20210101;
+ int homeworkId = 20230102;
try {
List personList = ExcelUtil.readExcel(excelPath);
diff --git a/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java b/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java
index 6df53d1..f3136bf 100644
--- a/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java
+++ b/src/main/java/net/educoder/ecsonar/task/ReadExcelRunnable.java
@@ -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());
+ }
+ }
+ }
+
+ }
+
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 3609fd7..0463adc 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -5,10 +5,10 @@
#spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.initSize=20
-spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
-#spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar
-spring.datasource.master.username=root
-spring.datasource.master.password=root
+#spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
+spring.datasource.master.url=jdbc:postgresql://117.50.14.123:5432/sonar
+spring.datasource.master.username=sonar
+spring.datasource.master.password=sonar
spring.datasource.master.driverClassName=org.postgresql.Driver
@@ -43,8 +43,8 @@ zip.save.path=/tmp/
#excel.template.path=/Users/guange/work/java/ecsonar/src/main/resources/template.xlsx
excel.template.path=template.xlsx
-sonar.url=http://127.0.0.1:9000
-#sonar.url=http://117.50.14.123:9000
+#sonar.url=http://127.0.0.1:9000
+sonar.url=http://117.50.14.123:9000
# token令牌
sonar.token=0253a518e824a976ea2f11aec17938cb0f8c0495
@@ -58,4 +58,4 @@ skip.checked=true
server.port=8081
-sonar.host=http://localhost:9000
\ No newline at end of file
+sonar.host=http://localhost:9000
diff --git a/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java b/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java
index dd4056a..c5c62db 100644
--- a/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java
+++ b/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java
@@ -67,8 +67,8 @@ public class EcsonarApplicationTests {
public void scanExcel(){
CountDownLatch countDownLatch = new CountDownLatch(1);
- String excelPath = "/Users/youyongsheng/Desktop/res.xls";
-// String excelPath = "/Users/youyongsheng/Desktop/res-test.xlsx";
+// String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.xlsx";
+ String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/datattt.xlsx";
sonarService.scanExcel(excelPath);
try {
@@ -81,13 +81,13 @@ public class EcsonarApplicationTests {
@Test
public void writeExcel() throws Exception {
- int homeworkId = 20210101;
- String directory = "/tmp/20210101/";
+ int homeworkId = 20230102;
+ String directory = "/tmp/20230102/";
File file = new File(directory);
File[] files = file.listFiles();
System.out.println("学生数:" + files.length);
- List personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/res.xls");
+ List personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.xlsx");
Map> collect = personList.stream().collect(Collectors.groupingBy(Person::getUid));
@@ -100,7 +100,7 @@ public class EcsonarApplicationTests {
Metrics metrics = reportService.getMetrics(projectName);
String templatePath = this.getClass().getClassLoader().getResource("template1.xlsx").getPath();
- String outPath = "/Users/youyongsheng/Desktop/202100000004.xlsx";
+ String outPath = "/Users/youyongsheng/Desktop/2222222.xlsx";
System.out.println("第"+(i++)+"个学生," + uid);
if (CollectionUtils.isEmpty(collect.get(uid))) {