Browse Source

Merge branch 'xjw' of http://git.mooctest.net/summer/crowdsource-backend into xjw

# Conflicts:
#	src/main/resources/application.properties
xujiawei 5 years ago
parent
commit
abcfddff45

+ 2 - 2
src/main/java/edu/nju/controller/ExtraController.java

@@ -449,7 +449,7 @@ public class ExtraController {
 
 	@RequestMapping(value = "/uploadJob", method = RequestMethod.POST)
 	@ResponseBody
-	public void uploadExamUrl(String jobJson, HttpServletResponse response) {
+	public void uploadReviewJob(String jobJson, HttpServletResponse response) {
 		try {
 //			System.out.println(jobJson);
 			PrintWriter out = response.getWriter();
@@ -469,7 +469,7 @@ public class ExtraController {
 
 	@RequestMapping(value = "/checkJob", method = RequestMethod.POST)
 	@ResponseBody
-	public void checkExam(String jobJson, String reportJson, HttpServletResponse response) {
+	public void checkReviewJobJson(String jobJson, String reportJson, HttpServletResponse response) {
 		try {
 //			System.out.println(jobJson);
 			PrintWriter out = response.getWriter();

+ 6 - 0
src/main/java/edu/nju/dao/ReviewReportDao.java

@@ -23,5 +23,11 @@ public class ReviewReportDao {
         if(list.size() == 0 || list == null) {return null;}
         return list.get(0);
     }
+
+    public String save(ReviewReport report) {
+        mongoOperations.save(report);
+        return report.getId();
+    }
+
 }
 

+ 39 - 5
src/main/java/edu/nju/entities/ReviewReport.java

@@ -22,20 +22,22 @@ public class ReviewReport implements java.io.Serializable {
 
     private String job_id;
 
+    private String name;
+
     private String description;
 
     private List<String> img_url;
 
     private List<String> file_url;
 
-    private String name;
-
-
 
     @PersistenceConstructor
-    public ReviewReport(List<String> item_id, String job_id) {
-        this.item_id = item_id;
+    public ReviewReport(String job_id, String name, String description, List<String> img_url, List<String> file_url) {
         this.job_id = job_id;
+        this.name = name;
+        this.description = description;
+        this.img_url = img_url;
+        this.file_url = file_url;
     }
 
     public String getId() {
@@ -61,4 +63,36 @@ public class ReviewReport implements java.io.Serializable {
     public void setJob_id(String job_id) {
         this.job_id = job_id;
     }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public List<String> getImg_url() {
+        return img_url;
+    }
+
+    public void setImg_url(List<String> img_url) {
+        this.img_url = img_url;
+    }
+
+    public List<String> getFile_url() {
+        return file_url;
+    }
+
+    public void setFile_url(List<String> file_url) {
+        this.file_url = file_url;
+    }
 }

+ 59 - 14
src/main/java/edu/nju/service/ExtraService.java

@@ -33,7 +33,13 @@ public class ExtraService {
 	ReviewItemDao itemDao;
 
 	@Autowired
+	ReviewAnswerDao answerDao;
+
+	@Autowired
 	ReviewService reviewService;
+
+	@Autowired
+	ReviewReportDao reviewReportDao;
 	
 	//测试用例相关
 	public String saveTestCase(String report_id, String name, String front, String behind, String description) {
@@ -143,43 +149,74 @@ public class ExtraService {
 		String name=jsonObject.getString("name");
 		String time=jsonObject.getString("time");
 		String type=jsonObject.getString("type");
-		String application_location=jsonObject.getString("application_location");
-		String requirement_location=jsonObject.getString("requirement_location");
+		String application_location=jsonObject.getString("application_url");
+		String requirement_location=jsonObject.getString("requirement_url");
 		String report_num=jsonObject.getString("report_num");
 		String worker_num=jsonObject.getString("worker_num");
-
 		String job_id=jobDao.save(new ReviewJob(description,name,time,type,application_location,requirement_location,report_num,worker_num));
 
+
+		JSONArray reportArray=jsonObject.getJSONArray("report_list");
+		HashMap<String,String>report_index_to_id=new HashMap<>();
+		for(int i=0;i<reportArray.length();i++){
+			JSONObject reportObject=reportArray.getJSONObject(i);
+			String report_index=reportObject.getString("index");
+			String id=saveReport(reportObject,job_id);
+			report_index_to_id.put(report_index,id);
+		}
+
 		JSONArray itemGroupArray=jsonObject.getJSONArray("item_group_list");
 		//save item
 		//item index-id
 		HashMap<String,Integer>item_id_to_option_num=new HashMap<>();
+		HashMap<String,String>item_index_to_id=new HashMap<>();
 		for(int i=0;i<itemGroupArray.length();i++) {
 			JSONObject itemGroupObject = itemGroupArray.getJSONObject(i);
-			saveItem(itemGroupObject,job_id,item_id_to_option_num);
+			saveItem(itemGroupObject,job_id,item_id_to_option_num,report_index_to_id,item_index_to_id);
 		}
 
 		//worker_id-item_id_list
 		JSONArray groupArray=jsonObject.getJSONArray("group_list");
-		createWorkerToItem(groupArray,job_id,item_id_to_option_num);
+		createWorkerToItem(groupArray,job_id,report_index_to_id,item_id_to_option_num);
 
 		return job_id;
 
 	}
 
-	private void saveItem(JSONObject itemGroupObject,String job_id,HashMap<String,Integer>item_id_to_option_num){
+	private String saveReport(JSONObject reportObject,String job_id){
+		JSONArray imgArray=reportObject.getJSONArray("img_url");
+		List<String> img_urls=new ArrayList<>();
+		for(int i=0;i<imgArray.length();i++){
+			JSONObject imgUrlObject=imgArray.getJSONObject(i);
+			img_urls.add(imgUrlObject.getString("url"));
+		}
+		JSONArray fileArray=reportObject.getJSONArray("file_url");
+		List<String> file_urls=new ArrayList<>();
+		for(int i=0;i<fileArray.length();i++){
+			JSONObject fileUrlObject=fileArray.getJSONObject(i);
+			file_urls.add(fileUrlObject.getString("url"));
+		}
+		String name=reportObject.getString("name");
+		String description=reportObject.getString("description");
+		ReviewReport reviewReport=new ReviewReport(job_id,name,description,img_urls,file_urls);
+		return reviewReportDao.save(reviewReport);
+
+	}
+
+	private void saveItem(JSONObject itemGroupObject,String job_id,HashMap<String,Integer>item_id_to_option_num,HashMap<String,String>report_index_to_id,HashMap<String,String>item_index_to_id){
 
 //			JSONObject itemObject=itemArray.getJSONObject(i);
-		List<String> urls=new ArrayList<>();
+		List<String> reportIds=new ArrayList<>();
 		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"));
+			JSONObject reportIndexObject=reportArray.getJSONObject(j);
+			reportIds.add(report_index_to_id.get(reportIndexObject.getString("report_index")));
 		}
 		JSONArray itemArray=itemGroupObject.getJSONArray("item_list");
+		List<String>itemIds=new ArrayList<>();
 		for (int j=0;j<itemArray.length();j++){
 			JSONObject itemObject=itemArray.getJSONObject(j);
+			String index=itemObject.getString("index");
 			String isMultiple=itemObject.getString("is_multiple");
 			String isRequired=itemObject.getString("is_required");
 			String description=itemObject.getString("description");
@@ -189,14 +226,21 @@ public class ExtraService {
 			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);
+			ReviewItem item=new ReviewItem(job_id,isRequired,isMultiple,options,description,reportIds,type);
 			String item_id = itemDao.saveItem(item);
+			itemIds.add(item_id);
 			item_id_to_option_num.put(item_id,options.size());
+			item_index_to_id.put(index,item_id);
+		}
+		for(int j=0;j<reportIds.size();j++){
+			ReviewReport report=reviewReportDao.findReviewReport(reportIds.get(j));
+			report.setItem_id(itemIds);
+			reviewReportDao.save(report);
 		}
 
 	}
 
-	private void createWorkerToItem(JSONArray groupArray,String job_id,HashMap<String,Integer>item_id_to_option_num){
+	private void createWorkerToItem(JSONArray groupArray,String job_id,HashMap<String,String>report_index_to_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");
@@ -211,7 +255,7 @@ public class ExtraService {
 			List<String> reportIdList=new ArrayList<>();
 			for (int j=0;j<reportIndexArray.length();j++){
 				JSONObject reportIndexObject=reportIndexArray.getJSONObject(j);
-				reportIdList.add(reportIndexObject.getString("report_id"));
+				reportIdList.add(report_index_to_id.get(reportIndexObject.getString("report_index")));
 			}
 			reviewService.saveGroup(name,description,workerList,job_id,reportIdList);
 			for(int j=0;j<workerList.size();j++){
@@ -223,7 +267,8 @@ public class ExtraService {
 					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);
+						ReviewAnswer answer=new ReviewAnswer(item_id,report_id,worker_id,job_id,optionNum);
+						answerDao.save(answer);
 					}
 				}
 			}

+ 1 - 5
src/main/java/edu/nju/service/ReviewService.java

@@ -43,11 +43,6 @@ public class ReviewService {
 //        return answerDao.save(answer);
 //    }
 
-    //对answer进行初始化
-    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> file_url){
         try {
@@ -103,4 +98,5 @@ public class ReviewService {
         return groupDao.save(group);
     }
 
+
 }

+ 50 - 7
src/main/java/jobjson

@@ -3,16 +3,16 @@
 	"name": "jobname",
 	"time":"2019/10/02~2019/10/22",
 	"type":"漏洞扫描分析",
-	"application_url":"url1".
+	"application_url":"url1",
 	"requirement_url":"url2",
 	"report_num":"50",
 	"worker_num":"50",
 	"item_group_list": [{
 		"index": "0",
 		"report_list": [{
-            "report_id": "0"
+            "report_index": "0"
         }, {
-            "report_id": "1"
+            "report_index": "1"
         }],
 		"item_list": [{
             "index": "0",
@@ -66,9 +66,9 @@
             "worker_id": "2"
         }],
 		"report_list": [{
-            "report_id": "0"
+            "report_index": "0"
         }, {
-            "report_id": "1"
+            "report_index": "1"
         }]
     }, {
         "group_id": "2",
@@ -80,9 +80,52 @@
             "worker_id": "4"
         }],
         "report_list": [{
-            "report_id": "0"
+            "report_index": "0"
         }, {
-            "report_id": "2"
+            "report_index": "2"
         }]
     }],
+    "report_list":[{
+        "index":"0",
+        "name":"name1",
+        "description":"des1",
+        "img_url":[{
+            "url":"url1",
+        },{
+            "url":"url2",
+        }],
+        "file_url":[{
+            "url":"url1",
+        },{
+            "url":"url2",
+        }],
+    },{
+        "index":"1",
+        "name":"name2",
+        "description":"des2",
+        "img_url":[{
+             "url":"url1",
+        },{
+            "url":"url2",
+        }],
+        "file_url":[{
+            "url":"url1",
+        },{
+            "url":"url2",
+        }],
+    },{
+        "index":"2",
+        "name":"name3",
+        "description":"des3",
+        "img_url":[{
+            "url":"url1",
+        },{
+            "url":"url2",
+        }],
+        "file_url":[{
+            "url":"url1",
+        },{
+            "url":"url2",
+        }],
+    }],
 }

+ 1 - 1
src/main/resources/application.properties

@@ -1,6 +1,6 @@
 server.port = 8090
 server.servlet.context-path = /Bug/api/
-#
+
 #spring.data.mongodb.host = ${MONGO_HOST:10.81.65.118}
 #spring.data.mongodb.port = ${MONGO_PORT:29019}
 #spring.data.mongodb.database = ${MONGO_DBNAME:co-report}