|
@@ -2,12 +2,14 @@ package com.mooctest.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.fasterxml.jackson.annotation.JsonAlias;
|
|
|
+import com.mooctest.dao.BugDao;
|
|
|
import com.mooctest.data.BugDTO;
|
|
|
import com.mooctest.data.ReportDTO;
|
|
|
+import com.mooctest.model.Bug;
|
|
|
import com.mooctest.service.BugReportService;
|
|
|
import com.mooctest.util.HttpUtil;
|
|
|
import com.mooctest.util.MongoAPIUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpMethod;
|
|
@@ -28,6 +30,9 @@ import static java.util.stream.Collectors.toMap;
|
|
|
@Service
|
|
|
public class BugReportServiceImpl implements BugReportService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ BugDao bugDao;
|
|
|
+
|
|
|
public List<ReportDTO> getReports(long examId, long caseId) {
|
|
|
|
|
|
HttpHeaders headers = MongoAPIUtil.createAuthHeaderForMongo();
|
|
@@ -67,7 +72,34 @@ public class BugReportServiceImpl implements BugReportService {
|
|
|
}
|
|
|
|
|
|
public List<BugDTO> getAllBugs(long examId, long caseId) {
|
|
|
- return mergeAllBugs(getReports(examId, caseId));
|
|
|
+ String caseTakeId = caseId + "-" + examId;
|
|
|
+ List<Bug> bugs = bugDao.findByCaseTakeId(caseTakeId);
|
|
|
+ return wrapList(bugs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BugDTO> wrapList(List<Bug> bugs) {
|
|
|
+
|
|
|
+ return bugs.parallelStream()
|
|
|
+ .map(bug -> wrap(bug))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private BugDTO wrap(Bug bug) {
|
|
|
+ String[] imgUrls = new String[0];
|
|
|
+ if (bug.getImgUrls() != null && !bug.getImgUrls().equals("")) {
|
|
|
+
|
|
|
+ imgUrls = bug.getImgUrls().split(",");
|
|
|
+ }
|
|
|
+ return BugDTO.builder()
|
|
|
+ .id(bug.getId())
|
|
|
+ .bugCategory(bug.getBugCategory())
|
|
|
+ .caseTakeId(bug.getCaseTakeId())
|
|
|
+ .createTimeMillis(bug.getCreateTimeMillis())
|
|
|
+ .description(bug.getDescription())
|
|
|
+ .imgUrls(imgUrls)
|
|
|
+ .recurrent(bug.getRecurrent())
|
|
|
+ .severity(bug.getSeverity())
|
|
|
+ .build();
|
|
|
}
|
|
|
|
|
|
public Map<String, BugDTO> getAllBugsMap(long examId, long caseId) {
|
|
@@ -75,19 +107,10 @@ public class BugReportServiceImpl implements BugReportService {
|
|
|
return bugs.stream().collect(toMap(BugDTO::getId, Function.identity()));
|
|
|
}
|
|
|
|
|
|
- public BugDTO getBugById(String bugId) {
|
|
|
- RestTemplate rt = HttpUtil.getRestTemplate();
|
|
|
- String url = "http://localhost:8080/api/kibug/bug/" + bugId;
|
|
|
- ResponseEntity<String> resp = rt.getForEntity(url, String.class);
|
|
|
- JSONObject body = JSONObject.parseObject(resp.getBody());
|
|
|
- JSONObject bug = (JSONObject) body.get("data");
|
|
|
- return bug.toJavaObject(BugDTO.class);
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
public BugDTO getBugById(String bugId, long examId, long caseId) {
|
|
|
- return getAllBugsMap(examId, caseId).get(bugId);
|
|
|
-
|
|
|
+ Bug bug = bugDao.findOne(bugId);
|
|
|
+ return wrap(bug);
|
|
|
}
|
|
|
|
|
|
public Map<String, List<BugDTO>> getMasterBugMap(Map<String, List<String>> masterBugIdsMap, Map<String, BugDTO> bugsMap) {
|