Переглянути джерело

根据caseId保存报告信息,导出为json,csv文件

xujiawei 4 роки тому
батько
коміт
0baf3deb1d

+ 48 - 0
src/main/java/edu/nju/controller/DataController.java

@@ -0,0 +1,48 @@
+package edu.nju.controller;
+import edu.nju.entities.BugDetail;
+import edu.nju.service.DataService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 10:40
+ * @Email xjwhhh233@outlook.com
+ */
+@Controller
+@RequestMapping(value = "/data")
+@CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
+public class DataController {
+
+    @Autowired
+    DataService dataService;
+
+    /**根据caseId获取原始bug报告,保存到本地,
+     * bug信息保存为json,csv文件,图片打包为zip文件
+     *
+     * @param caseId
+     */
+    @RequestMapping(value = "/outputByCaseId")
+    @ResponseBody
+    public List<BugDetail> getBugDetailByCaseId(String caseId) {
+        return dataService.getBugDetailByCaseId(caseId);
+    }
+
+
+    /**
+     * 根据oss文件保存原始bug报告数据
+     * @param filePath
+     * @param originalCaseId
+     * @return
+     */
+    @RequestMapping(value = "/inputFromOSS")
+    @ResponseBody
+    public List<BugDetail> saveBugDetailFromOss(String filePath,String originalCaseId) {
+        return dataService.saveBugDetailFromOss(filePath,originalCaseId);
+    }
+
+
+}

+ 31 - 0
src/main/java/edu/nju/dao/BugDetailDao.java

@@ -0,0 +1,31 @@
+package edu.nju.dao;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.core.query.Update;
+import org.springframework.stereotype.Repository;
+
+import edu.nju.entities.BugDetail;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-28 15:24
+ * @Email xjwhhh233@outlook.com
+ */
+@Repository
+public class BugDetailDao {
+    @Autowired
+    private MongoOperations mongoOperations;
+
+    //save存在则更新,不存在则插入
+    public String save(BugDetail bugDetail) {
+        mongoOperations.save(bugDetail);
+        return bugDetail.getId();
+    }
+}

+ 34 - 0
src/main/java/edu/nju/dao/CaseToBugDao.java

@@ -0,0 +1,34 @@
+package edu.nju.dao;
+
+import edu.nju.entities.CaseToBug;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Repository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 11:01
+ * @Email xjwhhh233@outlook.com
+ */
+@Repository
+public class CaseToBugDao {
+    @Autowired
+    private MongoOperations mongoOperations;
+
+
+    public CaseToBug findById(String testCaseId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("_id").is(testCaseId));
+        List<CaseToBug> caseToBugList = mongoOperations.find(query,CaseToBug.class);
+        if(caseToBugList.size()==0){
+            return null;
+        }else{
+            return caseToBugList.get(0);
+        }
+    }
+}

+ 6 - 0
src/main/java/edu/nju/dao/ReportDao.java

@@ -55,6 +55,12 @@ public class ReportDao {
 		return mongoOperations.find(query, Report.class);
 	}
 
