Ver Fonte

根据caseId获取bug报告数据

xujiawei há 4 anos atrás
pai
commit
b3cf497cac

+ 32 - 0
src/main/java/edu/nju/controller/DataController.java

@@ -0,0 +1,32 @@
+package edu.nju.controller;
+import edu.nju.entities.BugDetail;
+import edu.nju.service.DataService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 10:40
+ * @Email xjwhhh233@outlook.com
+ */
+@Controller
+@RequestMapping(value = "/data")
+@CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
+public class DataController {
+
+    @Autowired
+    DataService dataService;
+
+    /**根据caseId获取bug报告
+     *
+     * @param caseId
+     */
+    @RequestMapping(value = "/outputByCaseId")
+    @ResponseBody
+    public List<BugDetail> getBugDetailByCaseId(String caseId) {
+        return dataService.getBugDetailByCaseId(caseId);
+    }
+}

+ 34 - 0
src/main/java/edu/nju/dao/CaseToBugDao.java

@@ -0,0 +1,34 @@
+package edu.nju.dao;
+
+import edu.nju.entities.CaseToBug;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Repository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 11:01
+ * @Email xjwhhh233@outlook.com
+ */
+@Repository
+public class CaseToBugDao {
+    @Autowired
+    private MongoOperations mongoOperations;
+
+
+    public CaseToBug findById(String testCaseId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("_id").is(testCaseId));
+        List<CaseToBug> caseToBugList = mongoOperations.find(query,CaseToBug.class);
+        if(caseToBugList.size()==0){
+            return null;
+        }else{
+            return caseToBugList.get(0);
+        }
+    }
+}

+ 6 - 0
src/main/java/edu/nju/dao/ReportDao.java

@@ -65,4 +65,10 @@ public class ReportDao {
 		query.addCriteria(Criteria.where("worker_id").is(worker_id));
 		return mongoOperations.find(query, Report.class);
 	}
+
+	public List<Report> findByCaseId(String caseId){
+		Query query = new Query();
+		query.addCriteria(Criteria.where("case_id").is(caseId));
+		return mongoOperations.find(query, Report.class);
+	}
 }

+ 407 - 0
src/main/java/edu/nju/entities/BugDetail.java

