HistoryController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. package com.mooctest.controller;
  2. import com.mooctest.data.BugDTO;
  3. import com.mooctest.data.FinalReportDTO;
  4. import com.mooctest.data.SupplementDTO;
  5. import com.mooctest.data.TaskDTO;
  6. import com.mooctest.model.FinalReport;
  7. import com.mooctest.model.MasterReport;
  8. import com.mooctest.service.*;
  9. import com.mooctest.util.ReportUtil;
  10. import org.json.JSONArray;
  11. import org.json.JSONException;
  12. import org.json.JSONObject;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Controller;
  15. import org.springframework.ui.Model;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.servlet.http.HttpServletResponse;
  18. import javax.servlet.http.HttpSession;
  19. import java.io.IOException;
  20. import java.io.PrintWriter;
  21. import java.util.*;
  22. import java.util.function.Function;
  23. import java.util.stream.Collectors;
  24. @Controller
  25. @RequestMapping(value = "/history")
  26. @CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
  27. public class HistoryController {
  28. @Autowired
  29. HistoryService hisservice;
  30. @Autowired
  31. TaskService taskService;
  32. @Autowired
  33. AnalyzeService aservice;
  34. @Autowired
  35. RecommendService recservice;
  36. @Autowired
  37. BugReportService bugReportService;
  38. @Autowired
  39. FinalReportService finalReportService;
  40. @Autowired
  41. MasterReportService masterReportService;
  42. @Autowired
  43. BugReviewService bugReviewService;
  44. //获取指定节点的历史信息
  45. // @RequestMapping(value = "/getHistory")
  46. // @ResponseBody
  47. // public void getHistory(String id, HttpServletResponse response) {
  48. // try {
  49. // PrintWriter out = response.getWriter();
  50. // out.print(new JSONObject(hisservice.getHistory(id)));
  51. // out.flush();
  52. // out.close();
  53. // } catch (IOException e) {
  54. // e.printStackTrace();
  55. // } catch (JSONException e) {
  56. // e.printStackTrace();
  57. // }
  58. // }
  59. //获取所有根节点
  60. @RequestMapping(value = "/getRoots")
  61. @ResponseBody
  62. public void getRoots(String case_take_id, HttpServletResponse response) {
  63. try {
  64. PrintWriter out = response.getWriter();
  65. JSONObject result = new JSONObject();
  66. List<String> list = hisservice.getRoots(case_take_id);
  67. result.put("Count", list.size());
  68. result.put("TreeRoot", new JSONArray(list));
  69. out.print(result);
  70. out.flush();
  71. out.close();
  72. } catch (IOException e) {
  73. // TODO Auto-generated catch block
  74. e.printStackTrace();
  75. } catch (JSONException e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. @GetMapping(value = "/tree_list")
  80. public String showTreeList(@RequestParam("caseId") long caseId,@RequestParam("examId") long examId,
  81. Model model){
  82. String case_take_id = caseId+"-"+examId;
  83. JSONObject result = new JSONObject(); // 用来存放树状结构信息的reuslt;
  84. List<String> treeRootids = hisservice.getTreeRoots(caseId+"-"+examId); // 获得所有的根结点的id
  85. TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId); // infomation of task
  86. // List<List<String>> list = new ArrayList<List<String>>();
  87. // for(String id: treeRootids) {
  88. // list.add(hisservice.getDetail(id));
  89. // } // 获得树的信息。
  90. //获得每份报告的具体信息
  91. //history 报告对应的report列表列
  92. Map<String , List<String >> tree2BugIdsMap = hisservice.getTree2BugIdsMap(treeRootids);
  93. Map<String, BugDTO> bugsMap = bugReportService.getAllBugsMap(examId, caseId); //得到所有bug的对应map
  94. model.addAttribute("tree2BugIdsMap", tree2BugIdsMap); //
  95. model.addAttribute("bugMap", bugsMap); //
  96. model.addAttribute("examId", examId);
  97. model.addAttribute("caseId", caseId);
  98. model.addAttribute("task", task);
  99. model.addAttribute("aggNum", treeRootids.size()); //
  100. return "tree_report_list";
  101. }
  102. @RequestMapping(value = "/getTrees2")
  103. public String getTrees2(@RequestParam("case_take_id") String case_take_id) {
  104. return "managerCheck";
  105. }
  106. @GetMapping(value = "/report")
  107. public String showAggrReport(@RequestParam("treeId") String treeId,
  108. @RequestParam("examId") long examId,
  109. @RequestParam("caseId") long caseId,
  110. @RequestParam(value = "finalReportId", required = false) Long finalReportId,
  111. Model model) {
  112. Map<String, BugDTO> bugMap = bugReportService.getAllBugsMap(examId, caseId);
  113. BugDTO treeReport = bugMap.get(treeId); // 从bugmap中取得主报告的信息
  114. List<String> treeRootids = hisservice.getTreeRoots(caseId+"-"+examId); // 获得所有的根结点的id
  115. List<String> childReportIds = hisservice.getSingleRootReports(treeId); // 获得所有自报告的信息
  116. List<BugDTO> childReports = new ArrayList<>();
  117. childReportIds.forEach(s->{
  118. childReports.add(bugMap.get(s));
  119. });
  120. //按照时间排序
  121. childReports.sort((l,r)->{
  122. return (int) (Long.parseLong(l.getCreateTimeMillis()) - Long.parseLong(r.getCreateTimeMillis()));
  123. });
  124. Map<String, Long> categoryCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBugCategory, Collectors.counting()));
  125. Map<String, Long> pageCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBug_page,Collectors.counting()));
  126. Map<String, Long> recurrentCounts = childReports.stream()
  127. .map(BugDTO::getRecurrent)
  128. .map((recurrentNum) -> ReportUtil.recurrent2String.get(recurrentNum))
  129. .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  130. Map<String, Long> severityCounts = childReports.stream()
  131. .map(BugDTO::getSeverity)
  132. .map((severityNum) -> ReportUtil.severity2String.get(severityNum))
  133. .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  134. // List<FinalReportDTO> finalReports = new ArrayList<>();// 暂时还没有finalreport的数据
  135. Map<String,String> report2master = masterReportService.getBugIds2Master(masterReportService.getAllMasterIdByExamIdAndCaseId(examId, caseId));
  136. List<FinalReportDTO> finalReports = finalReportService.getBySourceId(treeId);
  137. model.addAttribute("categoryCounts", categoryCounts);
  138. model.addAttribute("severityCounts", severityCounts);
  139. model.addAttribute("pageCounts",pageCounts);
  140. model.addAttribute("recurrentCounts",recurrentCounts);
  141. model.addAttribute("aggReportId", "ML-TR-" + treeId.substring(10)); // 树报告的信息
  142. model.addAttribute("masterReport", treeReport);
  143. model.addAttribute("createTime", new Date(Long.parseLong(treeReport.getCreateTimeMillis())));
  144. model.addAttribute("supplements", childReports);
  145. model.addAttribute("finalReports", finalReports);
  146. model.addAttribute("category2String", ReportUtil.category2String);
  147. model.addAttribute("recurrent2String", ReportUtil.recurrent2String);
  148. model.addAttribute("severity2String", ReportUtil.severity2String);
  149. model.addAttribute("reviewed",bugReviewService.isBugReviewed(treeId));
  150. model.addAttribute("examId", examId);
  151. model.addAttribute("report2master",report2master);
  152. model.addAttribute("caseId", caseId);
  153. model.addAttribute("showReference",true);//是否展示其他聚合报告的参考标签
  154. return "tree_report_new";
  155. }
  156. @GetMapping(value = "/report_part")
  157. public String showTreerReportPart(@RequestParam("treeId") String treeId,
  158. @RequestParam("examId") long examId,
  159. @RequestParam("caseId") long caseId,
  160. @RequestParam(value = "finalReportId", required = false) Long finalReportId,
  161. Model model) {
  162. Map<String, BugDTO> bugMap = bugReportService.getAllBugsMap(examId, caseId);
  163. BugDTO treeReport = bugMap.get(treeId); // 从bugmap中取得主报告的信息
  164. List<String> treeRootids = hisservice.getTreeRoots(caseId+"-"+examId); // 获得所有的根结点的id
  165. List<String> childReportIds = hisservice.getSingleRootReports(treeId); // 获得所有自报告的信息
  166. List<BugDTO> childReports = new ArrayList<>();
  167. childReportIds.forEach(s->{
  168. childReports.add(bugMap.get(s));
  169. });
  170. Map<String, Long> categoryCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBugCategory, Collectors.counting()));
  171. Map<String, Long> pageCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBug_page,Collectors.counting()));
  172. Map<String, Long> recurrentCounts = childReports.stream()
  173. .map(BugDTO::getRecurrent)
  174. .map((recurrentNum) -> ReportUtil.recurrent2String.get(recurrentNum))
  175. .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  176. Map<String, Long> severityCounts = childReports.stream()
  177. .map(BugDTO::getSeverity)
  178. .map((severityNum) -> ReportUtil.severity2String.get(severityNum))
  179. .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  180. List<FinalReportDTO> finalReports = new ArrayList<>();// 暂时还没有finalreport的数据
  181. //report to master
  182. Map<String,String> report2master = masterReportService.getBugIds2Master(masterReportService.getAllMasterIdByExamIdAndCaseId(examId, caseId));
  183. model.addAttribute("severityCounts", severityCounts);
  184. model.addAttribute("categoryCounts", categoryCounts);
  185. model.addAttribute("pageCounts",pageCounts);
  186. model.addAttribute("recurrentCounts",recurrentCounts);
  187. model.addAttribute("aggReportId", "ML-TR-" + treeId.substring(10)); // 树报告的信息
  188. model.addAttribute("masterReport", treeReport);
  189. model.addAttribute("createTime", new Date(Long.parseLong(treeReport.getCreateTimeMillis())));
  190. model.addAttribute("supplements", childReports);
  191. model.addAttribute("finalReports", finalReports);
  192. model.addAttribute("category2String", ReportUtil.category2String);
  193. model.addAttribute("recurrent2String", ReportUtil.recurrent2String);
  194. model.addAttribute("severity2String", ReportUtil.severity2String);
  195. model.addAttribute("report2master",report2master); // report 2 master report//
  196. model.addAttribute("reviewed",false);
  197. model.addAttribute("examId", examId);
  198. model.addAttribute("caseId", caseId);
  199. model.addAttribute("showReference",false);//是否展示其他聚合报告的参考标签
  200. return "tree_report_new::treeBody";
  201. }
  202. //获取所有形成树状结构的bug根节点
  203. // case_take_id=1281-2724&start=0&count=10&page=null&identity=0&report_id=5cbc1a9f825a8960cdc7bd4f&worker_id=22383
  204. @RequestMapping(value = "/getTrees")
  205. public String getTrees(@RequestParam("case_take_id") String case_take_id, @RequestParam("start") String start,
  206. @RequestParam("count") String count, @RequestParam("page") String page,
  207. @RequestParam("identity") String identity, @RequestParam("report_id") String report_id,
  208. @RequestParam("worker_id") String worker_id,Model model) {
  209. System.out.println("case_take_id = " + case_take_id);
  210. String[] split = case_take_id.split("-");
  211. long caseId = Long.parseLong(split[0]);
  212. long examId = Long.parseLong(split[1]);
  213. try {
  214. JSONObject result = new JSONObject();
  215. List<String> all = hisservice.getTreeRoots(case_take_id);//获得所有的根结点。
  216. System.out.println("all.toString(): " + all.toString());
  217. hisservice.pageFilter(all, page);//清洗其他界面的bug报告,只留下本界面的。
  218. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count))); // 做一个筛选。
  219. List<List<String>> list = new ArrayList<List<String>>();
  220. System.out.println(ids.toString());
  221. for(String id: ids) {
  222. list.add(hisservice.getDetail(id));
  223. }
  224. TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId);
  225. result.put("Count", all.size());
  226. result.put("TreeRoot", new JSONArray(list));
  227. // System.out.println("list = " + list);
  228. System.out.println("/getTrees result = " + result);
  229. model.addAttribute("examId", examId);
  230. model.addAttribute("caseId", caseId);
  231. model.addAttribute("task", task);
  232. model.addAttribute("Count", all.size());
  233. model.addAttribute("TreeRoot", list);
  234. model.addAttribute("identity", identity);
  235. model.addAttribute("report_id", report_id);
  236. model.addAttribute("worker_id", worker_id);
  237. } catch (JSONException e) {
  238. e.printStackTrace();
  239. }
  240. return "managerCheck";
  241. }
  242. //获取所有形成树状结构的bug根节点
  243. @RequestMapping(value = "/getTreesList/{case_take_id}/{start}/{count}/{page}")
  244. @ResponseBody
  245. public String getTreesList(@PathVariable String case_take_id, @PathVariable String start,
  246. @PathVariable String count, @PathVariable String page) {
  247. System.out.println("case_take_id = " + case_take_id);
  248. JSONObject result = new JSONObject();
  249. String[] split = case_take_id.split("-");
  250. long caseId = Long.parseLong(split[0]);
  251. long examId = Long.parseLong(split[1]);
  252. List<String> all = hisservice.getTreeRoots(case_take_id);
  253. hisservice.pageFilter(all, page);
  254. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  255. List<List<String>> list = new ArrayList<List<String>>();
  256. for(String id: ids) {
  257. list.add(hisservice.getDetail(id));
  258. }
  259. TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId);
  260. try {
  261. result.put("Count", all.size());
  262. result.put("TreeRoot", new JSONArray(list));
  263. } catch (JSONException e) {
  264. e.printStackTrace();
  265. }
  266. return result.toString();
  267. }
  268. //获取所有单个节点的数据
  269. @RequestMapping(value = "/getSingle/{case_take_id}/{start}/{count}/{page}")
  270. @ResponseBody
  271. public String getSingle(@PathVariable String case_take_id, @PathVariable String start,
  272. @PathVariable String count, @PathVariable String page) {
  273. JSONObject result = new JSONObject();
  274. try {
  275. List<String> all = new ArrayList<String>();
  276. for(String id : hisservice.getRoots(case_take_id)) {
  277. if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
  278. }
  279. hisservice.pageFilter(all, page);
  280. List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
  281. List<String> invalid = hisservice.getInvalid(ids);
  282. for(String id: invalid) {
  283. if(ids.contains(id)) {ids.remove(id);}
  284. }
  285. List<List<String>> list = new ArrayList<List<String>>();
  286. for(String id : ids) {
  287. List<String> temp = new ArrayList<String>();
  288. temp.add(id);
  289. int score = aservice.getGrade(id);
  290. if(score != -1) {temp.add("true");}
  291. else {temp.add("false");}
  292. temp.add(recservice.getTitle(id));
  293. list.add(temp);
  294. }
  295. result.put("Count", all.size());
  296. result.put("TreeRoot", new JSONArray(list));
  297. } catch (JSONException e) {
  298. e.printStackTrace();
  299. }
  300. return result.toString();
  301. }
  302. //获取指定bug的所有路径
  303. @RequestMapping(value = "/getPath/{id}")
  304. @ResponseBody
  305. public String getPath(@PathVariable String id) {
  306. JSONObject result = new JSONObject();
  307. try {
  308. List<List<String>> lists = hisservice.getDepth(id);
  309. Set<String> filter = hisservice.filter(lists);
  310. result.put("path", new JSONArray(lists));
  311. result.put("invalid", new JSONArray(hisservice.getInvalid(filter)));
  312. List<String> ids = new ArrayList<String>(filter);
  313. result.put("score", new JSONArray(aservice.getScores(ids)));
  314. System.out.println("/getPath path = " + result);
  315. System.out.println("result.toString() = " + result.toString());
  316. } catch (JSONException e) {
  317. e.printStackTrace();
  318. }
  319. return result.toString();
  320. }
  321. @RequestMapping(value = "/fresh")
  322. @ResponseBody
  323. public void fresh(HttpSession session, HttpServletResponse response) {
  324. if(session.getAttribute("trees") != null) {session.removeAttribute("trees");}
  325. if(session.getAttribute("single") != null) {session.removeAttribute("single");}
  326. }
  327. }