123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package edu.nju.service;
- import java.util.*;
- import edu.nju.dao.*;
- import edu.nju.entities.*;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import edu.nju.util.ExcelToJson;
- @Service
- public class ExtraService {
- @Autowired
- ReportDao reportDao;
-
- @Autowired
- ExamDao examDao;
-
- @Autowired
- TestCaseDao testDao;
-
- @Autowired
- BugDao bugDao;
-
- //测试用例相关
- public String saveTestCase(String report_id, String name, String front, String behind, String description) {
- TestCase testCase = new TestCase(name, front, behind, description, report_id, Long.toString(System.currentTimeMillis()));
- return testDao.save(testCase);
- }
- // public String saveTestCase(String report_id, String name, String front, String behind, String description,String if_execute,String if_bug) {
- // TestCase testCase = new TestCase(name, front, behind, description, report_id, Long.toString(System.currentTimeMillis()),if_execute,if_bug);
- // return testDao.save(testCase);
- // }
-
- public boolean updateTestCase(String id, String report_id, String name, String front, String behind, String description) {
- try {
- testDao.updateTestCase(id, report_id, name, front, behind, description);
- return true;
- } catch (Exception e) { return false; }
- }
-
- public List<TestCase> getCaseList(String report_id) {
- return testDao.findByReport(report_id);
- }
-
- public TestCase getTestCase(String id) {
- return testDao.findById(id);
- }
-
-
- //测试报告相关
- public String saveReport(String case_id, String task_id, String case_take_id, String woker_id, String name, String device_model,
- String device_brand, String device_os, String script_location, String report_location, String log_location) {
- Report report = new Report(case_id, task_id, case_take_id, woker_id, name, Long.toString(System.currentTimeMillis()),
- device_model, device_brand, device_os, script_location, report_location, log_location);
- return reportDao.save(report);
- }
- public boolean updateReport(String report_id, String case_id, String task_id, String case_take_id, String woker_id, String name, String device_model,
- String device_brand, String device_os, String script_location, String report_location, String log_location) {
- Report report = new Report(case_id, task_id, case_take_id, woker_id, name, Long.toString(System.currentTimeMillis()),
- device_model, device_brand, device_os, script_location, report_location, log_location);
- return reportDao.update(report_id, report);
- }
-
- public Report getReport(String report_id) {
- return reportDao.findById(report_id);
- }
-
- public Report findByWorker(String case_take_id, String worker_id) {
- return reportDao.findByWoker(case_take_id, worker_id);
- }
-
- public List<Bug> getBugList(String report_id, String case_take_id) {
- return bugDao.findByReport(report_id, case_take_id);
- }
-
-
- //测试题目相关
- public String saveExam(String case_id, String path, String app_name, String paper_type, String test_type, String description) {
- String json = ExcelToJson.ExcelTranse(path).toString();
- Exam exam = new Exam(case_id, json, app_name, paper_type, test_type, description);
- examDao.save(exam);
- return json;
- }
- // public String saveExam1(String case_id, String path, String app_name, String paper_type, String test_type, String description,
- // String if_test_case,String if_bug) {
- // String json = ExcelToJson.ExcelTranse(path).toString();
- //// Exam exam = new Exam(case_id, json, app_name, paper_type, test_type, description);
- // Exam exam = new Exam(case_id, json, app_name, paper_type, test_type, description,if_test_case,if_bug);
- // examDao.save(exam);
- // return json;
- // }
- public JSONArray getExamList() {
- List<Exam> result = examDao.findAll();
- JSONArray array = new JSONArray();
- Set<String> ids = bugDao.findAllids();
- Map<String, Exam> exams = new HashMap<>();
- for(Exam exam: result) { exams.put(exam.getId(), exam); }
- for(String id: ids) {
- if(id == null || id.length() <= 0) { continue; }
- String[] strs = id.split("-");
- String case_id = strs[0];
- String task_id = strs[1];
- if(exams.containsKey(case_id)) {
- JSONObject object = new JSONObject();
- Exam exam = exams.get(case_id);
- object.put("name", exam.getName());
- object.put("description", exam.getDescription());
- object.put("testType", exam.getTest_type());
- object.put("case_id", case_id);
- object.put("task_id", task_id);
- array.put(object);
- }
- }
- return array;
- }
- public Exam getExam(String id) {
- return examDao.findById(id);
- }
- }
|