ExtraService.java 5.3 KB

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