|
@@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import edu.nju.util.ExcelToJson;
|
|
import edu.nju.util.ExcelToJson;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ExtraService {
|
|
public class ExtraService {
|
|
@@ -26,27 +25,6 @@ public class ExtraService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
BugDao bugDao;
|
|
BugDao bugDao;
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewJobDao jobDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewItemDao itemDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewAnswerDao answerDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewService reviewService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewReportDao reviewReportDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewPaperJsonDao reviewPaperJsonDao;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ReviewPaperDao reviewPaperDao;
|
|
|
|
|
|
|
|
//测试用例相关
|
|
//测试用例相关
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
public String saveTestCase(String report_id, String name, String front, String behind, String description) {
|
|
@@ -150,256 +128,5 @@ public class ExtraService {
|
|
return examDao.findById(id);
|
|
return examDao.findById(id);
|
|
}
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public JSONObject savePaper(String paperJson){
|
|
|
|
- JSONObject object = new JSONObject();
|
|
|
|
- String result=checkPaper(paperJson);
|
|
|
|
- if(!result.equals("success")){
|
|
|
|
- object.put("status","fail");
|
|
|
|
- object.put("message",result);
|
|
|
|
- return object;
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- JSONObject jsonObject = new JSONObject(paperJson);
|
|
|
|
- String description = jsonObject.getString("description");
|
|
|
|
- String name = jsonObject.getString("name");
|
|
|
|
- String time = jsonObject.getString("create_time");
|
|
|
|
- String type = jsonObject.getString("type");
|
|
|
|
- String applicationLocation = jsonObject.getString("application_url");
|
|
|
|
- String requirementLocation = jsonObject.getString("requirement_url");
|
|
|
|
- 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, paperId);
|
|
|
|
- reportIndexToId.put(reportIndex, id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- JSONArray itemGroupArray = jsonObject.getJSONArray("item_group_list");
|
|
|
|
- //save item
|
|
|
|
- //item index-id
|
|
|
|
- HashMap<String, Integer> itemIdToOptionNum = new HashMap<>();
|
|
|
|
- HashMap<Integer, String> itemIndexToId = new HashMap<>();
|
|
|
|
- for (int i = 0; i < itemGroupArray.length(); i++) {
|
|
|
|
- JSONObject itemGroupObject = itemGroupArray.getJSONObject(i);
|
|
|
|
- saveItem(itemGroupObject, paperId, itemIdToOptionNum, reportIndexToId, itemIndexToId);
|
|
|
|
- }
|
|
|
|
- }catch (Exception e){
|
|
|
|
- object.put("status","fail");
|
|
|
|
- object.put("message",e.getMessage());
|
|
|
|
- //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
- }
|
|
|
|
- return object;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private String saveReport(JSONObject reportObject,String paper_id)throws Exception{
|
|
|
|
- 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");
|
|
|
|
- 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());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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 {
|
|
|
|
- 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(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_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是否存在! ");
|
|
|
|
-// }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// 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 checkPaper(String paperJson){
|
|
|
|
- String result="success";
|
|
|
|
- try {
|
|
|
|
- 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");
|
|
|
|
-
|
|
|
|
- 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 originalId=report.getString("original_id");
|
|
|
|
- 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<Integer>itemReportIndexs=new HashSet<>();
|
|
|
|
-
|
|
|
|
- for(int i=0;i<itemGroupArray.length();i++){
|
|
|
|
- Set<Integer>itemIndexs=new HashSet<>();
|
|
|
|
- JSONObject itemGroup=itemGroupArray.getJSONObject(i);
|
|
|
|
- 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);
|
|
|
|
- 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");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// 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();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
}
|
|
}
|