diff --git a/src/main/java/net/educoder/ecsonar/controller/MainController.java b/src/main/java/net/educoder/ecsonar/controller/MainController.java index 0eb6f6f..0dd3c39 100644 --- a/src/main/java/net/educoder/ecsonar/controller/MainController.java +++ b/src/main/java/net/educoder/ecsonar/controller/MainController.java @@ -41,7 +41,7 @@ public class MainController { } - @PostMapping(value = "/scanExcel") + @RequestMapping(value = "/scanExcel", method = RequestMethod.POST) public String scanExcel(@RequestParam String excelPath) throws Exception { ecsonarService.scanExcel(excelPath); return "success"; diff --git a/src/main/java/net/educoder/ecsonar/services/SonarService.java b/src/main/java/net/educoder/ecsonar/services/SonarService.java index 8c307a7..e430e5b 100644 --- a/src/main/java/net/educoder/ecsonar/services/SonarService.java +++ b/src/main/java/net/educoder/ecsonar/services/SonarService.java @@ -190,21 +190,15 @@ public class SonarService { Map> collect = personList.stream().collect(Collectors.groupingBy(Person::getUid)); - - List list= new ArrayList<>(collect.size()); collect.forEach((k,v)->{ SonarRequest request = new SonarRequest(); request.setHomeworkId(homeworkId); request.setPersonList(v); // 开始调用sonar分析代码 - Future submit = executorService.submit(new ReadExcelRunnable(request, this)); - list.add(submit); + executorService.execute(new ReadExcelRunnable(request, this)); }); - for (Future future : list) { - System.out.println(future.get()); - } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0b02acd..07d38f3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ -spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7 -#spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar -spring.datasource.username=root -spring.datasource.password=root +#spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7 +spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar +spring.datasource.username=sonar +spring.datasource.password=sonar spring.datasource.driver-class-name=org.postgresql.Driver diff --git a/src/main/resources/template1.xlsx b/src/main/resources/template1.xlsx index 85e6407..6e80e04 100644 Binary files a/src/main/resources/template1.xlsx and b/src/main/resources/template1.xlsx differ diff --git a/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java b/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java index 7f7d5cd..9112652 100644 --- a/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java +++ b/src/test/java/net/educoder/ecsonar/EcsonarApplicationTests.java @@ -3,15 +3,22 @@ package net.educoder.ecsonar; import net.educoder.ecsonar.dao.ProjectDao; import net.educoder.ecsonar.model.Metrics; import net.educoder.ecsonar.model.Project; +import net.educoder.ecsonar.model.api.Person; import net.educoder.ecsonar.services.ReportService; import net.educoder.ecsonar.services.SonarService; +import net.educoder.ecsonar.utils.ExcelUtil; +import org.apache.commons.collections4.CollectionUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import java.io.IOException; +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.stream.Collectors; @RunWith(SpringRunner.class) @SpringBootTest @@ -58,8 +65,61 @@ public class EcsonarApplicationTests { @Test public void scanExcel(){ -// String excelPath = "/Users/youyongsheng/Desktop/res.xls"; - String excelPath = "/Users/youyongsheng/Desktop/res-test.xlsx"; + CountDownLatch countDownLatch = new CountDownLatch(1); + + String excelPath = "/Users/youyongsheng/Desktop/res.xls"; +// String excelPath = "/Users/youyongsheng/Desktop/res-test.xlsx"; sonarService.scanExcel(excelPath); + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + @Test + public void writeExcel() throws Exception { + int homeworkId = 20210101; + String directory = "/tmp/20210101/"; + File file = new File(directory); + File[] files = file.listFiles(); + System.out.println("学生数:" + files.length); + + List personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/res.xls"); + + Map> collect = personList.stream().collect(Collectors.groupingBy(Person::getUid)); + + + int i=1; + for (File file1 : files) { + String uid = file1.getName(); + String projectName = String.format("%d-%s", homeworkId, uid); + + Metrics metrics = reportService.getMetrics(projectName); + + String templatePath = this.getClass().getClassLoader().getResource("template1.xlsx").getPath(); + String outPath = "/Users/youyongsheng/Desktop/20210101.xlsx"; + + System.out.println("第"+(i++)+"个学生," + uid); + if (CollectionUtils.isEmpty(collect.get(uid))) { + + System.out.println(uid+"为空"); + continue; + } + + reportService.writeToExcel(uid, + collect.get(uid).get(0).getName(), + metrics, + outPath, + outPath, + 1); + + + } + + System.out.println("---------end------------"); + } }