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