+	public List<Report> findByCaseId(String caseId) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("case_id").is(caseId));
+		return mongoOperations.find(query, Report.class);
+	}
+
 	public List<Report> findByExamId(String task_id) {
 		Query query = new Query();
 		query.addCriteria(Criteria.where("task_id").is(task_id));

+ 450 - 0
src/main/java/edu/nju/entities/BugDetail.java

@@ -0,0 +1,450 @@
+package edu.nju.entities;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.annotation.PersistenceConstructor;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-24 15:53
+ * @Email xjwhhh233@outlook.com
+ */
+@Document
+public class BugDetail implements java.io.Serializable {
+
+    //bug属性
+    @Id
+    private String id;
+    private String bugCategory;
+    private String severity;
+    private String recurrent;
+    private String bugCreateTime;
+    private String bugPage;
+    private String title;
+    private String bugDescription;
+    private String imgUrl;
+    private int score;
+    private String parent;
+    private List<String> children;
+    private String root;
+    private int goodNum;
+    private Set<String> goodWorkerId;
+    private int badNum;
+    private Set<String> badWorkerId;
+
+    //测试用例属性
+    private String testCaseId;
+    private String testCaseName;
+    private String testCaseFront;
+    private String testCaseBehind;
+    private String testCaseDescription;
+    private String testCaseCreateTime;
+
+    //report属性
+    private String reportId;
+    private String reportName;
+    private String reportCreateTime;
+    private String scriptLocation;
+    private String reportLocation;
+    private String logLocation;
+    private String deviceModel;
+    private String deviceBrand;
+    private String deviceOs;
+
+    //工人属性
+    private String workerId;
+
+    //众测任务属性
+    private String caseAppName;
+    private String casePaperType;
+    private String caseTestType;
+    private String caseDescription;
+    private String caseRequireDoc;
+
+
+    //原系统中的case_take_id
+    private String caseTakeId;
+    //与目前系统中的哪个case对应
+    private String originalCaseId;
+
+    //cp系统序列号
+    private String cpSerialNum;
+
+    public BugDetail(){};
+
+    @PersistenceConstructor
+    public BugDetail(String id, String bugCategory, String severity, String recurrent, String bugCreateTime, String bugPage, String title, String bugDescription, String imgUrl, int score, String parent, List<String> children, String root, int goodNum, Set<String> goodWorkerId, int badNum, Set<String> badWorkerId, String testCaseId, String testCaseName, String testCaseFront, String testCaseBehind, String testCaseDescription, String testCaseCreateTime, String reportId, String reportName, String reportCreateTime, String scriptLocation, String reportLocation, String logLocation, String deviceModel, String deviceBrand, String deviceOs, String workerId, String caseAppName, String casePaperType, String caseTestType, String caseDescription, String caseRequireDoc, String caseTakeId, String originalCaseId, String cpSerialNum) {
+        this.id = id;
+        this.bugCategory = bugCategory;
+        this.severity = severity;
+        this.recurrent = recurrent;
+        this.bugCreateTime = bugCreateTime;
+        this.bugPage = bugPage;
+        this.title = title;
+        this.bugDescription = bugDescription;
+        this.imgUrl = imgUrl;
+        this.score = score;
+        this.parent = parent;
+        this.children = children;
+        this.root = root;
+        this.goodNum = goodNum;
+        this.goodWorkerId = goodWorkerId;
+        this.badNum = badNum;
+        this.badWorkerId = badWorkerId;
+        this.testCaseId = testCaseId;
+        this.testCaseName = testCaseName;
+        this.testCaseFront = testCaseFront;
+        this.testCaseBehind = testCaseBehind;
+        this.testCaseDescription = testCaseDescription;
+        this.testCaseCreateTime = testCaseCreateTime;
+        this.reportId = reportId;
+        this.reportName = reportName;
+        this.reportCreateTime = reportCreateTime;
+        this.scriptLocation = scriptLocation;
+        this.reportLocation = reportLocation;
+        this.logLocation = logLocation;
+        this.deviceModel = deviceModel;
+        this.deviceBrand = deviceBrand;
+        this.deviceOs = deviceOs;
+        this.workerId = workerId;
+        this.caseAppName = caseAppName;
+        this.casePaperType = casePaperType;
+        this.caseTestType = caseTestType;
+        this.caseDescription = caseDescription;
+        this.caseRequireDoc = caseRequireDoc;
+        this.caseTakeId = caseTakeId;
+        this.originalCaseId = originalCaseId;
+        this.cpSerialNum = cpSerialNum;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getBugCategory() {
+        return bugCategory;
+    }
+
+    public void setBugCategory(String bugCategory) {
+        this.bugCategory = bugCategory;
+    }
+
+    public String getSeverity() {
+        return severity;
+    }
+
+    public void setSeverity(String severity) {
+        this.severity = severity;
+    }
+
+    public String getRecurrent() {
+        return recurrent;
+    }
+
+    public void setRecurrent(String recurrent) {
+        this.recurrent = recurrent;
+    }
+
+    public String getBugCreateTime() {
+        return bugCreateTime;
+    }
+
+    public void setBugCreateTime(String bugCreateTime) {
+        this.bugCreateTime = bugCreateTime;
+    }
+
+    public String getBugPage() {
+        return bugPage;
+    }
+
+    public void setBugPage(String bugPage) {
+        this.bugPage = bugPage;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getBugDescription() {
+        return bugDescription;
+    }
+
+    public void setBugDescription(String bugDescription) {
+        this.bugDescription = bugDescription;
+    }
+
+    public String getImgUrl() {
+        return imgUrl;
+    }
+
+    public void setImgUrl(String imgUrl) {
+        this.imgUrl = imgUrl;
+    }
+
+    public int getScore() {
+        return score;
+    }
+
+    public void setScore(int score) {
+        this.score = score;
+    }
+
+    public String getParent() {
+        return parent;
+    }
+
+    public void setParent(String parent) {
+        this.parent = parent;
+    }
+
+    public List<String> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<String> children) {
+        this.children = children;
+    }
+
+    public String getRoot() {
+        return root;
+    }
+
+    public void setRoot(String root) {
+        this.root = root;
+    }
+
+    public Set<String> getGoodWorkerId() {
+        return goodWorkerId;
+    }
+
+    public int getGoodNum() {
+        return goodNum;
+    }
+
+    public void setGoodNum(int goodNum) {
+        this.goodNum = goodNum;
+    }
+
+    public int getBadNum() {
+        return badNum;
+    }
+
+    public void setBadNum(int badNum) {
+        this.badNum = badNum;
+    }
+
+    public void setGoodWorkerId(Set<String> goodWorkerId) {
+        this.goodWorkerId = goodWorkerId;
+    }
+
+    public Set<String> getBadWorkerId() {
+        return badWorkerId;
+    }
+
+    public void setBadWorkerId(Set<String> badWorkerId) {
+        this.badWorkerId = badWorkerId;
+    }
+
+    public String getTestCaseId() {
+        return testCaseId;
+    }
+
+    public void setTestCaseId(String testCaseId) {
+        this.testCaseId = testCaseId;
+    }
+
+    public String getTestCaseName() {
+        return testCaseName;
+    }
+
+    public void setTestCaseName(String testCaseName) {
+        this.testCaseName = testCaseName;
+    }
+
+    public String getTestCaseFront() {
+        return testCaseFront;
+    }
+
+    public void setTestCaseFront(String testCaseFront) {
+        this.testCaseFront = testCaseFront;
+    }
+
+    public String getTestCaseBehind() {
+        return testCaseBehind;
+    }
+
+    public void setTestCaseBehind(String testCaseBehind) {
+        this.testCaseBehind = testCaseBehind;
+    }
+
+    public String getTestCaseDescription() {
+        return testCaseDescription;
+    }
+
+    public void setTestCaseDescription(String testCaseDescription) {
+        this.testCaseDescription = testCaseDescription;
+    }
+
+    public String getTestCaseCreateTime() {
+        return testCaseCreateTime;
+    }
+
+    public void setTestCaseCreateTime(String testCaseCreateTime) {
+        this.testCaseCreateTime = testCaseCreateTime;
+    }
+
+    public String getReportId() {
+        return reportId;
+    }
+
+    public void setReportId(String reportId) {
+        this.reportId = reportId;
+    }
+
+    public String getReportName() {
+        return reportName;
+    }
+
+    public void setReportName(String reportName) {
+        this.reportName = reportName;
+    }
+
+    public String getReportCreateTime() {
+        return reportCreateTime;
+    }
+
+    public void setReportCreateTime(String reportCreateTime) {
+        this.reportCreateTime = reportCreateTime;
+    }
+
+    public String getScriptLocation() {
+        return scriptLocation;
+    }
+
+    public void setScriptLocation(String scriptLocation) {
+        this.scriptLocation = scriptLocation;
+    }
+
+    public String getReportLocation() {
+        return reportLocation;
+    }
+
+    public void setReportLocation(String reportLocation) {
+        this.reportLocation = reportLocation;
+    }
+
+    public String getLogLocation() {
+        return logLocation;
+    }
+
+    public void setLogLocation(String logLocation) {
+        this.logLocation = logLocation;
+    }
+
+    public String getDeviceModel() {
+        return deviceModel;
+    }
+
+    public void setDeviceModel(String deviceModel) {
+        this.deviceModel = deviceModel;
+    }
+
+    public String getDeviceBrand() {
+        return deviceBrand;
+    }
+
+    public void setDeviceBrand(String deviceBrand) {
+        this.deviceBrand = deviceBrand;
+    }
+
+    public String getDeviceOs() {
+        return deviceOs;
+    }
+
+    public void setDeviceOs(String deviceOs) {
+        this.deviceOs = deviceOs;
+    }
+
+    public String getWorkerId() {
+        return workerId;
+    }
+
+    public void setWorkerId(String workerId) {
+        this.workerId = workerId;
+    }
+
+    public String getCaseAppName() {
+        return caseAppName;
+    }
+
+    public void setCaseAppName(String caseAppName) {
+        this.caseAppName = caseAppName;
+    }
+
+    public String getCasePaperType() {
+        return casePaperType;
+    }
+
+    public void setCasePaperType(String casePaperType) {
+        this.casePaperType = casePaperType;
+    }
+
+    public String getCaseTestType() {
+        return caseTestType;
+    }
+
+    public void setCaseTestType(String caseTestType) {
+        this.caseTestType = caseTestType;
+    }
+
+    public String getCaseDescription() {
+        return caseDescription;
+    }
+
+    public void setCaseDescription(String caseDescription) {
+        this.caseDescription = caseDescription;
+    }
+
+    public String getCaseRequireDoc() {
+        return caseRequireDoc;
+    }
+
+    public void setCaseRequireDoc(String caseRequireDoc) {
+        this.caseRequireDoc = caseRequireDoc;
+    }
+
+    public String getCaseTakeId() {
+        return caseTakeId;
+    }
+
+    public void setCaseTakeId(String caseTakeId) {
+        this.caseTakeId = caseTakeId;
+    }
+
+    public String getOriginalCaseId() {
+        return originalCaseId;
+    }
+
+    public void setOriginalCaseId(String originalCaseId) {
+        this.originalCaseId = originalCaseId;
+    }
+
+    public String getCpSerialNum() {
+        return cpSerialNum;
+    }
+
+    public void setCpSerialNum(String cpSerialNum) {
+        this.cpSerialNum = cpSerialNum;
+    }
+}

+ 290 - 0
src/main/java/edu/nju/service/DataService.java

@@ -0,0 +1,290 @@
+package edu.nju.service;
+
+import com.alibaba.fastjson.JSON;
+import com.aliyun.oss.OSS;
+import edu.nju.dao.*;
+import edu.nju.entities.*;
+import edu.nju.util.OssAliyun;
+import edu.nju.util.TransUtil;
+import org.json.JSONArray;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 10:45
+ * @Email xjwhhh233@outlook.com
+ */
+@Service
+public class DataService {
+    @Autowired
+    ExamDao examDao;
+
+    @Autowired
+    BugDao bugDao;
+
+    @Autowired
+    ReportDao reportDao;
+
+    @Autowired
+    TestCaseDao testCaseDao;
+
+    @Autowired
+    CaseToBugDao caseToBugDao;
+
+    @Autowired
+    BugScoreDao bugScoreDao;
+
+    @Autowired
+    BugMirrorDao bugMirrorDao;
+
+    @Autowired
+    BugHistoryDao bugHistoryDao;
+
+    @Autowired
+    BugDetailDao bugDetailDao;
+
+//    @Value("${cpSerialNum}")
+    private String cpSerialNum="cp_ent_dev";
+
+    private static final String bucketName="mooctest-share";
+
+
+    /**
+     * 根据caseId获取对应bug信息
+     *
+     * @param caseId
+     * @return
+     */
+    public List<BugDetail> getBugDetailByCaseId(String caseId) {
+        List<BugDetail> bugDetailList = new ArrayList<>();
+        Exam crowdCase = examDao.findById(caseId);
+        if (crowdCase != null) {
+            List<Report> reportList = reportDao.findByCaseId(caseId);
+            for (Report report : reportList) {
+                String reportId = report.getId();
+                List<TestCase> testCaseList = testCaseDao.findByReport(reportId);
+                for (TestCase testCase : testCaseList) {
+                    String testCaseId = testCase.getId();
+                    CaseToBug caseToBug = caseToBugDao.findById(testCaseId);
+                    if (caseToBug != null) {
+                        List<String> bugIdList = caseToBug.getBug_id();
+                        for (String bugId : bugIdList) {
+                            BugDetail bugDetail = new BugDetail();
+                            bugDetail.setId(bugId);
+                            //bug基本属性
+                            Bug bug = bugDao.findByid(bugId);
+                            if (bug != null) {
+                                bugDetail.setBugCategory(bug.getBug_category());
+                                bugDetail.setSeverity(TransUtil.severityTransFromInt(bug.getSeverity()));
+                                bugDetail.setRecurrent(TransUtil.recurrentTransFromInt(bug.getRecurrent()));
+                                bugDetail.setBugCreateTime(TransUtil.formatTimeMillis(bug.getCreate_time_millis()));
+                                bugDetail.setBugPage(bug.getBug_page());
+                                bugDetail.setTitle(bug.getTitle());
+                                bugDetail.setBugDescription(bug.getDescription());
+                                bugDetail.setImgUrl(bug.getImg_url());
+                            }
+                            //bugScore属性
+                            BugScore bugScore = bugScoreDao.findById(bugId);
+                            if (bugScore != null) {
+                                bugDetail.setScore(bugScore.getGrade());
+                            }
+                            //bugMirror属性
+                            BugMirror bugMirror = bugMirrorDao.findById(bugId);
+                            if (bugMirror != null) {
+                                Set<String> goodWorkerIdSet = new HashSet<>();
+                                Set<String> badWorkerIdSet = new HashSet<>();
+                                Set<String> goodReportIdSet = bugMirror.getGood();
+                                Set<String> badReportIdSet = bugMirror.getBad();
+                                int goodNum = 0;
+                                int badNum = 0;
+                                for (String goodReportId : goodReportIdSet) {
+                                    Report goodReport = reportDao.findById(goodReportId);
+                                    if (goodReport != null) {
+                                        goodNum++;
+                                        goodWorkerIdSet.add(goodReport.getWorker_id());
+                                    }
+                                }
+                                for (String badReportId : badReportIdSet) {
+                                    Report badReport = reportDao.findById(badReportId);
+                                    if (badReport != null) {
+                                        badNum++;
+                                        badWorkerIdSet.add(badReport.getWorker_id());
+                                    }
+                                }
+                                bugDetail.setGoodNum(goodNum);
+                                bugDetail.setBadNum(badNum);
+                                bugDetail.setGoodWorkerId(goodWorkerIdSet);
+                                bugDetail.setBadWorkerId(badWorkerIdSet);
+                            }
+                            //bugHistory属性
+                            BugHistory bugHistory = bugHistoryDao.findByid(bugId);
+                            if (bugHistory != null) {
+                                bugDetail.setParent(bugHistory.getParent());
+                                bugDetail.setChildren(bugHistory.getChildren());
+                                bugDetail.setRoot(bugHistory.getRoot());
+                            }
+                            //testCase属性
+                            bugDetail.setTestCaseId(testCase.getId());
+                            bugDetail.setTestCaseName(testCase.getName());
+                            bugDetail.setTestCaseFront(testCase.getFront());
+                            bugDetail.setTestCaseBehind(testCase.getBehind());
+                            bugDetail.setTestCaseDescription(testCase.getDescription());
+                            bugDetail.setTestCaseCreateTime(TransUtil.formatTimeMillis(testCase.getCreate_time_millis()));
+                            //report属性
+                            bugDetail.setReportId(report.getId());
+                            bugDetail.setReportName(report.getName());
+                            bugDetail.setScriptLocation(report.getScript_location());
+                            bugDetail.setReportLocation(report.getReport_location());
+                            bugDetail.setLogLocation(report.getLog_location());
+                            bugDetail.setDeviceModel(report.getDevice_model());
+                            bugDetail.setDeviceBrand(report.getDevice_brand());
+                            bugDetail.setDeviceOs(report.getDevice_os());
+                            //worker属性
+                            bugDetail.setWorkerId(report.getWorker_id());
+                            //众测任务属性
+                            bugDetail.setCaseAppName(crowdCase.getName());
+                            bugDetail.setCasePaperType(crowdCase.getPaper_type());
+                            bugDetail.setCaseTestType(crowdCase.getTest_type());
+                            bugDetail.setCaseDescription(crowdCase.getDescription());
+                            bugDetail.setCaseRequireDoc("");
+                            bugDetail.setCaseTakeId(report.getCase_take_id());
+                            //cp序列号
+                            bugDetail.setCpSerialNum(cpSerialNum);
+                            bugDetailList.add(bugDetail);
+                        }
+                    }
+                }
+            }
+        }
+        bugDetailToFile(bugDetailList,caseId);
+        return bugDetailList;
+    }
+
+    public List<BugDetail> saveBugDetailFromOss(String filePath,String originalCaseId){
+        try {
+            //从oss下载文件
+            URL url = new URL(filePath);
+            URLConnection urlConnection = url.openConnection();
+            HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
+            httpURLConnection.setConnectTimeout(1000*5);
+            httpURLConnection.setRequestProperty("Charset", "UTF-8");
+            httpURLConnection.connect();
+            BufferedInputStream bufferedInputStream = new BufferedInputStream(httpURLConnection.getInputStream());
+            ByteArrayOutputStream buf = new ByteArrayOutputStream();
+            int result = bufferedInputStream.read();
+            while(result != -1) {
+                buf.write((byte) result);
+                result = bufferedInputStream.read();
+            }
+            String json= buf.toString();
+            //转为bugDetail
+            List<BugDetail> bugDetailList = JSON.parseArray(json, BugDetail.class);
+            for(BugDetail bugDetail:bugDetailList){
+                bugDetail.setOriginalCaseId(originalCaseId);
+                bugDetailDao.save(bugDetail);
+            }
+            return bugDetailList;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return new ArrayList<>();
+    }
+
+    private void bugDetailToFile(List<BugDetail> bugDetailList, String caseId) {
+        String[] titles = {"bug_id", "bug_category", "severity", "recurrent", "bug_create_time", "bug_page", "title",
+                "description", "img_url",
+                "score", "parent", "children", "root", "good_num", "good_worker_id", "bad_num", "bad_worker_id",
+                "test_case_id", "test_case_name", "test_case_front", "test_case_behind", "test_case_description", "test_case_create_time",
+                "report_id", "report_name", "report_create_time", "script_location", "report_location", "log_location","device_model", "device_brand", "device_os",
+                "worker_id",
+                "case_app_name","case_paper_type","case_test_type", "case_description", "case_require_doc",
+                "case_take_id","originalCaseId","cpSerialNum"};
+        File csvFile=exportCsv(titles, bugDetailList,caseId);
+        File jsonFile=exportJson(bugDetailList,caseId);
+
+//        uploadToOss(csvFile);
+//        uploadToOss(jsonFile);
+    }
+
+    private File exportJson(List<BugDetail> bugDetailList, String caseId){
+        try {
+            File file = new File("data/output/" + caseId + ".json");
+            JSONArray jsonArray=new JSONArray(bugDetailList);
+            Writer write = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
+            write.write(jsonArray.toString());
+            write.flush();
+            write.close();
+            return file;
+        }catch (IOException e){
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    private  <T> File exportCsv(String[] titles, List<T> list,String caseId) {
+        try {
+            File file = new File("data/output/"+caseId+".csv");
+            //构建输出流,同时指定编码
+            OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
+            //csv文件是逗号分隔,除第一个外,每次写入一个单元格数据后需要输入逗号
+            for (String title : titles) {
+                ow.write(title);
+                ow.write(",");
+            }
+            //写完文件头后换行
+            ow.write("\r\n");
+            //写内容
+            for (Object obj : list) {
+                //利用反射获取所有字段
+                Field[] fields = obj.getClass().getDeclaredFields();
+                for (Field field : fields) {
+                    //设置字段可见性
+                    field.setAccessible(true);
+                    //防止某个field没有赋值
+                    if (field.get(obj) == null) {
+                        ow.write("");
+                    } else {
+                        //解决csv文件中对于逗号和双引号的转义问题
+                        ow.write("\"" + field.get(obj).toString().replaceAll("\"","\"\"") + "\"");
+                    }
+                    ow.write(",");
+                }
+                //写完一行换行
+                ow.write("\r\n");
+            }
+            ow.flush();
+            ow.close();
+            return file;
+        } catch (IOException | IllegalAccessException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+//
+//    private void uploadToOss(File file){
+////        if(file!=null) {
+////            OSS ossClient = OssAliyun.initHangZhouOss();
+////            String objectName = "crowd-dataset/" + file.getName();
+////            OssAliyun.uploadFile(ossClient, bucketName, objectName, file);
+////        }else{
+////            System.out.println("file is null");
+////        }
+//    }
+
+}
+
+

+ 106 - 0
src/main/java/edu/nju/util/TransUtil.java

@@ -0,0 +1,106 @@
+package edu.nju.util;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @Author JiaWei Xu
+ * @Date 2020-12-25 11:12
+ * @Email xjwhhh233@outlook.com
+ */
+public class TransUtil {
+
+    private static final String UNDETERMINED = "待定";
+    private static final String LIGHTER = "较轻";
+    private static final String NORMAL = "一般";
+    private static final String SERIOUS = "严重";
+    private static final String URGENT = "紧急";
+    private static final String OTHER = "其他";
+    private static final String IRREGULAR = "无规律";
+    private static final String SMALL_PROBABILITY = "小概率复现";
+    private static final String BIG_PROBABILITY = "大概率复现";
+    private static final String CERTAIN = "必现";
+
+
+    public static int severityTransFromString(String str) {
+        if (UNDETERMINED.equals(str)) {
+            return 1;
+        }
+        if (LIGHTER.equals(str)) {
+            return 2;
+        }
+        if (NORMAL.equals(str)) {
+            return 3;
+        }
+        if (SERIOUS.equals(str)) {
+            return 4;
+        }
+        if (URGENT.equals(str)) {
+            return 5;
+        }
+        return 0;
+    }
+
+    public static int recurrentTransFromString(String str) {
+        if (OTHER.equals(str)) {
+            return 1;
+        }
+        if (IRREGULAR.equals(str)) {
+            return 2;
+        }
+        if (SMALL_PROBABILITY.equals(str)) {
+            return 3;
+        }
+        if (BIG_PROBABILITY.equals(str)) {
+            return 4;
+        }
+        if (CERTAIN.equals(str)) {
+            return 5;
+        }
+        return 0;
+    }
+
+    public static String severityTransFromInt(int num) {
+        switch (num) {
+            case 1:
+                return UNDETERMINED;
+            case 2:
+                return LIGHTER;
+            case 3:
+                return NORMAL;
+            case 4:
+                return SERIOUS;
+            case 5:
+                return URGENT;
+            default:
+                return "";
+        }
+    }
+
+    public static String recurrentTransFromInt(int num) {
+        switch (num) {
+            case 1:
+                return OTHER;
+            case 2:
+                return IRREGULAR;
+            case 3:
+                return SMALL_PROBABILITY;
+            case 4:
+                return BIG_PROBABILITY;
+            case 5:
+                return CERTAIN;
+            default:
+                return "";
+        }
+    }
+
+    public static String formatTimeMillis(String millis){
+        Date date = new Date();
+        date.setTime(Long.parseLong(millis));
+        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
+    }
+
+//    public static void main(String[] args){
+//        formatTimeMillis("1");
+//    }
+}