HistoryService.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package edu.nju.service;
  2. import java.util.*;
  3. import edu.nju.dao.BugDao;
  4. import edu.nju.entities.Bug;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import edu.nju.dao.BugHistoryDao;
  8. import edu.nju.dao.BugMirrorDao;
  9. import edu.nju.dao.BugPageDao;
  10. import edu.nju.entities.BugHistory;
  11. import edu.nju.entities.BugMirror;
  12. import edu.nju.entities.BugPage;
  13. @Service
  14. public class HistoryService {
  15. @Autowired
  16. BugHistoryDao historydao;
  17. @Autowired
  18. BugMirrorDao mirrordao;
  19. @Autowired
  20. BugPageDao pagedao;
  21. @Autowired
  22. RecommendService recservice;
  23. @Autowired
  24. AnalyzeService aservice;
  25. @Autowired
  26. BugPageDao bugPageDao;
  27. @Autowired
  28. BugDao bugDao;
  29. public BugHistory getHistory(String id) {
  30. return historydao.findByid(id);
  31. }
  32. public List<String> parents(String id) {
  33. Stack<String> stack = new Stack<String>();
  34. List<String> result = new ArrayList<String>();
  35. String parent = getHistory(id).getParent();
  36. while(!parent.equals("null")) {
  37. stack.push(parent);
  38. parent = getHistory(parent).getParent();
  39. }
  40. while(!stack.isEmpty()) {
  41. result.add(stack.pop());
  42. }
  43. result.add(id);
  44. return result;
  45. }
  46. public List<BugMirror> getNew(String case_take_id, String report_id) {
  47. List<String> ids = historydao.findRoots(recservice.getListIds(case_take_id));
  48. List<String> filter = new ArrayList<String>();
  49. if(ids.size() > 2) {
  50. int n = ids.size();
  51. filter.add(ids.get(n - 1));
  52. filter.add(ids.get(n - 2));
  53. } else {
  54. for(String id : ids) {
  55. filter.add(id);
  56. }
  57. }
  58. return mirrordao.findByIds(filter, report_id);
  59. }
  60. public List<String> getRoots(String case_take_id) {
  61. return historydao.findRoots(aservice.getValid(case_take_id));
  62. }
  63. public List<String> getTreeRoots(String case_take_id) {
  64. List<String> all = new ArrayList<String>();
  65. for(String id : getRoots(case_take_id)) {
  66. if(getHistory(id).getChildren().size() > 0) { all.add(id); }
  67. }
  68. return all;
  69. }
  70. public List<String> getInvalid(Set<String> ids) {
  71. List<String> result = new ArrayList<String>();
  72. for(String id: ids) {
  73. if(!mirrordao.findById(id).isFlag()) {result.add(id);}
  74. }
  75. return result;
  76. }
  77. public List<String> getInvalid(List<String> ids) {
  78. List<String> result = new ArrayList<String>();
  79. for(String id: ids) {
  80. if(!mirrordao.findById(id).isFlag()) {result.add(id);}
  81. }
  82. return result;
  83. }
  84. //单一状bug热度排序
  85. public void hotSortSingle(List<String> ids){
  86. Collections.shuffle(ids);
  87. ids.sort(new Comparator<String>() {
  88. public int compare(String id1, String id2) {
  89. BugMirror bugMirror1=mirrordao.findById(id1);
  90. BugMirror bugMirror2=mirrordao.findById(id2);
  91. return (bugMirror1.getGood().size()+bugMirror1.getBad().size()) - (bugMirror2.getGood().size()+bugMirror2.getBad().size());
  92. }
  93. });
  94. }
  95. //树状bug热度排序
  96. public void hotSortTree(List<String> ids){
  97. Collections.shuffle(ids);
  98. ids.sort(new Comparator<String>() {
  99. public int compare(String id1, String id2) {
  100. int hot1= getTreeHot(id1);
  101. int hot2= getTreeHot(id2);
  102. return hot1-hot2;
  103. }
  104. });
  105. }
  106. //获取树状bug热度
  107. private int getTreeHot(String id){
  108. BugHistory bugHistory=historydao.findByid(id);
  109. if(bugHistory.getChildren().size()==0){
  110. BugMirror bugMirror=mirrordao.findById(id);
  111. return bugMirror.getGood().size()+bugMirror.getBad().size();
  112. }else{
  113. BugMirror bugMirror=mirrordao.findById(id);
  114. int hot=bugMirror.getGood().size()+bugMirror.getBad().size();
  115. for(String childId:bugHistory.getChildren()){
  116. hot+=getTreeHot(childId);
  117. }
  118. return hot;
  119. }
  120. }
  121. public Set<String> filter(List<List<String>> lists) {
  122. Set<String> set = new HashSet<String>();
  123. for(List<String> list : lists) {
  124. for(String id: list) {
  125. set.add(id);
  126. }
  127. }
  128. return set;
  129. }
  130. //获取评分时树的信息
  131. public List<String> getDetail(String id) {
  132. List<String> result = new ArrayList<String>();
  133. List<List<String>> paths = getDepth(id);
  134. List<Set<String>> widths = new ArrayList<Set<String>>();
  135. Set<String> ids = new HashSet<String>();
  136. int max_height = 0;
  137. int max_width = 0;
  138. int count = 0;
  139. String flag = "true";
  140. for(List<String> path: paths) {
  141. max_height = Math.max(max_height, path.size());
  142. for(int i = 0; i < path.size(); i ++) {
  143. String temp = path.get(i);
  144. ids.add(temp);
  145. if(widths.size() <= i) {
  146. Set<String> set = new HashSet<String>();
  147. set.add(temp);
  148. widths.add(set);
  149. }
  150. else {widths.get(i).add(temp);}
  151. }
  152. }
  153. for(Set<String> width: widths) {
  154. max_width = Math.max(max_width, width.size());
  155. }
  156. for(String str: ids) {
  157. if(aservice.getGrade(str) == -1) {
  158. flag = "false";
  159. break;
  160. }
  161. }
  162. count = ids.size();
  163. result.add(id);
  164. result.add(Integer.toString(max_width));
  165. result.add(Integer.toString(max_height));
  166. result.add(Integer.toString(count));
  167. result.add(flag);
  168. result.add(recservice.getTitle(id));
  169. return result;
  170. }
  171. public void pageFilter(List<String> all, String page) {
  172. if(page.equals("null")) { return; }
  173. List<BugPage> mirrors = pagedao.findByIds(all);
  174. String[] pages = page.split("-");
  175. for(BugPage mirror : mirrors) {
  176. if(pages.length > 0 && !mirror.getPage1().equals(pages[0])) {
  177. all.remove(mirror.getId());
  178. continue;
  179. }
  180. if(pages.length > 1 && !mirror.getPage2().equals(pages[1])) {
  181. all.remove(mirror.getId());
  182. continue;
  183. }
  184. if(pages.length > 2 && !mirror.getPage3().equals(pages[2])) {
  185. all.remove(mirror.getId());
  186. continue;
  187. }
  188. }
  189. }
  190. public List<List<String>> getDepth(String id) {
  191. BugHistory root = historydao.findByid(id);
  192. List<List<String>> result = new ArrayList<List<String>>();
  193. if(root == null) { return result;}
  194. List<String> list = new ArrayList<String>();
  195. list.add(root.getId());
  196. dfs(root, result, list);
  197. return result;
  198. }
  199. private void dfs(BugHistory root, List<List<String>> result, List<String> list) {
  200. List<String> children = root.getChildren();
  201. if(children.size() != 0) {
  202. for(String child : children) {
  203. list.add(child);
  204. dfs(historydao.findByid(child), result, list);
  205. list.remove(child);
  206. }
  207. } else {
  208. result.add(new ArrayList<String>(list));
  209. }
  210. }
  211. public List<String> getBugIdListByPage(String case_take_id,String page,String start,String count){
  212. List<BugPage> bugPageList=bugPageDao.findByPage(case_take_id,page,start,count);
  213. List<String> bugIdList=new ArrayList<>();
  214. for(BugPage bugPage:bugPageList){
  215. bugIdList.add(bugPage.getId());
  216. }
  217. return bugIdList;
  218. }
  219. }