|
@@ -1,10 +1,14 @@
|
|
package edu.nju.service;
|
|
package edu.nju.service;
|
|
|
|
+
|
|
import edu.nju.dao.*;
|
|
import edu.nju.dao.*;
|
|
import edu.nju.entities.*;
|
|
import edu.nju.entities.*;
|
|
import edu.nju.util.TransUtil;
|
|
import edu.nju.util.TransUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -41,19 +45,19 @@ public class DataService {
|
|
@Autowired
|
|
@Autowired
|
|
BugHistoryDao bugHistoryDao;
|
|
BugHistoryDao bugHistoryDao;
|
|
|
|
|
|
- private static final String cpSerialNum="cp_dev";
|
|
|
|
-
|
|
|
|
|
|
+ private static final String cpSerialNum = "cp_dev";
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据caseId获取对应bug信息
|
|
* 根据caseId获取对应bug信息
|
|
|
|
+ *
|
|
* @param caseId
|
|
* @param caseId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public List<BugDetail> getBugDetailByCaseId(String caseId) {
|
|
public List<BugDetail> getBugDetailByCaseId(String caseId) {
|
|
- List<BugDetail> bugDetailList=new ArrayList<>();
|
|
|
|
- Exam crowdCase=examDao.findById(caseId);
|
|
|
|
- if(crowdCase!=null) {
|
|
|
|
|
|
+ List<BugDetail> bugDetailList = new ArrayList<>();
|
|
|
|
+ Exam crowdCase = examDao.findById(caseId);
|
|
|
|
+ if (crowdCase != null) {
|
|
List<Report> reportList = reportDao.findByCaseId(caseId);
|
|
List<Report> reportList = reportDao.findByCaseId(caseId);
|
|
for (Report report : reportList) {
|
|
for (Report report : reportList) {
|
|
String reportId = report.getId();
|
|
String reportId = report.getId();
|
|
@@ -151,11 +155,59 @@ public class DataService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ bugDetailToCsv(bugDetailList,caseId);
|
|
return bugDetailList;
|
|
return bugDetailList;
|
|
}
|
|
}
|
|
|
|
|
|
- public void bugDetailToCsv(List<BugDetail> bugDetailList){
|
|
|
|
|
|
+ public void bugDetailToCsv(List<BugDetail> bugDetailList,String caseId) {
|
|
|
|
+ String[] titles = {"bug_id", "bug_category", "severity", "recurrent", "bug_create_time", "bug_page", "title",
|
|
|
|
+ "description", "img_url",
|
|
|
|
+ "score", "parent", "children", "root", "good_num", "good_worker_id", "bad_num", "bad_worker_id",
|
|
|
|
+ "test_case_id", "test_case_name", "test_case_front", "test_case_behind", "test_case_description", "test_case_create_time",
|
|
|
|
+ "report_id", "report_name", "report_create_time", "script_location", "report_location", "log_location","device_model", "device_brand", "device_os",
|
|
|
|
+ "worker_id",
|
|
|
|
+ "case_app_name","case_paper_type","case_test_type", "case_description", "case_require_doc",
|
|
|
|
+ "case_take_id","originalCaseId","cpSerialNum"};
|
|
|
|
+ exportCsv(titles, bugDetailList,caseId);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public <T> void exportCsv(String[] titles, List<T> list,String caseId) {
|
|
|
|
+ try {
|
|
|
|
+ File file = new File("data/"+caseId+".csv");
|
|
|
|
+ //构建输出流,同时指定编码
|
|
|
|
+ OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
|
|
|
|
+ //csv文件是逗号分隔,除第一个外,每次写入一个单元格数据后需要输入逗号
|
|
|
|
+ for (String title : titles) {
|
|
|
|
+ ow.write(title);
|
|
|
|
+ ow.write(",");
|
|
|
|
+ }
|
|
|
|
+ //写完文件头后换行
|
|
|
|
+ ow.write("\r\n");
|
|
|
|
+ //写内容
|
|
|
|
+ for (Object obj : list) {
|
|
|
|
+ //利用反射获取所有字段
|
|
|
|
+ Field[] fields = obj.getClass().getDeclaredFields();
|
|
|
|
+ for (Field field : fields) {
|
|
|
|
+ //设置字段可见性
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
+ //防止某个field没有赋值
|
|
|
|
+ if (field.get(obj) == null) {
|
|
|
|
+ ow.write("");
|
|
|
|
+ } else {
|
|
|
|
+ //解决csv文件中对于逗号和双引号的转义问题
|
|
|
|
+ ow.write("\"" + field.get(obj).toString().replaceAll("\"","\"\"") + "\"");
|
|
|
|
+ }
|
|
|
|
+ ow.write(",");
|
|
|
|
+ }
|
|
|
|
+ //写完一行换行
|
|
|
|
+ ow.write("\r\n");
|
|
|
|
+ }
|
|
|
|
+ ow.flush();
|
|
|
|
+ ow.close();
|
|
|
|
+ } catch (IOException | IllegalAccessException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|