ExtraService.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package edu.nju.service;
  2. import java.util.*;
  3. import edu.nju.dao.*;
  4. import edu.nju.entities.*;
  5. import org.json.JSONArray;
  6. import org.json.JSONObject;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import edu.nju.util.ExcelToJson;
  10. @Service
  11. public class ExtraService {
  12. @Autowired
  13. ReportDao reportDao;
  14. @Autowired
  15. ExamDao examDao;
  16. @Autowired
  17. TestCaseDao testDao;
  18. @Autowired
  19. BugDao bugDao;
  20. //测试用例相关
  21. public String saveTestCase(String report_id, String name, String front, String behind, String description) {
  22. TestCase testCase = new TestCase(name, front, behind, description, report_id, Long.toString(System.currentTimeMillis()));
  23. return testDao.save(testCase);
  24. }
  25. // public String saveTestCase(String report_id, String name, String front, String behind, String description,String if_execute,String if_bug) {
  26. // TestCase testCase = new TestCase(name, front, behind, description, report_id, Long.toString(System.currentTimeMillis()),if_execute,if_bug);
  27. // return testDao.save(testCase);
  28. // }
  29. public boolean updateTestCase(String id, String report_id, String name, String front, String behind, String description) {
  30. try {
  31. testDao.updateTestCase(id, report_id, name, front, behind, description);
  32. return true;
  33. } catch (Exception e) { return false; }
  34. }
  35. public List<TestCase> getCaseList(String report_id) {
  36. return testDao.findByReport(report_id);
  37. }
  38. public TestCase getTestCase(String id) {
  39. return testDao.findById(id);
  40. }
  41. //测试报告相关
  42. public String saveReport(String case_id, String task_id, String case_take_id, String woker_id, String name, String device_model,
  43. String device_brand, String device_os, String script_location, String report_location, String log_location) {
  44. Report report = new Report(case_id, task_id, case_take_id, woker_id, name, Long.toString(System.currentTimeMillis()),
  45. device_model, device_brand, device_os, script_location, report_location, log_location);
  46. return reportDao.save(report);
  47. }
  48. public boolean updateReport(String report_id, String case_id, String task_id, String case_take_id, String woker_id, String name, String device_model,
  49. String device_brand, String device_os, String script_location, String report_location, String log_location) {
  50. Report report = new Report(case_id, task_id, case_take_id, woker_id, name, Long.toString(System.currentTimeMillis()),
  51. device_model, device_brand, device_os, script_location, report_location, log_location);
  52. return reportDao.update(report_id, report);
  53. }
  54. public Report getReport(String report_id) {
  55. return reportDao.findById(report_id);
  56. }
  57. public Report findByWorker(String case_take_id, String worker_id) {
  58. return reportDao.findByWoker(case_take_id, worker_id);
  59. }
  60. public List<Bug> getBugList(String report_id, String case_take_id) {
  61. return bugDao.findByReport(report_id, case_take_id);
  62. }
  63. //测试题目相关
  64. public String saveExam(String case_id, String path, String app_name, String paper_type, String test_type, String description) {
  65. String json = ExcelToJson.ExcelTranse(path).toString();
  66. Exam exam = new Exam(case_id, json, app_name, paper_type, test_type, description);
  67. examDao.save(exam);
  68. return json;
  69. }
  70. // public String saveExam1(String case_id, String path, String app_name, String paper_type, String test_type, String description,
  71. // String if_test_case,String if_bug) {
  72. // String json = ExcelToJson.ExcelTranse(path).toString();
  73. //// Exam exam = new Exam(case_id, json, app_name, paper_type, test_type, description);
  74. // Exam exam = new Exam(case_id, json, app_name, paper_type, test_type, description,if_test_case,if_bug);
  75. // examDao.save(exam);
  76. // return json;
  77. // }
  78. public JSONArray getExamList() {
  79. List<Exam> result = examDao.findAll();
  80. JSONArray array = new JSONArray();
  81. Set<String> ids = bugDao.findAllids();
  82. Map<String, Exam> exams = new HashMap<>();
  83. for(Exam exam: result) { exams.put(exam.getId(), exam); }
  84. for(String id: ids) {
  85. if(id == null || id.length() <= 0) { continue; }
  86. String[] strs = id.split("-");
  87. String case_id = strs[0];
  88. String task_id = strs[1];
  89. if(exams.containsKey(case_id)) {
  90. JSONObject object = new JSONObject();
  91. Exam exam = exams.get(case_id);
  92. object.put("name", exam.getName());
  93. object.put("description", exam.getDescription());
  94. object.put("testType", exam.getTest_type());
  95. object.put("case_id", case_id);
  96. object.put("task_id", task_id);
  97. array.put(object);
  98. }
  99. }
  100. return array;
  101. }
  102. public Exam getExam(String id) {
  103. return examDao.findById(id);
  104. }
  105. }