@@ -0,0 +1,407 @@
+package edu.nju.entities;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-24 15:53
+ * @Email xjwhhh233@outlook.com
+ */
+@Document
+public class BugDetail implements java.io.Serializable {
+    private static final long serialVersionUID = 8980368107739914394L;
+
+    //bug属性
+    @Id
+    private String id;
+    private String bugCategory;
+    private String severity;
+    private String recurrent;
+    private String bugCreateTime;
+    private String bugPage;
+    private String title;
+    private String bugDescription;
+    private String imgUrl;
+    private int score;
+    private String parent;
+    private List<String> children;
+    private String root;
+    private int goodNum;
+    private Set<String> goodWorkerId;
+    private int badNum;
+    private Set<String> badWorkerId;
+
+    //测试用例属性
+    private String testCaseId;
+    private String testCaseName;
+    private String testCaseFront;
+    private String testCaseBehind;
+    private String testCaseDescription;
+    private String testCaseCreateTime;
+
+    //report属性
+    private String reportId;
+    private String reportName;
+    private String reportCreateTime;
+    private String scriptLocation;
+    private String reportLocation;
+    private String logLocation;
+    private String deviceModel;
+    private String deviceBrand;
+    private String deviceOs;
+
+    //工人属性
+    private String workerId;
+
+    //众测任务属性
+    private String caseAppName;
+    private String casePaperType;
+    private String caseTestType;
+    private String caseDescription;
+    private String caseRequireDoc;
+
+
+    //自己的case_take_id
+    private String caseTakeId;
+    //与目前系统中的哪个case对应
+    private String originalCaseId;
+
+    //cp系统序列号
+    private String cpSerialNum;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getBugCategory() {
+        return bugCategory;
+    }
+
+    public void setBugCategory(String bugCategory) {
+        this.bugCategory = bugCategory;
+    }
+
+    public String getSeverity() {
+        return severity;
+    }
+
+    public void setSeverity(String severity) {
+        this.severity = severity;
+    }
+
+    public String getRecurrent() {
+        return recurrent;
+    }
+
+    public void setRecurrent(String recurrent) {
+        this.recurrent = recurrent;
+    }
+
+    public String getBugCreateTime() {
+        return bugCreateTime;
+    }
+
+    public void setBugCreateTime(String bugCreateTime) {
+        this.bugCreateTime = bugCreateTime;
+    }
+
+    public String getBugPage() {
+        return bugPage;
+    }
+
+    public void setBugPage(String bugPage) {
+        this.bugPage = bugPage;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getBugDescription() {
+        return bugDescription;
+    }
+
+    public void setBugDescription(String bugDescription) {
+        this.bugDescription = bugDescription;
+    }
+
+    public String getImgUrl() {
+        return imgUrl;
+    }
+
+    public void setImgUrl(String imgUrl) {
+        this.imgUrl = imgUrl;
+    }
+
+    public int getScore() {
+        return score;
+    }
+
+    public void setScore(int score) {
+        this.score = score;
+    }
+
+    public String getParent() {
+        return parent;
+    }
+
+    public void setParent(String parent) {
+        this.parent = parent;
+    }
+
+    public List<String> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<String> children) {
+        this.children = children;
+    }
+
+    public String getRoot() {
+        return root;
+    }
+
+    public void setRoot(String root) {
+        this.root = root;
+    }
+
+    public Set<String> getGoodWorkerId() {
+        return goodWorkerId;
+    }
+
+    public int getGoodNum() {
+        return goodNum;
+    }
+
+    public void setGoodNum(int goodNum) {
+        this.goodNum = goodNum;
+    }
+
+    public int getBadNum() {
+        return badNum;
+    }
+
+    public void setBadNum(int badNum) {
+        this.badNum = badNum;
+    }
+
+    public void setGoodWorkerId(Set<String> goodWorkerId) {
+        this.goodWorkerId = goodWorkerId;
+    }
+
+    public Set<String> getBadWorkerId() {
+        return badWorkerId;
+    }
+
+    public void setBadWorkerId(Set<String> badWorkerId) {
+        this.badWorkerId = badWorkerId;
+    }
+
+    public String getTestCaseId() {
+        return testCaseId;
+    }
+
+    public void setTestCaseId(String testCaseId) {
+        this.testCaseId = testCaseId;
+    }
+
+    public String getTestCaseName() {
+        return testCaseName;
+    }
+
+    public void setTestCaseName(String testCaseName) {
+        this.testCaseName = testCaseName;
+    }
+
+    public String getTestCaseFront() {
+        return testCaseFront;
+    }
+
+    public void setTestCaseFront(String testCaseFront) {
+        this.testCaseFront = testCaseFront;
+    }
+
+    public String getTestCaseBehind() {
+        return testCaseBehind;
+    }
+
+    public void setTestCaseBehind(String testCaseBehind) {
+        this.testCaseBehind = testCaseBehind;
+    }
+
+    public String getTestCaseDescription() {
+        return testCaseDescription;
+    }
+
+    public void setTestCaseDescription(String testCaseDescription) {
+        this.testCaseDescription = testCaseDescription;
+    }
+
+    public String getTestCaseCreateTime() {
+        return testCaseCreateTime;
+    }
+
+    public void setTestCaseCreateTime(String testCaseCreateTime) {
+        this.testCaseCreateTime = testCaseCreateTime;
+    }
+
+    public String getReportId() {
+        return reportId;
+    }
+
+    public void setReportId(String reportId) {
+        this.reportId = reportId;
+    }
+
+    public String getReportName() {
+        return reportName;
+    }
+
+    public void setReportName(String reportName) {
+        this.reportName = reportName;
+    }
+
+    public String getReportCreateTime() {
+        return reportCreateTime;
+    }
+
+    public void setReportCreateTime(String reportCreateTime) {
+        this.reportCreateTime = reportCreateTime;
+    }
+
+    public String getScriptLocation() {
+        return scriptLocation;
+    }
+
+    public void setScriptLocation(String scriptLocation) {
+        this.scriptLocation = scriptLocation;
+    }
+
+    public String getReportLocation() {
+        return reportLocation;
+    }
+
+    public void setReportLocation(String reportLocation) {
+        this.reportLocation = reportLocation;
+    }
+
+    public String getLogLocation() {
+        return logLocation;
+    }
+
+    public void setLogLocation(String logLocation) {
+        this.logLocation = logLocation;
+    }
+
+    public String getDeviceModel() {
+        return deviceModel;
+    }
+
+    public void setDeviceModel(String deviceModel) {
+        this.deviceModel = deviceModel;
+    }
+
+    public String getDeviceBrand() {
+        return deviceBrand;
+    }
+
+    public void setDeviceBrand(String deviceBrand) {
+        this.deviceBrand = deviceBrand;
+    }
+
+    public String getDeviceOs() {
+        return deviceOs;
+    }
+
+    public void setDeviceOs(String deviceOs) {
+        this.deviceOs = deviceOs;
+    }
+
+    public String getWorkerId() {
+        return workerId;
+    }
+
+    public void setWorkerId(String workerId) {
+        this.workerId = workerId;
+    }
+
+    public String getCaseAppName() {
+        return caseAppName;
+    }
+
+    public void setCaseAppName(String caseAppName) {
+        this.caseAppName = caseAppName;
+    }
+
+    public String getCasePaperType() {
+        return casePaperType;
+    }
+
+    public void setCasePaperType(String casePaperType) {
+        this.casePaperType = casePaperType;
+    }
+
+    public String getCaseTestType() {
+        return caseTestType;
+    }
+
+    public void setCaseTestType(String caseTestType) {
+        this.caseTestType = caseTestType;
+    }
+
+    public String getCaseDescription() {
+        return caseDescription;
+    }
+
+    public void setCaseDescription(String caseDescription) {
+        this.caseDescription = caseDescription;
+    }
+
+    public String getCaseRequireDoc() {
+        return caseRequireDoc;
+    }
+
+    public void setCaseRequireDoc(String caseRequireDoc) {
+        this.caseRequireDoc = caseRequireDoc;
+    }
+
+    public String getCaseTakeId() {
+        return caseTakeId;
+    }
+
+    public void setCaseTakeId(String caseTakeId) {
+        this.caseTakeId = caseTakeId;
+    }
+
+    public String getOriginalCaseId() {
+        return originalCaseId;
+    }
+
+    public void setOriginalCaseId(String originalCaseId) {
+        this.originalCaseId = originalCaseId;
+    }
+
+    public String getCpSerialNum() {
+        return cpSerialNum;
+    }
+
+    public void setCpSerialNum(String cpSerialNum) {
+        this.cpSerialNum = cpSerialNum;
+    }
+}

+ 162 - 0
src/main/java/edu/nju/service/DataService.java

@@ -0,0 +1,162 @@
+package edu.nju.service;
+import edu.nju.dao.*;
+import edu.nju.entities.*;
+import edu.nju.util.TransUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 10:45
+ * @Email xjwhhh233@outlook.com
+ */
+@Service
+public class DataService {
+    @Autowired
+    ExamDao examDao;
+
+    @Autowired
+    BugDao bugDao;
+
+    @Autowired
+    ReportDao reportDao;
+
+    @Autowired
+    TestCaseDao testCaseDao;
+
+    @Autowired
+    CaseToBugDao caseToBugDao;
+
+    @Autowired
+    BugScoreDao bugScoreDao;
+
+    @Autowired
+    BugMirrorDao bugMirrorDao;
+
+    @Autowired
+    BugHistoryDao bugHistoryDao;
+
+    private static final String cpSerialNum="cp_dev";
+
+
+
+    /**
+     * 根据caseId获取对应bug信息
+     * @param caseId
+     * @return
+     */
+    public List<BugDetail> getBugDetailByCaseId(String caseId) {
+        List<BugDetail> bugDetailList=new ArrayList<>();
+        Exam crowdCase=examDao.findById(caseId);
+        if(crowdCase!=null) {
+            List<Report> reportList = reportDao.findByCaseId(caseId);
+            for (Report report : reportList) {
+                String reportId = report.getId();
+                List<TestCase> testCaseList = testCaseDao.findByReport(reportId);
+                for (TestCase testCase : testCaseList) {
+                    String testCaseId = testCase.getId();
+                    CaseToBug caseToBug = caseToBugDao.findById(testCaseId);
+                    if (caseToBug != null) {
+                        List<String> bugIdList = caseToBug.getBug_id();
+                        for (String bugId : bugIdList) {
+                            BugDetail bugDetail = new BugDetail();
+                            bugDetail.setId(bugId);
+                            //bug基本属性
+                            Bug bug = bugDao.findByid(bugId);
+                            if (bug != null) {
+                                bugDetail.setBugCategory(bug.getBug_category());
+                                bugDetail.setSeverity(TransUtil.severityTransFromInt(bug.getSeverity()));
+                                bugDetail.setRecurrent(TransUtil.recurrentTransFromInt(bug.getRecurrent()));
+                                bugDetail.setBugCreateTime(TransUtil.formatTimeMillis(bug.getCreate_time_millis()));
+                                bugDetail.setBugPage(bug.getBug_page());
+                                bugDetail.setTitle(bug.getTitle());
+                                bugDetail.setBugDescription(bug.getDescription());
+                                bugDetail.setImgUrl(bug.getImg_url());
+                            }
+                            //bugScore属性
+                            BugScore bugScore = bugScoreDao.findById(bugId);
+                            if (bugScore != null) {
+                                bugDetail.setScore(bugScore.getGrade());
+                            }
+                            //bugMirror属性
+                            BugMirror bugMirror = bugMirrorDao.findById(bugId);
+                            if (bugMirror != null) {
+                                Set<String> goodWorkerIdSet = new HashSet<>();
+                                Set<String> badWorkerIdSet = new HashSet<>();
+                                Set<String> goodReportIdSet = bugMirror.getGood();
+                                Set<String> badReportIdSet = bugMirror.getBad();
+                                int goodNum = 0;
+                                int badNum = 0;
+                                for (String goodReportId : goodReportIdSet) {
+                                    Report goodReport = reportDao.findById(goodReportId);
+                                    if (goodReport != null) {
+                                        goodNum++;
+                                        goodWorkerIdSet.add(goodReport.getWorker_id());
+                                    }
+                                }
+                                for (String badReportId : badReportIdSet) {
+                                    Report badReport = reportDao.findById(badReportId);
+                                    if (badReport != null) {
+                                        badNum++;
+                                        badWorkerIdSet.add(badReport.getWorker_id());
+                                    }
+                                }
+                                bugDetail.setGoodNum(goodNum);
+                                bugDetail.setBadNum(badNum);
+                                bugDetail.setGoodWorkerId(goodWorkerIdSet);
+                                bugDetail.setBadWorkerId(badWorkerIdSet);
+                            }
+                            //bugHistory属性
+                            BugHistory bugHistory = bugHistoryDao.findByid(bugId);
+                            if (bugHistory != null) {
+                                bugDetail.setParent(bugHistory.getParent());
+                                bugDetail.setChildren(bugHistory.getChildren());
+                                bugDetail.setRoot(bugHistory.getRoot());
+                            }
+                            //testCase属性
+                            bugDetail.setTestCaseId(testCase.getId());
+                            bugDetail.setTestCaseName(testCase.getName());
+                            bugDetail.setTestCaseFront(testCase.getFront());
+                            bugDetail.setTestCaseBehind(testCase.getBehind());
+                            bugDetail.setTestCaseDescription(testCase.getDescription());
+                            bugDetail.setTestCaseCreateTime(TransUtil.formatTimeMillis(testCase.getCreate_time_millis()));
+                            //report属性
+                            bugDetail.setReportId(report.getId());
+                            bugDetail.setReportName(report.getName());
+                            bugDetail.setScriptLocation(report.getScript_location());
+                            bugDetail.setReportLocation(report.getReport_location());
+                            bugDetail.setLogLocation(report.getLog_location());
+                            bugDetail.setDeviceModel(report.getDevice_model());
+                            bugDetail.setDeviceBrand(report.getDevice_brand());
+                            bugDetail.setDeviceOs(report.getDevice_os());
+                            //worker属性
+                            bugDetail.setWorkerId(report.getWorker_id());
+                            //众测任务属性
+                            bugDetail.setCaseAppName(crowdCase.getName());
+                            bugDetail.setCasePaperType(crowdCase.getPaper_type());
+                            bugDetail.setCaseTestType(crowdCase.getTest_type());
+                            bugDetail.setCaseDescription(crowdCase.getDescription());
+                            bugDetail.setCaseRequireDoc("");
+                            bugDetail.setCaseTakeId(report.getCase_take_id());
+                            //cp序列号
+                            bugDetail.setCpSerialNum(cpSerialNum);
+                            bugDetailList.add(bugDetail);
+                        }
+                    }
+                }
+            }
+        }
+        return bugDetailList;
+    }
+
+    public void bugDetailToCsv(List<BugDetail> bugDetailList){
+
+    }
+}
+
+