|
@@ -1,8 +1,12 @@
|
|
|
package com.mooctest.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.mooctest.dao.FinalReportDao;
|
|
|
import com.mooctest.data.FinalReportDTO;
|
|
|
+import com.mooctest.data.TaskDTO;
|
|
|
import com.mooctest.model.FinalReport;
|
|
|
+import com.mooctest.util.ReportUtil;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -10,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -62,4 +67,44 @@ public class FinalReportService {
|
|
|
finalReportDao.delete(reportId);
|
|
|
}
|
|
|
|
|
|
+ public String getExportReportAddr(TaskDTO task) {
|
|
|
+ List<FinalReport> finalReports = finalReportDao.findByExamIdAndCaseId(task.getExamId(), task.getCaseId());
|
|
|
+
|
|
|
+ return genJsonForExport(task, finalReports).toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject genJsonForExport(TaskDTO task, List<FinalReport> finalReports) {
|
|
|
+ JSONObject root = new JSONObject();
|
|
|
+ JSONArray projects = new JSONArray();
|
|
|
+ JSONObject project = new JSONObject();
|
|
|
+
|
|
|
+ project.put("projectId", task.getExamId() + "-" +task.getCaseId());
|
|
|
+ project.put("icon", task.getIcon());
|
|
|
+ project.put("name", task.getName());
|
|
|
+ project.put("version", task.getName());
|
|
|
+ project.put("startTime", task.getName());
|
|
|
+ project.put("endTime", task.getName());
|
|
|
+ project.put("reports", finalReports);
|
|
|
+ projects.add(project);
|
|
|
+ root.put("projects", projects);
|
|
|
+ root.put("menu", new JSONArray().fluentAdd("众包测试报告"));
|
|
|
+
|
|
|
+ JSONObject projectStatistics = new JSONObject();
|
|
|
+ projectStatistics.put("categorys", genAttrArray(ReportUtil.category2String));
|
|
|
+ projectStatistics.put("severity", genAttrArray(ReportUtil.severity2String));
|
|
|
+ projectStatistics.put("recurrent", genAttrArray(ReportUtil.recurrent2String));
|
|
|
+ root.put("projectStatistics", projectStatistics);
|
|
|
+ return root;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONArray genAttrArray(Map map) {
|
|
|
+ JSONArray arr = new JSONArray();
|
|
|
+ map.forEach((k, v) -> {
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("name", v);
|
|
|
+ obj.put("value", k);
|
|
|
+ arr.add(obj);
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
}
|