|
|
@@ -111,6 +111,13 @@ public class CheckService {
|
|
|
if (StringUtils.isNull(labCheckInObj)) {
|
|
|
return R.fail(700, "未配置检查项");
|
|
|
}
|
|
|
+ //上传原始图片
|
|
|
+ String orgImgUrl = "";
|
|
|
+ R<SysFile> r = remoteFileService.upload(file);
|
|
|
+ //logger.info("【调用算法服务】 原文件上传结果:"+JSONObject.toJSONString(r));
|
|
|
+ if (r.getCode() == 200) {
|
|
|
+ orgImgUrl = r.getData().getUrl();
|
|
|
+ }
|
|
|
String labSkipped = "0";
|
|
|
String labCheckCount = "2";
|
|
|
Object labSkippedObj = map.get("skipped");
|
|
|
@@ -129,28 +136,32 @@ public class CheckService {
|
|
|
AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(code));
|
|
|
MultiValueMap<String, Object> params = getStringObjectMultiValueMap(checkValid, String.valueOf(id));
|
|
|
HttpEntity<MultiValueMap<String, Object>> files = getHttpEntityMap(toFile, params);
|
|
|
- //logger.info("===============4=================");
|
|
|
+ //添加一条算法请求记录
|
|
|
+ R alg = insertRequestRecordLog(orgImgUrl, subId, checkValid);
|
|
|
+ logger.info("【调用算法服务】 添加算法调用日志,添加结果:"+JSONObject.toJSONString(alg));
|
|
|
ImgPostResponse<AnalysisReturnData> send = HttpUtils.sendV5(restTemplateLocal, files, algorithmYml);
|
|
|
+ //算法记录更新
|
|
|
+ if (alg.getCode() == 200) {
|
|
|
+ try {
|
|
|
+ updateRequestRecordLog(alg.getData() != null?Long.valueOf(alg.getData()+""):null, send);
|
|
|
+ logger.info("【调用算法服务】 更新算法调用日志");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("【调用算法服务】 更新日志异常,异常信息",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断算法
|
|
|
if (send == null || send.getStatus_code() != 1000) {
|
|
|
assert send != null;
|
|
|
- //logger.error("==================4.1==================="+send.getStatus_code()+"==========="+send.getMessage());
|
|
|
+ logger.error("【调用算法服务】 算法服务调用失败,响应信息:"+ JSONObject.toJSONString(send));
|
|
|
return R.fail("算法服务错误,请重试!");
|
|
|
}
|
|
|
- //logger.info("===============5=================");
|
|
|
- R algorithm = saveAlgorithmV5(send, checkValid);
|
|
|
- if (algorithm.getCode() != 200) {
|
|
|
- //logger.error("==============="+algorithm.getCode()+"=================");
|
|
|
- return algorithm;
|
|
|
- }
|
|
|
- //logger.info("===============6=================");
|
|
|
AnalysisReturnData data = send.getData();
|
|
|
Map<String, Object> result = (Map<String, Object>) data.getResult();
|
|
|
- //logger.info("=========================7==============="+result.toString());
|
|
|
Map<String, Object> algorithmData = (Map<String, Object>) result.get("algorithm_data");
|
|
|
Map<String, Object> modelResult = (Map<String, Object>) result.get("model_data");
|
|
|
List<Map<String, Object>> objects = (List<Map<String, Object>>) modelResult.get("objects");
|
|
|
- logger.info("============算法请求日志打印:算法ID:{},请求结果:{}", code, algorithmData.getOrDefault("is_alert", ""));
|
|
|
- //通过的
|
|
|
+ logger.info("【调用算法服务】 算法请求日志打印:算法ID:{},请求结果:{}", code, algorithmData.getOrDefault("is_alert", ""));
|
|
|
+ //通过
|
|
|
if (algorithmData.getOrDefault("is_alert", "").toString().equals("false") && !objects.isEmpty()) {
|
|
|
alarmNum++;
|
|
|
} else {
|
|
|
@@ -176,13 +187,81 @@ public class CheckService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("e.getMessage:"+e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
+ logger.error("【算法服务异常】异常信息",e);
|
|
|
}
|
|
|
return R.fail();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 添加日志记录
|
|
|
+ * @param fileUrl
|
|
|
+ * @param subId
|
|
|
+ * @param checkValid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private R<Long> insertRequestRecordLog(String fileUrl, Long subId, AlgorithmYml.CheckValid checkValid) {
|
|
|
+ Algorithm algorithm = new Algorithm();
|
|
|
+ algorithm.setOriginalImg(fileUrl);
|
|
|
+ algorithm.setSubId(subId);
|
|
|
+ algorithm.setAlgorithmType("image");
|
|
|
+ algorithm.setAlgorithmName(checkValid.getAlgorithmName());
|
|
|
+ //logger.info("【算法服务】 添加日志记录实体:"+JSONObject.toJSONString(algorithm));
|
|
|
+ return laboratoryService.saveAlgorithmData(algorithm);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 算法调用日志更新
|
|
|
+ * @param id
|
|
|
+ * @param send
|
|
|
+ */
|
|
|
+ private void updateRequestRecordLog(Long id,ImgPostResponse<AnalysisReturnData> send) {
|
|
|
+ Algorithm algorithm = new Algorithm();
|
|
|
+ algorithm.setId(id);
|
|
|
+ //请求成功
|
|
|
+ if (send != null && send.getStatus_code() == 1000) {
|
|
|
+ AnalysisReturnData data = send.getData();
|
|
|
+ //识别后的图片
|
|
|
+ String picture = data.getRet_image();
|
|
|
+ String header = "data:image/jpeg;base64,"+picture;
|
|
|
+ MultipartFile multipartFile = Base64DecodedMultipartFile.base64ToMultipart(header);
|
|
|
+ R<SysFile> sysFileR = remoteFileService.upload(multipartFile);
|
|
|
+ String imageUrl = sysFileR.getData().getUrl();
|
|
|
+ algorithm.setAlgorithmResult(imageUrl);
|
|
|
+ //识别id
|
|
|
+ algorithm.setSignId(Long.parseLong(data.getCid()));
|
|
|
+ //是否报警
|
|
|
+ Map<String, Object> result =(Map<String, Object>)data.getResult();
|
|
|
+ Map<String, Object> algorithmData = (Map<String, Object>) result.get("algorithm_data");
|
|
|
+ Map<String, Object> modelResult = (Map<String, Object>) result.get("model_data");
|
|
|
+ List<Map<String, Object>> objects = (List<Map<String, Object>>) modelResult.get("objects");
|
|
|
+ if(algorithmData.getOrDefault("is_alert", "").toString().equals("false") && objects.size()>0){
|
|
|
+ algorithm.setIsAlarm(0);
|
|
|
+ }else{
|
|
|
+ algorithm.setIsAlarm(1);
|
|
|
+ }
|
|
|
+ algorithm.setStatus(1);
|
|
|
+ } else {
|
|
|
+ algorithm.setStatus(0);
|
|
|
+ }
|
|
|
+ //存原始数据
|
|
|
+ AnalysisReturnData respData = send != null?send.getData():null;
|
|
|
+ if (respData != null) {
|
|
|
+ respData.setRet_image("Removed to save respBody");
|
|
|
+ respData.setSrc_image("Removed to save respBody");
|
|
|
+ ImgPostResponse<AnalysisReturnData> response = new ImgPostResponse<>();
|
|
|
+ response.setData(respData);
|
|
|
+ response.setStatus_code(send.getStatus_code());
|
|
|
+ response.setMessage(send.getMessage());
|
|
|
+ algorithm.setRespData(JSONObject.toJSONString(response));
|
|
|
+ algorithm.setRespCode(send.getStatus_code());
|
|
|
+ }
|
|
|
+ algorithm.setUpdateTime(new Date());
|
|
|
+ //logger.info("【算法服务】 更新日志实体信息:"+JSONObject.toJSONString(algorithm));
|
|
|
+ laboratoryService.update(algorithm);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* @param id 进出记录ID
|
|
|
*/
|
|
|
public R checkAndCommit(String code, MultipartFile file, Long id) {
|
|
|
@@ -239,20 +318,8 @@ public class CheckService {
|
|
|
apply = R.fail("算法服务返回数据错误,请联系管理员!");
|
|
|
return apply;
|
|
|
} finally {
|
|
|
-// //无论成功失败,插入记录数据,异步请求远程接口
|
|
|
+ //无论成功失败,插入记录数据,异步请求远程接口
|
|
|
send(code, id, f, apply.getMsg());
|
|
|
-// //保存识别记录
|
|
|
-// String r = send == null ? null : send.toJSONString();
|
|
|
-// sendSginAccessLogService.saveAlgorithmResult(cereataAlgorithm(r, "image", f, apply.getMsg(), id, fail.getData()));
|
|
|
-// //持久化
|
|
|
-// Map<String, Object> data = (Map<String, Object>) send.get("data");
|
|
|
-// /* Object srcImage = data.get("src_image");
|
|
|
-// String srcImg = this.generateImage(srcImage.toString(),algorithmYml.getImgTemp());*/
|
|
|
-// data.put("src_img", fileR.getData().getUrl());
|
|
|
-// data.put("type", "image");
|
|
|
-// data.put("algorithmName", checkValid.getAlgorithmName());
|
|
|
-//// restTemplateLocal.postForEntity("http://192.168.1.17:9218/algorithm/save",data,String.class).getBody();
|
|
|
-// laboratoryService.saveData(Covert(data));
|
|
|
}
|
|
|
//=========算法服务返回结果验证结束
|
|
|
logger.info(apply.toString());
|
|
|
@@ -263,7 +330,6 @@ public class CheckService {
|
|
|
return apply;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 三合一
|
|
|
*
|
|
|
@@ -299,17 +365,20 @@ public class CheckService {
|
|
|
|
|
|
public Algorithm CovertV5(Map<String, Object> data) {
|
|
|
Algorithm algorithm = new Algorithm();
|
|
|
+ algorithm.setId(Long.valueOf(data.get("id").toString()));
|
|
|
algorithm.setAlgorithmType(data.get("type").toString());
|
|
|
algorithm.setAlgorithmResult(data.get("src_img").toString());
|
|
|
algorithm.setSubId(Long.valueOf(data.get("aid").toString()));
|
|
|
algorithm.setSignId(Long.valueOf(data.get("cid").toString()));
|
|
|
algorithm.setAlgorithmName(data.get("algorithmName").toString());
|
|
|
algorithm.setIsAlarm(Integer.parseInt(data.get("isAlarm").toString()));
|
|
|
+ algorithm.setOriginalImg(data.get("originalImg").toString());
|
|
|
+ algorithm.setRespData(data.get("requestData").toString());
|
|
|
+ algorithm.setUpdateTime(new Date());
|
|
|
algorithm.setStatus(0);
|
|
|
return algorithm;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* @param algorithmResult
|
|
|
* @param type
|
|
|
@@ -567,7 +636,7 @@ public class CheckService {
|
|
|
* @param send
|
|
|
* @param checkValid
|
|
|
*/
|
|
|
- private R saveAlgorithmV5(ImgPostResponse<AnalysisReturnData> send,AlgorithmYml.CheckValid checkValid){
|
|
|
+ private R saveAlgorithmV5(Long id,MultipartFile file,ImgPostResponse<AnalysisReturnData> send,AlgorithmYml.CheckValid checkValid){
|
|
|
String picture = send.getData().getRet_image();
|
|
|
String header = "data:image/jpeg;base64,"+picture;
|
|
|
MultipartFile multipartFile = Base64DecodedMultipartFile.base64ToMultipart(header);
|
|
|
@@ -589,9 +658,13 @@ public class CheckService {
|
|
|
map.put("aid", data.getAid());
|
|
|
map.put("cid", data.getCid());
|
|
|
map.put("src_img", imageUrl);
|
|
|
+ //map.put("originalImg", originalUrl);
|
|
|
map.put("type", "image");
|
|
|
map.put("algorithmName", checkValid.getAlgorithmName());
|
|
|
+ map.put("id",id);
|
|
|
+ map.put("requestData", JSONObject.toJSONString(send));
|
|
|
logger.info("=======================map.tostring()"+map.toString());
|
|
|
return laboratoryService.saveAlgorithmData(CovertV5(map));
|
|
|
+ // return laboratoryService.update(CovertV5(map));
|
|
|
}
|
|
|
}
|