|
@@ -2,7 +2,6 @@ package edu.nju.service;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
-import com.google.gson.JsonArray;
|
|
|
import edu.nju.dao.*;
|
|
|
import edu.nju.entities.*;
|
|
|
import org.json.JSONArray;
|
|
@@ -34,7 +33,7 @@ public class ExtraService {
|
|
|
ReviewItemDao itemDao;
|
|
|
|
|
|
@Autowired
|
|
|
- ItemService itemService;
|
|
|
+ ReviewService reviewService;
|
|
|
|
|
|
//测试用例相关
|
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
@@ -151,61 +150,53 @@ public class ExtraService {
|
|
|
|
|
|
String job_id=jobDao.save(new ReviewJob(description,name,time,type,application_location,requirement_location,report_num,worker_num));
|
|
|
|
|
|
- JSONArray itemArray=jsonObject.getJSONArray("item_list");
|
|
|
+ JSONArray itemGroupArray=jsonObject.getJSONArray("item_group_list");
|
|
|
//save item
|
|
|
//item index-id
|
|
|
- HashMap<String,String> item_index_to_id=new HashMap<>();
|
|
|
- HashMap<String,Integer>item_id_to_problem_num=new HashMap<>();
|
|
|
- for(int i=0;i<itemArray.length();i++) {
|
|
|
- JSONObject itemObject = itemArray.getJSONObject(i);
|
|
|
- String item_id=saveItem(itemObject,job_id,item_id_to_problem_num);
|
|
|
- String item_index=itemObject.getString("index");
|
|
|
- item_index_to_id.put(item_index,item_id);
|
|
|
+ HashMap<String,Integer>item_id_to_option_num=new HashMap<>();
|
|
|
+ for(int i=0;i<itemGroupArray.length();i++) {
|
|
|
+ JSONObject itemGroupObject = itemGroupArray.getJSONObject(i);
|
|
|
+ saveItem(itemGroupObject,job_id,item_id_to_option_num);
|
|
|
}
|
|
|
|
|
|
//worker_id-item_id_list
|
|
|
JSONArray groupArray=jsonObject.getJSONArray("group_list");
|
|
|
- createWorkerToItem(item_index_to_id,groupArray,job_id,item_id_to_problem_num);
|
|
|
+ createWorkerToItem(groupArray,job_id,item_id_to_option_num);
|
|
|
|
|
|
return job_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
- private String saveItem(JSONObject itemObject,String job_id,HashMap<String,Integer>item_id_to_problem_num){
|
|
|
+ private void saveItem(JSONObject itemGroupObject,String job_id,HashMap<String,Integer>item_id_to_option_num){
|
|
|
|
|
|
// JSONObject itemObject=itemArray.getJSONObject(i);
|
|
|
List<String> urls=new ArrayList<>();
|
|
|
- JSONArray urlArray=itemObject.getJSONArray("attachment_urls");
|
|
|
- for (int j=0;j<urlArray.length();j++){
|
|
|
- JSONObject imgUrlObject=urlArray.getJSONObject(j);
|
|
|
- urls.add(imgUrlObject.getString("url"));
|
|
|
- }
|
|
|
- JSONArray reportArray=itemObject.getJSONArray("report_list");
|
|
|
+ JSONArray reportArray=itemGroupObject.getJSONArray("report_list");
|
|
|
List<String> reports=new ArrayList<>();
|
|
|
for (int j=0;j<reportArray.length();j++){
|
|
|
JSONObject reportIdObject=reportArray.getJSONObject(j);
|
|
|
urls.add(reportIdObject.getString("report_id"));
|
|
|
}
|
|
|
- List<String> isRequired=new ArrayList<>();
|
|
|
- List<String> isMultiple=new ArrayList<>();
|
|
|
- List<String> options=new ArrayList<>();
|
|
|
- List<String> descriptions=new ArrayList<>();
|
|
|
- JSONArray problemArray=itemObject.getJSONArray("problem_list");
|
|
|
- for (int j=0;j<problemArray.length();j++){
|
|
|
- JSONObject problemObject=reportArray.getJSONObject(j);
|
|
|
- isMultiple.add(problemObject.getString("is_multiple"));
|
|
|
- isRequired.add(problemObject.getString("is_required"));
|
|
|
- descriptions.add(problemObject.getString("description"));
|
|
|
- options.add(problemObject.getString("options"));
|
|
|
+ JSONArray itemArray=itemGroupObject.getJSONArray("item_list");
|
|
|
+ for (int j=0;j<itemArray.length();j++){
|
|
|
+ JSONObject itemObject=itemArray.getJSONObject(j);
|
|
|
+ String isMultiple=itemObject.getString("is_multiple");
|
|
|
+ String isRequired=itemObject.getString("is_required");
|
|
|
+ String description=itemObject.getString("description");
|
|
|
+ String type=itemObject.getString("type");
|
|
|
+ List<String>options=new ArrayList<>();
|
|
|
+ JSONArray optionArray=itemObject.getJSONArray("options");
|
|
|
+ for(int k=0;k<optionArray.length();k++){
|
|
|
+ options.add(optionArray.getJSONObject(k).getString("option"));
|
|
|
+ }
|
|
|
+ ReviewItem item=new ReviewItem(job_id,isRequired,isMultiple,options,description,reports,type);
|
|
|
+ String item_id = itemDao.saveItem(item);
|
|
|
+ item_id_to_option_num.put(item_id,options.size());
|
|
|
}
|
|
|
- ReviewItem item=new ReviewItem(job_id,isRequired,isMultiple,options,descriptions,urls,reports);
|
|
|
- String item_id = itemDao.saveItem(item);
|
|
|
- item_id_to_problem_num.put(item_id,problemArray.length());
|
|
|
- return item_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void createWorkerToItem(HashMap<String,String> item_index_to_id,JSONArray groupArray,String job_id,HashMap<String,Integer>item_id_to_problem_num){
|
|
|
+ private void createWorkerToItem(JSONArray groupArray,String job_id,HashMap<String,Integer>item_id_to_option_num){
|
|
|
for(int i=0;i<groupArray.length();i++){
|
|
|
JSONObject groupObject=groupArray.getJSONObject(i);
|
|
|
String description=groupObject.getString("description");
|
|
@@ -216,23 +207,23 @@ public class ExtraService {
|
|
|
JSONObject workerObject=workerArray.getJSONObject(j);
|
|
|
workerList.add(workerObject.getString("worker_id"));
|
|
|
}
|
|
|
- JSONArray itemIndexArray=groupObject.getJSONArray("report_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")));
|
|
|
+ JSONArray reportIndexArray=groupObject.getJSONArray("report_list");
|
|
|
+ List<String> reportIdList=new ArrayList<>();
|
|
|
+ for (int j=0;j<reportIndexArray.length();j++){
|
|
|
+ JSONObject reportIndexObject=reportIndexArray.getJSONObject(j);
|
|
|
+ reportIdList.add(reportIndexObject.getString("report_id"));
|
|
|
}
|
|
|
- itemService.saveGroup(name,description,workerList,job_id,itemIdList);
|
|
|
+ reviewService.saveGroup(name,description,workerList,job_id,reportIdList);
|
|
|
for(int j=0;j<workerList.size();j++){
|
|
|
String worker_id=workerList.get(j);
|
|
|
-// itemService.saveUserToItem(worker_id,itemIdList,job_id,"","","","");
|
|
|
- for(int k=0;k<itemIdList.size();k++){
|
|
|
- String item_id=itemIdList.get(k);
|
|
|
- int optionNum=item_id_to_problem_num.get(item_id);
|
|
|
- List<String>reports=itemService.getReportsByItem(item_id);
|
|
|
- for(int l=0;l<reports.size();l++) {
|
|
|
- String report_id=reports.get(l);
|
|
|
- String answer_id = itemService.saveAnswer(item_id,report_id, worker_id, job_id, optionNum);
|
|
|
+// reviewService.saveUserToItem(worker_id,itemIdList,job_id,"","","","");
|
|
|
+ for(int k=0;k<reportIdList.size();k++){
|
|
|
+ String report_id=reportIdList.get(k);
|
|
|
+ List<ReviewItem>items= reviewService.getItemsByReport(report_id);
|
|
|
+ for(int l=0;l<items.size();l++) {
|
|
|
+ String item_id=items.get(l).getId();
|
|
|
+ int optionNum=item_id_to_option_num.get(item_id);
|
|
|
+ reviewService.initAnswer(item_id,report_id, worker_id, job_id, optionNum);
|
|
|
}
|
|
|
}
|
|
|
}
|