|
|
@@ -20,6 +20,7 @@ import com.zd.forward.domain.VideoRequestData;
|
|
|
import com.zd.forward.serivce.mqtt.CommonSend;
|
|
|
import com.zd.forward.util.Base64DecodedMultipartFile;
|
|
|
import com.zd.forward.util.FileUploadUtils;
|
|
|
+import com.zd.forward.util.HttpUtils;
|
|
|
import com.zd.system.api.RemoteFileService;
|
|
|
import com.zd.system.api.alarm.RemoteAlarmService;
|
|
|
import com.zd.system.api.alarm.domain.AlarmEntrty;
|
|
|
@@ -54,6 +55,8 @@ import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import static com.zd.forward.util.HttpUtils.*;
|
|
|
+
|
|
|
@Service
|
|
|
@EnableConfigurationProperties(AlgorithmYml.class)
|
|
|
@RefreshScope
|
|
|
@@ -125,10 +128,10 @@ public class CheckService {
|
|
|
String[] checkItem = labCheckIn.split(",");
|
|
|
for (String code : checkItem) {
|
|
|
//========= 获取算法INFO ===========
|
|
|
- AlgorithmYml.CheckValid checkValid = getCheckValid(Integer.valueOf(code));
|
|
|
+ AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(code));
|
|
|
MultiValueMap<String, Object> params = getStringObjectMultiValueMap(checkValid, String.valueOf(id));
|
|
|
HttpEntity<MultiValueMap<String, Object>> files=getHttpEntityMap(file,params);
|
|
|
- ImgPostResponse<DataPostAnalysisRespDto> send = send(files, checkValid, id);
|
|
|
+ ImgPostResponse<DataPostAnalysisRespDto> send = HttpUtils.send(restTemplateLocal,files,algorithmYml);
|
|
|
if (send == null || send.getStatus_code() != 1000) {
|
|
|
assert send != null;
|
|
|
logger.error(send.getMessage());
|
|
|
@@ -175,10 +178,7 @@ public class CheckService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param code
|
|
|
- * @param file
|
|
|
* @param id 进出记录ID
|
|
|
- * @return
|
|
|
*/
|
|
|
public R checkAndCommit(String code, MultipartFile file, Long id) {
|
|
|
//========= 请求超时验证部分开始 ===========
|
|
|
@@ -187,7 +187,7 @@ public class CheckService {
|
|
|
if (fail.getCode() != 200) return fail;
|
|
|
//========= 请求超时验证部分结束 ===========
|
|
|
//========= 获取算法INFO ===========
|
|
|
- AlgorithmYml.CheckValid checkValid = getCheckValid(Integer.valueOf(code));
|
|
|
+ AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(code));
|
|
|
//=========发送验证信息到算法服务开始
|
|
|
JSONObject send = null;
|
|
|
try {
|
|
|
@@ -270,7 +270,7 @@ public class CheckService {
|
|
|
String[] codesArrs = codes.split(",");
|
|
|
for (int i = 0; i < codesArrs.length; i++) {
|
|
|
R r = checkAndCommit(codesArrs[i], file[i], ids[i]);
|
|
|
- AlgorithmYml.CheckValid checkValid = getCheckValid(Integer.valueOf(codesArrs[i]));
|
|
|
+ AlgorithmYml.CheckValid checkValid = algorithmYml.getCheckValid(Integer.valueOf(codesArrs[i]));
|
|
|
result.put(checkValid.getAlgoId(), r.getMsg() == null ? "通过" : r.getMsg());
|
|
|
|
|
|
}
|
|
|
@@ -407,40 +407,6 @@ public class CheckService {
|
|
|
sendSginAccessLogService.sendAddLogRest(code, id, f, msg, token, algorithmYml.getLoginUri() + algorithmYml.getCheckLogUrl());
|
|
|
}
|
|
|
|
|
|
- private AlgorithmYml.CheckValid getCheckValid(Integer code) {
|
|
|
- return Optional.ofNullable(algorithmYml.getAlgorithmMap().get(code))
|
|
|
- .orElseThrow(() -> new ServiceException("未配置对应算法code:" + code));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 构造算法文件逆流
|
|
|
- * @param file
|
|
|
- * @param params
|
|
|
- * @return
|
|
|
- */
|
|
|
- private HttpEntity<MultiValueMap<String, Object>> getHttpEntityMap(MultipartFile file, MultiValueMap<String, Object> params){
|
|
|
- try {
|
|
|
- //设置请求头
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
- // 文件本地存储收集
|
|
|
- //FileUploadUtils.upload(localFilePath, file);
|
|
|
- //MultipartFile 转为临时文件
|
|
|
- File uploadFile = multipartFileToFile(file);
|
|
|
- //文件转为文件系统资源
|
|
|
- FileSystemResource fileSystemResource = new FileSystemResource(uploadFile);
|
|
|
- //设置请求体,注意是LinkedMultiValueMap
|
|
|
- MultiValueMap<String, Object> form = getStringObjectMultiValueMap(fileSystemResource);
|
|
|
- form.addAll(params);
|
|
|
- //用HttpEntity封装整个请求报文
|
|
|
- HttpEntity<MultiValueMap<String, Object>> files = new HttpEntity<>(form, headers);
|
|
|
- return files;
|
|
|
- }catch (IOException ex){
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取算法请求地址
|
|
|
* @param checkValid
|
|
|
@@ -460,23 +426,6 @@ public class CheckService {
|
|
|
return paramUrl;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public ImgPostResponse<DataPostAnalysisRespDto> send(HttpEntity<MultiValueMap<String, Object>> files,AlgorithmYml.CheckValid checkValid, Long id){
|
|
|
- ParameterizedTypeReference<ImgPostResponse<DataPostAnalysisRespDto>> reference = new ParameterizedTypeReference<ImgPostResponse<DataPostAnalysisRespDto>>() {
|
|
|
- };
|
|
|
- ResponseEntity<ImgPostResponse<DataPostAnalysisRespDto>> response = restTemplateLocal.exchange(algorithmYml.getImgPostUrl(), HttpMethod.POST, files, reference);
|
|
|
- if (response.getStatusCode()!=HttpStatus.OK){
|
|
|
- logger.error("算法服务请求异常,请查看算服务器");
|
|
|
- throw new ServiceException("算法服务请求异常,请查看算服务器");
|
|
|
- }
|
|
|
- if (response.getBody()==null){
|
|
|
- logger.error("算法服务接口返回异常");
|
|
|
- throw new ServiceException("算法服务接口返回异常");
|
|
|
- }
|
|
|
- return response.getBody();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 图片算法请求参数
|
|
|
*
|
|
|
@@ -500,13 +449,7 @@ public class CheckService {
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(uploadFile);
|
|
|
//设置请求体,注意是LinkedMultiValueMap
|
|
|
MultiValueMap<String, Object> params = getStringObjectMultiValueMap(checkValid, String.valueOf(id));
|
|
|
-// Set<String> keySet = params.keySet();
|
|
|
-// StringBuilder stb = new StringBuilder();
|
|
|
-// String paramStr = "";
|
|
|
-// for (String key : keySet) {
|
|
|
-// stb.append("&").append(key).append("=").append(params.get(key).get(0).toString());
|
|
|
-// }
|
|
|
-// paramStr = String.valueOf(stb).replaceFirst("&", "?");
|
|
|
+
|
|
|
MultiValueMap<String, Object> form = getStringObjectMultiValueMap(fileSystemResource);
|
|
|
params.addAll(form);
|
|
|
//用HttpEntity封装整个请求报文
|
|
|
@@ -524,61 +467,6 @@ public class CheckService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 构建算法图片post请求 参数:只构建文件
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @param fileSystemResource
|
|
|
- * @return
|
|
|
- */
|
|
|
- private MultiValueMap<String, Object> getStringObjectMultiValueMap(FileSystemResource fileSystemResource) {
|
|
|
- MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
|
|
|
- form.add("file", fileSystemResource);
|
|
|
- return form;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 构建算法图片post请求 参数
|
|
|
- *
|
|
|
- * @param checkValid
|
|
|
- * @return
|
|
|
- */
|
|
|
- private MultiValueMap<String, Object> getStringObjectMultiValueMap(AlgorithmYml.CheckValid checkValid, String extension) {
|
|
|
- MultiValueMap<String, Object> form = getStringObjectMultiValueMap(extension);
|
|
|
- form.add("algoId", checkValid.getAlgoId());
|
|
|
- form.add("did", checkValid.getDid());
|
|
|
- return form;
|
|
|
- }
|
|
|
-
|
|
|
- private MultiValueMap<String, Object> getStringObjectMultiValueMap() {
|
|
|
-
|
|
|
- return getStringObjectMultiValueMap(true, null);
|
|
|
- }
|
|
|
-
|
|
|
- private MultiValueMap<String, Object> getStringObjectMultiValueMap(String extension) {
|
|
|
-
|
|
|
- return getStringObjectMultiValueMap(true, extension);
|
|
|
- }
|
|
|
-
|
|
|
- private MultiValueMap<String, Object> getStringObjectMultiValueMap(boolean sync, String extension) {
|
|
|
- MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
|
|
|
- //1-同步(默认),0-异步
|
|
|
- form.add("sync", sync ? 1 : 0);
|
|
|
- form.add("timestamp", LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli() / 1000);
|
|
|
- form.add("extension", extension);
|
|
|
- return form;
|
|
|
- }
|
|
|
-
|
|
|
- public static File multipartFileToFile(MultipartFile file) throws IOException {
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
- String[] filename = originalFilename.split("\\.");
|
|
|
- File toFile = File.createTempFile(filename[0], "." + filename[1]);
|
|
|
- file.transferTo(toFile);
|
|
|
- //toFile.deleteOnExit();//在jvm 退出时删除
|
|
|
- return toFile;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* base64转图片/视频
|
|
|
*
|