|
|
@@ -0,0 +1,105 @@ |
|
|
|
package cn.com.taiji.iaw.manager; |
|
|
|
|
|
|
|
import cn.com.taiji.common.manager.ManagerException; |
|
|
|
import cn.com.taiji.common.manager.net.http.ServiceHandleException; |
|
|
|
import cn.com.taiji.common.pub.json.JsonTools; |
|
|
|
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.io.IOException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
public abstract class AbstractIawManager extends AbstractCommManager { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private OcrResultRepo ocrResultRepo; |
|
|
|
|
|
|
|
/** |
|
|
|
* type:1-身份证-人像面 2-身份证-国徽面 3-行驶证前页 4-行驶证背页 5-营业执照 |
|
|
|
* imagePath:图片地址 |
|
|
|
*/ |
|
|
|
protected AbstractAtsResponse getOcrResult(Integer type, String imagePath) throws ManagerException, IOException { |
|
|
|
OcrResult ocrResult = new OcrResult(); |
|
|
|
ocrResult.setCreateTime(LocalDateTime.now()); |
|
|
|
ocrResult.setUrl(imagePath); |
|
|
|
ocrResult.setOcrType(OcrType.findByCode(type)); |
|
|
|
// 相同的图片,直接取已有的结果 |
|
|
|
OcrResult exist = ocrResultRepo.findByUrlAndType(ocrResult.getUrl(), ocrResult.getOcrType()); |
|
|
|
switch (ocrResult.getOcrType()) { |
|
|
|
case id_front: |
|
|
|
if (exist != null) |
|
|
|
return JsonTools.json2Object(exist.getResult(), IdCardOcrResponse.class); |
|
|
|
return doIdCardOcr(1, imagePath, ocrResult); |
|
|
|
case id_back: |
|
|
|
if (exist != null) |
|
|
|
return JsonTools.json2Object(exist.getResult(), IdCardOcrResponse.class); |
|
|
|
return doIdCardOcr(2, imagePath, ocrResult); |
|
|
|
case vehicle_license_front: |
|
|
|
if (exist != null) |
|
|
|
return JsonTools.json2Object(exist.getResult(), VehicleLicenseOcrResponse.class); |
|
|
|
return doVehicleLicenseOcr(1, imagePath, ocrResult); |
|
|
|
case vehicle_license_back: |
|
|
|
if (exist != null) |
|
|
|
return JsonTools.json2Object(exist.getResult(), VehicleLicenseOcrResponse.class); |
|
|
|
return doVehicleLicenseOcr(2, imagePath, ocrResult); |
|
|
|
case business_license: |
|
|
|
if (exist != null) |
|
|
|
return JsonTools.json2Object(exist.getResult(), BusinessLicenseOcrResponse.class); |
|
|
|
return doBusinessLicenseOcr(imagePath, ocrResult); |
|
|
|
default: |
|
|
|
throw new ManagerException("OCR类型异常,请手动输入"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private IdCardOcrResponse doIdCardOcr(int type, String imagePath, OcrResult ocrResult) throws ManagerException { |
|
|
|
try { |
|
|
|
IdCardOcrRequest req = new IdCardOcrRequest(); |
|
|
|
req.setImageType(type+""); |
|
|
|
req.setUrl(imagePath); |
|
|
|
IdCardOcrResponse res = jsonPostRepeat(req); |
|
|
|
ocrResult.setResult(res.getBizContent()); |
|
|
|
ocrResult.setCode(res.getRespCode()); |
|
|
|
ocrResultRepo.save(ocrResult); |
|
|
|
res.setOcrResultId(ocrResult.getId()); |
|
|
|
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.getBizContent()); |
|
|
|
ocrResult.setCode(res.getRespCode()); |
|
|
|
ocrResultRepo.save(ocrResult); |
|
|
|
res.setOcrResultId(ocrResult.getId()); |
|
|
|
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.getBizContent()); |
|
|
|
ocrResult.setCode(res.getRespCode()); |
|
|
|
ocrResultRepo.save(ocrResult); |
|
|
|
res.setOcrResultId(ocrResult.getId()); |
|
|
|
return res; |
|
|
|
} catch (ServiceHandleException e) { |
|
|
|
throw new ManagerException("营业执照OCR识别异常,请手动输入信息"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |