Quellcode durchsuchen

exportReport相关操作

xujiawei vor 5 Jahren
Ursprung
Commit
3180def054

+ 44 - 0
src/main/java/edu/nju/controller/ExportController.java

@@ -0,0 +1,44 @@
+package edu.nju.controller;
+
+
+import edu.nju.model.ExportReportDTO;
+import edu.nju.service.ExportService;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
+import java.util.List;
+
+
+@Controller
+@RequestMapping(value = "/export")
+@CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
+public class ExportController {
+
+    @Autowired
+    ExportService exportService;
+
+    //根据用例获取所有有效bug
+    @RequestMapping(value = "/exportBug")
+    @ResponseBody
+    public void getValid(String case_take_id, HttpServletResponse response) {
+        try {
+            PrintWriter out = response.getWriter();
+            List<ExportReportDTO> list =exportService.getExportReport(case_take_id);
+            JSONArray result = new JSONArray(list);
+            out.print(result);
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+}

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

@@ -48,5 +48,11 @@ public class ReportDao {
 		if(list == null || list.size() == 0) { return null; }
 		else { return list.get(0); }
 	}
+
+	public List<Report> findByCaseTakeId(String case_take_id) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("case_take_id").is(case_take_id));
+		return mongoOperations.find(query, Report.class);
+	}
 	
 }

+ 89 - 0
src/main/java/edu/nju/model/ExportBugDTO.java

