MengyangDuan пре 5 година
родитељ
комит
b8d011398a

+ 27 - 27
src/main/java/edu/nju/controller/ReviewController.java

@@ -4,7 +4,7 @@ import edu.nju.entities.ReviewAnswer;
 import edu.nju.entities.ReviewItem;
 import edu.nju.entities.ReviewJob;
 import edu.nju.entities.ReviewReport;
-import edu.nju.service.ItemService;
+import edu.nju.service.ReviewService;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +22,7 @@ import java.util.List;
 public class ReviewController {
 
     @Autowired
-    ItemService iservice;
+    ReviewService iservice;
 
     @RequestMapping(value = "/getJob")
     @ResponseBody
@@ -39,21 +39,21 @@ public class ReviewController {
         }
     }
 
-    @RequestMapping(value = "/getItemsByJob")
-    @ResponseBody
-    public void getItemListByJobId(String job_id, HttpServletResponse response){
-        try {
-            PrintWriter out = response.getWriter();
-            List<ReviewItem> items = iservice.getJobItems(job_id);
-            out.print(new JSONArray(items));
-            out.flush();
-            out.close();
-        }catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-
-    }
+//    @RequestMapping(value = "/getItemsByJob")
+//    @ResponseBody
+//    public void getItemListByJobId(String job_id, HttpServletResponse response){
+//        try {
+//            PrintWriter out = response.getWriter();
+//            List<ReviewItem> items = iservice.getJobItems(job_id);
+//            out.print(new JSONArray(items));
+//            out.flush();
+//            out.close();
+//        }catch (IOException e) {
+//            // TODO Auto-generated catch block
+//            e.printStackTrace();
+//        }
+//
+//    }
 
     @RequestMapping(value = "/getReportsByWorkerJob")
     @ResponseBody
@@ -70,13 +70,13 @@ public class ReviewController {
         }
     }
 
-    @RequestMapping(value = "/getItemByReport")
+    @RequestMapping(value = "/getItemsByReport")
     @ResponseBody
