|
@@ -43,6 +43,9 @@ public class ExtraService {
|
|
|
|
|
|
@Autowired
|
|
|
ReviewReportDao reviewReportDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ReviewJobJsonDao reviewJobJsonDao;
|
|
|
|
|
|
//测试用例相关
|
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
@@ -149,6 +152,12 @@ public class ExtraService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject saveJob(String jobJson){
|
|
|
JSONObject object = new JSONObject();
|
|
|
+ String result=checkJob(jobJson);
|
|
|
+ if(!result.equals("success")){
|
|
|
+ object.put("status","fail");
|
|
|
+ object.put("message",result);
|
|
|
+ return object;
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
|
JSONObject jsonObject = new JSONObject(jobJson);
|
|
@@ -161,6 +170,7 @@ public class ExtraService {
|
|
|
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));
|
|
|
|
|
|
|
|
|
JSONArray reportArray = jsonObject.getJSONArray("report_list");
|
|
@@ -197,94 +207,112 @@ public class ExtraService {
|
|
|
}
|
|
|
|
|
|
private String saveReport(JSONObject reportObject,String job_id)throws Exception{
|
|
|
- JSONArray imgArray=reportObject.getJSONArray("img_url");
|
|
|
- List<String> img_urls=new ArrayList<>();
|
|
|
- for(int i=0;i<imgArray.length();i++){
|
|
|
- img_urls.add(String.valueOf(imgArray.get(i)));
|
|
|
- }
|
|
|
- JSONArray fileArray=reportObject.getJSONArray("file_url");
|
|
|
- List<String> file_urls=new ArrayList<>();
|
|
|
- for(int i=0;i<fileArray.length();i++){
|
|
|
- file_urls.add(String.valueOf(fileArray.get(i)));
|
|
|
+ try {
|
|
|
+ JSONArray imgArray=reportObject.getJSONArray("img_url");
|
|
|
+ List<String> img_urls=new ArrayList<>();
|
|
|
+ for(int i=0;i<imgArray.length();i++){
|
|
|
+ img_urls.add(String.valueOf(imgArray.get(i)));
|
|
|
+ }
|
|
|
+ JSONArray fileArray=reportObject.getJSONArray("file_url");
|
|
|
+ List<String> file_urls=new ArrayList<>();
|
|
|
+ for(int i=0;i<fileArray.length();i++){
|
|
|
+ file_urls.add(String.valueOf(fileArray.get(i)));
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new Exception("report 创建失败: "+e.getMessage());
|
|
|
}
|
|
|
- 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<Integer,String>report_index_to_id,HashMap<Integer,String>item_index_to_id)throws Exception{
|
|
|
-
|
|
|
-// JSONObject itemObject=itemArray.getJSONObject(i);
|
|
|
- List<String> reportIds=new ArrayList<>();
|
|
|
- JSONArray reportArray=itemGroupObject.getJSONArray("report_list");
|
|
|
- for (int j=0;j<reportArray.length();j++){
|
|
|
- int reportIndex= Integer.parseInt(String.valueOf(reportArray.get(j)));
|
|
|
- reportIds.add(report_index_to_id.get(reportIndex));
|
|
|
- }
|
|
|
- JSONArray itemArray=itemGroupObject.getJSONArray("item_list");
|
|
|
List<String>itemIds=new ArrayList<>();
|
|
|
- for (int j=0;j<itemArray.length();j++){
|
|
|
- JSONObject itemObject=itemArray.getJSONObject(j);
|
|
|
- int index=itemObject.getInt("index");
|
|
|
- Boolean isRequired=itemObject.getBoolean("is_required");
|
|
|
- String description=itemObject.getString("description");
|
|
|
- String type=itemObject.getString("type");
|
|
|
- List<String>options=new ArrayList<>();
|
|
|
- JSONArray optionArray=itemObject.getJSONArray("options");
|
|
|
- for(int k=0;k<optionArray.length();k++){
|
|
|
- options.add(String.valueOf(optionArray.get(k)));
|
|
|
+ List<String> reportIds=new ArrayList<>();
|
|
|
+ try {
|
|
|
+ JSONArray reportArray=itemGroupObject.getJSONArray("report_list");
|
|
|
+ for (int j=0;j<reportArray.length();j++){
|
|
|
+ int reportIndex= Integer.parseInt(String.valueOf(reportArray.get(j)));
|
|
|
+ reportIds.add(report_index_to_id.get(reportIndex));
|
|
|
+ }
|
|
|
+ JSONArray itemArray=itemGroupObject.getJSONArray("item_list");
|
|
|
+
|
|
|
+ for (int j=0;j<itemArray.length();j++){
|
|
|
+ JSONObject itemObject=itemArray.getJSONObject(j);
|
|
|
+ int index=itemObject.getInt("index");
|
|
|
+ Boolean isRequired=itemObject.getBoolean("is_required");
|
|
|
+ String description=itemObject.getString("description");
|
|
|
+ String type=itemObject.getString("type");
|
|
|
+ List<String>options=new ArrayList<>();
|
|
|
+ JSONArray optionArray=itemObject.getJSONArray("options");
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
}
|
|
|
- ReviewItem item=new ReviewItem(job_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_index_to_id.put(index,item_id);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new Exception("item 创建失败: "+e.getMessage());
|
|
|
}
|
|
|
- for(int j=0;j<reportIds.size();j++){
|
|
|
- ReviewReport report=reviewReportDao.findReviewReport(reportIds.get(j));
|
|
|
- report.setItem_id(itemIds);
|
|
|
- reviewReportDao.save(report);
|
|
|
+ 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{
|
|
|
for(int i=0;i<groupArray.length();i++){
|
|
|
- JSONObject groupObject=groupArray.getJSONObject(i);
|
|
|
- String description=groupObject.getString("description");
|
|
|
- String name=groupObject.getString("name");
|
|
|
- JSONArray workerArray=groupObject.getJSONArray("worker_list");
|
|
|
- List<String> workerList=new ArrayList<>();
|
|
|
- for (int j=0;j<workerArray.length();j++){
|
|
|
- workerList.add(String.valueOf(workerArray.get(j)));
|
|
|
- }
|
|
|
- JSONArray reportIndexArray=groupObject.getJSONArray("report_list");
|
|
|
List<String> reportIdList=new ArrayList<>();
|
|
|
- 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));
|
|
|
+ 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());
|
|
|
}
|
|
|
- reviewService.saveGroup(name,description,workerList,job_id,reportIdList);
|
|
|
- for(int j=0;j<workerList.size();j++){
|
|
|
- String worker_id=workerList.get(j);
|
|
|
+ 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);
|
|
|
+ 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="";
|
|
|
+ String result="success";
|
|
|
try {
|
|
|
JSONObject jsonObject=new JSONObject(jobJson);
|
|
|
String description=jsonObject.getString("description");
|
|
@@ -293,85 +321,93 @@ public class ExtraService {
|
|
|
String type=jsonObject.getString("type");
|
|
|
String application_location=jsonObject.getString("application_url");
|
|
|
String requirement_location=jsonObject.getString("requirement_url");
|
|
|
- String report_num=jsonObject.getString("report_num");
|
|
|
- checkNum(report_num);
|
|
|
- String worker_num=jsonObject.getString("worker_num");
|
|
|
- checkNum(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");
|
|
|
+ for(int i=0;i<reportList.length();i++){
|
|
|
+ JSONObject report=reportList.getJSONObject(i);
|
|
|
+ int index=report.getInt("index");
|
|
|
+ if(reportIndexs.contains(index)){
|
|
|
+ throw new Exception("report_list中report的index不能重复");
|
|
|
+ }else{
|
|
|
+ reportIndexs.add(index);
|
|
|
+ }
|
|
|
+ String reportName=report.getString("name");
|
|
|
+ String reportDescription=report.getString("description");
|
|
|
+ JSONArray imgUrls=report.getJSONArray("img_url");
|
|
|
+ JSONArray fileUrls=report.getJSONArray("file_url");
|
|
|
+ }
|
|
|
+
|
|
|
JSONArray itemGroupArray=jsonObject.getJSONArray("item_group_list");
|
|
|
- Set<String>reportIndexs=new HashSet<>();
|
|
|
- Set<String>itemIndexs=new HashSet<>();
|
|
|
+ Set<Integer>itemReportIndexs=new HashSet<>();
|
|
|
+
|
|
|
for(int i=0;i<itemGroupArray.length();i++){
|
|
|
+ Set<Integer>itemIndexs=new HashSet<>();
|
|
|
JSONObject itemGroup=itemGroupArray.getJSONObject(i);
|
|
|
- JSONArray reportList=itemGroup.getJSONArray("report_list");
|
|
|
- for(int j=0;j<reportList.length();j++){
|
|
|
- String reportIndex=reportList.getJSONObject(j).getString("report_index");
|
|
|
- if(reportIndexs.contains(reportIndex)){
|
|
|
-
|
|
|
+ JSONArray itemReportList=itemGroup.getJSONArray("report_list");
|
|
|
+ for(int j=0;j<itemReportList.length();j++){
|
|
|
+ int reportIndex=Integer.parseInt(String.valueOf(itemReportList.get(j)));
|
|
|
+ if(!reportIndexs.contains(reportIndex)){
|
|
|
+ throw new Exception("item_group_list中包含不存在的report ");
|
|
|
}else{
|
|
|
-
|
|
|
+ if(itemReportIndexs.contains(reportIndex)){
|
|
|
+ throw new Exception("item_group_list中的report不能重复");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ itemReportIndexs.add(reportIndex);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
JSONArray itemList=itemGroup.getJSONArray("item_list");
|
|
|
for(int j=0;j<itemList.length();j++){
|
|
|
JSONObject item=itemList.getJSONObject(j);
|
|
|
- String index=item.getString("index");
|
|
|
- String itemDescription=item.getString("descroption");
|
|
|
- String isRequired=item.getString("is_required");
|
|
|
+ int index=item.getInt("index");
|
|
|
+ if(itemIndexs.contains(index)){
|
|
|
+ throw new Exception("item_group_list中的item_index不能重复");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ itemIndexs.add(index);
|
|
|
+ }
|
|
|
+ String itemDescription=item.getString("description");
|
|
|
+ Boolean isRequired=item.getBoolean("is_required");
|
|
|
String itemType=item.getString("type");
|
|
|
JSONArray options=item.getJSONArray("options");
|
|
|
- for(int k=0;k<options.length();k++){
|
|
|
- String option=options.getJSONObject(k).getString("option");
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
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=workerList.getJSONObject(j).getString("worker_id");
|
|
|
- }
|
|
|
- JSONArray reportList=groupObject.getJSONArray("report_list");
|
|
|
- for(int j=0;j<reportList.length();j++){
|
|
|
- String reportIndex=reportList.getJSONObject(j).getString("report_index");
|
|
|
- }
|
|
|
- }
|
|
|
- JSONArray reportList=jsonObject.getJSONArray("report_list");
|
|
|
- for(int i=0;i<reportList.length();i++){
|
|
|
- JSONObject report=reportList.getJSONObject(i);
|
|
|
- String index=report.getString("index");
|
|
|
- String reportName=report.getString("name");
|
|
|
- String reportDescription=report.getString("description");
|
|
|
- JSONArray imgUrls=report.getJSONArray("img_url");
|
|
|
- for(int j=0;j<imgUrls.length();j++){
|
|
|
- String url=imgUrls.getJSONObject(j).getString("url");
|
|
|
+ String workerId=String.valueOf(workerList.get(j));
|
|
|
+ if(workers.contains(workerId)){
|
|
|
+ throw new Exception("同一个worker不能属于不同的group");
|
|
|
+ }else{
|
|
|
+ workers.add(workerId);
|
|
|
+ }
|
|
|
}
|
|
|
- JSONArray fileUrls=report.getJSONArray("file_url");
|
|
|
- for(int j=0;j<fileUrls.length();j++){
|
|
|
- String url=fileUrls.getJSONObject(j).getString("url");
|
|
|
+ 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();
|
|
|
}
|
|
|
-// String name=jsonObject.getString("name");
|
|
|
-// if(name==null){
|
|
|
-// return "标题为空";
|
|
|
-// }
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private void checkNum(String str) throws Exception {
|
|
|
- try{
|
|
|
- int n=Integer.parseInt(str);
|
|
|
- }catch(NumberFormatException e){
|
|
|
- throw new Exception("输入的字符串必须能够转化成数字!",e);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
}
|