@@ -0,0 +1,89 @@
+package edu.nju.model;
+
+import java.util.List;
+
+public class ExportBugDTO {
+    private String title;
+
+    private String description;
+
+    private String score;
+
+    private String page1;
+
+    private String page2;
+
+    private String page3;
+
+    private List<String> imgUrlList;
+
+    public ExportBugDTO(String title, String description, String score, String page1, String page2, String page3, List<String> imgUrlList) {
+        this.title = title;
+        this.description = description;
+        this.score = score;
+        this.page1 = page1;
+        this.page2 = page2;
+        this.page3 = page3;
+        this.imgUrlList = imgUrlList;
+    }
+
+    public ExportBugDTO(){
+
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getScore() {
+        return score;
+    }
+
+    public void setScore(String score) {
+        this.score = score;
+    }
+
+    public String getPage1() {
+        return page1;
+    }
+
+    public void setPage1(String page1) {
+        this.page1 = page1;
+    }
+
+    public String getPage2() {
+        return page2;
+    }
+
+    public void setPage2(String page2) {
+        this.page2 = page2;
+    }
+
+    public String getPage3() {
+        return page3;
+    }
+
+    public void setPage3(String page3) {
+        this.page3 = page3;
+    }
+
+    public List<String> getImgUrlList() {
+        return imgUrlList;
+    }
+
+    public void setImgUrlList(List<String> imgUrlList) {
+        this.imgUrlList = imgUrlList;
+    }
+}

+ 67 - 0
src/main/java/edu/nju/model/ExportReportDTO.java

@@ -0,0 +1,67 @@
+package edu.nju.model;
+
+import java.util.List;
+
+public class ExportReportDTO {
+    private String workerId;
+
+    private String workerName;
+
+    private String totalScore;
+
+    private String bugCount;
+
+    private List<ExportBugDTO> exportBugDTOList;
+
+    public ExportReportDTO(String workerId, String workerName, String totalScore, String bugCount, List<ExportBugDTO> exportBugDTOList) {
+        this.workerId = workerId;
+        this.workerName = workerName;
+        this.totalScore = totalScore;
+        this.bugCount = bugCount;
+        this.exportBugDTOList = exportBugDTOList;
+    }
+
+    public ExportReportDTO(){
+
+    }
+
+    public String getWorkerId() {
+        return workerId;
+    }
+
+    public void setWorkerId(String workerId) {
+        this.workerId = workerId;
+    }
+
+    public String getWorkerName() {
+        return workerName;
+    }
+
+    public void setWorkerName(String workerName) {
+        this.workerName = workerName;
+    }
+
+    public String getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(String totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public String getBugCount() {
+        return bugCount;
+    }
+
+    public void setBugCount(String bugCount) {
+        this.bugCount = bugCount;
+    }
+
+    public List<ExportBugDTO> getExportBugDTOList() {
+        return exportBugDTOList;
+    }
+
+    public void setExportBugDTOList(List<ExportBugDTO> exportBugDTOList) {
+        this.exportBugDTOList = exportBugDTOList;
+    }
+}

+ 93 - 0
src/main/java/edu/nju/service/ExportService.java

@@ -0,0 +1,93 @@
+package edu.nju.service;
+
+import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding;
+import edu.nju.dao.BugDao;
+import edu.nju.dao.BugScoreDao;
+import edu.nju.dao.ReportDao;
+import edu.nju.entities.Bug;
+import edu.nju.entities.BugScore;
+import edu.nju.entities.Report;
+import edu.nju.model.ExportBugDTO;
+import edu.nju.model.ExportReportDTO;
+import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import edu.nju.util.HTTP;
+
+@Service
+public class ExportService {
+
+    @Autowired
+    ReportDao reportDao;
+
+    @Autowired
+    BugDao bugDao;
+
+    @Autowired
+    BugScoreDao bugScoreDao;
+
+
+    public List<ExportReportDTO> getExportReport(String case_take_id){
+        List<Report> reportList=reportDao.findByCaseTakeId(case_take_id);
+        List<ExportReportDTO> exportReportDTOList=new ArrayList<>();
+        for(Report report:reportList){
+            String workerId=report.getWorker_id();
+            String result = HTTP.sendGet("http://114.55.91.83:8191/api/user/" + workerId, "");
+            String name="";
+            if(result != null && !result.equals("")) {
+                JSONObject json = new JSONObject(result);
+                if(json.has("name")&&!json.isNull("name")) {
+                    name = json.getString("name");
+                }
+            }
+            ExportReportDTO exportReportDTO=new ExportReportDTO();
+            exportReportDTO.setWorkerId(workerId);
+            exportReportDTO.setWorkerName(name);
+            String reportId=report.getId();
+            List<Bug> bugList=bugDao.findByReport(reportId,case_take_id);
+            exportReportDTO.setBugCount(String.valueOf(bugList.size()));
+            List<ExportBugDTO> exportBugDTOList=new ArrayList<>();
+            //获取bug信息
+            int totalScore=0;
+            List<ExportBugDTO> bugDTOList=new ArrayList<>();
+            for(Bug bug: bugList){
+                ExportBugDTO exportBugDTO=new ExportBugDTO();
+                BugScore bugScore=bugScoreDao.findById(bug.getId());
+                exportBugDTO.setTitle(bug.getTitle());
+                exportBugDTO.setDescription(bug.getDescription());
+                if(bugScore!=null) {
+                    exportBugDTO.setScore(String.valueOf(bugScore.getScore()));
+                    totalScore += bugScore.getScore();
+                }else{
+                    exportBugDTO.setScore("0");
+                }
+                String page=bug.getBug_page();
+                String[] pages=page.split("-");
+                exportBugDTO.setPage1("");
+                exportBugDTO.setPage2("");
+                exportBugDTO.setPage3("");
+                if(pages.length>0) {
+                    exportBugDTO.setPage1(pages[0]);
+                }
+                if(pages.length>1) {
+                    exportBugDTO.setPage2(pages[1]);
+                }
+                if(pages.length>2) {
+                    exportBugDTO.setPage3(pages[2]);
+                }
+                String imgUrl=bug.getImg_url();
+                String[] imgUrlList=imgUrl.split(",");
+                exportBugDTO.setImgUrlList(Arrays.asList(imgUrlList));
+                exportBugDTOList.add(exportBugDTO);
+            }
+            exportReportDTO.setExportBugDTOList(exportBugDTOList);
+            exportReportDTO.setTotalScore(String.valueOf(totalScore));
+            exportReportDTOList.add(exportReportDTO);
+        }
+        return exportReportDTOList;
+    }
+}