123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- package com.mooctest.controller;
- import com.mooctest.data.BugDTO;
- import com.mooctest.data.FinalReportDTO;
- import com.mooctest.data.SupplementDTO;
- import com.mooctest.data.TaskDTO;
- import com.mooctest.model.FinalReport;
- import com.mooctest.model.MasterReport;
- import com.mooctest.service.*;
- import com.mooctest.util.ReportUtil;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- @Controller
- @RequestMapping(value = "/history")
- @CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
- public class HistoryController {
-
- @Autowired
- HistoryService hisservice;
- @Autowired
- TaskService taskService;
- @Autowired
- AnalyzeService aservice;
-
- @Autowired
- RecommendService recservice;
- @Autowired
- BugReportService bugReportService;
- @Autowired
- FinalReportService finalReportService;
- @Autowired
- MasterReportService masterReportService;
- @Autowired
- BugReviewService bugReviewService;
- //获取指定节点的历史信息
- // @RequestMapping(value = "/getHistory")
- // @ResponseBody
- // public void getHistory(String id, HttpServletResponse response) {
- // try {
- // PrintWriter out = response.getWriter();
- // out.print(new JSONObject(hisservice.getHistory(id)));
- // out.flush();
- // out.close();
- // } catch (IOException e) {
- // e.printStackTrace();
- // } catch (JSONException e) {
- // e.printStackTrace();
- // }
- // }
-
- //获取所有根节点
- @RequestMapping(value = "/getRoots")
- @ResponseBody
- public void getRoots(String case_take_id, HttpServletResponse response) {
- try {
- PrintWriter out = response.getWriter();
- JSONObject result = new JSONObject();
- List<String> list = hisservice.getRoots(case_take_id);
- result.put("Count", list.size());
- result.put("TreeRoot", new JSONArray(list));
- out.print(result);
- out.flush();
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- @GetMapping(value = "/tree_list")
- public String showTreeList(@RequestParam("caseId") long caseId,@RequestParam("examId") long examId,
- Model model){
- String case_take_id = caseId+"-"+examId;
- JSONObject result = new JSONObject(); // 用来存放树状结构信息的reuslt;
- List<String> treeRootids = hisservice.getTreeRoots(caseId+"-"+examId); // 获得所有的根结点的id
- TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId); // infomation of task
- // List<List<String>> list = new ArrayList<List<String>>();
- // for(String id: treeRootids) {
- // list.add(hisservice.getDetail(id));
- // } // 获得树的信息。
- //获得每份报告的具体信息
- //history 报告对应的report列表列
- Map<String , List<String >> tree2BugIdsMap = hisservice.getTree2BugIdsMap(treeRootids);
- Map<String, BugDTO> bugsMap = bugReportService.getAllBugsMap(examId, caseId); //得到所有bug的对应map
- model.addAttribute("tree2BugIdsMap", tree2BugIdsMap); //
- model.addAttribute("bugMap", bugsMap); //
- model.addAttribute("examId", examId);
- model.addAttribute("caseId", caseId);
- model.addAttribute("task", task);
- model.addAttribute("aggNum", treeRootids.size()); //
- return "tree_report_list";
- }
- @RequestMapping(value = "/getTrees2")
- public String getTrees2(@RequestParam("case_take_id") String case_take_id) {
- return "managerCheck";
- }
- @GetMapping(value = "/report")
- public String showAggrReport(@RequestParam("treeId") String treeId,
- @RequestParam("examId") long examId,
- @RequestParam("caseId") long caseId,
- @RequestParam(value = "finalReportId", required = false) Long finalReportId,
- Model model) {
- Map<String, BugDTO> bugMap = bugReportService.getAllBugsMap(examId, caseId);
- BugDTO treeReport = bugMap.get(treeId); // 从bugmap中取得主报告的信息
- List<String> treeRootids = hisservice.getTreeRoots(caseId+"-"+examId); // 获得所有的根结点的id
- List<String> childReportIds = hisservice.getSingleRootReports(treeId); // 获得所有自报告的信息
- List<BugDTO> childReports = new ArrayList<>();
- childReportIds.forEach(s->{
- childReports.add(bugMap.get(s));
- });
- //按照时间排序
- childReports.sort((l,r)->{
- return (int) (Long.parseLong(l.getCreateTimeMillis()) - Long.parseLong(r.getCreateTimeMillis()));
- });
- Map<String, Long> categoryCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBugCategory, Collectors.counting()));
- Map<String, Long> pageCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBug_page,Collectors.counting()));
- Map<String, Long> recurrentCounts = childReports.stream()
- .map(BugDTO::getRecurrent)
- .map((recurrentNum) -> ReportUtil.recurrent2String.get(recurrentNum))
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
- Map<String, Long> severityCounts = childReports.stream()
- .map(BugDTO::getSeverity)
- .map((severityNum) -> ReportUtil.severity2String.get(severityNum))
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
- // List<FinalReportDTO> finalReports = new ArrayList<>();// 暂时还没有finalreport的数据
- Map<String,String> report2master = masterReportService.getBugIds2Master(masterReportService.getAllMasterIdByExamIdAndCaseId(examId, caseId));
- List<FinalReportDTO> finalReports = finalReportService.getBySourceId(treeId);
- model.addAttribute("categoryCounts", categoryCounts);
- model.addAttribute("severityCounts", severityCounts);
- model.addAttribute("pageCounts",pageCounts);
- model.addAttribute("recurrentCounts",recurrentCounts);
- model.addAttribute("aggReportId", "ML-TR-" + treeId.substring(10)); // 树报告的信息
- model.addAttribute("masterReport", treeReport);
- model.addAttribute("createTime", new Date(Long.parseLong(treeReport.getCreateTimeMillis())));
- model.addAttribute("supplements", childReports);
- model.addAttribute("finalReports", finalReports);
- model.addAttribute("category2String", ReportUtil.category2String);
- model.addAttribute("recurrent2String", ReportUtil.recurrent2String);
- model.addAttribute("severity2String", ReportUtil.severity2String);
- model.addAttribute("reviewed",bugReviewService.isBugReviewed(treeId));
- model.addAttribute("examId", examId);
- model.addAttribute("report2master",report2master);
- model.addAttribute("caseId", caseId);
- model.addAttribute("showReference",true);//是否展示其他聚合报告的参考标签
- return "tree_report_new";
- }
- @GetMapping(value = "/report_part")
- public String showTreerReportPart(@RequestParam("treeId") String treeId,
- @RequestParam("examId") long examId,
- @RequestParam("caseId") long caseId,
- @RequestParam(value = "finalReportId", required = false) Long finalReportId,
- Model model) {
- Map<String, BugDTO> bugMap = bugReportService.getAllBugsMap(examId, caseId);
- BugDTO treeReport = bugMap.get(treeId); // 从bugmap中取得主报告的信息
- List<String> treeRootids = hisservice.getTreeRoots(caseId+"-"+examId); // 获得所有的根结点的id
- List<String> childReportIds = hisservice.getSingleRootReports(treeId); // 获得所有自报告的信息
- List<BugDTO> childReports = new ArrayList<>();
- childReportIds.forEach(s->{
- childReports.add(bugMap.get(s));
- });
- Map<String, Long> categoryCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBugCategory, Collectors.counting()));
- Map<String, Long> pageCounts = childReports.stream().collect(Collectors.groupingBy(BugDTO::getBug_page,Collectors.counting()));
- Map<String, Long> recurrentCounts = childReports.stream()
- .map(BugDTO::getRecurrent)
- .map((recurrentNum) -> ReportUtil.recurrent2String.get(recurrentNum))
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
- Map<String, Long> severityCounts = childReports.stream()
- .map(BugDTO::getSeverity)
- .map((severityNum) -> ReportUtil.severity2String.get(severityNum))
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
- List<FinalReportDTO> finalReports = new ArrayList<>();// 暂时还没有finalreport的数据
- //report to master
- Map<String,String> report2master = masterReportService.getBugIds2Master(masterReportService.getAllMasterIdByExamIdAndCaseId(examId, caseId));
- model.addAttribute("severityCounts", severityCounts);
- model.addAttribute("categoryCounts", categoryCounts);
- model.addAttribute("pageCounts",pageCounts);
- model.addAttribute("recurrentCounts",recurrentCounts);
- model.addAttribute("aggReportId", "ML-TR-" + treeId.substring(10)); // 树报告的信息
- model.addAttribute("masterReport", treeReport);
- model.addAttribute("createTime", new Date(Long.parseLong(treeReport.getCreateTimeMillis())));
- model.addAttribute("supplements", childReports);
- model.addAttribute("finalReports", finalReports);
- model.addAttribute("category2String", ReportUtil.category2String);
- model.addAttribute("recurrent2String", ReportUtil.recurrent2String);
- model.addAttribute("severity2String", ReportUtil.severity2String);
- model.addAttribute("report2master",report2master); // report 2 master report//
- model.addAttribute("reviewed",false);
- model.addAttribute("examId", examId);
- model.addAttribute("caseId", caseId);
- model.addAttribute("showReference",false);//是否展示其他聚合报告的参考标签
- return "tree_report_new::treeBody";
- }
- //获取所有形成树状结构的bug根节点
- // case_take_id=1281-2724&start=0&count=10&page=null&identity=0&report_id=5cbc1a9f825a8960cdc7bd4f&worker_id=22383
- @RequestMapping(value = "/getTrees")
- public String getTrees(@RequestParam("case_take_id") String case_take_id, @RequestParam("start") String start,
- @RequestParam("count") String count, @RequestParam("page") String page,
- @RequestParam("identity") String identity, @RequestParam("report_id") String report_id,
- @RequestParam("worker_id") String worker_id,Model model) {
- System.out.println("case_take_id = " + case_take_id);
- String[] split = case_take_id.split("-");
- long caseId = Long.parseLong(split[0]);
- long examId = Long.parseLong(split[1]);
- try {
- JSONObject result = new JSONObject();
- List<String> all = hisservice.getTreeRoots(case_take_id);//获得所有的根结点。
- System.out.println("all.toString(): " + all.toString());
- hisservice.pageFilter(all, page);//清洗其他界面的bug报告,只留下本界面的。
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count))); // 做一个筛选。
- List<List<String>> list = new ArrayList<List<String>>();
- System.out.println(ids.toString());
- for(String id: ids) {
- list.add(hisservice.getDetail(id));
- }
- TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId);
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- // System.out.println("list = " + list);
- System.out.println("/getTrees result = " + result);
- model.addAttribute("examId", examId);
- model.addAttribute("caseId", caseId);
- model.addAttribute("task", task);
- model.addAttribute("Count", all.size());
- model.addAttribute("TreeRoot", list);
- model.addAttribute("identity", identity);
- model.addAttribute("report_id", report_id);
- model.addAttribute("worker_id", worker_id);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return "managerCheck";
- }
- //获取所有形成树状结构的bug根节点
- @RequestMapping(value = "/getTreesList/{case_take_id}/{start}/{count}/{page}")
- @ResponseBody
- public String getTreesList(@PathVariable String case_take_id, @PathVariable String start,
- @PathVariable String count, @PathVariable String page) {
- System.out.println("case_take_id = " + case_take_id);
- JSONObject result = new JSONObject();
- String[] split = case_take_id.split("-");
- long caseId = Long.parseLong(split[0]);
- long examId = Long.parseLong(split[1]);
- List<String> all = hisservice.getTreeRoots(case_take_id);
- hisservice.pageFilter(all, page);
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id: ids) {
- list.add(hisservice.getDetail(id));
- }
- TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId);
- try {
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return result.toString();
- }
-
- //获取所有单个节点的数据
- @RequestMapping(value = "/getSingle/{case_take_id}/{start}/{count}/{page}")
- @ResponseBody
- public String getSingle(@PathVariable String case_take_id, @PathVariable String start,
- @PathVariable String count, @PathVariable String page) {
- JSONObject result = new JSONObject();
- try {
- List<String> all = new ArrayList<String>();
- for(String id : hisservice.getRoots(case_take_id)) {
- if(hisservice.getHistory(id).getChildren().size() == 0) {all.add(id);}
- }
- hisservice.pageFilter(all, page);
- List<String> ids = all.subList(Integer.parseInt(start), Math.min(all.size(), Integer.parseInt(start) + Integer.parseInt(count)));
- List<String> invalid = hisservice.getInvalid(ids);
- for(String id: invalid) {
- if(ids.contains(id)) {ids.remove(id);}
- }
-
- List<List<String>> list = new ArrayList<List<String>>();
- for(String id : ids) {
- List<String> temp = new ArrayList<String>();
- temp.add(id);
- int score = aservice.getGrade(id);
- if(score != -1) {temp.add("true");}
- else {temp.add("false");}
- temp.add(recservice.getTitle(id));
- list.add(temp);
- }
- result.put("Count", all.size());
- result.put("TreeRoot", new JSONArray(list));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return result.toString();
- }
-
- //获取指定bug的所有路径
- @RequestMapping(value = "/getPath/{id}")
- @ResponseBody
- public String getPath(@PathVariable String id) {
- JSONObject result = new JSONObject();
- try {
- List<List<String>> lists = hisservice.getDepth(id);
- Set<String> filter = hisservice.filter(lists);
- result.put("path", new JSONArray(lists));
- result.put("invalid", new JSONArray(hisservice.getInvalid(filter)));
- List<String> ids = new ArrayList<String>(filter);
- result.put("score", new JSONArray(aservice.getScores(ids)));
- System.out.println("/getPath path = " + result);
- System.out.println("result.toString() = " + result.toString());
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return result.toString();
- }
-
- @RequestMapping(value = "/fresh")
- @ResponseBody
- public void fresh(HttpSession session, HttpServletResponse response) {
- if(session.getAttribute("trees") != null) {session.removeAttribute("trees");}
- if(session.getAttribute("single") != null) {session.removeAttribute("single");}
- }
- }
|