|
@@ -1,17 +1,24 @@
|
|
|
package com.cirs.biz.controller;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.cirs.biz.domain.*;
|
|
|
import com.cirs.biz.service.ITElectronComponentService;
|
|
|
+import com.cirs.biz.service.ITVerificationTaskService;
|
|
|
import com.cirs.common.utils.DictUtils;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import jdk.nashorn.internal.parser.JSONParser;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -43,6 +50,9 @@ public class TVerificationTaskDetailController extends BaseController
|
|
|
@Autowired
|
|
|
private ITElectronComponentService tElectronComponentService;//之前写在元器件接口不太方便
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ITVerificationTaskService tVerificationTaskService;
|
|
|
+
|
|
|
private WebClient webClient = WebClient.builder()
|
|
|
// .baseUrl("http://jsonplaceholder.typicode.com")
|
|
|
.build();
|
|
@@ -167,18 +177,34 @@ public class TVerificationTaskDetailController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('biz:detail:verification')")
|
|
|
@GetMapping("/verification")
|
|
|
public AjaxResult verification(Long taskid) {
|
|
|
-
|
|
|
+ TVerificationTask task = tVerificationTaskService.selectTVerificationTaskById(taskid);
|
|
|
try {
|
|
|
|
|
|
+
|
|
|
+ task.setStartTime(new Date());
|
|
|
+
|
|
|
String model_path = DictUtils.getDictValue("biz_algorithm_config","model_path");
|
|
|
String verification_uri = DictUtils.getDictValue("biz_algorithm_config","verification_uri");
|
|
|
|
|
|
+
|
|
|
+// logger.info(taskid.toString());
|
|
|
+// System.out.println(taskid);
|
|
|
+
|
|
|
+// getComponentIds(taskid);
|
|
|
Map<String, Object> objectMap=new HashMap<>();
|
|
|
List<VerificationData> dataset = tVerificationTaskDetailService.getComponentids(taskid);//id就是taskdetail的id,由此更新相应的taskdetail
|
|
|
+// for(int i=0;i<dataset.size();i++){
|
|
|
+// dataset.get(i).setId((long)(i+1));
|
|
|
+// }
|
|
|
|
|
|
objectMap.put("dataSet", dataset);
|
|
|
objectMap.put("modelPath", model_path);
|
|
|
- logger.info("request payload: {}", JSON.toJSONString(objectMap));
|
|
|
+ // 创建一个 ObjectMapper 实例
|
|
|
+// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+// 将对象转换为 JSON 字符串
|
|
|
+// String json = objectMapper.writeValueAsString(objectMap);
|
|
|
+// logger.info("post json: {}", json);
|
|
|
// 发送请求
|
|
|
Mono<String> mono = webClient
|
|
|
.post() // POST 请求
|
|
@@ -190,25 +216,46 @@ public class TVerificationTaskDetailController extends BaseController
|
|
|
|
|
|
AjaxResult res = new AjaxResult();
|
|
|
String result = mono.block();//返回值有accuracyRate和recallRate属性
|
|
|
+ task.setEndTime(new Date());
|
|
|
+ task.setTaskStatus("运行成功");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("dataSet");
|
|
|
+ task.setAccuracyRate(jsonObject.getJSONObject("data").getString("accuracyRate")+"%");
|
|
|
+ task.setRecallRate(jsonObject.getJSONObject("data").getString("recallRate")+"%");
|
|
|
+
|
|
|
+ List<VerificationData> dataSet = JSONArray.parseArray(jsonArray.toJSONString(),VerificationData.class);
|
|
|
+
|
|
|
+ tVerificationTaskService.updateTVerificationTask(task);
|
|
|
+ updateDetails(dataSet);
|
|
|
+
|
|
|
//
|
|
|
// GsonJsonParser jsonParser = new GsonJsonParser();
|
|
|
//
|
|
|
// System.out.println(jsonParser.parseMap(result).get("dataSet").toString());
|
|
|
|
|
|
// 这里后端GsonJsonParser解析json语句报错Handler dispatch failed;,所以返回到前端解析
|
|
|
- res.put("data",result);
|
|
|
- res.put("msg","任务"+taskid+"验证算法调用成功");
|
|
|
- res.put("code",200);
|
|
|
+// res.put("data",result);
|
|
|
+// res.put("msg","任务"+taskid+"验证算法调用成功");
|
|
|
+// res.put("code",200);
|
|
|
// todo System.out.println System.out.println应该使用logger框架替换
|
|
|
// System.out.println(result);
|
|
|
logger.info(result);
|
|
|
- return res;
|
|
|
+ if(jsonObject.getIntValue("code")!=200){
|
|
|
+
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ return success(jsonObject.getString("msg"));
|
|
|
|
|
|
// return success("任务"+taskid+"验证算法调用成功");
|
|
|
} catch (Exception e) {
|
|
|
+ task.setTaskStatus("运行失败");
|
|
|
+ tVerificationTaskService.updateTVerificationTask(task);
|
|
|
logger.error("任务"+taskid+"验证算法调用失败", e);
|
|
|
return error("任务"+taskid+"验证算法调用失败");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|