|
|
@@ -3,7 +3,6 @@ package com.zd.alg.forward.serivce;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zd.alg.forward.config.AlgorithmYml;
|
|
|
import com.zd.alg.forward.domain.*;
|
|
|
@@ -23,6 +22,7 @@ import com.zd.common.core.utils.ServletUtils;
|
|
|
import com.zd.common.core.utils.StringUtils;
|
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
|
import com.zd.model.constant.BaseConstants;
|
|
|
+import com.zd.model.constant.HttpStatus;
|
|
|
import com.zd.model.constant.SecurityConstants;
|
|
|
import com.zd.model.domain.R;
|
|
|
import com.zd.model.entity.Algorithm;
|
|
|
@@ -56,11 +56,6 @@ public class CheckService {
|
|
|
Logger logger = LoggerFactory.getLogger(CheckService.class);
|
|
|
@Resource(name = "restTemplateLocal")
|
|
|
private RestTemplate restTemplateLocal;
|
|
|
- /**
|
|
|
- * 上传文件存储在本地的根路径
|
|
|
- */
|
|
|
- @Value("${file.path:/home/AIPIC}")
|
|
|
- private String localFilePath;
|
|
|
|
|
|
@Autowired
|
|
|
private AlgorithmYml algorithmYml;
|
|
|
@@ -95,15 +90,9 @@ public class CheckService {
|
|
|
public R checkAndCommit(Long id, MultipartFile file, Long subId) {
|
|
|
try {
|
|
|
int alarmNum = 0;
|
|
|
- //========= 请求超时验证部分开始 ===========
|
|
|
- //600 则代表退出验证流程 需要重新刷卡
|
|
|
- R<Long> fail = getObjectR(id);
|
|
|
- if (fail.getCode() != 200) {
|
|
|
- return fail;
|
|
|
- }
|
|
|
//根据实验室id查询检查项
|
|
|
R<Map<Object, Object>> subject = laboratoryService.getCheckInfo(subId);
|
|
|
- if (subject.getCode() != 200) {
|
|
|
+ if (subject.getCode() != HttpStatus.SUCCESS) {
|
|
|
return subject;
|
|
|
}
|
|
|
Map<Object, Object> map = subject.getData();
|
|
|
@@ -114,8 +103,7 @@ public class CheckService {
|
|
|
//上传原始图片
|
|
|
String orgImgUrl = "";
|
|
|
R<SysFile> r = remoteFileService.upload(file);
|
|
|
- //logger.info("【调用算法服务】 原文件上传结果:"+JSONObject.toJSONString(r));
|
|
|
- if (r.getCode() == 200) {
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS) {
|
|
|
orgImgUrl = r.getData().getUrl();
|
|
|
}
|
|
|
String labSkipped = "0";
|
|
|
@@ -139,60 +127,106 @@ public class CheckService {
|
|
|
//添加一条算法请求记录
|
|
|
R alg = insertRequestRecordLog(orgImgUrl, subId, checkValid);
|
|
|
logger.info("【调用算法服务】 添加算法调用日志,添加结果:"+JSONObject.toJSONString(alg));
|
|
|
+
|
|
|
+ //请求算法服务
|
|
|
ImgPostResponse<AnalysisReturnData> send = HttpUtils.sendV5(restTemplateLocal, files, algorithmYml);
|
|
|
- //算法记录更新
|
|
|
+ AlgorithmResponseResult responseResult = getResponseResult(send);
|
|
|
+ //添加成功,更新算法日志记录
|
|
|
if (alg.getCode() == 200) {
|
|
|
- try {
|
|
|
- updateRequestRecordLog(alg.getData() != null?Long.valueOf(alg.getData()+""):null, send);
|
|
|
- logger.info("【调用算法服务】 更新算法调用日志");
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("【调用算法服务】 更新日志异常,异常信息",e);
|
|
|
- }
|
|
|
+ updateRequestRecordLog(alg.getData() != null?Long.valueOf(alg.getData()+""):null, responseResult);
|
|
|
+ logger.info("【调用算法服务】 更新算法调用日志记录");
|
|
|
}
|
|
|
//判断算法
|
|
|
- if (send == null || send.getStatus_code() != 1000) {
|
|
|
- assert send != null;
|
|
|
- logger.error("【调用算法服务】 算法服务调用失败,响应信息:"+ JSONObject.toJSONString(send));
|
|
|
- return R.fail("算法服务错误,请重试!");
|
|
|
- }
|
|
|
- AnalysisReturnData data = send.getData();
|
|
|
- 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");
|
|
|
- logger.info("【调用算法服务】 算法请求日志打印:算法ID:{},请求结果:{}", code, algorithmData.getOrDefault("is_alert", ""));
|
|
|
- //通过
|
|
|
- if (algorithmData.getOrDefault("is_alert", "").toString().equals("false") && !objects.isEmpty()) {
|
|
|
- alarmNum++;
|
|
|
- } else {
|
|
|
- //不跳过
|
|
|
- if (StringUtils.isNotEmpty(labSkipped) && labSkipped.equals("1")) {
|
|
|
- //如果没有通过则次数加一
|
|
|
- //键为前缀+签到id +下划线+验证类型
|
|
|
- String key = BaseConstants.SINGIN_CHECK_JUMP_KEY + id + "_" + code;
|
|
|
- Long increment = redisTemplate.opsForValue().increment(key);
|
|
|
- redisService.expire(key, BaseConstants.SINGIN_OUT_TIME);
|
|
|
- if (increment != null && increment >= Integer.parseInt(labCheckCount)) {
|
|
|
- //黎晨这里让把跳过时状态码改为700,所以700的含义为检查失败并且跳过
|
|
|
- return R.fail(700, "符合跳过条件执行跳过");
|
|
|
+ if (responseResult.getCode() == 1000) {
|
|
|
+ //通过
|
|
|
+ if (responseResult.getIsPass()) {
|
|
|
+ alarmNum++;
|
|
|
+ } else {
|
|
|
+ //不跳过
|
|
|
+ if (StringUtils.isNotEmpty(labSkipped) && labSkipped.equals("1")) {
|
|
|
+ //如果没有通过则次数加一
|
|
|
+ //键为前缀+签到id +下划线+验证类型
|
|
|
+ String key = BaseConstants.SINGIN_CHECK_JUMP_KEY + id + "_" + code;
|
|
|
+ Long increment = redisTemplate.opsForValue().increment(key);
|
|
|
+ redisService.expire(key, BaseConstants.SINGIN_OUT_TIME);
|
|
|
+ if (increment != null && increment >= Integer.parseInt(labCheckCount)) {
|
|
|
+ //黎晨这里让把跳过时状态码改为700,所以700的含义为检查失败并且跳过
|
|
|
+ return R.fail(700, "符合跳过条件执行跳过");
|
|
|
+ }
|
|
|
}
|
|
|
+ return R.fail(300, "算法识别未通过", code);
|
|
|
}
|
|
|
- return R.fail(300, "算法识别未通过", code);
|
|
|
+ Boolean f = send.getStatus_code() == 1000;
|
|
|
+ String msg = f ? "解析成功!" : "解析失败!";
|
|
|
+ send(code, id, f, msg);
|
|
|
+ } else {
|
|
|
+ assert send != null;
|
|
|
+ //logger.error("【调用算法服务】 算法服务调用失败,响应信息:"+ JSONObject.toJSONString(send));
|
|
|
+ return R.fail("算法服务错误,请重试!");
|
|
|
}
|
|
|
- Boolean f = send.getStatus_code() == 1000;
|
|
|
- String msg = f ? "解析成功!" : "解析失败!";
|
|
|
- send(code, id, f, msg);
|
|
|
}
|
|
|
if (alarmNum == checkItem.length) {
|
|
|
return R.ok();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- logger.error("【算法服务异常】异常信息",e);
|
|
|
+ logger.error("【调用算法服务】 算法服务调用发生异常", e);
|
|
|
}
|
|
|
return R.fail();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取响应结果
|
|
|
+ * @param send
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AlgorithmResponseResult getResponseResult(ImgPostResponse<AnalysisReturnData> send) {
|
|
|
+ AlgorithmResponseResult responseResult = new AlgorithmResponseResult();
|
|
|
+ if (send != null) {
|
|
|
+ responseResult.setCode(send.getStatus_code());
|
|
|
+ responseResult.setMessage(send.getMessage());
|
|
|
+ if (send.getStatus_code() == 1000 && send.getData() != null) {
|
|
|
+ AnalysisReturnData data = send.getData();
|
|
|
+ responseResult.setAid(data.getAid());
|
|
|
+ responseResult.setCid(data.getCid());
|
|
|
+ responseResult.setRetImage(data.getRet_image());
|
|
|
+ responseResult.setSrcImage(data.getSrc_image());
|
|
|
+ //检查结果
|
|
|
+ JSONObject result = (JSONObject) data.getResult();
|
|
|
+ JSONObject algorithmData = result.getJSONObject("algorithm_data");
|
|
|
+ JSONObject model = result.getJSONObject("model_data");
|
|
|
+ List<Object> objects = model.getJSONArray("objects");
|
|
|
+ //是否验证通过
|
|
|
+ //if(!algorithmData.getBoolean("is_alert") && objects.size()>0){
|
|
|
+ //算法厂家技术人员前期要添加objects判断精准性,后面对接人员要让去掉对objects的判断
|
|
|
+ if (!algorithmData.getBoolean("is_alert")) {
|
|
|
+ //不报警,代表验证通过
|
|
|
+ responseResult.setIsPass(Boolean.TRUE);
|
|
|
+ } else {
|
|
|
+ //报警,代表不通过
|
|
|
+ responseResult.setIsPass(Boolean.FALSE);
|
|
|
+ }
|
|
|
+ responseResult.setObjects(objects);
|
|
|
+ //存响应实体数据,去掉图片
|
|
|
+ data.setRet_image("");
|
|
|
+ data.setSrc_image("");
|
|
|
+ ImgPostResponse<AnalysisReturnData> response = new ImgPostResponse<>();
|
|
|
+ response.setData(data);
|
|
|
+ response.setStatus_code(send.getStatus_code());
|
|
|
+ response.setMessage(send.getMessage());
|
|
|
+ responseResult.setResponseBody(JSONObject.toJSONString(response));
|
|
|
+ } else {
|
|
|
+ responseResult.setResponseBody(JSONObject.toJSONString(send));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ responseResult.setCode(0L);
|
|
|
+ responseResult.setMessage("算法服务未响应");
|
|
|
+ responseResult.setResponseBody("算法服务未响应");
|
|
|
+ }
|
|
|
+ logger.info("【调用算法服务】 算法服务请求结果:code = {}, message = {}, isPass = {}", responseResult.getCode(), responseResult.getMessage(), responseResult.getIsPass());
|
|
|
+ return responseResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加日志记录
|
|
|
* @param fileUrl
|
|
|
* @param subId
|
|
|
@@ -213,96 +247,74 @@ public class CheckService {
|
|
|
/**
|
|
|
* 算法调用日志更新
|
|
|
* @param id
|
|
|
- * @param send
|
|
|
+ * @param responseResult
|
|
|
*/
|
|
|
- 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);
|
|
|
+ private void updateRequestRecordLog(Long id, AlgorithmResponseResult responseResult) {
|
|
|
+ try {
|
|
|
+ Algorithm algorithm = new Algorithm();
|
|
|
+ algorithm.setId(id);
|
|
|
+ if (responseResult.getCode() == 1000) {
|
|
|
+ //识别后的图片
|
|
|
+ String picture = responseResult.getRetImage();
|
|
|
+ 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(responseResult.getCid()));
|
|
|
+ //是否通过
|
|
|
+ algorithm.setIsAlarm(responseResult.getIsPass()?0:1);
|
|
|
+ algorithm.setStatus(1);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ algorithm.setStatus(0);
|
|
|
}
|
|
|
- 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.setRespData(responseResult.getResponseBody());
|
|
|
+ algorithm.setRespCode(responseResult.getCode());
|
|
|
+ algorithm.setUpdateTime(new Date());
|
|
|
+ //logger.info("【算法服务】 更新日志实体信息:"+JSONObject.toJSONString(algorithm));
|
|
|
+ laboratoryService.update(algorithm);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("【调用算法服务】调用算法服务后,更新日志记录发生异常", e);
|
|
|
}
|
|
|
- algorithm.setUpdateTime(new Date());
|
|
|
- //logger.info("【算法服务】 更新日志实体信息:"+JSONObject.toJSONString(algorithm));
|
|
|
- laboratoryService.update(algorithm);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param id 进出记录ID
|
|
|
*/
|
|
|
public R checkAndCommit(String code, MultipartFile file, Long id) {
|
|
|
- //========= 请求超时验证部分开始 ===========
|
|
|
- //600 则代表退出验证流程 需要重新刷卡
|
|
|
- R<Long> fail = getObjectR(id);
|
|
|
- if (fail.getCode() != 200) {
|
|
|
- return fail;
|
|
|
+ //上传原始图片
|
|
|
+ String orgImgUrl = "";
|
|
|
+ R<SysFile> r = remoteFileService.upload(file);
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS) {
|
|
|
+ orgImgUrl = r.getData().getUrl();
|
|
|
}
|
|
|
- //========= 请求超时验证部分结束 ===========
|
|
|
//========= 获取算法INFO ===========
|
|
|
AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(code));
|
|
|
- //=========发送验证信息到算法服务开始
|
|
|
- JSONObject send = null;
|
|
|
- try {
|
|
|
- send = send(file, checkValid, id);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
+ //添加一条算法请求记录
|
|
|
+ R alg = insertRequestRecordLog(orgImgUrl, 0L, checkValid);
|
|
|
+ logger.info("【调用算法服务】 添加算法调用日志,添加结果:"+JSONObject.toJSONString(alg));
|
|
|
+
|
|
|
+ File toFile = multipartFileToFile(file);
|
|
|
+ //请求算法服务
|
|
|
+ MultiValueMap<String, Object> params = getStringObjectMultiValueMap(checkValid, String.valueOf(id));
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> files = getHttpEntityMap(toFile, params);
|
|
|
+ ImgPostResponse<AnalysisReturnData> send = HttpUtils.sendV5(restTemplateLocal, files, algorithmYml);
|
|
|
+ AlgorithmResponseResult responseResult = getResponseResult(send);
|
|
|
+ //添加成功,更新算法日志记录
|
|
|
+ if (alg.getCode() == 200) {
|
|
|
+ updateRequestRecordLog(alg.getData() != null?Long.valueOf(alg.getData()+""):null, responseResult);
|
|
|
+ logger.info("【调用算法服务】 更新算法调用日志记录");
|
|
|
}
|
|
|
- //=========发送验证信息到算法服务结束
|
|
|
- //=========算法服务返回结果验证开始
|
|
|
- R apply = R.fail("算法服务错误,请重试!");
|
|
|
- Boolean f = false;
|
|
|
- try {
|
|
|
- if (send == null || send.getInteger("status_code") != 1000L) {
|
|
|
- apply = R.fail("算法服务错误,请重试!");
|
|
|
- return apply;
|
|
|
- }
|
|
|
- Map<String, Object> result = null;
|
|
|
- try {
|
|
|
- result = send.getJSONObject("data").getJSONObject("result").getInnerMap();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- apply = R.fail("算法服务返回数据错误,请联系管理员!");
|
|
|
- return apply;
|
|
|
- }
|
|
|
- //todo 获取 检测结果
|
|
|
- apply = checkValid.getCheckResultValid().apply(result);
|
|
|
- f = apply.getCode() == 200;
|
|
|
- if (!f && algorithmYml.getJumpThreshold() != -1) {
|
|
|
+ //插入记录数据,异步请求远程接口
|
|
|
+ String msg = (responseResult.getCode() == 1000 && responseResult.getIsPass())?"解析成功":"解析失败";
|
|
|
+ send(code, id, responseResult.getIsPass(), msg);
|
|
|
+ //判断算法
|
|
|
+ if (responseResult.getCode() == 1000) {
|
|
|
+ boolean isPass = responseResult.getIsPass();
|
|
|
+ if (!isPass && algorithmYml.getJumpThreshold() != -1) {
|
|
|
//如果没有通过则次数加一
|
|
|
//键为前缀+签到id +下划线+验证类型
|
|
|
String key = BaseConstants.SINGIN_CHECK_JUMP_KEY + id + "_" + code;
|
|
|
@@ -310,47 +322,18 @@ public class CheckService {
|
|
|
redisService.expire(key, BaseConstants.SINGIN_OUT_TIME);
|
|
|
if (increment >= algorithmYml.getJumpThreshold()) {
|
|
|
//黎晨这里让把跳过时状态码改为700,所以700的含义为检查失败并且跳过
|
|
|
- apply.setCode(700);
|
|
|
+ return R.fail(700,"算法服务错误,请重试!");
|
|
|
}
|
|
|
}
|
|
|
- } catch (Exception ex) {
|
|
|
- ex.printStackTrace();
|
|
|
- apply = R.fail("算法服务返回数据错误,请联系管理员!");
|
|
|
- return apply;
|
|
|
- } finally {
|
|
|
- //无论成功失败,插入记录数据,异步请求远程接口
|
|
|
- send(code, id, f, apply.getMsg());
|
|
|
- }
|
|
|
- //=========算法服务返回结果验证结束
|
|
|
- logger.info(apply.toString());
|
|
|
- if (apply.getCode() == 200) {
|
|
|
- //加奖励分
|
|
|
- // laboratoryService.addRecord();
|
|
|
- }
|
|
|
- return apply;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 三合一
|
|
|
- *
|
|
|
- * @param ids
|
|
|
- * @param file
|
|
|
- * @param codes
|
|
|
- * @return
|
|
|
- */
|
|
|
- public R<Map<Object, String>> checkInAll(Long[] ids, MultipartFile file[], String codes) {
|
|
|
- Map<Object, String> result = new HashMap<>();
|
|
|
- String[] codesArrs = codes.split(",");
|
|
|
- for (int i = 0; i < codesArrs.length; i++) {
|
|
|
- R r = checkAndCommit(codesArrs[i], file[i], ids[i]);
|
|
|
- AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(codesArrs[i]));
|
|
|
- result.put(checkValid.getAlgoId(), r.getMsg() == null ? "通过" : r.getMsg());
|
|
|
-
|
|
|
+ if (responseResult.getIsPass()) {
|
|
|
+ //加奖励分
|
|
|
+ // laboratoryService.addRecord();
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
- return R.ok(result);
|
|
|
+ return R.fail("算法服务错误,请重试!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public Algorithm Covert(Map<String, Object> data) {
|
|
|
Algorithm algorithm = new Algorithm();
|
|
|
algorithm.setAlgorithmType(data.get("type").toString());
|
|
|
@@ -363,23 +346,6 @@ public class CheckService {
|
|
|
return algorithm;
|
|
|
}
|
|
|
|
|
|
- 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
|
|
|
@@ -454,25 +420,8 @@ public class CheckService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private R<Long> getObjectR(Long id) {
|
|
|
- Long subId = redisService.getCacheObject(BaseConstants.SINGIN_id_KEY + id);
|
|
|
- if (subId == null) {
|
|
|
- return R.fail(600, "签到&签出已超时,请重新刷卡重试!");
|
|
|
- }
|
|
|
- //刷新key
|
|
|
- boolean expire = redisService.expire(BaseConstants.SINGIN_id_KEY + id, 120);
|
|
|
- if (!expire) {
|
|
|
- return R.fail(600, "签到&签出已超时,请重新刷卡重试!");
|
|
|
- }
|
|
|
- return R.ok(subId);
|
|
|
- }
|
|
|
-
|
|
|
//给黎晨用的模拟方法 他让给他mock个方法测试
|
|
|
public R mockTest(String code, MultipartFile file, Long id) {
|
|
|
- R<Long> objectR = getObjectR(id);
|
|
|
- if (objectR.getCode() != 200) {
|
|
|
- return objectR;
|
|
|
- }
|
|
|
//随机成功或失败
|
|
|
Boolean f = RandomUtil.randomInt(0, 2) == 0;
|
|
|
//无论成功失败,插入记录数据,异步请求远程接口
|
|
|
@@ -494,7 +443,6 @@ public class CheckService {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public void send(String code, Long id, Boolean f, String msg) {
|
|
|
String token = Objects.requireNonNull(ServletUtils.getRequest()).getHeader(SecurityConstants.TOKEN_AUTHENTICATION);
|
|
|
if (CharSequenceUtil.isBlank(token)) {
|
|
|
@@ -504,26 +452,6 @@ public class CheckService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取算法请求地址
|
|
|
- *
|
|
|
- * @param checkValid
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String getPostUrl(AlgorithmYml.CheckValid checkValid, Long id) {
|
|
|
- //设置请求体,注意是LinkedMultiValueMap
|
|
|
- MultiValueMap<String, Object> params = getStringObjectMultiValueMap(checkValid, String.valueOf(id));
|
|
|
- Set<String> keySet = params.keySet();
|
|
|
- StringBuffer stb = new StringBuffer();
|
|
|
- for (String key : keySet) {
|
|
|
- stb.append("&" + key + "=" + params.get(key).get(0).toString());
|
|
|
- }
|
|
|
- String paramUrl = algorithmYml.getImgPostUrl() + String.valueOf(stb).replaceFirst("&", "?");
|
|
|
- logger.info(paramUrl);
|
|
|
- return paramUrl;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 图片算法请求参数
|
|
|
*
|
|
|
* @param file
|
|
|
@@ -531,17 +459,13 @@ public class CheckService {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
-
|
|
|
- public JSONObject send(MultipartFile file, AlgorithmYml.CheckValid checkValid, Long id) throws IOException {
|
|
|
+ public JSONObject send(MultipartFile file, AlgorithmYml.CheckValid checkValid, Long id) {
|
|
|
//设置请求头
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
- File uploadFile = null;
|
|
|
try {
|
|
|
- // 文件本地存储收集
|
|
|
- FileUploadUtils.upload(localFilePath, file);
|
|
|
//MultipartFile 转为临时文件
|
|
|
- uploadFile = multipartFileToFile(file);
|
|
|
+ File uploadFile = multipartFileToFile(file);
|
|
|
//文件转为文件系统资源
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(uploadFile);
|
|
|
//设置请求体,注意是LinkedMultiValueMap
|
|
|
@@ -552,15 +476,13 @@ public class CheckService {
|
|
|
//用HttpEntity封装整个请求报文
|
|
|
HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(params, headers);
|
|
|
String paramUrl = algorithmYml.getImgPostUrl();
|
|
|
- logger.info(paramUrl);
|
|
|
+ //logger.info(paramUrl);
|
|
|
JSONObject body = restTemplateLocal.postForObject(paramUrl, files, JSONObject.class);
|
|
|
- logger.info(body.toJSONString());
|
|
|
+ //logger.info(body.toJSONString());
|
|
|
return body;
|
|
|
- } finally {
|
|
|
- //删除临时文件
|
|
|
-// if (uploadFile != null) {
|
|
|
-// uploadFile.delete();
|
|
|
-// }
|
|
|
+ } catch (Exception e){
|
|
|
+ logger.error("【算法服务】 send方法执行异常,异常信息:",e);
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -592,80 +514,4 @@ public class CheckService {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 存储数据
|
|
|
- *
|
|
|
- * @param send
|
|
|
- * @param checkValid
|
|
|
- */
|
|
|
- private R saveAlgorithm(ImgPostResponse<DataPostAnalysisRespDto> send, AlgorithmYml.CheckValid checkValid) {
|
|
|
- DataPostAnalysisRespDto analysisRespDto = send.getData();
|
|
|
- List<AnalysisData> analysisDatas = analysisRespDto.getAnalysisDatas();
|
|
|
- if (!analysisDatas.isEmpty()) {
|
|
|
- for (AnalysisData data : analysisDatas) {
|
|
|
- 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();
|
|
|
- Map<String, Object> result = (Map<String, Object>) data.getResult();
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- 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) {
|
|
|
- map.put("isAlarm", 0);
|
|
|
- } else {
|
|
|
- map.put("isAlarm", 1);
|
|
|
- }
|
|
|
- map.put("did", checkValid.getDid());
|
|
|
- map.put("aid", checkValid.getAlgoId());
|
|
|
- map.put("src_img", imageUrl);
|
|
|
- map.put("type", "image");
|
|
|
- map.put("algorithmName", checkValid.getAlgorithmName());
|
|
|
- return laboratoryService.saveData(Covert(map));
|
|
|
- }
|
|
|
- }
|
|
|
- logger.error("接口数据返回异常");
|
|
|
- throw new ServiceException("接口数据返回异常");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 存储数据
|
|
|
- * @param send
|
|
|
- * @param 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);
|
|
|
- R<SysFile> sysFileR = remoteFileService.upload(multipartFile);
|
|
|
- String imageUrl = sysFileR.getData().getUrl();
|
|
|
- logger.info("==================================imageUrl:"+imageUrl);
|
|
|
- AnalysisReturnData data = send.getData();
|
|
|
- Map<String, Object> map =new HashMap<>();
|
|
|
- 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){
|
|
|
- map.put("isAlarm", 0);
|
|
|
- }else{
|
|
|
- map.put("isAlarm", 1);
|
|
|
- }
|
|
|
- map.put("isAlarm", 1);
|
|
|
- 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));
|
|
|
- }
|
|
|
}
|