浏览代码

添加getAnswersByWorkerItem接口

MengyangDuan 5 年之前
父节点
当前提交
3509172487
共有 2 个文件被更改,包括 60 次插入46 次删除
  1. 18 6
      src/main/java/edu/nju/entities/ReviewReport.java
  2. 42 40
      src/main/java/edu/nju/service/ExtraService.java

+ 18 - 6
src/main/java/edu/nju/entities/ReviewReport.java

@@ -17,7 +17,9 @@ public class ReviewReport implements java.io.Serializable {
     @Id
     private String id;
 
-    private List<String> item_id;
+    //private List<String> item_id;
+
+    private String original_id;
 
     private String paper_id;
 
@@ -31,7 +33,8 @@ public class ReviewReport implements java.io.Serializable {
 
 
     @PersistenceConstructor
-    public ReviewReport(String paper_id, String name, String description, List<String> img_url, List<String> file_url) {
+    public ReviewReport(String original_id,String paper_id, String name, String description, List<String> img_url, List<String> file_url) {
+        this.original_id=original_id;
         this.paper_id = paper_id;
         this.name = name;
         this.description = description;
@@ -47,12 +50,21 @@ public class ReviewReport implements java.io.Serializable {
         this.id = id;
     }
 
-    public List<String> getItem_id() {
-        return item_id;
+//    public List<String> getItem_id() {
+//        return item_id;
+//    }
+//
+//    public void setItem_id(List<String> item_id) {
+//        this.item_id = item_id;
+//    }
+
+
+    public String getOriginal_id() {
+        return original_id;
     }
 
-    public void setItem_id(List<String> item_id) {
-        this.item_id = item_id;
+    public void setOriginal_id(String original_id) {
+        this.original_id = original_id;
     }
 
     public String getPaper_id() {

+ 42 - 40
src/main/java/edu/nju/service/ExtraService.java

@@ -153,7 +153,7 @@ public class ExtraService {
 	@Transactional(rollbackFor = Exception.class)
 	public  JSONObject savePaper(String paperJson){
 		JSONObject object = new JSONObject();
-		String result=checkJob(paperJson);
+		String result=checkPaper(paperJson);
 		if(!result.equals("success")){
 			object.put("status","fail");
 			object.put("message",result);
@@ -210,7 +210,8 @@ public class ExtraService {
 			}
 			String name=reportObject.getString("name");
 			String description=reportObject.getString("description");
-			ReviewReport reviewReport=new ReviewReport(paper_id,name,description,img_urls,file_urls);
+			String original_id=reportObject.getString("original_id");
+			ReviewReport reviewReport=new ReviewReport(original_id,paper_id,name,description,img_urls,file_urls);
 			return reviewReportDao.save(reviewReport);
 		}catch (Exception e){
 			throw new Exception("report 创建失败: "+e.getMessage());
@@ -218,7 +219,7 @@ public class ExtraService {
 	}
 
 	private void saveItem(JSONObject itemGroupObject,String paper_id,HashMap<String,Integer>item_id_to_option_num,HashMap<Integer,String>report_index_to_id,HashMap<Integer,String>item_index_to_id)throws Exception{
-		List<String>itemIds=new ArrayList<>();
+		//List<String>itemIds=new ArrayList<>();
 		List<String> reportIds=new ArrayList<>();
 		try {
 			JSONArray reportArray=itemGroupObject.getJSONArray("report_list");
@@ -241,22 +242,22 @@ public class ExtraService {
 				}
 				ReviewItem item=new ReviewItem(paper_id,isRequired,options,description,reportIds,type);
 				String item_id = itemDao.saveItem(item);
-				itemIds.add(item_id);
+//				itemIds.add(item_id);
 //				item_id_to_option_num.put(item_id,options.size());
 				item_index_to_id.put(index,item_id);
 			}
 		}catch (Exception e){
 			throw new Exception("item 创建失败: "+e.getMessage());
 		}
-		try {
-			for(int j=0;j<reportIds.size();j++){
-				ReviewReport report=reviewReportDao.findReviewReport(reportIds.get(j));
-				report.setItem_id(itemIds);
-				reviewReportDao.save(report);
-			}
-		}catch (Exception e){
-			throw new Exception("item创建失败,请检查配置的report_index是否存在! ");
-		}
+//		try {
+//			for(int j=0;j<reportIds.size();j++){
+//				ReviewReport report=reviewReportDao.findReviewReport(reportIds.get(j));
+//				report.setItem_id(itemIds);
+//				reviewReportDao.save(report);
+//			}
+//		}catch (Exception e){
+//			throw new Exception("item创建失败,请检查配置的report_index是否存在! ");
+//		}
 	}
 
 //	private void createWorkerToItem(JSONArray groupArray,String job_id,HashMap<Integer,String>report_index_to_id,HashMap<String,Integer>item_id_to_option_num)throws Exception{
@@ -301,18 +302,18 @@ public class ExtraService {
 //		}
 //	}
 
-	public String checkJob(String jobJson){
+	public String checkPaper(String paperJson){
 		String result="success";
 		try {
-			JSONObject jsonObject=new JSONObject(jobJson);
+			JSONObject jsonObject=new JSONObject(paperJson);
 			String description=jsonObject.getString("description");
 			String name=jsonObject.getString("name");
 			String time=jsonObject.getString("time");
 			String type=jsonObject.getString("type");
 			String application_location=jsonObject.getString("application_url");
 			String requirement_location=jsonObject.getString("requirement_url");
-			int report_num=jsonObject.getInt("report_num");
-			int worker_num=jsonObject.getInt("worker_num");
+//			int report_num=jsonObject.getInt("report_num");
+//			int worker_num=jsonObject.getInt("worker_num");
 
 			Set<Integer>reportIndexs=new HashSet<>();
 			JSONArray reportList=jsonObject.getJSONArray("report_list");
@@ -325,6 +326,7 @@ public class ExtraService {
 					reportIndexs.add(index);
 				}
 				String reportName=report.getString("name");
+				String originalId=report.getString("original_id");
 				String reportDescription=report.getString("description");
 				JSONArray imgUrls=report.getJSONArray("img_url");
 				JSONArray fileUrls=report.getJSONArray("file_url");
@@ -368,29 +370,29 @@ public class ExtraService {
 			}
 
 
-			JSONArray groupList=jsonObject.getJSONArray("group_list");
-			Set<String>workers=new HashSet<>();
-			for(int i=0;i<groupList.length();i++){
-				JSONObject groupObject=groupList.getJSONObject(i);
-				String groupName=groupObject.getString("name");
-				String groupDescription=groupObject.getString("description");
-				JSONArray workerList=groupObject.getJSONArray("worker_list");
-				for(int j=0;j<workerList.length();j++){
-					String workerId=String.valueOf(workerList.get(j));
-					if(workers.contains(workerId)){
-						throw new Exception("同一个worker不能属于不同的group");
-					}else{
-						workers.add(workerId);
-					}
-				}
-				JSONArray workerReportList=groupObject.getJSONArray("report_list");
-				for(int j=0;j<workerReportList.length();j++){
-					int reportIndex= Integer.parseInt(String.valueOf(workerReportList.get(j)));
-					if(!reportIndexs.contains(reportIndex)){
-						throw new Exception("group_report_list中包含不存在的report ");
-					}
-				}
-			}
+//			JSONArray groupList=jsonObject.getJSONArray("group_list");
+//			Set<String>workers=new HashSet<>();
+//			for(int i=0;i<groupList.length();i++){
+//				JSONObject groupObject=groupList.getJSONObject(i);
+//				String groupName=groupObject.getString("name");
+//				String groupDescription=groupObject.getString("description");
+//				JSONArray workerList=groupObject.getJSONArray("worker_list");
+//				for(int j=0;j<workerList.length();j++){
+//					String workerId=String.valueOf(workerList.get(j));
+//					if(workers.contains(workerId)){
+//						throw new Exception("同一个worker不能属于不同的group");
+//					}else{
+//						workers.add(workerId);
+//					}
+//				}
+//				JSONArray workerReportList=groupObject.getJSONArray("report_list");
+//				for(int j=0;j<workerReportList.length();j++){
+//					int reportIndex= Integer.parseInt(String.valueOf(workerReportList.get(j)));
+//					if(!reportIndexs.contains(reportIndex)){
+//						throw new Exception("group_report_list中包含不存在的report ");
+//					}
+//				}
+//			}
 		}catch (Exception e){
 			return e.getMessage();
 		}