HistoryService.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package edu.nju.service;
  2. import java.util.ArrayList;
  3. import java.util.HashSet;
  4. import java.util.List;
  5. import java.util.Set;
  6. import java.util.Stack;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import edu.nju.dao.BugHistoryDao;
  10. import edu.nju.dao.BugMirrorDao;
  11. import edu.nju.dao.BugPageDao;
  12. import edu.nju.entities.BugHistory;
  13. import edu.nju.entities.BugMirror;
  14. import edu.nju.entities.BugPage;
  15. @Service
  16. public class HistoryService {
  17. @Autowired
  18. BugHistoryDao historydao;
  19. @Autowired
  20. BugMirrorDao mirrordao;
  21. @Autowired
  22. BugPageDao pagedao;
  23. @Autowired
  24. RecommendService recservice;
  25. @Autowired
  26. AnalyzeService aservice;
  27. public BugHistory getHistory(String id) {
  28. return historydao.findByid(id);
  29. }
  30. public List<String> parents(String id) {
  31. Stack<String> stack = new Stack<String>();
  32. List<String> result = new ArrayList<String>();
  33. String parent = getHistory(id).getParent();
  34. while(!parent.equals("null")) {
  35. stack.push(parent);
  36. parent = getHistory(parent).getParent();
  37. }
  38. while(!stack.isEmpty()) {
  39. result.add(stack.pop());
  40. }
  41. result.add(id);
  42. return result;
  43. }
  44. public List<BugMirror> getNew(String case_take_id, String report_id) {
  45. List<String> ids = historydao.findRoots(recservice.getListIds(case_take_id));
  46. List<String> filter = new ArrayList<String>();
  47. if(ids.size() > 2) {
  48. int n = ids.size();
  49. filter.add(ids.get(n - 1));
  50. filter.add(ids.get(n - 2));
  51. } else {
  52. for(String id : ids) {
  53. filter.add(id);
  54. }
  55. }
  56. return mirrordao.findByIds(filter, report_id);
  57. }
  58. public List<String> getRoots(String case_take_id) {
  59. return historydao.findRoots(aservice.getValid(case_take_id));
  60. }
  61. public List<String> getTreeRoots(String case_take_id) {
  62. List<String> all = new ArrayList<String>();
  63. for(String id : getRoots(case_take_id)) {
  64. if(getHistory(id).getChildren().size() > 0) { all.add(id); }
  65. }
  66. return all;
  67. }
  68. public List<String> getInvalid(Set<String> ids) {
  69. List<String> result = new ArrayList<String>();
  70. for(String id: ids) {
  71. if(!mirrordao.findById(id).isFlag()) {result.add(id);}
  72. }
  73. return result;
  74. }
  75. public List<String> getInvalid(List<String> ids) {
  76. List<String> result = new ArrayList<String>();
  77. for(String id: ids) {
  78. if(!mirrordao.findById(id).isFlag()) {result.add(id);}
  79. }
  80. return result;
  81. }
  82. public Set<String> filter(List<List<String>> lists) {
  83. Set<String> set = new HashSet<String>();
  84. for(List<String> list : lists) {
  85. for(String id: list) {
  86. set.add(id);
  87. }
  88. }
  89. return set;
  90. }
  91. //获取评分时树的信息
  92. public List<String> getDetail(String id) {
  93. List<String> result = new ArrayList<String>();
  94. List<List<String>> paths = getDepth(id);
  95. List<Set<String>> widths = new ArrayList<Set<String>>();
  96. Set<String> ids = new HashSet<String>();
  97. int max_height = 0;
  98. int max_width = 0;
  99. int count = 0;
  100. String flag = "true";
  101. for(List<String> path: paths) {
  102. max_height = Math.max(max_height, path.size());
  103. for(int i = 0; i < path.size(); i ++) {
  104. String temp = path.get(i);
  105. ids.add(temp);
  106. if(widths.size() <= i) {
  107. Set<String> set = new HashSet<String>();
  108. set.add(temp);
  109. widths.add(set);
  110. }
  111. else {widths.get(i).add(temp);}
  112. }
  113. }
  114. for(Set<String> width: widths) {
  115. max_width = Math.max(max_width, width.size());
  116. }
  117. for(String str: ids) {
  118. if(aservice.getGrade(str) == -1) {
  119. flag = "false";
  120. break;
  121. }
  122. }
  123. count = ids.size();
  124. result.add(id);
  125. result.add(Integer.toString(max_width));
  126. result.add(Integer.toString(max_height));
  127. result.add(Integer.toString(count));
  128. result.add(flag);
  129. result.add(recservice.getTitle(id));
  130. return result;
  131. }
  132. public void pageFilter(List<String> all, String page) {
  133. if(page.equals("null")) { return; }
  134. List<BugPage> mirrors = pagedao.findByIds(all);
  135. String[] pages = page.split("-");
  136. for(BugPage mirror : mirrors) {
  137. if(pages.length > 0 && !mirror.getPage1().equals(pages[0])) {
  138. all.remove(mirror.getId());
  139. continue;
  140. }
  141. if(pages.length > 1 && !mirror.getPage2().equals(pages[1])) {
  142. all.remove(mirror.getId());
  143. continue;
  144. }
  145. if(pages.length > 2 && !mirror.getPage3().equals(pages[2])) {
  146. all.remove(mirror.getId());
  147. continue;
  148. }
  149. }
  150. }
  151. public List<List<String>> getDepth(String id) {
  152. BugHistory root = historydao.findByid(id);
  153. List<List<String>> result = new ArrayList<List<String>>();
  154. if(root == null) { return result;}
  155. List<String> list = new ArrayList<String>();
  156. list.add(root.getId());
  157. dfs(root, result, list);
  158. return result;
  159. }
  160. private void dfs(BugHistory root, List<List<String>> result, List<String> list) {
  161. List<String> children = root.getChildren();
  162. if(children.size() != 0) {
  163. for(String child : children) {
  164. list.add(child);
  165. dfs(historydao.findByid(child), result, list);
  166. list.remove(child);
  167. }
  168. } else {
  169. result.add(new ArrayList<String>(list));
  170. }
  171. }
  172. }