|
@@ -144,7 +144,7 @@ public class ExtraService {
|
|
|
String name=jsonObject.getString("name");
|
|
|
// String create_time_millis=Long.toString(System.currentTimeMillis());
|
|
|
|
|
|
- String job_id=jobDao.save(new Job(description,name,Long.toString(System.currentTimeMillis()),"","","","","",""));
|
|
|
+ String job_id=jobDao.save(new Job(description,name,"","",""));
|
|
|
|
|
|
JSONArray itemArray=jsonObject.getJSONArray("itemList");
|
|
|
//save item
|
|
@@ -159,8 +159,8 @@ public class ExtraService {
|
|
|
}
|
|
|
|
|
|
//worker_id-item_id_list
|
|
|
- JSONArray workerArray=jsonObject.getJSONArray("workerList");
|
|
|
- createWorkerToItem(item_index_to_id,workerArray,job_id,item_id_to_optionNum);
|
|
|
+ JSONArray groupArray=jsonObject.getJSONArray("groupList");
|
|
|
+ createWorkerToItem(item_index_to_id,groupArray,job_id,item_id_to_optionNum);
|
|
|
|
|
|
return job_id;
|
|
|
|
|
@@ -169,6 +169,7 @@ public class ExtraService {
|
|
|
private String saveItem(JSONObject itemObject,String job_id,HashMap<String,Integer>item_id_to_optionNum){
|
|
|
|
|
|
// JSONObject itemObject=itemArray.getJSONObject(i);
|
|
|
+ String name=itemObject.getString("name");
|
|
|
String description=itemObject.getString("description");
|
|
|
List<String> img_urls=new ArrayList<>();
|
|
|
JSONArray imgUrlArray=itemObject.getJSONArray("img_urls");
|
|
@@ -195,31 +196,39 @@ public class ExtraService {
|
|
|
// System.out.println(optionObject.getString("option"));
|
|
|
options.add(optionObject.getString("option"));
|
|
|
}
|
|
|
- Item item=new Item(description,img_urls,isRequired,isMultiple,file_urls,options,job_id);
|
|
|
+ Item item=new Item(name,description,img_urls,isRequired,isMultiple,file_urls,options,job_id);
|
|
|
String item_id = itemDao.saveItem(item);
|
|
|
item_id_to_optionNum.put(item_id,optionArray.length());
|
|
|
return item_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void createWorkerToItem(HashMap<String,String> item_index_to_id,JSONArray workerArray,String job_id,HashMap<String,Integer>item_id_to_optionNum){
|
|
|
- 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");
|
|
|
+ private void createWorkerToItem(HashMap<String,String> item_index_to_id,JSONArray groupArray,String job_id,HashMap<String,Integer>item_id_to_optionNum){
|
|
|
+ for(int i=0;i<groupArray.length();i++){
|
|
|
+ JSONObject groupObject=groupArray.getJSONObject(i);
|
|
|
+ String description=groupObject.getString("description");
|
|
|
+ String name=groupObject.getString("name");
|
|
|
+ JSONArray workerArray=groupObject.getJSONArray("worker_list");
|
|
|
+ List<String> workerList=new ArrayList<>();
|
|
|
+ for (int j=0;j<workerArray.length();j++){
|
|
|
+ JSONObject workerObject=workerArray.getJSONObject(j);
|
|
|
+ workerList.add(workerObject.getString("worker_id"));
|
|
|
+ }
|
|
|
+ JSONArray itemIndexArray=groupObject.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);
|
|
|
- itemService.saveUserToItem(worker_id,itemIdList,job_id);
|
|
|
- for(int j=0;j<itemIdList.size();j++){
|
|
|
- String item_id=itemIdList.get(j);
|
|
|
- int optionNum=item_id_to_optionNum.get(item_id);
|
|
|
- String answer_id=itemService.saveAnswer(item_id,worker_id,job_id,optionNum);
|
|
|
+ itemService.saveGroup(name,description,workerList,job_id,itemIdList);
|
|
|
+ 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_optionNum.get(item_id);
|
|
|
+ String answer_id=itemService.saveAnswer(item_id,worker_id,job_id,optionNum);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|