|
@@ -1,10 +1,16 @@
|
|
|
package edu.nju.service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStreamWriter;
|
|
|
+import java.io.Writer;
|
|
|
import java.util.*;
|
|
|
|
|
|
import edu.nju.dao.*;
|
|
|
import edu.nju.entities.*;
|
|
|
+import edu.nju.util.FormatJson;
|
|
|
import edu.nju.util.HTTP;
|
|
|
+import edu.nju.util.OssAliyun;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -29,6 +35,15 @@ public class ExtraService {
|
|
|
|
|
|
@Autowired
|
|
|
TaskDao taskDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BugMirrorDao mirrorDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ReviewPaperService reviewPaperService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CrowdSourceToReviewPaperDao crowdSourceToReviewPaperDao;
|
|
|
|
|
|
//测试用例相关
|
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
@@ -168,5 +183,89 @@ public class ExtraService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String reportsToReviewPaper(String case_take_id){
|
|
|
+ int[]options={1,2,3,4,5,6,7,8,9,10};
|
|
|
+ try {
|
|
|
+ CrowdSourceToReviewPaper crowdSourceToReviewPaper=crowdSourceToReviewPaperDao.getByCaseTakeId(case_take_id);
|
|
|
+ if(crowdSourceToReviewPaper!=null){
|
|
|
+ String url=crowdSourceToReviewPaper.getUrl();
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+ JSONObject result=new JSONObject();
|
|
|
+ List<Bug>bugs=bugDao.findByCaseid(case_take_id);
|
|
|
+ JSONArray reportArray=new JSONArray();
|
|
|
+ int[]indexArray=new int[bugs.size()];
|
|
|
+ for(int i=0;i<bugs.size();i++) {
|
|
|
+ Bug bug=bugs.get(i);
|
|
|
+ BugMirror mirror=mirrorDao.findById(bug.getId());
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("index",i);
|
|
|
+ indexArray[i]=i;
|
|
|
+ jsonObject.put("name",bug.getTitle());
|
|
|
+ jsonObject.put("original_id",bug.getId());
|
|
|
+ String description="";
|
|
|
+ description+=bug.getDescription()+"\n";
|
|
|
+ description+=bug.getBug_page()+"\n";
|
|
|
+ description+=bug.getBug_category()+"\n";
|
|
|
+ description+=bug.getSeverity()+"\n";
|
|
|
+ description+=bug.getRecurrent()+"\n";
|
|
|
+ description+=bug.getCreate_time_millis()+"\n";
|
|
|
+ description+=mirror.getGood().size()+"\n";
|
|
|
+ description+=mirror.getBad().size();
|
|
|
+ jsonObject.put("description",description);
|
|
|
+ //JSONArray urlArray=new JSONArray();
|
|
|
+ String[]urlArray=new String[1];
|
|
|
+ urlArray[0]=bug.getImg_url();
|
|
|
+ //JSONObject temp=new JSONObject(bug.getImg_url());
|
|
|
+ //urlArray.put(temp);
|
|
|
+ jsonObject.put("img_url",urlArray);
|
|
|
+ JSONArray fileArray=new JSONArray();
|
|
|
+ jsonObject.put("file_url",fileArray);
|
|
|
+ reportArray.put(jsonObject);
|
|
|
+ }
|
|
|
+ result.put("report_list",reportArray);
|
|
|
+ result.put("description","");
|
|
|
+ result.put("name","");
|
|
|
+ result.put("create_time",String.valueOf(System.currentTimeMillis()));
|
|
|
+ result.put("type","众测任务");
|
|
|
+ result.put("application_url","");
|
|
|
+ result.put("requirement_url","");
|
|
|
+ JSONArray itemGroupArray=new JSONArray();
|
|
|
+ JSONObject itemGroupObject=new JSONObject();
|
|
|
+ JSONArray itemArray=new JSONArray();
|
|
|
+ JSONObject itemObject=new JSONObject();
|
|
|
+ itemObject.put("index",0);
|
|
|
+ itemObject.put("description","请评分");
|
|
|
+ itemObject.put("is_required",true);
|
|
|
+ itemObject.put("type","Single");
|
|
|
+ itemObject.put("options",options);
|
|
|
+ itemArray.put(itemObject);
|
|
|
+ itemGroupObject.put("report_list",indexArray);
|
|
|
+ itemGroupObject.put("item_list",itemArray);
|
|
|
+ itemGroupArray.put(itemGroupObject);
|
|
|
+ result.put("item_group_list",itemGroupArray);
|
|
|
+ String jsonString = FormatJson.formatJson(result.toString());
|
|
|
+ // 将格式化后的字符串写入文件
|
|
|
+ String fileName=case_take_id+".json";
|
|
|
+ File file=new File(fileName);
|
|
|
+ Writer write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
|
|
|
+ write.write(jsonString);
|
|
|
+ write.flush();
|
|
|
+ write.close();
|
|
|
+ //OssAliyun.uploadFile("paperjson/"+case_take_id,file);
|
|
|
+ JSONObject jsonObject=reviewPaperService.uploadPaper(result.toString());
|
|
|
+ String paperId=jsonObject.getString("paperId");
|
|
|
+ String url="http://mooctest-site.oss-cn-shanghai.aliyuncs.com/paperjson/"+case_take_id;
|
|
|
+ crowdSourceToReviewPaperDao.save(new CrowdSourceToReviewPaper(paperId,case_take_id,url));
|
|
|
+ return url;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|