ExportService.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package edu.nju.service;
  2. import edu.nju.dao.BugDao;
  3. import edu.nju.dao.BugScoreDao;
  4. import edu.nju.dao.ReportDao;
  5. import edu.nju.entities.Bug;
  6. import edu.nju.entities.BugScore;
  7. import edu.nju.entities.Report;
  8. import edu.nju.model.ExportBugDTO;
  9. import edu.nju.model.ExportReportDTO;
  10. import org.json.JSONObject;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import java.util.ArrayList;
  14. import java.util.Arrays;
  15. import java.util.Comparator;
  16. import java.util.List;
  17. import edu.nju.util.HTTP;
  18. @Service
  19. public class ExportService {
  20. @Autowired
  21. ReportDao reportDao;
  22. @Autowired
  23. BugDao bugDao;
  24. @Autowired
  25. BugScoreDao bugScoreDao;
  26. public List<ExportReportDTO> getExportReport(String case_take_id){
  27. List<Report> reportList=reportDao.findByCaseTakeId(case_take_id);
  28. List<ExportReportDTO> exportReportDTOList=new ArrayList<>();
  29. for(Report report:reportList){
  30. String workerId=report.getWorker_id();
  31. String result = HTTP.sendGet("http://114.55.91.83:8191/api/user/" + workerId, "");
  32. String name="";
  33. if(result != null && !result.equals("")) {
  34. JSONObject json = new JSONObject(result);
  35. if(json.has("name")&&!json.isNull("name")) {
  36. name = json.getString("name");
  37. }
  38. }
  39. ExportReportDTO exportReportDTO=new ExportReportDTO();
  40. exportReportDTO.setWorkerId(workerId);
  41. exportReportDTO.setWorkerName(name);
  42. String reportId=report.getId();
  43. List<Bug> bugList=bugDao.findByReport(reportId,case_take_id);
  44. exportReportDTO.setBugCount(String.valueOf(bugList.size()));
  45. List<ExportBugDTO> exportBugDTOList=new ArrayList<>();
  46. //获取bug信息
  47. int totalScore=0;
  48. List<ExportBugDTO> bugDTOList=new ArrayList<>();
  49. for(Bug bug: bugList){
  50. ExportBugDTO exportBugDTO=new ExportBugDTO();
  51. BugScore bugScore=bugScoreDao.findById(bug.getId());
  52. exportBugDTO.setTitle(bug.getTitle());
  53. exportBugDTO.setDescription(bug.getDescription());
  54. if(bugScore!=null) {
  55. exportBugDTO.setScore(String.valueOf(bugScore.getGrade()));
  56. totalScore += bugScore.getGrade();
  57. }else{
  58. exportBugDTO.setScore("0");
  59. }
  60. String page=bug.getBug_page();
  61. String[] pages=page.split("-");
  62. exportBugDTO.setPage1("");
  63. exportBugDTO.setPage2("");
  64. exportBugDTO.setPage3("");
  65. if(pages.length>0) {
  66. exportBugDTO.setPage1(pages[0]);
  67. }
  68. if(pages.length>1) {
  69. exportBugDTO.setPage2(pages[1]);
  70. }
  71. if(pages.length>2) {
  72. exportBugDTO.setPage3(pages[2]);
  73. }
  74. String imgUrl=bug.getImg_url();
  75. String[] imgUrlList=imgUrl.split(",");
  76. exportBugDTO.setImgUrlList(Arrays.asList(imgUrlList));
  77. exportBugDTOList.add(exportBugDTO);
  78. }
  79. exportReportDTO.setExportBugDTOList(exportBugDTOList);
  80. exportReportDTO.setTotalScore(String.valueOf(totalScore));
  81. exportReportDTOList.add(exportReportDTO);
  82. }
  83. totalScoreSort(exportReportDTOList);
  84. return exportReportDTOList;
  85. }
  86. public void totalScoreSort(List<ExportReportDTO> list ){
  87. list.sort(new Comparator<ExportReportDTO>() {
  88. public int compare(ExportReportDTO report1, ExportReportDTO report2) {
  89. return (Integer.parseInt(report2.getTotalScore()) - Integer.parseInt(report1.getTotalScore()));
  90. }
  91. });
  92. }
  93. }