|
@@ -3,11 +3,17 @@ package com.mooctest.service;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.mongodb.MongoClient;
|
|
|
|
+import com.mongodb.client.FindIterable;
|
|
|
|
+import com.mongodb.client.MongoCollection;
|
|
|
|
+import com.mongodb.client.MongoCursor;
|
|
|
|
+import com.mongodb.client.MongoDatabase;
|
|
import com.mooctest.dao.MasterReportDao;
|
|
import com.mooctest.dao.MasterReportDao;
|
|
|
|
+import com.mooctest.dao.TaskDao;
|
|
import com.mooctest.data.TaskDTO;
|
|
import com.mooctest.data.TaskDTO;
|
|
-import com.mooctest.model.BugData;
|
|
|
|
import com.mooctest.model.Task;
|
|
import com.mooctest.model.Task;
|
|
import com.mooctest.util.TimeUtil;
|
|
import com.mooctest.util.TimeUtil;
|
|
|
|
+import org.bson.Document;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -44,6 +50,9 @@ public class TaskService {
|
|
MasterReportDao masterReportDao;
|
|
MasterReportDao masterReportDao;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ TaskDao taskDao;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
BugReportService bugReportService;
|
|
BugReportService bugReportService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -60,44 +69,118 @@ public class TaskService {
|
|
private final String HTTP = "http://";
|
|
private final String HTTP = "http://";
|
|
|
|
|
|
|
|
|
|
|
|
+ // 获得所有任务
|
|
public List<TaskDTO> getAllTasks() {
|
|
public List<TaskDTO> getAllTasks() {
|
|
|
|
+ // 传统情况下在java代码里访问restful服务,一般使用Apache的HttpClient。不过此种方法使用起来太过繁琐。
|
|
|
|
+ // spring提供了一种简单便捷的模板类来进行操作,这就是RestTemplate。
|
|
RestTemplate rt = new RestTemplate();
|
|
RestTemplate rt = new RestTemplate();
|
|
|
|
+ // springMVC通过StringHttpMessageConverter将Controller的返回对象转为字符串
|
|
StringHttpMessageConverter stringHttpMessageConverter=new StringHttpMessageConverter(Charset.forName("UTF-8"));
|
|
StringHttpMessageConverter stringHttpMessageConverter=new StringHttpMessageConverter(Charset.forName("UTF-8"));
|
|
List<HttpMessageConverter<?>> list=new ArrayList<HttpMessageConverter<?>>();
|
|
List<HttpMessageConverter<?>> list=new ArrayList<HttpMessageConverter<?>>();
|
|
list.add(stringHttpMessageConverter);
|
|
list.add(stringHttpMessageConverter);
|
|
rt.setMessageConverters(list);
|
|
rt.setMessageConverters(list);
|
|
|
|
+ // 将获得task字符船以json格式解析
|
|
JSONObject tasksJson = JSON.parseObject(rt.getForObject(taskInfoAddr, String.class));
|
|
JSONObject tasksJson = JSON.parseObject(rt.getForObject(taskInfoAddr, String.class));
|
|
|
|
+ // 获得tasksJson中的“data”字段的迭代器
|
|
ListIterator<Object> tasksIter = tasksJson.getJSONArray("data").listIterator();
|
|
ListIterator<Object> tasksIter = tasksJson.getJSONArray("data").listIterator();
|
|
-
|
|
|
|
|
|
+ // 新建TaskDTO队列,TaskDTO没有持久化处理
|
|
List<TaskDTO> dtos = new ArrayList<>();
|
|
List<TaskDTO> dtos = new ArrayList<>();
|
|
|
|
+ // 遍历taskJson中“data“
|
|
while (tasksIter.hasNext()) {
|
|
while (tasksIter.hasNext()) {
|
|
|
|
+ // 获得每个”data“对象
|
|
JSONObject taskInfo = (JSONObject) tasksIter.next();
|
|
JSONObject taskInfo = (JSONObject) tasksIter.next();
|
|
-
|
|
|
|
TaskDTO dto = new TaskDTO();
|
|
TaskDTO dto = new TaskDTO();
|
|
|
|
+ // 将获得的每个taskJson的exam_id,case_id,name赋给taskdto
|
|
dto.setExamId(Long.parseLong(taskInfo.getString("task_id")));
|
|
dto.setExamId(Long.parseLong(taskInfo.getString("task_id")));
|
|
dto.setCaseId(Long.parseLong(taskInfo.getString("case_id")));
|
|
dto.setCaseId(Long.parseLong(taskInfo.getString("case_id")));
|
|
dto.setName(taskInfo.getString("name"));
|
|
dto.setName(taskInfo.getString("name"));
|
|
-
|
|
|
|
|
|
+ // 将taskdto加入taskdtos队列
|
|
dtos.add(dto);
|
|
dtos.add(dto);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ // return中是给taskDTO各个属性赋值的过程
|
|
return dtos.stream()
|
|
return dtos.stream()
|
|
.map(taskDTO -> {
|
|
.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<>();
|
|
|
|
+ /*
|
|
|
|
+ * MongoClient 连接服务器
|
|
|
|
+ * MongoDatabase 连接数据库
|
|
|
|
+ * MongoCollection 连接表
|
|
|
|
+ * FindIterable<Document> 记录型迭代器
|
|
|
|
+ * MongoCursor 记录游标
|
|
|
|
+ * 应用顺序: 服务器-->数据库-->表-->记录迭代器-->记录游标
|
|
|
|
+ */
|
|
|
|
+// MongoClient mongoClient = new MongoClient("localhost", 27017);
|
|
|
|
+// MongoDatabase mongoDatabase = mongoClient.getDatabase("crowd_review");
|
|
|
|
+// MongoCollection<Document> collection = mongoDatabase.getCollection("Task");
|
|
|
|
+// FindIterable<Document> findIterable = collection.find();
|
|
|
|
+// MongoCursor<Document> mongoCursor = findIterable.iterator();
|
|
|
|
+ List<Task> tasks = taskDao.findAll();
|
|
|
|
+ for (Task task: tasks) {
|
|
|
|
+ TaskDTO taskDTO = new TaskDTO((long) task.getTaskId(), (long) task.getCaseId(), task.getName());
|
|
|
|
+ taskDTOs.add(taskDTO);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// while(mongoCursor.hasNext()){
|
|
|
|
+// Document task = mongoCursor.next();
|
|
|
|
+// TaskDTO taskDTO = new TaskDTO();
|
|
|
|
+// taskDTO.setExamId((long)task.getInteger("task_id"));
|
|
|
|
+// taskDTO.setCaseId((long)task.getInteger("case_id"));
|
|
|
|
+// taskDTO.setName(task.getString("name"));
|
|
|
|
+// taskDTOs.add(taskDTO);
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ return taskDTOs.stream()
|
|
|
|
+ .map(taskDTO -> {
|
|
|
|
+ // 获得报告数量
|
|
long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
long totalBugs = bugDataService.getReportNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
|
|
+ // 设没有处理的Bug数为0
|
|
long undealBugs = 0;
|
|
long undealBugs = 0;
|
|
|
|
+ // 如果总Bug报告数为0(没有初始化),将没有处理的报告数设置为报告总数
|
|
if (totalBugs == 0) {
|
|
if (totalBugs == 0) {
|
|
totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
totalBugs = bugReportService.getAllBugs(taskDTO.getExamId(), taskDTO.getCaseId()).size();
|
|
undealBugs = totalBugs;
|
|
undealBugs = totalBugs;
|
|
} else {
|
|
} else {
|
|
|
|
+ // 否则将获得没有处理的报告数
|
|
undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
undealBugs = bugDataService.getReportUnDealNum(taskDTO.getExamId(),taskDTO.getCaseId());
|
|
}
|
|
}
|
|
|
|
+ // 给taskDTO的总bug数和为处理的bug数赋值
|
|
taskDTO.setNumOfTotalBug(totalBugs);
|
|
taskDTO.setNumOfTotalBug(totalBugs);
|
|
taskDTO.setNumOfUndeal(undealBugs);
|
|
taskDTO.setNumOfUndeal(undealBugs);
|
|
return taskDTO;
|
|
return taskDTO;
|
|
}).sorted(Comparator.comparing(TaskDTO::getExamId).reversed())
|
|
}).sorted(Comparator.comparing(TaskDTO::getExamId).reversed())
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
public List<TaskDTO> getAllTasks2() {
|
|
public List<TaskDTO> getAllTasks2() {
|
|
return tasks.stream()
|
|
return tasks.stream()
|
|
.map(task -> {
|
|
.map(task -> {
|