|
@@ -0,0 +1,70 @@
|
|
|
|
+package com.mooctest.service;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.mooctest.data.BugDTO;
|
|
|
|
+import com.mooctest.data.FinalReportDTO;
|
|
|
|
+import com.mooctest.data.TaskDTO;
|
|
|
|
+import com.mooctest.model.Bug;
|
|
|
|
+import com.mooctest.model.FinalReport;
|
|
|
|
+import com.sun.javafx.tk.Toolkit;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
+
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class BlockchainService {
|
|
|
|
+
|
|
|
|
+// @Value("${blockchain.host}")
|
|
|
|
+ String blockChainHost = "111.231.68.200:8082";
|
|
|
|
+ private final String HTTP = "http://";
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ BugReportService bugReportService;
|
|
|
|
+ @Autowired
|
|
|
|
+ TaskService taskService;
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public void addFinalToBlockChain(FinalReport finalReport) throws InterruptedException{
|
|
|
|
+ if(finalReport==null){
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ TaskDTO task = taskService.getByExamIdAndCaseId(finalReport.getExamId(), finalReport.getCaseId());
|
|
|
|
+ JSONObject wordObj = new JSONObject();
|
|
|
|
+ wordObj.fluentPut("reportHash",finalReport.getId()+"");
|
|
|
|
+ wordObj.fluentPut("reportMixer",finalReport.getWriterId()+"");
|
|
|
|
+ wordObj.fluentPut("taskId",task.getCaseId()+"-"+task.getExamId());
|
|
|
|
+ wordObj.fluentPut("taskName",task.getName());
|
|
|
|
+ wordObj.fluentPut("type",0);
|
|
|
|
+ wordObj.fluentPut("updateTime",System.currentTimeMillis());
|
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
+ Bug bug = bugReportService.getSourceBugById(finalReport.getSourceId());
|
|
|
|
+ obj.fluentPut("bugId",bug.getId());
|
|
|
|
+ obj.fluentPut("bugName",bug.getTitle());
|
|
|
|
+ array.add(obj);
|
|
|
|
+ wordObj.fluentPut("bugReportList",array);
|
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
|
+ String url = HTTP+blockChainHost+"/finalReport"; // 上传最终的报告
|
|
|
|
+ template.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
|
+ headers.setContentType(type);
|
|
|
|
+ HttpEntity<String> entity = new HttpEntity<String>(wordObj.toJSONString(),headers);
|
|
|
|
+ template.postForEntity(url, entity, String.class);
|
|
|
|
+// JSONObject tasksJson = JSON.parseObject(response2.getBody());
|
|
|
|
+ }
|
|
|
|
+}
|