-    public void getItemByReport(String report_id, HttpServletResponse response){
+    public void getItemsByReport(String report_id, HttpServletResponse response){
         try {
             PrintWriter out = response.getWriter();
-            ReviewItem item = iservice.getItemByReport(report_id);
-            out.print(new JSONObject(item));
+            List<ReviewItem> items = iservice.getItemsByReport(report_id);
+            out.print(new JSONArray(items));
             out.flush();
             out.close();
         }catch (IOException e) {
@@ -102,13 +102,13 @@ public class ReviewController {
 //
 //    }
 
-    @RequestMapping(value = "/getAnswerByWorkerReport")
+    @RequestMapping(value = "/getAnswersByWorkerReport")
     @ResponseBody
-    public void getAnswerByWorkerReport(String report_id,String worker_id, HttpServletResponse response){
+    public void getAnswersByWorkerReport(String report_id,String worker_id, HttpServletResponse response){
         try {
             PrintWriter out = response.getWriter();
-            ReviewAnswer answer = iservice.getAnswerByReportWorker(report_id, worker_id);
-            out.print(new JSONObject(answer));
+            List<ReviewAnswer> answers = iservice.getAnswersByReportWorker(report_id, worker_id);
+            out.print(new JSONArray(answers));
             out.flush();
             out.close();
         }catch (IOException e) {
@@ -157,9 +157,9 @@ public class ReviewController {
 
     @RequestMapping(value = "/updateAnswer", method = RequestMethod.POST)
     @ResponseBody
-    public void updateAnswer(String id, @RequestParam("answers")List<String>answers,@RequestParam("attachment_location") List<String> attachment_location, HttpServletResponse response){
+    public void updateAnswer(String id, @RequestParam("answers")List<String>answers,@RequestParam("attachment_location") List<String> file_url, HttpServletResponse response){
         JSONObject result = new JSONObject();
-        if(iservice.updateAnswer(id, answers, attachment_location)){
+        if(iservice.updateAnswer(id, answers, file_url)){
             result.put("status", "200");
         } else {
             result.put("status", "500");

+ 2 - 5
src/main/java/edu/nju/dao/ReviewAnswerDao.java

@@ -15,14 +15,11 @@ public class ReviewAnswerDao {
     @Autowired
     private MongoOperations mongoOperations;
 
-    public ReviewAnswer findAnswerByReportWorker(String report_id, String worker_id){
+    public List<ReviewAnswer> findAnswersByReportWorker(String report_id, String worker_id){
         Query query = new Query();
         query.addCriteria(Criteria.where("report_id").is(report_id).and("worker_id").is(worker_id));
         List<ReviewAnswer>answers= mongoOperations.find(query, ReviewAnswer.class);
-        if(answers!=null&&answers.size()!=0){
-            return answers.get(0);
-        }
-        return null;
+        return answers;
     }
 
     public List<ReviewAnswer> findAnswersByReport(String report_id){

+ 7 - 10
src/main/java/edu/nju/dao/ReviewItemDao.java

@@ -22,20 +22,17 @@ public class ReviewItemDao {
         return item.getId();
     }
 
-    public List<ReviewItem>findItemsByJob(String job_id){
-        Query query = new Query();
-        query.addCriteria(Criteria.where("job_id").is(job_id));
-        return mongoOperations.find(query, ReviewItem.class);
-    }
+//    public List<ReviewItem>findItemsByJob(String job_id){
+//        Query query = new Query();
+//        query.addCriteria(Criteria.where("job_id").is(job_id));
+//        return mongoOperations.find(query, ReviewItem.class);
+//    }
 
-    public ReviewItem findItemsByReport(String report_id){
+    public List<ReviewItem> findItemsByReport(String report_id){
         Query query = new Query();
         query.addCriteria(Criteria.where("report_id").is(report_id));
         List<ReviewItem>reviewItems=mongoOperations.find(query, ReviewItem.class);
-        if(reviewItems==null||reviewItems.size()==0)
-            return null;
-        else
-            return reviewItems.get(0);
+        return reviewItems;
     }
 
     public ReviewItem findById(String item_id){

+ 8 - 8
src/main/java/edu/nju/entities/ReviewAnswer.java

@@ -26,15 +26,15 @@ public class ReviewAnswer implements java.io.Serializable{
 
     private String job_id;
 
-    private List<String> attachment_location;
+    private List<String> file_url;
 
     @PersistenceConstructor
-    public ReviewAnswer(String item_id,String report_id, List<String> answers, String worker_id, List<String> attachment_location,String job_id) {
+    public ReviewAnswer(String item_id,String report_id, List<String> answers, String worker_id, List<String> file_url,String job_id) {
         this.item_id = item_id;
         this.report_id=report_id;
         this.answers = answers;
         this.worker_id = worker_id;
-        this.attachment_location = attachment_location;
+        this.file_url=file_url;
         this.job_id=job_id;
     }
     @PersistenceConstructor
@@ -42,7 +42,7 @@ public class ReviewAnswer implements java.io.Serializable{
         this.item_id = item_id;
         this.report_id=report_id;
         this.worker_id = worker_id;
-        this.attachment_location = new ArrayList<>();
+        this.file_url = new ArrayList<>();
         this.job_id=job_id;
         this.answers=new ArrayList<>();
         for(int i=0;i<optionNum;i++){
@@ -90,12 +90,12 @@ public class ReviewAnswer implements java.io.Serializable{
         this.worker_id = worker_id;
     }
 
-    public List<String> getAttachment_location() {
-        return attachment_location;
+    public List<String> getFile_url() {
+        return file_url;
     }
 
-    public void setAttachment_location(List<String> attachment_location) {
-        this.attachment_location = attachment_location;
+    public void setFile_url(List<String> file_url) {
+        this.file_url = file_url;
     }
 
     public String getJob_id() {

+ 23 - 22
src/main/java/edu/nju/entities/ReviewItem.java

@@ -16,30 +16,31 @@ public class ReviewItem implements java.io.Serializable {
 
     private String job_id;
 
-    private List<String> isRequired;
+    private String isRequired;
 
-    private List<String> isMultiple;
+    private String isMultiple;
 
     private List<String> options;
 
-    private List<String> description;
+    private String description;
 
-    private List<String>attachment_location;
+    private List<String> report_id;
 
-    private List<String>report_id;
+    private String type;
 
 
     @PersistenceConstructor
-    public ReviewItem(String job_id, List<String> isRequired, List<String> isMultiple, List<String> options, List<String> description,List<String>attachment_location,List<String>report_id) {
+    public ReviewItem(String job_id, String isRequired, String isMultiple, List<String> options, String description, List<String> report_id, String type) {
         this.job_id = job_id;
         this.isRequired = isRequired;
         this.isMultiple = isMultiple;
         this.options = options;
         this.description = description;
-        this.attachment_location=attachment_location;
-        this.report_id=report_id;
+        this.report_id = report_id;
+        this.type = type;
     }
 
+
     public String getId() {
         return id;
     }
@@ -56,19 +57,19 @@ public class ReviewItem implements java.io.Serializable {
         this.job_id = job_id;
     }
 
-    public List<String> getIsRequired() {
+    public String getIsRequired() {
         return isRequired;
     }
 
-    public void setIsRequired(List<String> isRequired) {
+    public void setIsRequired(String isRequired) {
         this.isRequired = isRequired;
     }
 
-    public List<String> getIsMultiple() {
+    public String getIsMultiple() {
         return isMultiple;
     }
 
-    public void setIsMultiple(List<String> isMultiple) {
+    public void setIsMultiple(String isMultiple) {
         this.isMultiple = isMultiple;
     }
 
@@ -80,22 +81,14 @@ public class ReviewItem implements java.io.Serializable {
         this.options = options;
     }
 
-    public List<String> getDescription() {
+    public String getDescription() {
         return description;
     }
 
-    public void setDescription(List<String> description) {
+    public void setDescription(String description) {
         this.description = description;
     }
 
-    public List<String> getAttachment_location() {
-        return attachment_location;
-    }
-
-    public void setAttachment_location(List<String> attachment_location) {
-        this.attachment_location = attachment_location;
-    }
-
     public List<String> getReport_id() {
         return report_id;
     }
@@ -103,4 +96,12 @@ public class ReviewItem implements java.io.Serializable {
     public void setReport_id(List<String> report_id) {
         this.report_id = report_id;
     }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
 }

+ 14 - 4
src/main/java/edu/nju/entities/ReviewReport.java

@@ -18,12 +18,22 @@ public class ReviewReport implements java.io.Serializable {
     @Id
     private String id;
 
-    private String item_id;
+    private List<String> item_id;
 
     private String job_id;
 
+    private String description;
+
+    private List<String> img_url;
+
+    private List<String> file_url;
+
+    private String name;
+
+
+
     @PersistenceConstructor
-    public ReviewReport(String item_id, String job_id) {
+    public ReviewReport(List<String> item_id, String job_id) {
         this.item_id = item_id;
         this.job_id = job_id;
     }
@@ -36,11 +46,11 @@ public class ReviewReport implements java.io.Serializable {
         this.id = id;
     }
 
-    public String getItem_id() {
+    public List<String> getItem_id() {
         return item_id;
     }
 
-    public void setItem_id(String item_id) {
+    public void setItem_id(List<String> item_id) {
         this.item_id = item_id;
     }
 

+ 39 - 48
src/main/java/edu/nju/service/ExtraService.java

@@ -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);
 					}
 				}
 			}

+ 13 - 13
src/main/java/edu/nju/service/ItemService.java → src/main/java/edu/nju/service/ReviewService.java

@@ -9,7 +9,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 @Service
-public class ItemService {
+public class ReviewService {
     @Autowired
     ReviewItemDao itemDao;
     @Autowired
@@ -23,16 +23,16 @@ public class ItemService {
     @Autowired
     ReviewReportDao reportDao;
 
-    public List<ReviewItem>getJobItems(String job_id){
-        return itemDao.findItemsByJob(job_id);
-    }
+//    public List<ReviewItem>getJobItems(String job_id){
+//        return itemDao.findItemsByJob(job_id);
+//    }
 
     public ReviewJob getJob(String job_id){
         return jobDao.findJob(job_id);
     }
 
-    public ReviewAnswer getAnswerByReportWorker(String report_id, String worker_id){
-        return answerDao.findAnswerByReportWorker(report_id, worker_id);
+    public List<ReviewAnswer> getAnswersByReportWorker(String report_id, String worker_id){
+        return answerDao.findAnswersByReportWorker(report_id, worker_id);
     }
     public List<ReviewAnswer> getAnswersByReport(String report_id){
         return answerDao.findAnswersByReport(report_id);
@@ -44,18 +44,18 @@ public class ItemService {
 //    }
 
     //对answer进行初始化
-    public String saveAnswer(String item_id, String report_id,String worker_id,String job_id, int problemNum){
-        ReviewAnswer answer=new ReviewAnswer(item_id,report_id,worker_id,job_id,problemNum);
+    public String initAnswer(String item_id, String report_id,String worker_id,String job_id,int optionNum){
+        ReviewAnswer answer=new ReviewAnswer(item_id,report_id,worker_id,job_id,optionNum);
         return answerDao.save(answer);
     }
 
-    public boolean updateAnswer(String id, List<String>answers,List<String> attachment_location){
+    public boolean updateAnswer(String id, List<String>answers,List<String> file_url){
         try {
             if(id == null || id.equals("undefined")) { return false; }
             ReviewAnswer answer=answerDao.getAnswerById(id);
 //            answer.setId(id);
             answer.setAnswers(answers);
-            answer.setAttachment_location(attachment_location);
+            answer.setFile_url(file_url);
             answerDao.save(answer);
             return true;
         } catch(Exception e) {
@@ -77,9 +77,9 @@ public class ItemService {
         return reports;
     }
 
-    public ReviewItem getItemByReport(String report_id){
-        ReviewItem item=itemDao.findItemsByReport(report_id);
-        return item;
+    public List<ReviewItem> getItemsByReport(String report_id){
+        List<ReviewItem> items=itemDao.findItemsByReport(report_id);
+        return items;
     }
 
     public List<String> getReportsByItem(String item_id){

+ 42 - 26
src/main/java/jobjson

@@ -7,38 +7,54 @@
 	"requirement_url":"url2",
 	"report_num":"50",
 	"worker_num":"50",
-	"item_list": [{
+	"item_group_list": [{
 		"index": "0",
 		"report_list": [{
             "report_id": "0"
         }, {
             "report_id": "1"
         }],
-		"attachment_urls": [{
-			"url": "url1",
-			"description":"des1"
-		}, {
-			"url": "url2",
-			"description":"des2"
-		}, {
-			"url": "url3",
-			"description":"des3"
-		}],
-		"problem_list":[{
-		    "description":"des1",
-		    "is_required":"1",
-		    "options":"",
-		},{
-		    "description":"des2",
-		    "is_required":"1",
-		    "options":"op1;op2;op3"
-		    "is_multiple":"1",
-		},{
-		    "description":"des3",
-             "is_required":"1",
-             "options":"op1;op2;op3"
-             "is_multiple":"0",
-		}]
+		"item_list": [{
+            "index": "0",
+            "description":"des1",
+        	"is_required":"1",
+        	"is_multiple":"0",
+        	"type":"File",
+        	"options":[{
+        	    "option":""
+        	}]
+        },{
+            "index": "1",
+            "description":"des2",
+            "is_required":"1",
+            "is_multiple":"0",
+            "type":"Single",
+            "options":[{
+                "option":"op1"
+            },{
+                "option":"op2"
+            }]
+        },{
+            "index": "2",
+            "description":"des3",
+            "is_required":"1",
+            "is_multiple":"1",
+            "type":"Multiple",
+            "options":[{
+                "option":"op1"
+            },{
+                "option":"op2"
+            }]
+        },{
+            "index": "3",
+            "description":"des4",
+            "is_required":"1",
+            "is_multiple":"0",
+            "type":"Description",
+            "options":[{
+                "option":""
+            }]
+        }],
 	}],
 	"group_list": [{
 		"group_id": "1",