瀏覽代碼

ocr父类

master
qiubh 1 周之前
父節點
當前提交
a91cdab158

+ 1
- 0
zhywpt-app-userw/build.gradle 查看文件

@@ -8,6 +8,7 @@ dependencies {
implementation "${groupname}:common-core:1.0.0-SNAPSHOT"
implementation "${groupname}:entity-core:1.0.0-SNAPSHOT"
implementation "${groupname}:comm-core:1.0.0-SNAPSHOT"
implementation "${groupname}:ats-protocol:1.0.0-SNAPSHOT"
implementation "${groupname}:sample-protocol:1.0.0-SNAPSHOT"
implementation('cn.com.taiji.common:sso-client:2.3.10.7')
implementation "org.springframework.boot:spring-boot-starter-security"

+ 84
- 0
zhywpt-app-userw/src/main/java/cn/com/taiji/userw/manager/AbstractUserwManager.java 查看文件

@@ -0,0 +1,84 @@
package cn.com.taiji.userw.manager;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.manager.net.http.ServiceHandleException;
import cn.com.taiji.core.entity.comm.OcrResult;
import cn.com.taiji.core.entity.dict.OcrType;
import cn.com.taiji.core.model.comm.protocol.ats.AbstractAtsResponse;
import cn.com.taiji.core.model.comm.protocol.ats.ocr.*;
import cn.com.taiji.core.repo.jpa.comm.OcrResultRepo;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

public abstract class AbstractUserwManager extends AbstractCommManager {

@Autowired
private OcrResultRepo ocrResultRepo;

protected AbstractAtsResponse getOcrResult(Integer type, String imagePath) throws ManagerException {
OcrResult ocrResult = new OcrResult();
ocrResult.setCreateTime(LocalDateTime.now());
ocrResult.setUrl(imagePath);
ocrResult.setOcrType(OcrType.findByCode(type));
switch (ocrResult.getOcrType()) {
case id_front:
return doIdCardOcr(1, imagePath, ocrResult);
case id_back:
return doIdCardOcr(2, imagePath, ocrResult);
case vehicle_license_front:
return doVehicleLicenseOcr(1, imagePath, ocrResult);
case vehicle_license_back:
return doVehicleLicenseOcr(2, imagePath, ocrResult);
case business_license:
return doBusinessLicenseOcr(imagePath, ocrResult);
default:
throw new ManagerException("OCR类型异常");
}
}

private IdCardOcrResponse doIdCardOcr(int type, String imagePath, OcrResult ocrResult) throws ManagerException {
IdCardOcrRequest req = new IdCardOcrRequest();
req.setImageType(type+"");
req.setUrl(imagePath);
try {
IdCardOcrResponse res = jsonPostRepeat(req);
ocrResult.setResult(res.toJson());
ocrResult.setCode(res.getRespCode());
ocrResultRepo.save(ocrResult);
return res;
} catch (ServiceHandleException e) {
throw new ManagerException("身份证OCR识别异常");
}
}

private VehicleLicenseOcrResponse doVehicleLicenseOcr(int type, String imagePath, OcrResult ocrResult) throws ManagerException {
VehicleLicenseOcrRequest req = new VehicleLicenseOcrRequest();
req.setImageType(type+"");
req.setUrl(imagePath);
try {
VehicleLicenseOcrResponse res = jsonPostRepeat(req);
ocrResult.setResult(res.toJson());
ocrResult.setCode(res.getRespCode());
ocrResultRepo.save(ocrResult);
return res;
} catch (ServiceHandleException e) {
throw new ManagerException("行驶证OCR识别异常");
}
}

private BusinessLicenseOcrResponse doBusinessLicenseOcr(String imagePath, OcrResult ocrResult) throws ManagerException {
BusinessLicenseOcrRequest req = new BusinessLicenseOcrRequest();
req.setUrl(imagePath);
try {
BusinessLicenseOcrResponse res = jsonPostRepeat(req);
ocrResult.setResult(res.toJson());
ocrResult.setCode(res.getRespCode());
ocrResultRepo.save(ocrResult);
return res;
} catch (ServiceHandleException e) {
throw new ManagerException("营业执照OCR识别异常");
}
}

}

Loading…
取消
儲存