|
@@ -23,6 +23,7 @@ import com.zd.common.core.utils.ServletUtils;
|
|
|
import com.zd.common.core.utils.StringUtils;
|
|
import com.zd.common.core.utils.StringUtils;
|
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
|
import com.zd.model.constant.BaseConstants;
|
|
import com.zd.model.constant.BaseConstants;
|
|
|
|
|
+import com.zd.model.constant.HttpStatus;
|
|
|
import com.zd.model.constant.SecurityConstants;
|
|
import com.zd.model.constant.SecurityConstants;
|
|
|
import com.zd.model.domain.R;
|
|
import com.zd.model.domain.R;
|
|
|
import com.zd.model.entity.Algorithm;
|
|
import com.zd.model.entity.Algorithm;
|
|
@@ -95,15 +96,9 @@ public class CheckService {
|
|
|
public R checkAndCommit(Long id, MultipartFile file, Long subId) {
|
|
public R checkAndCommit(Long id, MultipartFile file, Long subId) {
|
|
|
try {
|
|
try {
|
|
|
int alarmNum = 0;
|
|
int alarmNum = 0;
|
|
|
- //========= 请求超时验证部分开始 ===========
|
|
|
|
|
- //600 则代表退出验证流程 需要重新刷卡
|
|
|
|
|
- R<Long> fail = getObjectR(id);
|
|
|
|
|
- if (fail.getCode() != 200) {
|
|
|
|
|
- return fail;
|
|
|
|
|
- }
|
|
|
|
|
//根据实验室id查询检查项
|
|
//根据实验室id查询检查项
|
|
|
R<Map<Object, Object>> subject = laboratoryService.getCheckInfo(subId);
|
|
R<Map<Object, Object>> subject = laboratoryService.getCheckInfo(subId);
|
|
|
- if (subject.getCode() != 200) {
|
|
|
|
|
|
|
+ if (subject.getCode() != HttpStatus.SUCCESS) {
|
|
|
return subject;
|
|
return subject;
|
|
|
}
|
|
}
|
|
|
Map<Object, Object> map = subject.getData();
|
|
Map<Object, Object> map = subject.getData();
|
|
@@ -114,8 +109,7 @@ public class CheckService {
|
|
|
//上传原始图片
|
|
//上传原始图片
|
|
|
String orgImgUrl = "";
|
|
String orgImgUrl = "";
|
|
|
R<SysFile> r = remoteFileService.upload(file);
|
|
R<SysFile> r = remoteFileService.upload(file);
|
|
|
- //logger.info("【调用算法服务】 原文件上传结果:"+JSONObject.toJSONString(r));
|
|
|
|
|
- if (r.getCode() == 200) {
|
|
|
|
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS) {
|
|
|
orgImgUrl = r.getData().getUrl();
|
|
orgImgUrl = r.getData().getUrl();
|
|
|
}
|
|
}
|
|
|
String labSkipped = "0";
|
|
String labSkipped = "0";
|
|
@@ -142,12 +136,8 @@ public class CheckService {
|
|
|
ImgPostResponse<AnalysisReturnData> send = HttpUtils.sendV5(restTemplateLocal, files, algorithmYml);
|
|
ImgPostResponse<AnalysisReturnData> send = HttpUtils.sendV5(restTemplateLocal, files, algorithmYml);
|
|
|
//算法记录更新
|
|
//算法记录更新
|
|
|
if (alg.getCode() == 200) {
|
|
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, send);
|
|
|
|
|
+ logger.info("【调用算法服务】 更新算法调用日志记录");
|
|
|
}
|
|
}
|
|
|
//判断算法
|
|
//判断算法
|
|
|
if (send == null || send.getStatus_code() != 1000) {
|
|
if (send == null || send.getStatus_code() != 1000) {
|
|
@@ -187,7 +177,7 @@ public class CheckService {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- logger.error("【算法服务异常】异常信息",e);
|
|
|
|
|
|
|
+ logger.error("【调用算法服务】 算法服务调用发生异常", e);
|
|
|
}
|
|
}
|
|
|
return R.fail();
|
|
return R.fail();
|
|
|
}
|
|
}
|
|
@@ -245,16 +235,23 @@ public class CheckService {
|
|
|
algorithm.setStatus(0);
|
|
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));
|
|
|
|
|
|
|
+ if (send != null) {
|
|
|
|
|
+ if (send.getData() != null) {
|
|
|
|
|
+ AnalysisReturnData respData = send.getData();
|
|
|
|
|
+ respData.setRet_image("");
|
|
|
|
|
+ respData.setSrc_image("");
|
|
|
|
|
+ ImgPostResponse<AnalysisReturnData> response = new ImgPostResponse<>();
|
|
|
|
|
+ response.setData(respData);
|
|
|
|
|
+ response.setStatus_code(send.getStatus_code());
|
|
|
|
|
+ response.setMessage(send.getMessage());
|
|
|
|
|
+ algorithm.setRespData(JSONObject.toJSONString(response));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ algorithm.setRespData(JSONObject.toJSONString(send));
|
|
|
|
|
+ }
|
|
|
algorithm.setRespCode(send.getStatus_code());
|
|
algorithm.setRespCode(send.getStatus_code());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ algorithm.setRespCode(0L);
|
|
|
|
|
+ algorithm.setRespData("算法服务未响应");
|
|
|
}
|
|
}
|
|
|
algorithm.setUpdateTime(new Date());
|
|
algorithm.setUpdateTime(new Date());
|
|
|
//logger.info("【算法服务】 更新日志实体信息:"+JSONObject.toJSONString(algorithm));
|
|
//logger.info("【算法服务】 更新日志实体信息:"+JSONObject.toJSONString(algorithm));
|
|
@@ -265,13 +262,7 @@ public class CheckService {
|
|
|
* @param id 进出记录ID
|
|
* @param id 进出记录ID
|
|
|
*/
|
|
*/
|
|
|
public R checkAndCommit(String code, MultipartFile file, Long id) {
|
|
public R checkAndCommit(String code, MultipartFile file, Long id) {
|
|
|
- //========= 请求超时验证部分开始 ===========
|
|
|
|
|
- //600 则代表退出验证流程 需要重新刷卡
|
|
|
|
|
- R<Long> fail = getObjectR(id);
|
|
|
|
|
- if (fail.getCode() != 200) {
|
|
|
|
|
- return fail;
|
|
|
|
|
- }
|
|
|
|
|
- //========= 请求超时验证部分结束 ===========
|
|
|
|
|
|
|
+
|
|
|
//========= 获取算法INFO ===========
|
|
//========= 获取算法INFO ===========
|
|
|
AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(code));
|
|
AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(code));
|
|
|
//=========发送验证信息到算法服务开始
|
|
//=========发送验证信息到算法服务开始
|
|
@@ -363,22 +354,6 @@ public class CheckService {
|
|
|
return algorithm;
|
|
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 algorithmResult
|
|
|
* @param type
|
|
* @param type
|
|
@@ -453,25 +428,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个方法测试
|
|
//给黎晨用的模拟方法 他让给他mock个方法测试
|
|
|
public R mockTest(String code, MultipartFile file, Long id) {
|
|
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;
|
|
Boolean f = RandomUtil.randomInt(0, 2) == 0;
|
|
|
//无论成功失败,插入记录数据,异步请求远程接口
|
|
//无论成功失败,插入记录数据,异步请求远程接口
|
|
@@ -493,7 +451,6 @@ public class CheckService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void send(String code, Long id, Boolean f, String msg) {
|
|
public void send(String code, Long id, Boolean f, String msg) {
|
|
|
String token = Objects.requireNonNull(ServletUtils.getRequest()).getHeader(SecurityConstants.TOKEN_AUTHENTICATION);
|
|
String token = Objects.requireNonNull(ServletUtils.getRequest()).getHeader(SecurityConstants.TOKEN_AUTHENTICATION);
|
|
|
if (CharSequenceUtil.isBlank(token)) {
|
|
if (CharSequenceUtil.isBlank(token)) {
|
|
@@ -591,80 +548,4 @@ public class CheckService {
|
|
|
return null;
|
|
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));
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|