TaskController.java 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package com.mooctest.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.mooctest.data.BugDTO;
  5. import com.mooctest.data.SimpleResponse;
  6. import com.mooctest.data.TaskDTO;
  7. import com.mooctest.model.*;
  8. import com.mooctest.service.*;
  9. import com.mooctest.service.ConfigurationService;
  10. import com.mooctest.util.ReportUtil;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.ui.Model;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import java.sql.Timestamp;
  21. import java.util.ArrayList;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.function.Function;
  26. import java.util.stream.Collectors;
  27. import static java.util.stream.Collectors.toMap;
  28. /**
  29. * 任务相关接口
  30. */
  31. @Controller
  32. public class TaskController {
  33. @Autowired
  34. TaskService taskService;
  35. @Autowired
  36. BugReportService bugReportService;
  37. @Autowired
  38. HistoryService historyService;
  39. @Autowired
  40. MasterReportService masterReportService;
  41. @Autowired
  42. BugDataService bugDataService;
  43. @Autowired
  44. JobService jobService;
  45. @Autowired
  46. ConfigurationService configurationService;
  47. @Value("${baseurl.report.host}")
  48. String reportHost;
  49. @Value("${useOss}")
  50. boolean useOss;
  51. @Value("${baseurl.urlpath}")
  52. String urlPrefix;
  53. /**
  54. * 获取任务列表 /crowdTask
  55. * @param model
  56. * @return
  57. */
  58. @GetMapping("/crowdTask")
  59. public String home(Model model) {
  60. // 获得所有taskDTO,包括本地和慕测端
  61. List<TaskDTO> tasks = taskService.getAllTasks();
  62. List<TaskDTO> localTasks = taskService.findTask();
  63. tasks.addAll(localTasks);
  64. Collections.sort(tasks,(o1,o2)->{
  65. return (int)(o2.getExamId()-o1.getExamId());
  66. });
  67. // 将获得任务传给前端
  68. model.addAttribute("tasks", tasks);
  69. // 转到task_list页面
  70. return "task_list";
  71. }
  72. @GetMapping("/home")
  73. public String home2(Model model ){
  74. // 获得所有taskDTO,包括本地和慕测端
  75. List<TaskDTO> tasks = taskService.getAllTasks();
  76. List<TaskDTO> localTasks = taskService.findTask();
  77. tasks.addAll(localTasks);
  78. Collections.sort(tasks,(o1,o2)->{
  79. return (int)(o2.getExamId()-o1.getExamId());
  80. });
  81. JSONArray jsonArray = jobService.getJobs(); // 所有的数据
  82. List<Object> list = new ArrayList<>();
  83. for (Object single : jsonArray){
  84. changeTime2Long(single); // 修改创建时间的格式 以便前段展示
  85. list.add(single);
  86. }
  87. model.addAttribute("jobs",list.subList(0,Math.min(15,list.size())));
  88. model.addAttribute("tasks", tasks.subList(0,Math.min(15,tasks.size())));
  89. return "home";
  90. }
  91. @GetMapping("/taskDashBoard")
  92. public String dashBoard ( @RequestParam("taskId") long taskId ,
  93. @RequestParam("caseId") long caseId ,
  94. Model model){
  95. JSONObject data = taskService.getAllTaskDashboard(caseId, taskId);
  96. model.addAttribute("task",data);
  97. return "crowdTaskDashboard";
  98. }
  99. // TODO: 2020/4/1 sweager崩了没有测试
  100. @GetMapping("/distribute")
  101. @ResponseBody
  102. public String distributePeople (@RequestParam("examId") String examId,
  103. @RequestParam("caseId")String caseId){
  104. if(caseId == null || caseId.length()==0) return "fail";
  105. return taskService.distribute(examId,caseId)?"success":"fail";
  106. }
  107. @GetMapping("/")
  108. public String root(Model model) {
  109. return "redirect:/home";
  110. }
  111. @GetMapping("/task_detail")
  112. public String taskDetail(@RequestParam("examId") long examId,
  113. @RequestParam("caseId") long caseId,
  114. Model model) {
  115. // first check is there some data in bugData document
  116. // 将bug表中的信息同步到BugData中
  117. bugDataService.importBugData(examId, caseId);// 访问任务的时候同步报告信息
  118. // after import the bug data
  119. // 在MasterReport表中查找融合报告的数量,若大于0,则认为已经融合
  120. boolean aggregated = masterReportService.isAggregated(examId, caseId); // 检查报告是否已经聚合
  121. // 在bug表中查找所有的bug报告数
  122. List<BugDTO> allReports = bugReportService.getAllBugs(examId, caseId); // 得到所有的报告
  123. // 在BugData表中查找bug数据,<bugid,BugData>
  124. Map<String , BugData> bugIds2Data = bugDataService.bugId2BugData(examId, caseId);
  125. // 将单一状报告转化成树状
  126. Map<String,String> single2rootMap = historyService.getSingle2Root(caseId, examId);
  127. // 若被融合
  128. if (aggregated) { // add the information that where present when reports have been aggregated
  129. List<String> bugIds = allReports.stream().map(BugDTO::getId).collect(Collectors.toList());
  130. // MasterReport表中获得所有的报告
  131. List<MasterReport> mrs = masterReportService.getByBugIds(bugIds);
  132. Map<String, MasterReport> mrMap = mrs.stream().collect(toMap(MasterReport::getBugId, Function.identity()));
  133. allReports.forEach(bug -> {
  134. bug.setMasterId(mrMap.get(bug.getId()).getMasterId());
  135. });
  136. }
  137. allReports.forEach(bug->{
  138. String te = single2rootMap.get(bug.getId());
  139. bug.setTreeId(te==null?"null":te);
  140. bug.setStatus(bugIds2Data.get(bug.getId()).getStatus());
  141. bug.setReviewerId(bugIds2Data.get(bug.getId()).getReviewerId());
  142. });
  143. // 从json中获得的task数据保存到TaskDTO中返回
  144. TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId);
  145. // 返回服务序列号
  146. // String encodedUrl = taskService.getEncodeTaskReportUrl(examId, caseId) ;
  147. // 返回大图信息
  148. model.addAttribute("dtUrl",taskService.getTaskDaPanUrl(examId,caseId));
  149. model.addAttribute("aggregated", aggregated);
  150. // allReport是ButDTO集合
  151. model.addAttribute("allReports", allReports);
  152. model.addAttribute("severity2String", ReportUtil.severity2String);
  153. model.addAttribute("recurrent2String", ReportUtil.recurrent2String);
  154. model.addAttribute("task", task);
  155. model.addAttribute("reviewMap", ReportUtil.reviewerMap);
  156. model.addAttribute("examId", examId);
  157. model.addAttribute("caseId", caseId);
  158. model.addAttribute("reportHost",reportHost);
  159. // model.addAttribute("encodedUrl",encodedUrl);
  160. return "task_detail";
  161. }
  162. private void changeTime2Long ( Object input){
  163. JSONObject temp = (JSONObject) input;
  164. temp.put("create_time",new Timestamp(Long.parseLong(temp.get("create_time").toString()))); // 修改创建时间的格式 以便前段展示
  165. }
  166. @GetMapping("/addCrowdTask")
  167. public String addCrowdTask(Model model){
  168. model.addAttribute("templateUrl",useOss?"http://mooctest-site.oss-cn-shanghai.aliyuncs.com/excel-template.xlsx":urlPrefix+"excel-template.xlsx");
  169. return "addCrowdTask";
  170. }
  171. /**
  172. * 添加任务 /addCrowdTask
  173. * @param name 任务名称
  174. * @param description 任务描述
  175. * @param os 任务的操作系统
  176. * @param threePage 测试大纲表格
  177. * @param model
  178. * @return
  179. */
  180. @PostMapping("/addCrowdTask")
  181. @ResponseBody
  182. public SimpleResponse addCrowdTask2(@RequestParam("name")String name, @RequestParam("description")String description,
  183. @RequestParam("os")String os, @RequestParam("threePage") MultipartFile threePage,
  184. Model model){
  185. return taskService.addCrowdTask(name, description, os, threePage);
  186. }
  187. /**
  188. * 信创创建任务后调用此接口在众测新建任务 /addCrowdTaskDefault
  189. * collaborativeType 0-非协作 1-协作
  190. * @param name
  191. * @param description
  192. * @param collaborativeType
  193. * @return
  194. */
  195. @PostMapping("/addCrowdTaskDefault")
  196. @ResponseBody
  197. public SimpleResponse addCrowdTaskDefault(@RequestParam("name")String name, @RequestParam("description")String description,
  198. @RequestParam("collaborativeType")int collaborativeType,
  199. @RequestParam("threePageUrl") String threePageUrl, @RequestParam("fileName") String fileName){
  200. Map<String, Object> configurationMap = configurationService.getConfigurationMap();
  201. String os = configurationMap.get("os").toString();
  202. // 后边generatePaperType方法中会根据;进行split
  203. os = os.replaceAll(",", ";").replaceAll(" ", "").replaceAll("\\[", "").replaceAll("\\]", "");
  204. if(threePageUrl == null || threePageUrl.equals("")) {
  205. return new SimpleResponse(400,"请提交三级页面");
  206. }
  207. long caseId = taskService.addCrowdTaskDefault(name, description, os, threePageUrl, fileName, collaborativeType);
  208. long examId = caseId;
  209. // 返回大图url
  210. String taskDaPanUrl = taskService.getTaskDaPanUrl(examId, caseId);
  211. taskDaPanUrl = taskDaPanUrl.replaceAll("%3D", "=");
  212. TaskExtend taskExtend = new TaskExtend(examId, caseId, taskDaPanUrl);
  213. return caseId != -1 ? new SimpleResponse(200,"创建成功", taskExtend) : new SimpleResponse(400,"创建失败");
  214. }
  215. }