|
@@ -7,12 +7,10 @@ import edu.nju.entities.*;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import edu.nju.util.ExcelToJson;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
@Service
|
|
|
public class ExtraService {
|
|
@@ -45,7 +43,10 @@ public class ExtraService {
|
|
|
ReviewReportDao reviewReportDao;
|
|
|
|
|
|
@Autowired
|
|
|
- ReviewJobJsonDao reviewJobJsonDao;
|
|
|
+ ReviewPaperJsonDao reviewPaperJsonDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ReviewPaperDao reviewPaperDao;
|
|
|
|
|
|
//测试用例相关
|
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
@@ -150,35 +151,31 @@ public class ExtraService {
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public JSONObject saveJob(String jobJson){
|
|
|
+ public JSONObject savePaper(String paperJson){
|
|
|
JSONObject object = new JSONObject();
|
|
|
- String result=checkJob(jobJson);
|
|
|
+ String result=checkJob(paperJson);
|
|
|
if(!result.equals("success")){
|
|
|
object.put("status","fail");
|
|
|
object.put("message",result);
|
|
|
return object;
|
|
|
}
|
|
|
-
|
|
|
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 time = jsonObject.getString("create_time");
|
|
|
String type = jsonObject.getString("type");
|
|
|
String applicationLocation = jsonObject.getString("application_url");
|
|
|
String requirementLocation = jsonObject.getString("requirement_url");
|
|
|
- int reportNum = jsonObject.getInt("report_num");
|
|
|
- int workerNum = jsonObject.getInt("worker_num");
|
|
|
- String jobId = jobDao.save(new ReviewJob(description, name, time, type, applicationLocation, requirementLocation, reportNum, workerNum));
|
|
|
- reviewJobJsonDao.save(new ReviewJobJson(jobId,jobJson));
|
|
|
-
|
|
|
+ String paperId = reviewPaperDao.save(new ReviewPaper(description, name, time, type, applicationLocation, requirementLocation));
|
|
|
+ reviewPaperJsonDao.save(new ReviewPaperJson(paperId,paperJson));
|
|
|
|
|
|
JSONArray reportArray = jsonObject.getJSONArray("report_list");
|
|
|
HashMap<Integer, String> reportIndexToId = new HashMap<>();
|
|
|
for (int i = 0; i < reportArray.length(); i++) {
|
|
|
JSONObject reportObject = reportArray.getJSONObject(i);
|
|
|
int reportIndex = reportObject.getInt("index");
|
|
|
- String id = saveReport(reportObject, jobId);
|
|
|
+ String id = saveReport(reportObject, paperId);
|
|
|
reportIndexToId.put(reportIndex, id);
|
|
|
}
|
|
|
|
|
@@ -189,24 +186,17 @@ public class ExtraService {
|
|
|
HashMap<Integer, String> itemIndexToId = new HashMap<>();
|
|
|
for (int i = 0; i < itemGroupArray.length(); i++) {
|
|
|
JSONObject itemGroupObject = itemGroupArray.getJSONObject(i);
|
|
|
- saveItem(itemGroupObject, jobId, itemIdToOptionNum, reportIndexToId, itemIndexToId);
|
|
|
+ saveItem(itemGroupObject, paperId, itemIdToOptionNum, reportIndexToId, itemIndexToId);
|
|
|
}
|
|
|
-
|
|
|
- //worker_id-item_id_list
|
|
|
- JSONArray groupArray = jsonObject.getJSONArray("group_list");
|
|
|
- createWorkerToItem(groupArray, jobId, reportIndexToId, itemIdToOptionNum);
|
|
|
- object.put("status","sucess");
|
|
|
- object.put("id",jobId);
|
|
|
}catch (Exception e){
|
|
|
object.put("status","fail");
|
|
|
object.put("message",e.getMessage());
|
|
|
//TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
-
|
|
|
}
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
- private String saveReport(JSONObject reportObject,String job_id)throws Exception{
|
|
|
+ private String saveReport(JSONObject reportObject,String paper_id)throws Exception{
|
|
|
try {
|
|
|
JSONArray imgArray=reportObject.getJSONArray("img_url");
|
|
|
List<String> img_urls=new ArrayList<>();
|
|
@@ -220,14 +210,14 @@ public class ExtraService {
|
|
|
}
|
|
|
String name=reportObject.getString("name");
|
|
|
String description=reportObject.getString("description");
|
|
|
- ReviewReport reviewReport=new ReviewReport(job_id,name,description,img_urls,file_urls);
|
|
|
+ ReviewReport reviewReport=new ReviewReport(paper_id,name,description,img_urls,file_urls);
|
|
|
return reviewReportDao.save(reviewReport);
|
|
|
}catch (Exception e){
|
|
|
throw new Exception("report 创建失败: "+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void saveItem(JSONObject itemGroupObject,String job_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{
|
|
|
+ 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> reportIds=new ArrayList<>();
|
|
|
try {
|
|
@@ -249,10 +239,10 @@ public class ExtraService {
|
|
|
for(int k=0;k<optionArray.length();k++){
|
|
|
options.add(String.valueOf(optionArray.get(k)));
|
|
|
}
|
|
|
- ReviewItem item=new ReviewItem(job_id,isRequired,options,description,reportIds,type);
|
|
|
+ ReviewItem item=new ReviewItem(paper_id,isRequired,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_id_to_option_num.put(item_id,options.size());
|
|
|
item_index_to_id.put(index,item_id);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
@@ -269,47 +259,47 @@ public class ExtraService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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{
|
|
|
- for(int i=0;i<groupArray.length();i++){
|
|
|
- List<String> reportIdList=new ArrayList<>();
|
|
|
- List<String> workerList=new ArrayList<>();
|
|
|
- try {
|
|
|
- JSONObject groupObject=groupArray.getJSONObject(i);
|
|
|
- String description=groupObject.getString("description");
|
|
|
- String name=groupObject.getString("name");
|
|
|
- JSONArray workerArray=groupObject.getJSONArray("worker_list");
|
|
|
- for (int j=0;j<workerArray.length();j++){
|
|
|
- workerList.add(String.valueOf(workerArray.get(j)));
|
|
|
- }
|
|
|
- JSONArray reportIndexArray=groupObject.getJSONArray("report_list");
|
|
|
- for (int j=0;j<reportIndexArray.length();j++){
|
|
|
- int reportIndex=Integer.parseInt(String.valueOf(reportIndexArray.get(j)));
|
|
|
- reportIdList.add(report_index_to_id.get(reportIndex));
|
|
|
- }
|
|
|
- reviewService.saveGroup(name,description,workerList,job_id,reportIdList);
|
|
|
- }catch (Exception e){
|
|
|
- throw new Exception("group 创建失败: "+e.getMessage());
|
|
|
- }
|
|
|
- try {
|
|
|
- for(int j=0;j<workerList.size();j++){
|
|
|
- String worker_id=workerList.get(j);
|
|
|
-// 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);
|
|
|
- ReviewAnswer answer=new ReviewAnswer(item_id,report_id,worker_id,job_id,optionNum);
|
|
|
- answerDao.save(answer);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- throw new Exception("group创建失败,请检查配置的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{
|
|
|
+// for(int i=0;i<groupArray.length();i++){
|
|
|
+// List<String> reportIdList=new ArrayList<>();
|
|
|
+// List<String> workerList=new ArrayList<>();
|
|
|
+// try {
|
|
|
+// JSONObject groupObject=groupArray.getJSONObject(i);
|
|
|
+// String description=groupObject.getString("description");
|
|
|
+// String name=groupObject.getString("name");
|
|
|
+// JSONArray workerArray=groupObject.getJSONArray("worker_list");
|
|
|
+// for (int j=0;j<workerArray.length();j++){
|
|
|
+// workerList.add(String.valueOf(workerArray.get(j)));
|
|
|
+// }
|
|
|
+// JSONArray reportIndexArray=groupObject.getJSONArray("report_list");
|
|
|
+// for (int j=0;j<reportIndexArray.length();j++){
|
|
|
+// int reportIndex=Integer.parseInt(String.valueOf(reportIndexArray.get(j)));
|
|
|
+// reportIdList.add(report_index_to_id.get(reportIndex));
|
|
|
+// }
|
|
|
+// reviewService.saveGroup(name,description,workerList,job_id,reportIdList);
|
|
|
+// }catch (Exception e){
|
|
|
+// throw new Exception("group 创建失败: "+e.getMessage());
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// for(int j=0;j<workerList.size();j++){
|
|
|
+// String worker_id=workerList.get(j);
|
|
|
+//// 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);
|
|
|
+// ReviewAnswer answer=new ReviewAnswer(item_id,report_id,worker_id,job_id,optionNum);
|
|
|
+// answerDao.save(answer);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }catch (Exception e){
|
|
|
+// throw new Exception("group创建失败,请检查配置的report_index是否存在! ");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
public String checkJob(String jobJson){
|
|
|
String result="success";
|