Explorar o código

Merge remote-tracking branch 'origin/xjw' into xjw

xujiawei %!s(int64=5) %!d(string=hai) anos
pai
achega
d2f9f06340

+ 15 - 0
src/main/java/edu/nju/controller/ReviewJobController.java

@@ -74,6 +74,21 @@ public class ReviewJobController {
         }
     }
 
+    @RequestMapping(value = "/uploadJobByJson", method = RequestMethod.POST)
+    @ResponseBody
+    public void uploadJobByJson(String jobJson, HttpServletResponse response){
+        try {
+            PrintWriter out = response.getWriter();
+            JSONObject result = reviewJobService.uploadJobByJson(jobJson);
+            out.print(result);
+            out.flush();
+            out.close();
+        }catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
     @RequestMapping(value = "/updateJob", method = RequestMethod.POST)
     @ResponseBody
     public void updateJob(String jobId, String name, String description, String paperId,String startTime, String endTime,@RequestParam("workerList")List<String>workerList,String workerDistribution, HttpServletResponse response){

+ 11 - 10
src/main/java/edu/nju/service/ExtraService.java

@@ -133,16 +133,17 @@ public class ExtraService {
 	}
 
 	public Task saveTask(String id){
-		String result = HTTP.sendGet("http://114.55.91.83:8191/api/exam/" + id+"/info", "");
-		if(result != null && !result.equals("")) {
-			JSONObject json = new JSONObject(result);
-			String beginTime=json.getString("beginTime");
-			String endTime=json.getString("endTime");
-			double totalMins=(Long.parseLong(endTime)-Long.parseLong(beginTime))/1000/60.0;
-			Task task=new Task(id,beginTime,endTime,totalMins,totalMins) ;
-			return taskDao.save(task);
-		}
-		return null;
+//		String result = HTTP.sendGet("http://114.55.91.83:8191/api/exam/" + id+"/info", "");
+//		if(result != null && !result.equals("")) {
+//			JSONObject json = new JSONObject(result);
+//			String beginTime=json.getString("beginTime");
+//			String endTime=json.getString("endTime");
+//			double totalMins=(Long.parseLong(endTime)-Long.parseLong(beginTime))/1000/60.0;
+//			Task task=new Task(id,beginTime,endTime,totalMins,totalMins) ;
+//			return taskDao.save(task);
+//		}
+//		return null;
+		return taskDao.findById(id);
 	}
 
 	public boolean updateTask(String id,double writeMins){

+ 56 - 4
src/main/java/edu/nju/service/ReviewJobService.java

@@ -1,10 +1,10 @@
 package edu.nju.service;
 
 import edu.nju.dao.*;
-import edu.nju.entities.ReviewGroup;
-import edu.nju.entities.ReviewJob;
-import edu.nju.entities.ReviewReport;
-import edu.nju.entities.ReviewWorker;
+import edu.nju.entities.*;
+import edu.nju.model.ReviewPaperVO;
+import org.json.JSONArray;
+import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -22,6 +22,8 @@ public class ReviewJobService {
     ReviewReportDao reportDao;
     @Autowired
     ReviewWorkerDao reviewWorkerDao;
+    @Autowired
+    ReviewPaperService reviewPaperService;
 
     public ReviewJob getJob(String job_id){
         return jobDao.findJob(job_id);
@@ -48,6 +50,56 @@ public class ReviewJobService {
         return jobId;
     }
 
+    public JSONObject uploadJobByJson(String jobJson){
+        JSONObject object = new JSONObject();
+        JSONObject jsonObject = new JSONObject(jobJson);
+        String jobName = jsonObject.getString("job_name");
+        String jobDescription = jsonObject.getString("job_description");
+        String startTime = jsonObject.getString("start_time");
+        String endTime = jsonObject.getString("end_time");
+        JSONArray workerArray = jsonObject.getJSONArray("worker_list");
+        List<String>workerList=new ArrayList<>();
+        for(int i=0;i<workerArray.length();i++){
+            workerList.add(String.valueOf(workerArray.get(i)));
+        }
+        JSONObject paperObject = jsonObject.getJSONObject("paper");
+        String result=checkJob(jobJson);
+        if(!result.equals("success")){
+            object.put("status","fail");
+            object.put("message",result);
+            return object;
+        }
+        JSONObject paperResult = reviewPaperService.savePaper(String.valueOf(paperObject));
+        if(!paperResult.has("paperId")){
+            object.put("status","fail");
+            object.put("message","创建paper失败");
+            return object;
+        }
+        String paperId=paperResult.getString("paperId");
+        String jobId=uploadJob(jobName,jobDescription,paperId,startTime,endTime,workerList,"");
+        return object;
+    }
+
+    public String checkJob(String jobJson){
+        String result="success";
+        try {
+            JSONObject jsonObject = new JSONObject(jobJson);
+            String jobName = jsonObject.getString("job_name");
+            String jobDescription = jsonObject.getString("job_description");
+            String startTime = jsonObject.getString("start_time");
+            String endTime = jsonObject.getString("end_time");
+            JSONArray workerList = jsonObject.getJSONArray("worker_list");
+            JSONObject paperObject = jsonObject.getJSONObject("paper");
+            String paperCheck=reviewPaperService.checkPaper(String.valueOf(paperObject));
+            if(!paperCheck.equals("success")){
+                result=paperCheck;
+            }
+        }catch (Exception e){
+            result=e.getMessage();
+        }
+        return result;
+    }
+
     public boolean updateJob(String jobId,String name, String description, String paperId,String startTime, String endTime,List<String>workerList,String workerDistribution){
         try {
             ReviewJob reviewJob=jobDao.findJob(jobId);

+ 7 - 1
src/main/java/edu/nju/service/ReviewPaperService.java

@@ -104,6 +104,12 @@ public class ReviewPaperService {
             object.put("message",result);
             return object;
         }
+        object=savePaper(paperJson);
+        return object;
+    }
+
+    public JSONObject savePaper(String paperJson){
+        JSONObject object = new JSONObject();
         try {
             JSONObject jsonObject = new JSONObject(paperJson);
             ReviewPaperVO reviewPaperVO = getReviewPaperVO(jsonObject);
@@ -173,7 +179,7 @@ public class ReviewPaperService {
         }
     }
 
-    private ReviewPaperVO getReviewPaperVO(JSONObject jsonObject)throws Exception{
+    public ReviewPaperVO getReviewPaperVO(JSONObject jsonObject)throws Exception{
         try {
             String description = jsonObject.getString("description");
             String name = jsonObject.getString("name");

+ 65 - 0
src/main/java/jobjson

@@ -0,0 +1,65 @@
+{
+    "job_name":"job_name",
+    "job_description":"description",
+    "start_time":"time1",
+    "end_time":"time2",
+    "worker_list":{"workerId1","workerId2","workerId3"},
+    "paper":{
+        "description": "job描述ddd",
+        "name": "jobname",
+        "create_time":"2019/10/02",
+        "type":"漏洞扫描分析",
+        "application_url":"url1",
+        "requirement_url":"url2",
+        "item_group_list": [{
+            "report_list": [0,1],
+            "item_list": [{
+                "index": 0,
+                "description":"des1dd",
+                "is_required":true,
+                "type":"File",
+                "options":[]
+            },{
+                "index": 1,
+                "description":"des2dd",
+                "is_required":true,
+                "type":"Single",
+                "options":["op1","op2"]
+            },{
+                "index": 2,
+                "description":"des3dd",
+                "is_required":true,
+                "type":"Multiple",
+                "options":["op1","op2"]
+            },{
+                "index": 3,
+                "description":"des4dd",
+                "is_required":true,
+                "type":"Description",
+                "options":[]
+            }],
+        }],
+        "report_list":[{
+            "index":0,
+            "name":"name111",
+            "original_id":"id1",
+            "description":"des1",
+            "img_url":["url1","url2"],
+            "file_url":["url1","url2"]
+        },{
+            "index":1,
+            "name":"name2222",
+            "original_id":"id2",
+            "description":"des2",
+            "img_url":["url1","url2"],
+            "file_url":["url1","url2"]
+        },{
+            "index":2,
+            "name":"name3333",
+            "original_id":"id3",
+            "description":"des3",
+            "img_url":["url1","url2"],
+            "file_url":["url1","url2"]
+        }]
+    }
+}