|
|
|
|
|
|
|
|
|
|
|
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识别异常"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |