|
@@ -1,449 +1,450 @@
|
|
|
-package com.mooctest.service;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.mooctest.dao.MasterReportDao;
|
|
|
-import com.mooctest.dao.TaskDao;
|
|
|
-import com.mooctest.dao2.CrowdTaskDao;
|
|
|
-import com.mooctest.data.SimpleResponse;
|
|
|
-import com.mooctest.data.TaskDTO;
|
|
|
-import com.mooctest.data.enums.CollaborativeType;
|
|
|
-import com.mooctest.model.CrowdTask;
|
|
|
-import com.mooctest.model.Task;
|
|
|
-import com.mooctest.util.EncodeUtil;
|
|
|
-import com.mooctest.util.TimeUtil;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.core.io.ByteArrayResource;
|
|
|
-import org.springframework.http.*;
|
|
|
-import org.springframework.http.converter.HttpMessageConverter;
|
|
|
-import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.LinkedMultiValueMap;
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.nio.charset.Charset;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class TaskService {
|
|
|
- List<Task> tasks = Arrays.asList(
|
|
|
- new Task(2613, 1489, "途牛旅游", "/static/images/apps/tuniu.png", "9.56.0", 0, "2018-11-12", "2018-12-20"),
|
|
|
- new Task(2613, 1489, "花田小憩", "/static/images/apps/huatianxiaoqi.png", "6.5.0", 1, "2018-10-12", "2018-10-20"),
|
|
|
- new Task(2613, 1489, "小猿搜题", "/static/images/apps/xiaoyuansouti.png", "8.5.0", 1, "2018-10-03", "2018-10-15"),
|
|
|
- new Task(2613, 1489, "途牛旅游", "/static/images/apps/tuniu.png", "9.50.0", 1, "2018-10-02", "2018-10-12"),
|
|
|
- new Task(2613, 1489, "JayMe", "/static/images/apps/JayMe.jpeg", "3.5.8", 1, "2018-10-01", "2018-11-01"),
|
|
|
- new Task(2613, 1489, "和苗智家", "/static/images/apps/hemiaozhijia.png", "1.0.8", 1, "2018-09-22", "2018-09-29"),
|
|
|
- new Task(2613, 1489, "邻里快讯", "/static/images/apps/linlikuaixun.png", "2.1.3", 1, "2018-09-18", "2018-09-29"),
|
|
|
- new Task(2613, 1489, "探记", "/static/images/apps/tanji.png", "4.1.0", 1, "2018-09-13", "2018-09-22"),
|
|
|
- new Task(2973, 1717, "月度赛", "/static/images/apps/tanji.png", "4.1.0", 1, "2018-09-13", "2018-09-22")
|
|
|
- );
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MasterReportDao masterReportDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- TaskDao taskDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CrowdTaskDao crowdTaskDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- BugReportService bugReportService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- BugDataService bugDataService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- FileService fileService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ConfigurationService configurationService;
|
|
|
-
|
|
|
- @Value("${baseurl.taskDistribute}")
|
|
|
- String distributeUrl;
|
|
|
-
|
|
|
- @Value("${baseurl.report.host}")
|
|
|
- String reportHost ;
|
|
|
- private final String HTTP = "http://";
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获得所有任务
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<TaskDTO> getAllTasks() {
|
|
|
- // 传统情况下在java代码里访问restful服务,一般使用Apache的HttpClient。不过此种方法使用起来太过繁琐。
|
|
|
- // spring提供了一种简单便捷的模板类来进行操作,这就是RestTemplate。
|
|
|
- RestTemplate rt = new RestTemplate();
|
|
|
- // springMVC通过StringHttpMessageConverter将Controller的返回对象转为字符串
|
|
|
- StringHttpMessageConverter stringHttpMessageConverter=new StringHttpMessageConverter(Charset.forName("UTF-8"));
|
|
|
- List<HttpMessageConverter<?>> list=new ArrayList<HttpMessageConverter<?>>();
|
|
|
- list.add(stringHttpMessageConverter);
|
|
|
- rt.setMessageConverters(list);
|
|
|
- // 将获得task字符串以json格式解析
|
|
|
- String taskInfoAddr = HTTP + reportHost + "/Bug/api/extra/getExamList";
|
|
|
- System.out.println("taskInfoAddr:" + taskInfoAddr);
|
|
|
- JSONObject tasksJson = JSON.parseObject(rt.getForObject(taskInfoAddr, String.class));
|
|
|
- // 获得tasksJson中的“data”字段的迭代器
|
|
|
- ListIterator<Object> tasksIter = tasksJson.getJSONArray("data").listIterator();
|
|
|
- // 新建TaskDTO队列,TaskDTO没有持久化处理
|
|
|
- List<TaskDTO> dtos = new ArrayList<>();
|
|
|
- // 遍历taskJson中“data“
|
|
|
- while (tasksIter.hasNext()) {
|
|
|
- // 获得每个”data“对象
|
|
|
- JSONObject taskInfo = (JSONObject) tasksIter.next();
|
|
|
- TaskDTO dto = new TaskDTO();
|
|
|
- // 将获得的每个taskJson的exam_id,case_id,name赋给taskdto
|
|
|
- dto.setExamId(Long.parseLong(taskInfo.getString("task_id")));
|
|
|
- dto.setCaseId(Long.parseLong(taskInfo.getString("case_id")));
|
|
|
- dto.setName(taskInfo.getString("name"));
|
|
|
- // 将taskdto加入taskdtos队列
|
|
|
- dtos.add(dto);
|
|
|
- }
|
|
|
-
|
|
|
- // return中是给taskDTO各个属性赋值的过程
|
|
|
- return dtos.stream()
|
|
|
- .map(taskDTO -> {
|
|
|
- // 获得报告数量
|
|
|
- long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
- // 设没有处理的Bug数为0
|
|
|
- long undealBugs = 0;
|
|
|
- // 如果总Bug报告数为0(没有初始化),将没有处理的报告数设置为报告总数
|
|
|
- if (totalBugs == 0) {
|
|
|
- totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
- undealBugs = totalBugs;
|
|
|
- } else {
|
|
|
- // 否则将获得没有处理的报告数
|
|
|
- undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
- }
|
|
|
- // 给taskDTO的总bug数和为处理的bug数赋值
|
|
|
- taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
- taskDTO.setNumOfUndeal(undealBugs);
|
|
|
- return taskDTO;
|
|
|
- }).sorted(Comparator.comparing(TaskDTO::getExamId).reversed())
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 在本地获得task方法
|
|
|
- public List<TaskDTO> findTask() {
|
|
|
- List<TaskDTO> taskDTOs = new ArrayList<>();
|
|
|
-
|
|
|
- List<Task> tasks = taskDao.findAll();
|
|
|
- for (Task task: tasks) {
|
|
|
- TaskDTO taskDTO = TaskDTO.builder().examId((long) task.getTaskId()).caseId( (long) task.getCaseId()).name(task.getName()).build();
|
|
|
- taskDTOs.add(taskDTO);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return taskDTOs.stream()
|
|
|
- .map(taskDTO -> {
|
|
|
- // 获得报告数量
|
|
|
- long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
- // 设没有处理的Bug数为0
|
|
|
- long undealBugs = 0;
|
|
|
- // 如果总Bug报告数为0(没有初始化),将没有处理的报告数设置为报告总数
|
|
|
- if (totalBugs == 0) {
|
|
|
- totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
- undealBugs = totalBugs;
|
|
|
- } else {
|
|
|
- // 否则将获得没有处理的报告数
|
|
|
- undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
- }
|
|
|
- // 给taskDTO的总bug数和为处理的bug数赋值
|
|
|
- taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
- taskDTO.setNumOfUndeal(undealBugs);
|
|
|
- return taskDTO;
|
|
|
- }).sorted(Comparator.comparing(TaskDTO::getExamId).reversed())
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public List<TaskDTO> getAllTasks2() {
|
|
|
- return tasks.stream()
|
|
|
- .map(task -> {
|
|
|
- TaskDTO taskDTO = new TaskDTO();
|
|
|
- BeanUtils.copyProperties(task, taskDTO);
|
|
|
- return taskDTO;
|
|
|
- })
|
|
|
- .map(taskDTO -> {
|
|
|
- if (taskDTO.getName().equals("途牛旅游") && taskDTO.getVersion().equals("9.56.0")) {
|
|
|
- long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
- long undealBugs = 0;
|
|
|
- if (totalBugs == 0) {
|
|
|
- totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
- undealBugs = totalBugs;
|
|
|
- } else {
|
|
|
- undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
- }
|
|
|
- taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
- taskDTO.setNumOfUndeal(undealBugs);
|
|
|
- } else {
|
|
|
- Random r = new Random();
|
|
|
- int n = r.nextInt(100)%(100-20+1) + 20;
|
|
|
- taskDTO.setNumOfTotalBug(n * 10);
|
|
|
- taskDTO.setNumOfUndeal(0);
|
|
|
- }
|
|
|
- return taskDTO;
|
|
|
- }).sorted(Comparator.comparing(TaskDTO::getStatus))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public JSONObject getAllTaskDashboard (long caseId,long taskId){
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
- String url = HTTP+reportHost+"/Bug/api/analyze/analyseExam";
|
|
|
- MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
|
|
|
- paramMap.add("caseId", caseId);
|
|
|
- paramMap.add("taskId", taskId);
|
|
|
- template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap,headers);
|
|
|
- ResponseEntity<String> response2 = template.postForEntity(url, httpEntity, String.class);
|
|
|
- JSONObject tasksJson = JSON.parseObject(response2.getBody());
|
|
|
- tasksJson.put("taskName","第一次众测测试");
|
|
|
- tasksJson.put("startTime", TimeUtil.timestamp2strSimple(tasksJson.get("startTime").toString()));
|
|
|
- tasksJson.put("endTime", TimeUtil.timestamp2strSimple(tasksJson.get("endTime").toString()));
|
|
|
- tasksJson.put("gradeArray" , getGradeInt(tasksJson.getJSONObject("gradeDistrubute")));
|
|
|
- return tasksJson;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public boolean distribute(String examId,String caseId){
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
- String url = distributeUrl+"team/dopreteam";
|
|
|
- JSONObject vo = new JSONObject();
|
|
|
- vo.fluentPut("clusterNum",4); // 默认大小
|
|
|
- vo.fluentPut("peopleSizeInTeam",4); // 默认大小
|
|
|
- JSONObject exam = new JSONObject();
|
|
|
- TaskDTO task = getByExamIdAndCaseId(Long.parseLong(examId),Long.parseLong(caseId));
|
|
|
- exam.fluentPut("beginTime",TimeUtil.timestampTo24format(Long.parseLong(task.getStartTime())));
|
|
|
- exam.fluentPut("endTime",TimeUtil.timestampTo24format(Long.parseLong(task.getEndTime())));
|
|
|
- exam.fluentPut("caseTakeId",examId + "-" + caseId);
|
|
|
- exam.fluentPut("caseTypeId",1); // 默认是app类型的
|
|
|
- exam.fluentPut("state",0); // 有默认值无需传
|
|
|
- exam.fluentPut("groupId",30); // 需要从前端获取
|
|
|
- exam.fluentPut("id",0);
|
|
|
- vo.fluentPut("exam",exam);
|
|
|
- template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- HttpEntity<String> entity = new HttpEntity<String>(vo.toJSONString(),headers);
|
|
|
- ResponseEntity<String> response2 = template.postForEntity(url, entity, String.class);
|
|
|
- JSONArray tasksJson = JSON.parseArray(response2.getBody());
|
|
|
- return tasksJson != null;
|
|
|
- }
|
|
|
-
|
|
|
- private int [] getGradeInt(JSONObject jsonObject){
|
|
|
- int [] res = new int[11];
|
|
|
-// for (int i = 0 ; i < 11 ; i++ ){
|
|
|
-// res[i] = Integer.parseInt(jsonObject.get(i+"").toString());
|
|
|
-// }
|
|
|
- Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
- while(sIterator.hasNext()){
|
|
|
- // 获得key
|
|
|
- String key = sIterator.next();
|
|
|
- // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
|
|
|
- String value = jsonObject.getString(key);
|
|
|
- res[Integer.valueOf(key)]+=Integer.getInteger(value);
|
|
|
- }
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- public String addCrowdTaskPure(String name,String description,String time,String type,MultipartFile threePage){
|
|
|
- if(threePage ==null || threePage.isEmpty()) return "请提交三级页面";
|
|
|
- String threePageUrl = fileService.uploadFile(threePage);
|
|
|
- try {
|
|
|
- long flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),"",getMaxCaseId()+1,type,description,name, CollaborativeType.IS_COLLABORATIVE.getId());
|
|
|
- return flag!=-1 ?""+flag:"创建失败";
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "创建众测失败";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public SimpleResponse addCrowdTask(String name, String description, String os, MultipartFile threePage){
|
|
|
- if(threePage ==null || threePage.isEmpty()) return new SimpleResponse(400,"请提交三级页面");
|
|
|
- String threePageUrl = fileService.uploadFile(threePage);
|
|
|
- try {
|
|
|
- long flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),generatePaperType(os),getMaxCaseId()+1,"",description,name, CollaborativeType.IS_COLLABORATIVE.getId());
|
|
|
- return flag!=-1 ?new SimpleResponse(200,"创建成功,id为"+flag):new SimpleResponse(400,"创建失败");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return new SimpleResponse(400,"创建众测失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public long addCrowdTaskDefault(String name, String description, String os, String threePageUrl, String fileName, int collaborativeType){
|
|
|
- // 不进行上传是否存在问题
|
|
|
-// String threePageUrl = fileService.uploadFile(threePage);
|
|
|
- try {
|
|
|
- long caseId = createCrowdTest(threePageUrl,fileName,generatePaperType(os),getMaxCaseId()+1,"",description,name, collaborativeType);
|
|
|
- return caseId;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return -1;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public long createCrowdTest(String file, String fileName, String paperType, Long caseId, String testType, String description, String appName, int collaborativeType) throws Exception {
|
|
|
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
- params.add("file", file);
|
|
|
- params.add("file_name", fileName);
|
|
|
- params.add("paper_type", paperType);
|
|
|
- params.add("case_id", caseId + "");
|
|
|
- params.add("test_type", testType);
|
|
|
- params.add("description", description);
|
|
|
- params.add("app_name", appName);
|
|
|
- params.add("collaborative_type", collaborativeType + "");
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.postForEntity
|
|
|
- ("http://" + reportHost + "/Bug/api/extra/uploadExamUrl", params, String.class);
|
|
|
- System.out.println("http://" + reportHost + "/Bug/api/extra/uploadExamUrl " + responseEntity.getStatusCode());
|
|
|
- if (responseEntity.getStatusCode().equals(HttpStatus.OK)){
|
|
|
- fileService.uploadJson(responseEntity.getBody(),caseId);
|
|
|
- return caseId;
|
|
|
- }else {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public String getEncodeTaskReportUrl(long examId,long caseId){
|
|
|
-// String url = HTTP + reportHost + "/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
- String url = HTTP + "127.0.0.1:5555/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
- String encodedUrl = EncodeUtil.strConvertBase(url);
|
|
|
- return encodedUrl;
|
|
|
- }
|
|
|
-
|
|
|
- public String getTaskReportUrl(long examId,long caseId){
|
|
|
- // 修改
|
|
|
-// return HTTP + reportHost + "/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
- return HTTP + "127.0.0.1:5555/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
- }
|
|
|
-
|
|
|
- public TaskDTO getByExamIdAndCaseId(long examId, long caseId) {
|
|
|
- TaskDTO taskDefault = new TaskDTO();
|
|
|
- taskDefault.setExamId(examId);
|
|
|
- taskDefault.setCaseId(caseId);
|
|
|
- taskDefault.setName("no name");
|
|
|
- List<TaskDTO> tasks = getAllTasks();
|
|
|
- TaskDTO taskDTO = tasks.stream().filter(task -> task.getExamId() == examId && task.getCaseId() == caseId).findFirst().orElse(taskDefault);
|
|
|
-
|
|
|
- long totalBugs = bugDataService.getReportNum(examId, caseId);
|
|
|
- long undealBugs = 0;
|
|
|
- if (totalBugs == 0) {
|
|
|
- totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
- undealBugs = totalBugs;
|
|
|
- } else {
|
|
|
- undealBugs = bugDataService.getReportUnDealNum(examId, caseId);
|
|
|
- }
|
|
|
- taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
- taskDTO.setNumOfUndeal(undealBugs);
|
|
|
- return taskDTO;
|
|
|
- }
|
|
|
-
|
|
|
- private long getMaxCaseId(){
|
|
|
- List<CrowdTask> list = crowdTaskDao.findAll();
|
|
|
- long max =0;
|
|
|
- long temp =0;
|
|
|
- for(CrowdTask task : list){
|
|
|
- temp=Long.parseLong(task.getId());
|
|
|
- max=temp>max?temp:max;
|
|
|
- }
|
|
|
-// CrowdTask task = crowdTaskDao.findFirstByOrderByIdDesc();
|
|
|
- return max;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean exportTask(String caseId){
|
|
|
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
- params.add("caseId", caseId);
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.postForEntity
|
|
|
- ("http://" + reportHost + "/Bug/api/data/outputByCaseId", params, String.class);
|
|
|
- return responseEntity.getStatusCode().equals(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean importTask(String number,String originId,
|
|
|
- MultipartFile zipFile, MultipartFile jsonFile) {
|
|
|
-
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- MediaType type = MediaType.parseMediaType("multipart/form-data");
|
|
|
- // 设置请求的格式类型
|
|
|
- headers.setContentType(type);
|
|
|
- ByteArrayResource zipFileResource = null;
|
|
|
- ByteArrayResource jsonFileResource = null;
|
|
|
- try {
|
|
|
- zipFileResource= new ByteArrayResource(zipFile.getBytes()) {
|
|
|
- @Override
|
|
|
- public String getFilename() {
|
|
|
- return zipFile.getOriginalFilename();
|
|
|
- }
|
|
|
- };
|
|
|
- jsonFileResource= new ByteArrayResource(jsonFile.getBytes()) {
|
|
|
- @Override
|
|
|
- public String getFilename() {
|
|
|
- return jsonFile.getOriginalFilename();
|
|
|
- }
|
|
|
- };
|
|
|
- }catch (IOException e){
|
|
|
- return false;
|
|
|
- }
|
|
|
- MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
|
|
- params.add("zipFile", zipFileResource);
|
|
|
- params.add("jsonFile", jsonFileResource);
|
|
|
- params.add("originalCaseId", originId);
|
|
|
- params.add("cpSerialNum", number);
|
|
|
- HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(params, headers);
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://" + reportHost + "/Bug/api/data/inputFromFile", files, String.class);
|
|
|
- return responseEntity.getStatusCode().equals(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private static String generatePaperType(String os){
|
|
|
- StringBuffer value = new StringBuffer();
|
|
|
- if(os==null||os.length()==0){
|
|
|
- value.append("\"windows\",\"linux\",\"macos\"");
|
|
|
- }else{
|
|
|
- String [] data = os.split(";");
|
|
|
- for(int i =0;i<data.length;i++){
|
|
|
- if(i!=data.length-1){
|
|
|
- value.append("\""+data[i]+"\",");
|
|
|
- }else{
|
|
|
- value.append("\""+data[i]+"\"");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return "{\"title\":\"测试报告名称\",\"subTitles\":[{\"name\":\"设备名称\", \"type\":\"text\"},{\"name\":\"设备品牌\",\"type\":\"text\"},{\"name\":\"操作系统\",\"type\":\"enum\",\"value\":["
|
|
|
- +value.toString()
|
|
|
- + "]}],\"caseList\":true,\"bugList\": true,\"testScript\":false,\"suppleReport\":false,\"testLog\":false}";
|
|
|
- }
|
|
|
-
|
|
|
- public String getTaskDaPanUrl(long taskId,long caseId){
|
|
|
-// return "test";
|
|
|
- MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
- params.add("caseId", caseId+"");
|
|
|
- params.add("taskId", taskId+"");
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.postForEntity
|
|
|
- ("http://" + reportHost + "/Bug/api/analyze/analyse/getTaskToken", params, String.class);
|
|
|
- if (responseEntity.getStatusCode().equals(HttpStatus.OK)){
|
|
|
- String token = responseEntity.getBody();
|
|
|
- return "http://"+reportHost+"/dashboard/#/taskboard?token="+token;
|
|
|
- }else return "error";
|
|
|
- }
|
|
|
-}
|
|
|
+package com.mooctest.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.mooctest.dao.MasterReportDao;
|
|
|
+import com.mooctest.dao.TaskDao;
|
|
|
+import com.mooctest.dao2.CrowdTaskDao;
|
|
|
+import com.mooctest.data.SimpleResponse;
|
|
|
+import com.mooctest.data.TaskDTO;
|
|
|
+import com.mooctest.data.enums.CollaborativeType;
|
|
|
+import com.mooctest.model.CrowdTask;
|
|
|
+import com.mooctest.model.Task;
|
|
|
+import com.mooctest.util.EncodeUtil;
|
|
|
+import com.mooctest.util.TimeUtil;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.core.io.ByteArrayResource;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.http.converter.HttpMessageConverter;
|
|
|
+import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class TaskService {
|
|
|
+ List<Task> tasks = Arrays.asList(
|
|
|
+ new Task(2613, 1489, "途牛旅游", "/static/images/apps/tuniu.png", "9.56.0", 0, "2018-11-12", "2018-12-20"),
|
|
|
+ new Task(2613, 1489, "花田小憩", "/static/images/apps/huatianxiaoqi.png", "6.5.0", 1, "2018-10-12", "2018-10-20"),
|
|
|
+ new Task(2613, 1489, "小猿搜题", "/static/images/apps/xiaoyuansouti.png", "8.5.0", 1, "2018-10-03", "2018-10-15"),
|
|
|
+ new Task(2613, 1489, "途牛旅游", "/static/images/apps/tuniu.png", "9.50.0", 1, "2018-10-02", "2018-10-12"),
|
|
|
+ new Task(2613, 1489, "JayMe", "/static/images/apps/JayMe.jpeg", "3.5.8", 1, "2018-10-01", "2018-11-01"),
|
|
|
+ new Task(2613, 1489, "和苗智家", "/static/images/apps/hemiaozhijia.png", "1.0.8", 1, "2018-09-22", "2018-09-29"),
|
|
|
+ new Task(2613, 1489, "邻里快讯", "/static/images/apps/linlikuaixun.png", "2.1.3", 1, "2018-09-18", "2018-09-29"),
|
|
|
+ new Task(2613, 1489, "探记", "/static/images/apps/tanji.png", "4.1.0", 1, "2018-09-13", "2018-09-22"),
|
|
|
+ new Task(2973, 1717, "月度赛", "/static/images/apps/tanji.png", "4.1.0", 1, "2018-09-13", "2018-09-22")
|
|
|
+ );
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MasterReportDao masterReportDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TaskDao taskDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CrowdTaskDao crowdTaskDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BugReportService bugReportService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BugDataService bugDataService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FileService fileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ConfigurationService configurationService;
|
|
|
+
|
|
|
+ @Value("${baseurl.taskDistribute}")
|
|
|
+ String distributeUrl;
|
|
|
+
|
|
|
+ @Value("${baseurl.report.host}")
|
|
|
+ String reportHost ;
|
|
|
+ private final String HTTP = "http://";
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得所有任务
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<TaskDTO> getAllTasks() {
|
|
|
+ // 传统情况下在java代码里访问restful服务,一般使用Apache的HttpClient。不过此种方法使用起来太过繁琐。
|
|
|
+ // spring提供了一种简单便捷的模板类来进行操作,这就是RestTemplate。
|
|
|
+ RestTemplate rt = new RestTemplate();
|
|
|
+ // springMVC通过StringHttpMessageConverter将Controller的返回对象转为字符串
|
|
|
+ StringHttpMessageConverter stringHttpMessageConverter=new StringHttpMessageConverter(Charset.forName("UTF-8"));
|
|
|
+ List<HttpMessageConverter<?>> list=new ArrayList<HttpMessageConverter<?>>();
|
|
|
+ list.add(stringHttpMessageConverter);
|
|
|
+ rt.setMessageConverters(list);
|
|
|
+ // 将获得task字符串以json格式解析
|
|
|
+ String taskInfoAddr = HTTP + reportHost + "/Bug/api/extra/getExamList";
|
|
|
+ System.out.println("taskInfoAddr:" + taskInfoAddr);
|
|
|
+ JSONObject tasksJson = JSON.parseObject(rt.getForObject(taskInfoAddr, String.class));
|
|
|
+ // 获得tasksJson中的“data”字段的迭代器
|
|
|
+ ListIterator<Object> tasksIter = tasksJson.getJSONArray("data").listIterator();
|
|
|
+ // 新建TaskDTO队列,TaskDTO没有持久化处理
|
|
|
+ List<TaskDTO> dtos = new ArrayList<>();
|
|
|
+ // 遍历taskJson中“data“
|
|
|
+ while (tasksIter.hasNext()) {
|
|
|
+ // 获得每个”data“对象
|
|
|
+ JSONObject taskInfo = (JSONObject) tasksIter.next();
|
|
|
+ TaskDTO dto = new TaskDTO();
|
|
|
+ // 将获得的每个taskJson的exam_id,case_id,name赋给taskdto
|
|
|
+ dto.setExamId(Long.parseLong(taskInfo.getString("task_id")));
|
|
|
+ dto.setCaseId(Long.parseLong(taskInfo.getString("case_id")));
|
|
|
+ dto.setName(taskInfo.getString("name"));
|
|
|
+ // 将taskdto加入taskdtos队列
|
|
|
+ dtos.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ // return中是给taskDTO各个属性赋值的过程
|
|
|
+ return dtos.stream()
|
|
|
+ .map(taskDTO -> {
|
|
|
+ // 获得报告数量
|
|
|
+ long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
+ // 设没有处理的Bug数为0
|
|
|
+ long undealBugs = 0;
|
|
|
+ // 如果总Bug报告数为0(没有初始化),将没有处理的报告数设置为报告总数
|
|
|
+ if (totalBugs == 0) {
|
|
|
+ totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
+ undealBugs = totalBugs;
|
|
|
+ } else {
|
|
|
+ // 否则将获得没有处理的报告数
|
|
|
+ undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
+ }
|
|
|
+ // 给taskDTO的总bug数和为处理的bug数赋值
|
|
|
+ taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
+ taskDTO.setNumOfUndeal(undealBugs);
|
|
|
+ return taskDTO;
|
|
|
+ }).sorted(Comparator.comparing(TaskDTO::getExamId).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 在本地获得task方法
|
|
|
+ public List<TaskDTO> findTask() {
|
|
|
+ List<TaskDTO> taskDTOs = new ArrayList<>();
|
|
|
+
|
|
|
+ List<Task> tasks = taskDao.findAll();
|
|
|
+ for (Task task: tasks) {
|
|
|
+ TaskDTO taskDTO = TaskDTO.builder().examId((long) task.getTaskId()).caseId( (long) task.getCaseId()).name(task.getName()).build();
|
|
|
+ taskDTOs.add(taskDTO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return taskDTOs.stream()
|
|
|
+ .map(taskDTO -> {
|
|
|
+ // 获得报告数量
|
|
|
+ long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
+ // 设没有处理的Bug数为0
|
|
|
+ long undealBugs = 0;
|
|
|
+ // 如果总Bug报告数为0(没有初始化),将没有处理的报告数设置为报告总数
|
|
|
+ if (totalBugs == 0) {
|
|
|
+ totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
+ undealBugs = totalBugs;
|
|
|
+ } else {
|
|
|
+ // 否则将获得没有处理的报告数
|
|
|
+ undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
+ }
|
|
|
+ // 给taskDTO的总bug数和为处理的bug数赋值
|
|
|
+ taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
+ taskDTO.setNumOfUndeal(undealBugs);
|
|
|
+ return taskDTO;
|
|
|
+ }).sorted(Comparator.comparing(TaskDTO::getExamId).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public List<TaskDTO> getAllTasks2() {
|
|
|
+ return tasks.stream()
|
|
|
+ .map(task -> {
|
|
|
+ TaskDTO taskDTO = new TaskDTO();
|
|
|
+ BeanUtils.copyProperties(task, taskDTO);
|
|
|
+ return taskDTO;
|
|
|
+ })
|
|
|
+ .map(taskDTO -> {
|
|
|
+ if (taskDTO.getName().equals("途牛旅游") && taskDTO.getVersion().equals("9.56.0")) {
|
|
|
+ long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
+ long undealBugs = 0;
|
|
|
+ if (totalBugs == 0) {
|
|
|
+ totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
+ undealBugs = totalBugs;
|
|
|
+ } else {
|
|
|
+ undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
+ }
|
|
|
+ taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
+ taskDTO.setNumOfUndeal(undealBugs);
|
|
|
+ } else {
|
|
|
+ Random r = new Random();
|
|
|
+ int n = r.nextInt(100)%(100-20+1) + 20;
|
|
|
+ taskDTO.setNumOfTotalBug(n * 10);
|
|
|
+ taskDTO.setNumOfUndeal(0);
|
|
|
+ }
|
|
|
+ return taskDTO;
|
|
|
+ }).sorted(Comparator.comparing(TaskDTO::getStatus))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getAllTaskDashboard (long caseId,long taskId){
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ String url = HTTP+reportHost+"/Bug/api/analyze/analyseExam";
|
|
|
+ MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
|
|
|
+ paramMap.add("caseId", caseId);
|
|
|
+ paramMap.add("taskId", taskId);
|
|
|
+ template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap,headers);
|
|
|
+ ResponseEntity<String> response2 = template.postForEntity(url, httpEntity, String.class);
|
|
|
+ JSONObject tasksJson = JSON.parseObject(response2.getBody());
|
|
|
+ tasksJson.put("taskName","第一次众测测试");
|
|
|
+ tasksJson.put("startTime", TimeUtil.timestamp2strSimple(tasksJson.get("startTime").toString()));
|
|
|
+ tasksJson.put("endTime", TimeUtil.timestamp2strSimple(tasksJson.get("endTime").toString()));
|
|
|
+ tasksJson.put("gradeArray" , getGradeInt(tasksJson.getJSONObject("gradeDistrubute")));
|
|
|
+ return tasksJson;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public boolean distribute(String examId,String caseId){
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ String url = distributeUrl+"team/dopreteam";
|
|
|
+ JSONObject vo = new JSONObject();
|
|
|
+ vo.fluentPut("clusterNum",4); // 默认大小
|
|
|
+ vo.fluentPut("peopleSizeInTeam",4); // 默认大小
|
|
|
+ JSONObject exam = new JSONObject();
|
|
|
+ TaskDTO task = getByExamIdAndCaseId(Long.parseLong(examId),Long.parseLong(caseId));
|
|
|
+ exam.fluentPut("beginTime",TimeUtil.timestampTo24format(Long.parseLong(task.getStartTime())));
|
|
|
+ exam.fluentPut("endTime",TimeUtil.timestampTo24format(Long.parseLong(task.getEndTime())));
|
|
|
+ exam.fluentPut("caseTakeId",examId + "-" + caseId);
|
|
|
+ exam.fluentPut("caseTypeId",1); // 默认是app类型的
|
|
|
+ exam.fluentPut("state",0); // 有默认值无需传
|
|
|
+ exam.fluentPut("groupId",30); // 需要从前端获取
|
|
|
+ exam.fluentPut("id",0);
|
|
|
+ vo.fluentPut("exam",exam);
|
|
|
+ template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ HttpEntity<String> entity = new HttpEntity<String>(vo.toJSONString(),headers);
|
|
|
+ ResponseEntity<String> response2 = template.postForEntity(url, entity, String.class);
|
|
|
+ JSONArray tasksJson = JSON.parseArray(response2.getBody());
|
|
|
+ return tasksJson != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int [] getGradeInt(JSONObject jsonObject){
|
|
|
+ int [] res = new int[11];
|
|
|
+// for (int i = 0 ; i < 11 ; i++ ){
|
|
|
+// res[i] = Integer.parseInt(jsonObject.get(i+"").toString());
|
|
|
+// }
|
|
|
+ Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
+ while(sIterator.hasNext()){
|
|
|
+ // 获得key
|
|
|
+ String key = sIterator.next();
|
|
|
+ // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
|
|
|
+ String value = jsonObject.getString(key);
|
|
|
+ res[Integer.valueOf(key)]+=Integer.getInteger(value);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String addCrowdTaskPure(String name,String description,String time,String type,MultipartFile threePage){
|
|
|
+ if(threePage ==null || threePage.isEmpty()) return "请提交三级页面";
|
|
|
+ String threePageUrl = fileService.uploadFile(threePage);
|
|
|
+ try {
|
|
|
+ long flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),"",getMaxCaseId()+1,type,description,name, CollaborativeType.IS_COLLABORATIVE.getId());
|
|
|
+ return flag!=-1 ?""+flag:"创建失败";
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "创建众测失败";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public SimpleResponse addCrowdTask(String name, String description, String os, MultipartFile threePage){
|
|
|
+ if(threePage ==null || threePage.isEmpty()) return new SimpleResponse(400,"请提交三级页面");
|
|
|
+ String threePageUrl = fileService.uploadFile(threePage);
|
|
|
+ try {
|
|
|
+ long flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),generatePaperType(os),getMaxCaseId()+1,"",description,name, CollaborativeType.IS_COLLABORATIVE.getId());
|
|
|
+ return flag!=-1 ?new SimpleResponse(200,"创建成功,id为"+flag):new SimpleResponse(400,"创建失败");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new SimpleResponse(400,"创建众测失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public long addCrowdTaskDefault(String name, String description, String os, String threePageUrl, String fileName, int collaborativeType){
|
|
|
+ // 不进行上传是否存在问题
|
|
|
+// String threePageUrl = fileService.uploadFile(threePage);
|
|
|
+ try {
|
|
|
+ long caseId = createCrowdTest(threePageUrl,fileName,generatePaperType(os),getMaxCaseId()+1,"",description,name, collaborativeType);
|
|
|
+ return caseId;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public long createCrowdTest(String file, String fileName, String paperType, Long caseId, String testType, String description, String appName, int collaborativeType) throws Exception {
|
|
|
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("file", file);
|
|
|
+ params.add("file_name", fileName);
|
|
|
+ params.add("paper_type", paperType);
|
|
|
+ params.add("case_id", caseId + "");
|
|
|
+ params.add("test_type", testType);
|
|
|
+ params.add("description", description);
|
|
|
+ params.add("app_name", appName);
|
|
|
+ params.add("collaborative_type", collaborativeType + "");
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity
|
|
|
+ ("http://" + reportHost + "/Bug/api/extra/uploadExamUrl", params, String.class);
|
|
|
+ System.out.println("http://" + reportHost + "/Bug/api/extra/uploadExamUrl " + responseEntity.getStatusCode());
|
|
|
+ if (responseEntity.getStatusCode().equals(HttpStatus.OK)){
|
|
|
+ // 上传三级菜单的json
|
|
|
+ fileService.uploadJson(responseEntity.getBody(),caseId);
|
|
|
+ return caseId;
|
|
|
+ }else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getEncodeTaskReportUrl(long examId,long caseId){
|
|
|
+// String url = HTTP + reportHost + "/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
+ String url = HTTP + "127.0.0.1:5555/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
+ String encodedUrl = EncodeUtil.strConvertBase(url);
|
|
|
+ return encodedUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTaskReportUrl(long examId,long caseId){
|
|
|
+ // 修改
|
|
|
+// return HTTP + reportHost + "/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
+ return HTTP + "127.0.0.1:5555/report/detail/" + examId +"/" +caseId +"/userId";
|
|
|
+ }
|
|
|
+
|
|
|
+ public TaskDTO getByExamIdAndCaseId(long examId, long caseId) {
|
|
|
+ TaskDTO taskDefault = new TaskDTO();
|
|
|
+ taskDefault.setExamId(examId);
|
|
|
+ taskDefault.setCaseId(caseId);
|
|
|
+ taskDefault.setName("no name");
|
|
|
+ List<TaskDTO> tasks = getAllTasks();
|
|
|
+ TaskDTO taskDTO = tasks.stream().filter(task -> task.getExamId() == examId && task.getCaseId() == caseId).findFirst().orElse(taskDefault);
|
|
|
+
|
|
|
+ long totalBugs = bugDataService.getReportNum(examId, caseId);
|
|
|
+ long undealBugs = 0;
|
|
|
+ if (totalBugs == 0) {
|
|
|
+ totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
|
+ undealBugs = totalBugs;
|
|
|
+ } else {
|
|
|
+ undealBugs = bugDataService.getReportUnDealNum(examId, caseId);
|
|
|
+ }
|
|
|
+ taskDTO.setNumOfTotalBug(totalBugs);
|
|
|
+ taskDTO.setNumOfUndeal(undealBugs);
|
|
|
+ return taskDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private long getMaxCaseId(){
|
|
|
+ List<CrowdTask> list = crowdTaskDao.findAll();
|
|
|
+ long max =0;
|
|
|
+ long temp =0;
|
|
|
+ for(CrowdTask task : list){
|
|
|
+ temp=Long.parseLong(task.getId());
|
|
|
+ max=temp>max?temp:max;
|
|
|
+ }
|
|
|
+// CrowdTask task = crowdTaskDao.findFirstByOrderByIdDesc();
|
|
|
+ return max;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean exportTask(String caseId){
|
|
|
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("caseId", caseId);
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity
|
|
|
+ ("http://" + reportHost + "/Bug/api/data/outputByCaseId", params, String.class);
|
|
|
+ return responseEntity.getStatusCode().equals(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean importTask(String number,String originId,
|
|
|
+ MultipartFile zipFile, MultipartFile jsonFile) {
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ MediaType type = MediaType.parseMediaType("multipart/form-data");
|
|
|
+ // 设置请求的格式类型
|
|
|
+ headers.setContentType(type);
|
|
|
+ ByteArrayResource zipFileResource = null;
|
|
|
+ ByteArrayResource jsonFileResource = null;
|
|
|
+ try {
|
|
|
+ zipFileResource= new ByteArrayResource(zipFile.getBytes()) {
|
|
|
+ @Override
|
|
|
+ public String getFilename() {
|
|
|
+ return zipFile.getOriginalFilename();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ jsonFileResource= new ByteArrayResource(jsonFile.getBytes()) {
|
|
|
+ @Override
|
|
|
+ public String getFilename() {
|
|
|
+ return jsonFile.getOriginalFilename();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }catch (IOException e){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("zipFile", zipFileResource);
|
|
|
+ params.add("jsonFile", jsonFileResource);
|
|
|
+ params.add("originalCaseId", originId);
|
|
|
+ params.add("cpSerialNum", number);
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(params, headers);
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://" + reportHost + "/Bug/api/data/inputFromFile", files, String.class);
|
|
|
+ return responseEntity.getStatusCode().equals(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static String generatePaperType(String os){
|
|
|
+ StringBuffer value = new StringBuffer();
|
|
|
+ if(os==null||os.length()==0){
|
|
|
+ value.append("\"windows\",\"linux\",\"macos\"");
|
|
|
+ }else{
|
|
|
+ String [] data = os.split(";");
|
|
|
+ for(int i =0;i<data.length;i++){
|
|
|
+ if(i!=data.length-1){
|
|
|
+ value.append("\""+data[i]+"\",");
|
|
|
+ }else{
|
|
|
+ value.append("\""+data[i]+"\"");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "{\"title\":\"测试报告名称\",\"subTitles\":[{\"name\":\"设备名称\", \"type\":\"text\"},{\"name\":\"设备品牌\",\"type\":\"text\"},{\"name\":\"操作系统\",\"type\":\"enum\",\"value\":["
|
|
|
+ +value.toString()
|
|
|
+ + "]}],\"caseList\":true,\"bugList\": true,\"testScript\":false,\"suppleReport\":false,\"testLog\":false}";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTaskDaPanUrl(long taskId,long caseId){
|
|
|
+// return "test";
|
|
|
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("caseId", caseId+"");
|
|
|
+ params.add("taskId", taskId+"");
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity
|
|
|
+ ("http://" + reportHost + "/Bug/api/analyze/analyse/getTaskToken", params, String.class);
|
|
|
+ if (responseEntity.getStatusCode().equals(HttpStatus.OK)){
|
|
|
+ String token = responseEntity.getBody();
|
|
|
+ return "http://"+reportHost+"/dashboard/#/taskboard?token="+token;
|
|
|
+ }else return "error";
|
|
|
+ }
|
|
|
+}
|