|
@@ -2,9 +2,6 @@ package com.qmth.ops.biz.service;
|
|
|
|
|
|
import com.qmth.boot.core.ai.model.ocr.ImageType;
|
|
import com.qmth.boot.core.ai.model.ocr.ImageType;
|
|
import com.qmth.boot.core.ai.model.ocr.OcrType;
|
|
import com.qmth.boot.core.ai.model.ocr.OcrType;
|
|
-import com.qmth.boot.core.ai.model.ocr.ParseDocTask;
|
|
|
|
-import com.qmth.boot.core.ai.model.ocr.ParseDocTaskResult;
|
|
|
|
-import com.qmth.ops.biz.ai.client.DocApiClient;
|
|
|
|
import com.qmth.ops.biz.ai.client.OcrApiClient;
|
|
import com.qmth.ops.biz.ai.client.OcrApiClient;
|
|
import com.qmth.ops.biz.ai.client.OcrApiConfig;
|
|
import com.qmth.ops.biz.ai.client.OcrApiConfig;
|
|
import com.qmth.ops.biz.ai.exception.OcrClientNotFound;
|
|
import com.qmth.ops.biz.ai.exception.OcrClientNotFound;
|
|
@@ -35,6 +32,7 @@ public class OcrClientService {
|
|
public synchronized void init() {
|
|
public synchronized void init() {
|
|
defaultClient = null;
|
|
defaultClient = null;
|
|
clientMap = new HashMap<>();
|
|
clientMap = new HashMap<>();
|
|
|
|
+
|
|
List<OcrSupplier> list = ocrSupplierService.list();
|
|
List<OcrSupplier> list = ocrSupplierService.list();
|
|
for (OcrSupplier supplier : list) {
|
|
for (OcrSupplier supplier : list) {
|
|
initApiClient(supplier);
|
|
initApiClient(supplier);
|
|
@@ -43,7 +41,7 @@ public class OcrClientService {
|
|
|
|
|
|
private void initApiClient(OcrSupplier supplier) {
|
|
private void initApiClient(OcrSupplier supplier) {
|
|
try {
|
|
try {
|
|
- String className = OcrApiClient.class.getName().replace("OcrApiClient", supplier.getClientClass());
|
|
|
|
|
|
+ String className = OcrApiClient.class.getName().replace(OcrApiClient.class.getSimpleName(), supplier.getClientClass());
|
|
OcrApiConfig config = new OcrApiConfig(supplier);
|
|
OcrApiConfig config = new OcrApiConfig(supplier);
|
|
Class<?> clientClass = Class.forName(className);
|
|
Class<?> clientClass = Class.forName(className);
|
|
|
|
|
|
@@ -55,11 +53,9 @@ public class OcrClientService {
|
|
if (supplier.getEnable() && defaultClient == null) {
|
|
if (supplier.getEnable() && defaultClient == null) {
|
|
defaultClient = client;
|
|
defaultClient = client;
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- log.warn("DocApiClient supplier:{} class:{}", supplier.getName(), supplier.getClientClass());
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("OcrApiClient init error, supplier:{} class:{}", supplier.getName(), supplier.getClientClass());
|
|
|
|
|
|
+ log.warn("OcrApiClient init error, supplier:{} class:{}", supplier.getName(), supplier.getClientClass());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -78,29 +74,4 @@ public class OcrClientService {
|
|
return defaultClient.forImage(type, imageData, imageType);
|
|
return defaultClient.forImage(type, imageData, imageType);
|
|
}
|
|
}
|
|
|
|
|
|
- public ParseDocTask parseDocTask(byte[] fileData, String fileName) throws Exception {
|
|
|
|
- DocApiClient client = this.getDefaultDocApiClient();
|
|
|
|
- return client.parseDocTask(fileData, fileName);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public ParseDocTaskResult parseDocTaskQuery(String taskId) throws Exception {
|
|
|
|
- DocApiClient client = this.getDefaultDocApiClient();
|
|
|
|
- return client.parseDocTaskQuery(taskId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private DocApiClient getDefaultDocApiClient() {
|
|
|
|
- OcrSupplier supplier = ocrSupplierService.getById(3L);//todo
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- String className = DocApiClient.class.getName().replace(DocApiClient.class.getSimpleName(), supplier.getClientClass());
|
|
|
|
- OcrApiConfig config = new OcrApiConfig(supplier);
|
|
|
|
- Class<?> clientClass = Class.forName(className);
|
|
|
|
-
|
|
|
|
- return (DocApiClient) clientClass.getConstructor(OcrApiConfig.class).newInstance(config);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("DocApiClient init error, supplier:{} class:{}", supplier.getName(), supplier.getClientClass());
|
|
|
|
- throw new OcrClientNotFound();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|