|
@@ -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;
|
|
|
+ }
|
|
|
+}
|