|
|
|
@ -3,6 +3,7 @@ package com.project.information.domain.service.impl; |
|
|
|
import com.project.information.domain.entity.InformationFileEntity; |
|
|
|
import com.project.information.domain.service.PostToDataExtractDomainService; |
|
|
|
import com.project.information.utils.MinIoUtils; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.compress.utils.IOUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -12,13 +13,14 @@ import org.springframework.http.HttpEntity; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.Executor; |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送子文件到数据服务解析 |
|
|
|
@ -32,21 +34,20 @@ public class PostToDataExtractDomainServiceImpl implements PostToDataExtractDoma |
|
|
|
@Autowired |
|
|
|
private MinIoUtils minIoUtils; |
|
|
|
|
|
|
|
private final RestTemplate restTemplate = new RestTemplate(); |
|
|
|
|
|
|
|
/** 数据服务地址(待确认) */ |
|
|
|
@Value("${dataExtract.host:http://172.16.204.50}") |
|
|
|
private String dataExtractHost; |
|
|
|
@Resource(name = "asycExecutor") |
|
|
|
private Executor asycExecutor; |
|
|
|
|
|
|
|
@Value("${dataExtract.port:8888}") |
|
|
|
private String dataExtractPort; |
|
|
|
private final RestTemplate restTemplate = new RestTemplate(); |
|
|
|
|
|
|
|
@Value("${dataExtract.url:/word/parse}") |
|
|
|
@Value("${dataExtract.url:http://172.16.204.50/dataExtract/ai-check/api/documents-parse}") |
|
|
|
private String dataExtractUrl; |
|
|
|
|
|
|
|
@Value("${dataExtract.callback-url:http://172.16.204.50/evaluator-api/api/interaction/dataExtractCallback}") |
|
|
|
private String callbackUrl; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Async("asycExecutor") |
|
|
|
public void postToDataExtract(InformationFileEntity file, Long informationId) { |
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
try { |
|
|
|
log.info(">>> [数据服务] 正在发送子文件解析请求, fileId={}, fileName={}", file.getId(), file.getFileName()); |
|
|
|
|
|
|
|
@ -69,19 +70,19 @@ public class PostToDataExtractDomainServiceImpl implements PostToDataExtractDoma |
|
|
|
body.add("file", fileResource); |
|
|
|
body.add("fileId", file.getId()); |
|
|
|
body.add("informationId", informationId); |
|
|
|
body.add("contentCategory", file.getContentCategory()); |
|
|
|
body.add("fileName", file.getFileName()); |
|
|
|
body.add("callbackUrl", callbackUrl); |
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers); |
|
|
|
|
|
|
|
// 发送请求(同步,但整个方法在异步线程中执行)
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity( |
|
|
|
dataExtractHost + ":" + dataExtractPort + dataExtractUrl, |
|
|
|
requestEntity, String.class); |
|
|
|
dataExtractUrl, requestEntity, String.class); |
|
|
|
|
|
|
|
log.info(">>> [数据服务] 子文件 {} 解析请求已发送, response={}", file.getFileName(), response.getBody()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(">>> [数据服务] 子文件解析请求异常, fileId={}", file.getId(), e); |
|
|
|
} |
|
|
|
}, asycExecutor); |
|
|
|
} |
|
|
|
} |
|
|
|
|