|
@@ -2,15 +2,22 @@ package edu.nju.service;
|
|
|
|
|
|
import edu.nju.dao.*;
|
|
import edu.nju.dao.*;
|
|
import edu.nju.entities.*;
|
|
import edu.nju.entities.*;
|
|
|
|
+import edu.nju.model.JobJsonDTO;
|
|
|
|
+import edu.nju.model.MessageVO;
|
|
import edu.nju.model.ReviewPaperVO;
|
|
import edu.nju.model.ReviewPaperVO;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+
|
|
|
|
+import static edu.nju.util.HTTP.readStringFromUrl;
|
|
|
|
+
|
|
@Service
|
|
@Service
|
|
public class ReviewJobService {
|
|
public class ReviewJobService {
|
|
|
|
|
|
@@ -50,54 +57,35 @@ public class ReviewJobService {
|
|
return jobId;
|
|
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");
|
|
|
|
|
|
+ public MessageVO uploadJobByJson(@RequestBody JobJsonDTO jobJsonDTO){
|
|
|
|
+ String jobName=jobJsonDTO.getJob_name();
|
|
|
|
+ String jobDescription=jobJsonDTO.getJob_description();
|
|
|
|
+ String startTime=jobJsonDTO.getStart_time();
|
|
|
|
+ String endTime=jobJsonDTO.getEnd_time();
|
|
|
|
+ JSONArray workerList_Array=new JSONArray(jobJsonDTO.getWorker_list());
|
|
|
|
+ String paperUrl=jobJsonDTO.getPaperUrl();
|
|
List<String>workerList=new ArrayList<>();
|
|
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;
|
|
|
|
|
|
+ for(int i=0;i<workerList_Array.length();i++){
|
|
|
|
+ workerList.add(String.valueOf(workerList_Array.get(i)));
|
|
}
|
|
}
|
|
- 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";
|
|
|
|
|
|
+ MessageVO messageVO=new MessageVO();
|
|
try {
|
|
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;
|
|
|
|
|
|
+ String paperJson=readStringFromUrl(paperUrl);
|
|
|
|
+ JSONObject paperResult=reviewPaperService.uploadPaper(paperJson);
|
|
|
|
+ if(!paperResult.getString("status").equals("success")){
|
|
|
|
+ messageVO.setStatus("500");
|
|
|
|
+ messageVO.setMessage("创建paper失败");
|
|
|
|
+ return messageVO;
|
|
}
|
|
}
|
|
- }catch (Exception e){
|
|
|
|
- result=e.getMessage();
|
|
|
|
|
|
+ String paperId=paperResult.getString("paperId");
|
|
|
|
+ String jobId=uploadJob(jobName,jobDescription,paperId,startTime,endTime,workerList,"");
|
|
|
|
+ messageVO.setStatus("200");
|
|
|
|
+ messageVO.setMessage(jobId);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ messageVO.setStatus("500");
|
|
|
|
+ messageVO.setMessage(e.getMessage());
|
|
}
|
|
}
|
|
- return result;
|
|
|
|
|
|
+ return messageVO;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean updateJob(String jobId,String name, String description, String paperId,String startTime, String endTime,List<String>workerList,String workerDistribution){
|
|
public boolean updateJob(String jobId,String name, String description, String paperId,String startTime, String endTime,List<String>workerList,String workerDistribution){
|