package edu.nju.service; import java.util.*; import edu.nju.dao.*; import edu.nju.entities.*; import edu.nju.util.HTTP; 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; @Autowired TaskDao taskDao; //测试用例相关 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 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 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 result = examDao.findAll(); JSONArray array = new JSONArray(); Set ids = bugDao.findAllids(); Map 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); } public Task saveTask(String id){ // String result = HTTP.sendGet("http://114.55.91.83:8191/api/exam/" + id+"/info", ""); // if(result != null && !result.equals("")) { // JSONObject json = new JSONObject(result); // String beginTime=json.getString("beginTime"); // String endTime=json.getString("endTime"); // double totalMins=(Long.parseLong(endTime)-Long.parseLong(beginTime))/1000/60.0; // Task task=new Task(id,beginTime,endTime,totalMins,totalMins) ; // return taskDao.save(task); // } // return null; return taskDao.findById(id); } public boolean updateTask(String id,double writeMins){ try { Task task =taskDao.findById(id); task.setWrite_time(writeMins); taskDao.save(task); return true; }catch (Exception e){ return false; } } }