|
@@ -0,0 +1,130 @@
|
|
|
|
+// package com.qmth.ops.biz.ai.client.aliyun.doc;
|
|
|
|
+//
|
|
|
|
+// import com.aliyun.docmind_api20220711.Client;
|
|
|
|
+// import com.aliyun.docmind_api20220711.models.*;
|
|
|
|
+// import com.aliyun.teaopenapi.models.Config;
|
|
|
|
+// import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
|
+// import com.fasterxml.jackson.databind.json.JsonMapper;
|
|
|
|
+// import com.qmth.boot.core.ai.model.doc.ParseDocTask;
|
|
|
|
+// import com.qmth.boot.core.ai.model.doc.ParseDocTaskResult;
|
|
|
|
+// import com.qmth.boot.core.ai.model.doc.ParseDocTaskStatus;
|
|
|
|
+// import com.qmth.boot.core.exception.StatusException;
|
|
|
|
+// import com.qmth.boot.tools.codec.CodecUtils;
|
|
|
|
+// import com.qmth.ops.biz.ai.client.DocApiClient;
|
|
|
|
+// import com.qmth.ops.biz.ai.client.DocApiConfig;
|
|
|
|
+// import com.qmth.ops.biz.ai.exception.DocRateLimitExceeded;
|
|
|
|
+// import org.slf4j.Logger;
|
|
|
|
+// import org.slf4j.LoggerFactory;
|
|
|
|
+//
|
|
|
|
+// import java.io.ByteArrayInputStream;
|
|
|
|
+//
|
|
|
|
+// public class AliyunParseDocClient extends DocApiClient {
|
|
|
|
+//
|
|
|
|
+// private static final Logger log = LoggerFactory.getLogger(AliyunParseDocClient.class);
|
|
|
|
+//
|
|
|
|
+// public AliyunParseDocClient(DocApiConfig config) {
|
|
|
|
+// super(config);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public ParseDocTask parseDocTask(byte[] fileData, String fileName) throws Exception {
|
|
|
|
+// if (getQueryRateLimiter() != null && !getQueryRateLimiter().acquire()) {
|
|
|
|
+// throw new DocRateLimitExceeded(getConfig().getQps());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Config config = new Config().setEndpoint(getConfig().getUrl())
|
|
|
|
+// .setAccessKeyId(getConfig().getKey())
|
|
|
|
+// .setAccessKeySecret(getConfig().getSecret());
|
|
|
|
+//
|
|
|
|
+// RuntimeOptions runtimeOptions = new RuntimeOptions();
|
|
|
|
+// runtimeOptions.connectTimeout = 10000;
|
|
|
|
+// runtimeOptions.readTimeout = 50000;
|
|
|
|
+//
|
|
|
|
+// Client client = new Client(config);
|
|
|
|
+// SubmitDocParserJobAdvanceRequest request = new SubmitDocParserJobAdvanceRequest();
|
|
|
|
+// request.fileUrlObject = new ByteArrayInputStream(fileData);
|
|
|
|
+// request.fileName = CodecUtils.urlEncode(fileName);
|
|
|
|
+//
|
|
|
|
+// try {
|
|
|
|
+// SubmitDocParserJobResponse response = client.submitDocParserJobAdvance(request, runtimeOptions);
|
|
|
|
+// SubmitDocParserJobResponseBody body = response.getBody();
|
|
|
|
+//
|
|
|
|
+// if (response.getStatusCode() == 200 && body.getData() != null) {
|
|
|
|
+// return new ParseDocTask(encodeTaskId(body.getData().getId()));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// String respBodyStr = new JsonMapper().writeValueAsString(body);
|
|
|
|
+// log.warn("responseCode:{} {}", response.getStatusCode(), respBodyStr);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("Aliyun parseDocTask fail. {}", e.getMessage(), e);
|
|
|
|
+// }
|
|
|
|
+// throw new StatusException("请求文档解析任务失败");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public ParseDocTaskResult parseDocTaskQuery(String taskId) throws Exception {
|
|
|
|
+// if (getQueryRateLimiter() != null && !getQueryRateLimiter().acquire()) {
|
|
|
|
+// throw new DocRateLimitExceeded(getConfig().getQps());
|
|
|
|
+// }
|
|
|
|
+// taskId = decodeTaskId(taskId)[2];
|
|
|
|
+//
|
|
|
|
+// Config config = new Config().setEndpoint(getConfig().getUrl())
|
|
|
|
+// .setAccessKeyId(getConfig().getKey())
|
|
|
|
+// .setAccessKeySecret(getConfig().getSecret());
|
|
|
|
+//
|
|
|
|
+// Client client = new Client(config);
|
|
|
|
+// QueryDocParserStatusRequest request = new QueryDocParserStatusRequest();
|
|
|
|
+// request.id = taskId;
|
|
|
|
+//
|
|
|
|
+// try {
|
|
|
|
+// QueryDocParserStatusResponse response = client.queryDocParserStatus(request);
|
|
|
|
+// QueryDocParserStatusResponseBody body = response.getBody();
|
|
|
|
+//
|
|
|
|
+// if (response.getStatusCode() == 200 && body.getData() != null) {
|
|
|
|
+// ParseDocTaskResult result = new ParseDocTaskResult();
|
|
|
|
+// if ("success".equals(body.getData().getStatus())) {
|
|
|
|
+// result.setStatus(ParseDocTaskStatus.SUCCESS);
|
|
|
|
+//
|
|
|
|
+// GetDocParserResultRequest resultRequest = new GetDocParserResultRequest();
|
|
|
|
+// resultRequest.id = taskId;
|
|
|
|
+// resultRequest.layoutNum = 0;
|
|
|
|
+// resultRequest.layoutStepSize = 10;
|
|
|
|
+// GetDocParserResultResponse resultResponse = client.getDocParserResult(resultRequest);
|
|
|
|
+// if (resultResponse.getStatusCode() == 200 && resultResponse.getBody().getData() != null) {
|
|
|
|
+// result.setContent(resultResponse.getBody().getData().get("markdownContent").toString());
|
|
|
|
+// }
|
|
|
|
+// } else if ("Fail".equals(body.getData().getStatus())) {
|
|
|
|
+// result.setStatus(ParseDocTaskStatus.FAILED);
|
|
|
|
+// } else {
|
|
|
|
+// result.setStatus(ParseDocTaskStatus.PROCESSING);
|
|
|
|
+// }
|
|
|
|
+// return result;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// String respBodyStr = new JsonMapper().writeValueAsString(body);
|
|
|
|
+// log.warn("responseCode:{} {}", response.getStatusCode(), respBodyStr);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("Aliyun parseDocTaskQuery fail. {}", e.getMessage(), e);
|
|
|
|
+// }
|
|
|
|
+// throw new StatusException("查询文档解析结果失败");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public static void main(String[] args) throws Exception {
|
|
|
|
+// DocApiConfig config = new DocApiConfig();
|
|
|
|
+// config.setUrl("docmind-api.cn-hangzhou.aliyuncs.com");
|
|
|
|
+// config.setKey("xxx");
|
|
|
|
+// config.setSecret("xxx");
|
|
|
|
+// config.setQps(10);
|
|
|
|
+// config.setSupplier("1@@aliyun.doc.AliyunParseDocClient");
|
|
|
|
+// DocApiClient client = new AliyunParseDocClient(config);
|
|
|
|
+//
|
|
|
|
+// // File file = new File("D:\\home\\大纲.pdf");
|
|
|
|
+// // byte[] fileData = ByteArray.fromFile(file).value();
|
|
|
|
+// // System.out.println(client.parseDocTask(fileData, file.getName()).getTaskId());
|
|
|
|
+//
|
|
|
|
+// ParseDocTaskResult result = client.parseDocTaskQuery("M0BAYmFpZHUuZG9jLkJhaWR1UGFyc2VEb2NDbGllbnRAQHRhc2stdnVrV1RHZnNSbFNJdDFBaDNsRUxqNzRRczJzdXNhOXk=");
|
|
|
|
+// System.out.println(result.getStatus());
|
|
|
|
+// System.out.println(result.getContent());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|