|
@@ -2,16 +2,14 @@ package edu.nju.service;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+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.dao.ReportDao;
|
|
|
-import edu.nju.dao.BugDao;
|
|
|
-import edu.nju.dao.ExamDao;
|
|
|
-import edu.nju.dao.TestCaseDao;
|
|
|
import edu.nju.util.ExcelToJson;
|
|
|
|
|
|
@Service
|
|
@@ -28,6 +26,12 @@ public class ExtraService {
|
|
|
|
|
|
@Autowired
|
|
|
BugDao bugDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ JobDao jobDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ItemDao itemDao;
|
|
|
|
|
|
|
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
@@ -135,41 +139,151 @@ public class ExtraService {
|
|
|
JSONObject jsonObject=new JSONObject(jobJson);
|
|
|
String description=jsonObject.getString("description");
|
|
|
String name=jsonObject.getString("name");
|
|
|
- String create_time_millis=Long.toString(System.currentTimeMillis());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- saveItem(jsonObject.getJSONArray("itemList"),"111");
|
|
|
-
|
|
|
- return null;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
+ String job_id=jobDao.save(new Job(description,name,Long.toString(System.currentTimeMillis()),"","","","","",""));
|
|
|
|
|
|
+ JSONArray itemArray=jsonObject.getJSONArray("itemList");
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<String,String> item_index_to_id=new HashMap<>();
|
|
|
+ for(int i=0;i<itemArray.length();i++) {
|
|
|
+ JSONObject itemObject = itemArray.getJSONObject(i);
|
|
|
+ String item_id=saveItem(itemObject,job_id);
|
|
|
+ String item_index=itemObject.getString("index");
|
|
|
+ item_index_to_id.put(item_index,item_id);
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ JSONArray workerArray=jsonObject.getJSONArray("workerList");
|
|
|
+ createWorkerToItem(item_index_to_id,workerArray);
|
|
|
|
|
|
+ return job_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void saveItem(JSONArray itemArray,String job_id){
|
|
|
- for(int i=0;i<itemArray.length();i++){
|
|
|
- JSONObject itemObject=itemArray.getJSONObject(i);
|
|
|
+ private String saveItem(JSONObject itemObject,String job_id){
|
|
|
+
|
|
|
+
|
|
|
String description=itemObject.getString("description");
|
|
|
- Set<String> img_urls=new HashSet<>();
|
|
|
+ List<String> img_urls=new ArrayList<>();
|
|
|
JSONArray imgUrlArray=itemObject.getJSONArray("img_urls");
|
|
|
for (int j=0;j<imgUrlArray.length();j++){
|
|
|
- img_urls.add(imgUrlArray.getString(i));
|
|
|
+ JSONObject imgUrlObject=imgUrlArray.getJSONObject(j);
|
|
|
+ img_urls.add(imgUrlObject.getString("url"));
|
|
|
}
|
|
|
boolean isRequired=Boolean.parseBoolean(itemObject.getString("isRequired"));
|
|
|
boolean isMultiple=Boolean.parseBoolean(itemObject.getString("isMultiple"));
|
|
|
-
|
|
|
-
|
|
|
+ List<String> file_urls=new ArrayList<>();
|
|
|
+ JSONArray fileArray=itemObject.getJSONArray("file_urls");
|
|
|
+
|
|
|
+ for (int j=0;j<fileArray.length();j++){
|
|
|
+ JSONObject fileObject=fileArray.getJSONObject(j);
|
|
|
+
|
|
|
+ file_urls.add(fileObject.getString("url"));
|
|
|
|
|
|
+ }
|
|
|
|
|
|
+ List<String> options=new ArrayList<>();
|
|
|
+ JSONArray optionArray=itemObject.getJSONArray("options");
|
|
|
+
|
|
|
+ for (int j=0;j<optionArray.length();j++){
|
|
|
+ JSONObject optionObject=optionArray.getJSONObject(j);
|
|
|
+
|
|
|
+ options.add(optionObject.getString("option"));
|
|
|
+ }
|
|
|
+ Item item=new Item(description,img_urls,isRequired,isMultiple,file_urls,options,job_id);
|
|
|
+ return itemDao.saveItem(item);
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
+ private void createWorkerToItem(HashMap<String,String> item_index_to_id,JSONArray workerArray){
|
|
|
+ HashMap<String,List<String>> worker_to_item=new HashMap<>();
|
|
|
|
|
|
+ for(int i=0;i<workerArray.length();i++){
|
|
|
+ JSONObject workerObject=workerArray.getJSONObject(i);
|
|
|
+ String worker_id=workerObject.getString("worker_id");
|
|
|
+ JSONArray itemIndexArray=workerObject.getJSONArray("item_index_list");
|
|
|
+ List<String> itemIdList=new ArrayList<>();
|
|
|
+ for (int j=0;j<itemIndexArray.length();j++){
|
|
|
+ JSONObject itemIndexObject=itemIndexArray.getJSONObject(j);
|
|
|
+ itemIdList.add(item_index_to_id.get(itemIndexObject.getString("index")));
|
|
|
+ }
|
|
|
+ worker_to_item.put(worker_id,itemIdList);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|