youys 3 years ago
parent 5ee02d5957
commit f2ed9b2fed

@ -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";

@ -190,21 +190,15 @@ public class SonarService {
Map<String, List<Person>> collect = personList.stream().collect(Collectors.groupingBy(Person::getUid));
List<Future> 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();

@ -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

Binary file not shown.

@ -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<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/res.xls");
Map<String, List<Person>> 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------------");
}
}

Loading…
Cancel
Save