123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- package com.mooctest.controller;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.mooctest.data.BugDTO;
- import com.mooctest.data.SimpleResponse;
- import com.mooctest.data.TaskDTO;
- import com.mooctest.model.*;
- import com.mooctest.service.*;
- import com.mooctest.service.ConfigurationService;
- import com.mooctest.util.ReportUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.multipart.MultipartFile;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Map;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- import static java.util.stream.Collectors.toMap;
- /**
- * 任务相关接口
- */
- @Controller
- public class TaskController {
- @Autowired
- TaskService taskService;
- @Autowired
- BugReportService bugReportService;
- @Autowired
- HistoryService historyService;
- @Autowired
- MasterReportService masterReportService;
- @Autowired
- BugDataService bugDataService;
- @Autowired
- JobService jobService;
- @Autowired
- ConfigurationService configurationService;
- @Value("${baseurl.report.host}")
- String reportHost;
- @Value("${useOss}")
- boolean useOss;
- @Value("${baseurl.urlpath}")
- String urlPrefix;
- /**
- * 获取任务列表 /crowdTask
- * @param model
- * @return
- */
- @GetMapping("/crowdTask")
- public String home(Model model) {
- // 获得所有taskDTO,包括本地和慕测端
- List<TaskDTO> tasks = taskService.getAllTasks();
- List<TaskDTO> localTasks = taskService.findTask();
- tasks.addAll(localTasks);
- Collections.sort(tasks,(o1,o2)->{
- return (int)(o2.getExamId()-o1.getExamId());
- });
- // 将获得任务传给前端
- model.addAttribute("tasks", tasks);
- // 转到task_list页面
- return "task_list";
- }
- @GetMapping("/home")
- public String home2(Model model ){
- // 获得所有taskDTO,包括本地和慕测端
- List<TaskDTO> tasks = taskService.getAllTasks();
- List<TaskDTO> localTasks = taskService.findTask();
- tasks.addAll(localTasks);
- Collections.sort(tasks,(o1,o2)->{
- return (int)(o2.getExamId()-o1.getExamId());
- });
- JSONArray jsonArray = jobService.getJobs(); // 所有的数据
- List<Object> list = new ArrayList<>();
- for (Object single : jsonArray){
- changeTime2Long(single); // 修改创建时间的格式 以便前段展示
- list.add(single);
- }
- model.addAttribute("jobs",list.subList(0,Math.min(15,list.size())));
- model.addAttribute("tasks", tasks.subList(0,Math.min(15,tasks.size())));
- return "home";
- }
- @GetMapping("/taskDashBoard")
- public String dashBoard ( @RequestParam("taskId") long taskId ,
- @RequestParam("caseId") long caseId ,
- Model model){
- JSONObject data = taskService.getAllTaskDashboard(caseId, taskId);
- model.addAttribute("task",data);
- return "crowdTaskDashboard";
- }
- // TODO: 2020/4/1 sweager崩了没有测试
- @GetMapping("/distribute")
- @ResponseBody
- public String distributePeople (@RequestParam("examId") String examId,
- @RequestParam("caseId")String caseId){
- if(caseId == null || caseId.length()==0) return "fail";
- return taskService.distribute(examId,caseId)?"success":"fail";
- }
- @GetMapping("/")
- public String root(Model model) {
- return "redirect:/home";
- }
- @GetMapping("/task_detail")
- public String taskDetail(@RequestParam("examId") long examId,
- @RequestParam("caseId") long caseId,
- Model model) {
- // first check is there some data in bugData document
- // 将bug表中的信息同步到BugData中
- bugDataService.importBugData(examId, caseId);// 访问任务的时候同步报告信息
- // after import the bug data
- // 在MasterReport表中查找融合报告的数量,若大于0,则认为已经融合
- boolean aggregated = masterReportService.isAggregated(examId, caseId); // 检查报告是否已经聚合
- // 在bug表中查找所有的bug报告数
- List<BugDTO> allReports = bugReportService.getAllBugs(examId, caseId); // 得到所有的报告
- // 在BugData表中查找bug数据,<bugid,BugData>
- Map<String , BugData> bugIds2Data = bugDataService.bugId2BugData(examId, caseId);
- // 将单一状报告转化成树状
- Map<String,String> single2rootMap = historyService.getSingle2Root(caseId, examId);
- // 若被融合
- if (aggregated) { // add the information that where present when reports have been aggregated
- List<String> bugIds = allReports.stream().map(BugDTO::getId).collect(Collectors.toList());
- // MasterReport表中获得所有的报告
- List<MasterReport> mrs = masterReportService.getByBugIds(bugIds);
- Map<String, MasterReport> mrMap = mrs.stream().collect(toMap(MasterReport::getBugId, Function.identity()));
- allReports.forEach(bug -> {
- bug.setMasterId(mrMap.get(bug.getId()).getMasterId());
- });
- }
- allReports.forEach(bug->{
- String te = single2rootMap.get(bug.getId());
- bug.setTreeId(te==null?"null":te);
- bug.setStatus(bugIds2Data.get(bug.getId()).getStatus());
- bug.setReviewerId(bugIds2Data.get(bug.getId()).getReviewerId());
- });
- // 从json中获得的task数据保存到TaskDTO中返回
- TaskDTO task = taskService.getByExamIdAndCaseId(examId, caseId);
- // 返回服务序列号
- // String encodedUrl = taskService.getEncodeTaskReportUrl(examId, caseId) ;
- // 返回大图信息
- model.addAttribute("dtUrl",taskService.getTaskDaPanUrl(examId,caseId));
- model.addAttribute("aggregated", aggregated);
- // allReport是ButDTO集合
- model.addAttribute("allReports", allReports);
- model.addAttribute("severity2String", ReportUtil.severity2String);
- model.addAttribute("recurrent2String", ReportUtil.recurrent2String);
- model.addAttribute("task", task);
- model.addAttribute("reviewMap", ReportUtil.reviewerMap);
- model.addAttribute("examId", examId);
- model.addAttribute("caseId", caseId);
- model.addAttribute("reportHost",reportHost);
- // model.addAttribute("encodedUrl",encodedUrl);
- return "task_detail";
- }
- private void changeTime2Long ( Object input){
- JSONObject temp = (JSONObject) input;
- temp.put("create_time",new Timestamp(Long.parseLong(temp.get("create_time").toString()))); // 修改创建时间的格式 以便前段展示
- }
- @GetMapping("/addCrowdTask")
- public String addCrowdTask(Model model){
- model.addAttribute("templateUrl",useOss?"http://mooctest-site.oss-cn-shanghai.aliyuncs.com/excel-template.xlsx":urlPrefix+"excel-template.xlsx");
- return "addCrowdTask";
- }
- /**
- * 添加任务 /addCrowdTask
- * @param name 任务名称
- * @param description 任务描述
- * @param os 任务的操作系统
- * @param threePage 测试大纲表格
- * @param model
- * @return
- */
- @PostMapping("/addCrowdTask")
- @ResponseBody
- public SimpleResponse addCrowdTask2(@RequestParam("name")String name, @RequestParam("description")String description,
- @RequestParam("os")String os, @RequestParam("threePage") MultipartFile threePage,
- Model model){
- return taskService.addCrowdTask(name, description, os, threePage);
- }
- /**
- * 信创创建任务后调用此接口在众测新建任务 /addCrowdTaskDefault
- * collaborativeType 0-非协作 1-协作
- * @param name
- * @param description
- * @param collaborativeType
- * @return
- */
- @PostMapping("/addCrowdTaskDefault")
- @ResponseBody
- public SimpleResponse addCrowdTaskDefault(@RequestParam("name")String name, @RequestParam("description")String description,
- @RequestParam("collaborativeType")int collaborativeType,
- @RequestParam("threePageUrl") String threePageUrl, @RequestParam("fileName") String fileName){
- Map<String, Object> configurationMap = configurationService.getConfigurationMap();
- String os = configurationMap.get("os").toString();
- // 后边generatePaperType方法中会根据;进行split
- os = os.replaceAll(",", ";").replaceAll(" ", "").replaceAll("\\[", "").replaceAll("\\]", "");
- if(threePageUrl == null || threePageUrl.equals("")) {
- return new SimpleResponse(400,"请提交三级页面");
- }
- long caseId = taskService.addCrowdTaskDefault(name, description, os, threePageUrl, fileName, collaborativeType);
- long examId = caseId;
- // 返回大图url
- String taskDaPanUrl = taskService.getTaskDaPanUrl(examId, caseId);
- taskDaPanUrl = taskDaPanUrl.replaceAll("%3D", "=");
- TaskExtend taskExtend = new TaskExtend(examId, caseId, taskDaPanUrl);
- return caseId != -1 ? new SimpleResponse(200,"创建成功", taskExtend) : new SimpleResponse(400,"创建失败");
- }
- }
|