123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- package edu.nju.service;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import edu.nju.util.HTTP;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import edu.nju.dao.BugDao;
- import edu.nju.dao.BugHistoryDao;
- import edu.nju.dao.BugMirrorDao;
- import edu.nju.dao.BugPageDao;
- import edu.nju.dao.KWDao;
- import edu.nju.dao.StuInfoDao;
- import edu.nju.dao.ThumsUpDao;
- import edu.nju.entities.Bug;
- import edu.nju.entities.BugHistory;
- import edu.nju.entities.BugMirror;
- import edu.nju.entities.BugPage;
- import edu.nju.entities.KeyWords;
- import edu.nju.entities.ThumsUp;
- import edu.nju.util.StringMatch;
- @Service
- public class SaveService {
-
- @Autowired
- BugMirrorDao mirrordao;
-
- @Autowired
- BugDao bugdao;
-
- @Autowired
- BugHistoryDao historydao;
-
- @Autowired
- BugPageDao pagedao;
-
- @Autowired
- HistoryService hisservice;
-
- @Autowired
- DotService dotservice;
-
- @Autowired
- KWDao kwdao;
-
- @Autowired
- ThumsUpDao tdao;
-
- @Autowired
- StuInfoDao sdao;
-
- @Autowired
- AnalyzeService aservice;
- @Value("${main.site}")
- private String mainSite;
- @Value("${main.userInfoApi}")
- private String mainUserInfoApi;
-
- public String save(String case_take_id, String bug_category, String description, String img_url, String severity, String recurrent, String title, String report_id, String parent, String page, String useCase, String case_id) {
- try {
- StringMatch match = new StringMatch();
- // System.out.println("report"+report_id);
- String id = bugdao.save(new Bug(case_take_id, Long.toString(System.currentTimeMillis()), bug_category, description, img_url, severityTranse(severity), recurrentTranse(recurrent), title, report_id, page, case_id));
- mirrordao.save(new BugMirror(id, case_take_id, bug_category, severityTranse(severity), recurrentTranse(recurrent), title, img_url, new HashSet<String>(), new HashSet<String>(), report_id, useCase, true));
- kwdao.save(new KeyWords(id, match.Ansj(title), match.Ansj(description)));
- if(!parent.equals("null")) {
- String[] sp = parent.split("-");
- dotservice.saveType1(id, sp[1]);
- historydao.addChild(sp[0], id);
- String p = hisservice.parents(sp[0]).get(0);
- historydao.save(new BugHistory(id, sp[0], new ArrayList<String>(), p));
- } else {
- historydao.save(new BugHistory(id, parent, new ArrayList<String>(), id));
- }
-
- if(!page.equals("")) {
- savePage(id, case_take_id, page);
- }
- return id;
- } catch(Exception e) {
- e.printStackTrace();
- return "";
- }
- }
-
- // public boolean update(String id, String case_take_id, String bug_category, String description, String img_url, int severity, int recurrent, String title, String report_id, String parent,String page, String useCase, String case_id) {
- // try {
- // bugdao.save(new Bug(id, case_take_id, Long.toString(System.currentTimeMillis()), bug_category, description, img_url, severityTranse(severity), recurrentTranse(recurrent), title, report_id, page, case_id));
- // mirrordao.save(new BugMirror(id, case_take_id, bug_category, severityTranse(severity), recurrentTranse(recurrent), title, img_url, new HashSet<String>(), new HashSet<String>(), report_id, useCase, true));
- // if(!page.equals("")) {
- // savePage(id, case_take_id, page);
- // }
- // return true;
- // } catch(Exception e) {
- // e.printStackTrace();
- // return false;
- // }
- // }
-
- public boolean saveStu(String report_id, String worker_id) {
- try {
- String name = sdao.findById(report_id);
- if(name.equals("null") || name.equals("")) {
- String result = HTTP.sendGet(mainSite + mainUserInfoApi + worker_id, "");
- if(result != null && !result.equals("")) {
- JSONObject json = new JSONObject(result);
- sdao.save(report_id, worker_id, json.getString("name"));
- }
- }
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public boolean repair(String id, String page, String case_take_id, String bug_category, String description, String img_url, String severity, String recurrent, String report_id, String case_id) {
- try {
- if(id == null || id.equals("undefined")) { return false; }
- KeyWords keywords = kwdao.findById(id);
- String title = "";
- if(keywords != null) { title = keywords.getTitle().replaceAll(",", ""); }
- Bug bug = new Bug(case_take_id, Long.toString(System.currentTimeMillis()), bug_category, description, img_url, severityTranse(severity), recurrentTranse(recurrent), title, report_id, page, case_id);
- bug.setId(id);
- bugdao.save(bug);
- mirrordao.save(new BugMirror(id, case_take_id, bug_category, severityTranse(severity), recurrentTranse(recurrent), title, img_url, new HashSet<String>(), new HashSet<String>(), report_id, "null", true)); //null为useCase
- return true;
- } catch(Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public boolean repairThums(String case_take_id) {
- try {
- List<Bug> bugs = bugdao.findByCaseid(case_take_id);
- Set<String> reports = new HashSet<String>();
- for(Bug bug: bugs) {
- String report_id = bug.getReport_id();
- if(!reports.contains(report_id)) {
- reports.add(report_id);
- ThumsUp thumsup = tdao.findByReport(report_id);
- if(thumsup == null) { continue; }
- Set<String> thums = thumsup.getThums();
- Set<String> diss = thumsup.getDiss();
- if(thums != null && !thums.isEmpty()) {
- for(String id : thums) {
- BugMirror mirror = mirrordao.findById(id);
- if(mirror == null) { continue; }
- mirror.getGood().add(report_id);
- mirrordao.save(mirror);
- }
- }
- if(diss != null && !diss.isEmpty()) {
- for(String id : diss) {
- BugMirror mirror = mirrordao.findById(id);
- if(mirror == null) { continue; }
- mirror.getBad().add(report_id);
- mirrordao.save(mirror);
- }
- }
- }
- }
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public boolean repairTime(String case_take_id) {
- try {
- SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- // long start = dateformat.parse("2018-11-16 08:05:17").getCreate_time();
- // long middle = dateformat.parse("2018-11-16 09:15:17").getCreate_time();
- // long end = dateformat.parse("2018-11-16 11:55:17").getCreate_time();
- long start = dateformat.parse("2018-11-16 17:05:17").getTime();
- long middle = dateformat.parse("2018-11-16 18:15:17").getTime();
- long end = dateformat.parse("2018-11-16 19:55:17").getTime();
- List<String> ids = aservice.getValid(case_take_id);
- Collections.sort(ids);
- int size = ids.size();
- int middle_size = (int)(size * 0.7);
- Long gap1 = (middle - start) / middle_size;
- Long gap2 = (end - middle) / (size - middle_size);
- for(int i = 0; i < middle_size; i ++) {
- long new_time = start + gap1 * i;
- Bug bug = bugdao.findByid(ids.get(i));
- bug.setCreate_time_millis(Long.toString(new_time));
- bugdao.save(bug);
- }
- for(int i = middle_size; i < size; i ++) {
- long new_time = middle + gap2 * (i - middle_size);
- Bug bug = bugdao.findByid(ids.get(i));
- bug.setCreate_time_millis(Long.toString(new_time));
- bugdao.save(bug);
- }
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public boolean saveTitle(String id, String title) {
- try {
- Bug bug = bugdao.findByid(id);
- if(bug != null) {
- bug.setTitle(title);
- bugdao.save(bug);
- }
- BugMirror mirror = mirrordao.findById(id);
- if(mirror != null) {
- mirror.setTitle(title);
- mirrordao.save(mirror);
- }
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
-
- public boolean confirm(String id, String report_id) {
- try {
- if(mirrordao.haveJudged(id, report_id)) {
- mirrordao.good(id, report_id);
- tdao.saveGood(id, report_id);
- return true;
- }
- return false;
- } catch(Exception e) {
- return false;
- }
- }
-
- public boolean cancelGood(String id, String report_id) {
- try {
- mirrordao.cancelGood(id, report_id);
- tdao.cancelGood(id, report_id);
- return true;
- } catch(Exception e) {
- return false;
- }
- }
-
- public boolean diss(String id, String report_id) {
- try {
- if(mirrordao.haveJudged(id, report_id)) {
- mirrordao.bad(id, report_id);
- tdao.saveDiss(id, report_id);
- return true;
- }
- return false;
- } catch(Exception e) {
- return false;
- }
- }
-
- public boolean cancelDiss(String id, String report_id) {
- try {
- mirrordao.canelBad(id, report_id);
- tdao.cancelDiss(id, report_id);
- return true;
- } catch(Exception e) {
- return false;
- }
- }
-
- private void savePage(String id, String case_take_id, String page) {
- String[] pages = page.split("-");
- int length = pages.length;
- String page2 = "";
- String page3 = "";
- if(length == 2) {
- page2 = pages[1];
- } else if(length == 3) {
- page2 = pages[1];
- page3 = pages[2];
- }
- //如果在第三级页面出现了-
- else{
- page2=pages[1];
- for(int i=2;i<length-1;i++){
- page3+=(pages[i]+"-");
- }
- page3+=pages[pages.length-1];
- }
- BugPage save = new BugPage(id, pages[0], page2, page3, case_take_id);
- pagedao.save(save);
- }
-
- private int severityTranse(String str) {
- if(str.equals("待定")) {
- return 1;
- }
- if(str.equals("较轻")) {
- return 2;
- }
- if(str.equals("一般")) {
- return 3;
- }
- if(str.equals("严重")) {
- return 4;
- }
- if(str.equals("紧急")) {
- return 5;
- }
- return 0;
- }
-
- private int recurrentTranse(String str) {
- if(str.equals("其他")) {
- return 1;
- }
- if(str.equals("无规律复现")) {
- return 2;
- }
- if(str.equals("小概率复现")) {
- return 3;
- }
- if(str.equals("大概率复现")) {
- return 4;
- }
- if(str.equals("必现")) {
- return 5;
- }
- return 0;
- }
- }
|