|
@@ -2,22 +2,14 @@ package edu.nju.util;
|
|
|
|
|
|
import edu.nju.dao.BugDao;
|
|
|
import edu.nju.dao.ReportDao;
|
|
|
-import edu.nju.dao.StuInfoDao;
|
|
|
-import edu.nju.dao.TaskDao;
|
|
|
import edu.nju.entities.Bug;
|
|
|
import edu.nju.entities.Report;
|
|
|
-import edu.nju.entities.StuInfo;
|
|
|
-import edu.nju.entities.Task;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.*;
|
|
|
-import org.json.JSONArray;
|
|
|
-import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
@@ -36,17 +28,6 @@ public class BlockChainAspect {
|
|
|
@Autowired
|
|
|
ReportDao reportDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- TaskDao taskDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StuInfoDao stuInfoDao;
|
|
|
-
|
|
|
- private static final String blockChainHost="http://111.231.68.200:8082/";
|
|
|
-
|
|
|
- @Value("${mooctest.url}")
|
|
|
- private String MOOCTEST_HOST;
|
|
|
-
|
|
|
|
|
|
|
|
|
* 定义切入点,切入点为com.example.demo.aop.AopController中的所有函数
|
|
@@ -61,13 +42,34 @@ public class BlockChainAspect {
|
|
|
public void saveBugGrade(){
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ * @description 在连接点执行之前执行的通知
|
|
|
+ */
|
|
|
+ @Before("saveBugGrade()")
|
|
|
+ public void doBeforeGame(JoinPoint joinPoint){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @description 在连接点执行之后执行的通知(返回通知和异常通知的异常)
|
|
|
+ */
|
|
|
+ @After("saveBugGrade()")
|
|
|
+ public void doAfterGame(JoinPoint joinPoint){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
* @description 保存bug分数后传递给区块链
|
|
|
*/
|
|
|
@AfterReturning(value="saveBugGrade()",returning = "keys")
|
|
|
public void doAfterReturningSaveBugGrade(JoinPoint joinPoint,Object keys){
|
|
|
- System.out.println("传递给区块链");
|
|
|
Object[] obj = joinPoint.getArgs();
|
|
|
for (Object argItem : obj) {
|
|
|
System.out.println("---->now-->argItem:" + argItem);
|
|
@@ -80,231 +82,57 @@ public class BlockChainAspect {
|
|
|
|
|
|
Bug bug=bugDao.findByid(bugId);
|
|
|
Report report=reportDao.findById(bug.getReport_id());
|
|
|
+ String crowdTestId=report.getCase_take_id();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- String defaultString="慕测管理员";
|
|
|
-
|
|
|
- JSONObject bugReviewVO=new JSONObject();
|
|
|
-
|
|
|
- if(report==null){
|
|
|
- bugReviewVO.put("bugReportId",bugId);
|
|
|
- bugReviewVO.put("bugReportScore",Integer.parseInt(grade));
|
|
|
- bugReviewVO.put("reportReviewer",defaultString);
|
|
|
- bugReviewVO.put("taskId",defaultString);
|
|
|
- bugReviewVO.put("taskName",defaultString);
|
|
|
- bugReviewVO.put("testReportId",defaultString);
|
|
|
- bugReviewVO.put("type",0);
|
|
|
- bugReviewVO.put("updateTime",System.currentTimeMillis());
|
|
|
- }else{
|
|
|
- bugReviewVO.put("bugReportId",bugId);
|
|
|
- bugReviewVO.put("bugReportScore",Integer.parseInt(grade));
|
|
|
- bugReviewVO.put("reportReviewer",defaultString);
|
|
|
- bugReviewVO.put("taskId",report.getCase_take_id());
|
|
|
-
|
|
|
- Task task=taskDao.findById(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- task=getAndSaveTaskInfo(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- bugReviewVO.put("taskName",defaultString);
|
|
|
- }else{
|
|
|
- bugReviewVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- }else {
|
|
|
- bugReviewVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- bugReviewVO.put("testReportId",report.getId());
|
|
|
- bugReviewVO.put("type",0);
|
|
|
- bugReviewVO.put("updateTime",System.currentTimeMillis());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- String url=blockChainHost+"reportReview";
|
|
|
- try {
|
|
|
- String result = HTTP.postBody(url, bugReviewVO.toString());
|
|
|
- if (!result.equals("")) {
|
|
|
- JSONObject resultJson = new JSONObject(result);
|
|
|
- System.out.println(resultJson);
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
+ String bugReviewerId="default";
|
|
|
}
|
|
|
|
|
|
- private Task getAndSaveTaskInfo(String id){
|
|
|
- String result = HTTP.sendGet(MOOCTEST_HOST+"/api/exam/" + id + "/info", "");
|
|
|
- if (!"".equals(result)) {
|
|
|
- JSONObject json = new JSONObject(result);
|
|
|
- long beginTime = json.getLong("beginTime");
|
|
|
- long endTime = json.getLong("endTime");
|
|
|
- String name=json.getString("name");
|
|
|
- double totalMins = (endTime - beginTime) / 1000 / 60.0;
|
|
|
- Task newTask = new Task(id, name,beginTime, endTime, totalMins, totalMins);
|
|
|
- taskDao.save(newTask);
|
|
|
- return newTask;
|
|
|
- }else{
|
|
|
- return null;
|
|
|
+
|
|
|
+ * @description 上传bug后传递给区块链
|
|
|
+ */
|
|
|
+ @AfterReturning(value="bugSubmit()",returning = "keys")
|
|
|
+ public void doAfterReturningBugSubmit(JoinPoint joinPoint,Object keys){
|
|
|
+ Object[] obj = joinPoint.getArgs();
|
|
|
+ for (Object argItem : obj) {
|
|
|
+ System.out.println("---->now-->argItem:" + argItem);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- public void uploadTestReportInfo(String case_take_id){
|
|
|
- String defaultString="defaultString";
|
|
|
- List<Report> reportList=reportDao.findByCaseTakeId(case_take_id);
|
|
|
- if(reportList!=null){
|
|
|
- for(Report report:reportList){
|
|
|
- JSONObject testReportVO=new JSONObject();
|
|
|
- testReportVO.put("reportHash",defaultString);
|
|
|
- testReportVO.put("taskId",report.getCase_take_id());
|
|
|
- Task task=taskDao.findById(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- task=getAndSaveTaskInfo(report.getTask_id());
|
|
|
- if(task==null){
|
|
|
- testReportVO.put("taskName",defaultString);
|
|
|
- }else{
|
|
|
- testReportVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- }else {
|
|
|
- testReportVO.put("taskName",task.getName());
|
|
|
- }
|
|
|
- testReportVO.put("testReportId",report.getId());
|
|
|
- testReportVO.put("testReportName",report.getName());
|
|
|
- testReportVO.put("type",0);
|
|
|
- testReportVO.put("updateTime",System.currentTimeMillis());
|
|
|
- testReportVO.put("workerId",report.getWorker_id());
|
|
|
- String workerName=stuInfoDao.findWorkerName(report.getId());
|
|
|
- if(!"null".equals(workerName)){
|
|
|
- testReportVO.put("workerName",workerName);
|
|
|
- }else{
|
|
|
- testReportVO.put("workerName",defaultString);
|
|
|
- }
|
|
|
- List<Bug> bugList=bugDao.findByReport(report.getId(),case_take_id);
|
|
|
- JSONArray bugReportList=new JSONArray();
|
|
|
- for(Bug bug:bugList){
|
|
|
- JSONObject bugInfo=new JSONObject();
|
|
|
- bugInfo.put("bugId",bug.getId());
|
|
|
- bugInfo.put("bugName",bug.getTitle());
|
|
|
- bugReportList.put(bugInfo);
|
|
|
- }
|
|
|
- testReportVO.put("bugReportList",bugReportList);
|
|
|
-
|
|
|
- String url=blockChainHost+"testReport";
|
|
|
- try {
|
|
|
- String result = HTTP.postBody(url, testReportVO.toString());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
+ String bugId= (String) obj[0];
|
|
|
+ String grade=(String) obj[1];
|
|
|
|
|
|
- public boolean uploadTestReportInfoToBlockChain(String bug_id){
|
|
|
- Bug bug=bugDao.findByid(bug_id);
|
|
|
- String report_id=bug.getReport_id();
|
|
|
- String defaultString="defaultString";
|
|
|
- Report report=reportDao.findById(report_id);
|
|
|
- if(report!=null) {
|
|
|
- JSONObject testReportVO = new JSONObject();
|
|
|
- testReportVO.put("reportHash", defaultString);
|
|
|
- testReportVO.put("taskId", report.getCase_take_id());
|
|
|
- Task task = taskDao.findById(report.getTask_id());
|
|
|
- if (task == null) {
|
|
|
- task = getAndSaveTaskInfo(report.getTask_id());
|
|
|
- if (task == null) {
|
|
|
- testReportVO.put("taskName", defaultString);
|
|
|
- } else {
|
|
|
- testReportVO.put("taskName", task.getName());
|
|
|
- }
|
|
|
- } else {
|
|
|
- testReportVO.put("taskName", task.getName());
|
|
|
- }
|
|
|
- testReportVO.put("testReportId", report.getId());
|
|
|
- testReportVO.put("testReportName", report.getName());
|
|
|
- testReportVO.put("type", 0);
|
|
|
- testReportVO.put("updateTime", System.currentTimeMillis());
|
|
|
- testReportVO.put("workerId", report.getWorker_id());
|
|
|
- String workerName = stuInfoDao.findWorkerName(report.getId());
|
|
|
- if (!"null".equals(workerName)) {
|
|
|
- testReportVO.put("workerName", workerName);
|
|
|
- } else {
|
|
|
- testReportVO.put("workerName", defaultString);
|
|
|
- }
|
|
|
- List<Bug> bugList = bugDao.findByReport(report.getId(), report.getCase_take_id());
|
|
|
- JSONArray bugReportList = new JSONArray();
|
|
|
- JSONObject bugInfo = new JSONObject();
|
|
|
- bugInfo.put("bugId", bug.getId());
|
|
|
- bugInfo.put("bugName", bug.getTitle());
|
|
|
- bugReportList.put(bugInfo);
|
|
|
- testReportVO.put("bugReportList", bugReportList);
|
|
|
- String url = blockChainHost + "testReport";
|
|
|
- try {
|
|
|
- String result = HTTP.postBody(url, testReportVO.toString());
|
|
|
- if (!result.equals("")) {
|
|
|
- JSONObject resultJson = new JSONObject(result);
|
|
|
-
|
|
|
-
|
|
|
- if("200".equals(resultJson.get("code").toString())){
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return false;
|
|
|
- }
|
|
|
+ Bug bug=bugDao.findByid(bugId);
|
|
|
+ Report report=reportDao.findById(bug.getReport_id());
|
|
|
+ String crowdTestId=report.getCase_take_id();
|
|
|
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+ String bugReviewerId="default";
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|