fix:证照日期相关和orc

This commit is contained in:
guohb
2024-04-28 10:16:13 +08:00
parent baf6dfd44f
commit 56fb6764b2
9 changed files with 150 additions and 22 deletions

View File

@@ -166,6 +166,8 @@ public enum ErrorCodeEnum {
LICENSE_NOT_EXIST(109006, "证照不存在",null), LICENSE_NOT_EXIST(109006, "证照不存在",null),
FOOD_BUSINESS_LICENSE_PARSE_FAIL(109007, "食营证照解析失败", null),
INSERT_OPENING_OPERATION_PLAN_AUDIT_FALSE(103001,"插入运营方案审核信息失败",null), INSERT_OPENING_OPERATION_PLAN_AUDIT_FALSE(103001,"插入运营方案审核信息失败",null),
INSERT_OPENING_OPERATION_PLAN_FALSE(103002,"插入运营方案失败",null), INSERT_OPENING_OPERATION_PLAN_FALSE(103002,"插入运营方案失败",null),
SHOP_ID_IS_NULL(103003,"验参shopId失败为空",null), SHOP_ID_IS_NULL(103003,"验参shopId失败为空",null),

View File

@@ -37,6 +37,9 @@ public class SubmitLicenseRequest {
@ApiModelProperty("营业执照经营场所") @ApiModelProperty("营业执照经营场所")
private String licenseAddress; private String licenseAddress;
@ApiModelProperty("有效期类型 0长期有效不用传validity 1效期内")
private Integer validityType;
@ApiModelProperty("有效期") @ApiModelProperty("有效期")
private Date validity; private Date validity;
@@ -96,32 +99,22 @@ public class SubmitLicenseRequest {
licenseTransactDO.setBusinessProject(this.businessProject); licenseTransactDO.setBusinessProject(this.businessProject);
licenseTransactDO.setRemark(this.remark); licenseTransactDO.setRemark(this.remark);
licenseTransactDO.setRemarkUrl(this.remarkUrl); licenseTransactDO.setRemarkUrl(this.remarkUrl);
// Not mapped LicenseTransactDO fields:
// shopId
licenseTransactDO.setShopId(this.shopId); licenseTransactDO.setShopId(this.shopId);
// businessLicense
licenseTransactDO.setBusinessLicense(this.licenseName); licenseTransactDO.setBusinessLicense(this.licenseName);
// creditCode
licenseTransactDO.setCreditCode(this.socialCreditCode); licenseTransactDO.setCreditCode(this.socialCreditCode);
// creditUrl
licenseTransactDO.setCreditUrl(this.licenseUrl); licenseTransactDO.setCreditUrl(this.licenseUrl);
// validity if (this.validityType == 0){
licenseTransactDO.setValidity(null);
}else if (this.validityType == 1){
licenseTransactDO.setValidity(this.validity); licenseTransactDO.setValidity(this.validity);
// idCardPositiveCreditUrl }
licenseTransactDO.setIdCardPositiveCreditUrl(this.idCardAndLicense1); licenseTransactDO.setIdCardPositiveCreditUrl(this.idCardAndLicense1);
// idCardNegativeCreditUrl
licenseTransactDO.setIdCardNegativeCreditUrl(this.idCardAndLicense2); licenseTransactDO.setIdCardNegativeCreditUrl(this.idCardAndLicense2);
// foodBusinessLicenseCode
licenseTransactDO.setFoodBusinessLicenseCode(this.foodLicenseCode); licenseTransactDO.setFoodBusinessLicenseCode(this.foodLicenseCode);
// foodLicenseAddress
licenseTransactDO.setFoodLicenseAddress(this.businessPremises); licenseTransactDO.setFoodLicenseAddress(this.businessPremises);
// foodBusinessStartTime
licenseTransactDO.setFoodBusinessStartTime(this.foodLicenseStartTime); licenseTransactDO.setFoodBusinessStartTime(this.foodLicenseStartTime);
// foodBusinessEndTime
licenseTransactDO.setFoodBusinessEndTime(this.foodLicenseEndTime); licenseTransactDO.setFoodBusinessEndTime(this.foodLicenseEndTime);
// foodBusinessLicenseUrl licenseTransactDO.setFoodBusinessLicenseUrl(this.foodLicenseUrl);
licenseTransactDO.setFoodBusinessLicenseUrl(this.getFoodLicenseUrl());
// submitStatus
licenseTransactDO.setSubmitStatus(this.submitStatus); licenseTransactDO.setSubmitStatus(this.submitStatus);
return licenseTransactDO; return licenseTransactDO;
} }

View File

@@ -39,7 +39,7 @@ public class SubmitLicenseResponse {
@ApiModelProperty("营业执照经营场所") @ApiModelProperty("营业执照经营场所")
private String licenseAddress; private String licenseAddress;
@ApiModelProperty("有效期") @ApiModelProperty("有效期(如果为空则是长期有效)")
private Date validity; private Date validity;

View File

@@ -11,8 +11,41 @@ public class BusinessLicenseInfoVO {
@ApiModelProperty("公司地址") @ApiModelProperty("公司地址")
private String address; private String address;
@ApiModelProperty("法人")
private String legalPerson;
@ApiModelProperty("有效期")
private String validPeriod;
@ApiModelProperty("建立日期")
private String establishDate;
@ApiModelProperty("营业执照名称")
private String name;
@ApiModelProperty("类型")
private String type;
public BusinessLicenseInfoVO(String registerNumber, String address) { public BusinessLicenseInfoVO(String registerNumber, String address) {
this.registerNumber = registerNumber; this.registerNumber = registerNumber;
this.address = address; this.address = address;
} }
public BusinessLicenseInfoVO(String registerNumber, String address, String legalPerson, String validPeriod, String establishDate) {
this.registerNumber = registerNumber;
this.address = address;
this.legalPerson = legalPerson;
this.validPeriod = validPeriod;
this.establishDate = establishDate;
}
public BusinessLicenseInfoVO(String registerNumber, String address, String legalPerson, String validPeriod, String establishDate, String name, String type) {
this.registerNumber = registerNumber;
this.address = address;
this.legalPerson = legalPerson;
this.validPeriod = validPeriod;
this.establishDate = establishDate;
this.name = name;
this.type = type;
}
} }

View File

@@ -0,0 +1,20 @@
package com.cool.store.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class FoodLicenseVO {
@ApiModelProperty("经营者名称")
private String operatorName;
@ApiModelProperty("法人")
private String legalRepresentative;
@ApiModelProperty("经营场所")
private String businessAddress;
@ApiModelProperty("主体业态")
private String mainBusiness;
@ApiModelProperty("经营项目")
private String businessScope;
@ApiModelProperty("许可证编号")
private String licenceNumber;
}

View File

@@ -72,6 +72,11 @@
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>ocr20191230</artifactId> <artifactId>ocr20191230</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>ocr_api20210707</artifactId>
<version>2.0.7</version>
</dependency>
<dependency> <dependency>
<groupId>org.aspectj</groupId> <groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId> <artifactId>aspectjrt</artifactId>

View File

@@ -5,6 +5,7 @@ import com.cool.store.enums.SmsCodeTypeEnum;
import com.cool.store.exception.ApiException; import com.cool.store.exception.ApiException;
import com.cool.store.response.ResponseResult; import com.cool.store.response.ResponseResult;
import com.cool.store.vo.BusinessLicenseInfoVO; import com.cool.store.vo.BusinessLicenseInfoVO;
import com.cool.store.vo.FoodLicenseVO;
import com.cool.store.vo.IdentityCardInfoVO; import com.cool.store.vo.IdentityCardInfoVO;
public interface AliyunService { public interface AliyunService {
@@ -18,7 +19,7 @@ public interface AliyunService {
IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl, IDCardSideEnum sideEnum) throws ApiException; IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl, IDCardSideEnum sideEnum) throws ApiException;
/** /**
* ORC识别 * ORC识别营业执
* @param imageUrl * @param imageUrl
* @return * @return
* @throws ApiException * @throws ApiException
@@ -33,5 +34,10 @@ public interface AliyunService {
*/ */
ResponseResult sendMessage(String mobile, SmsCodeTypeEnum codeType); ResponseResult sendMessage(String mobile, SmsCodeTypeEnum codeType);
/**
* ORC食营证照解析
* @param imageUrl
* @return
*/
FoodLicenseVO getFoodLicense(String imageUrl) throws ApiException ;
} }

View File

@@ -1,7 +1,12 @@
package com.cool.store.service.impl; package com.cool.store.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyun.ocr20191230.models.*; import com.aliyun.ocr20191230.models.*;
import com.aliyun.ocr_api20210707.Client;
import com.aliyun.ocr_api20210707.models.RecognizeAdvancedRequest;
import com.aliyun.ocr_api20210707.models.RecognizeFoodManageLicenseRequest;
import com.aliyun.ocr_api20210707.models.RecognizeFoodManageLicenseResponse;
import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonRequest;
import com.aliyuncs.http.MethodType; import com.aliyuncs.http.MethodType;
import com.cool.store.enums.ErrorCodeEnum; import com.cool.store.enums.ErrorCodeEnum;
@@ -13,6 +18,7 @@ import com.cool.store.response.ResponseResult;
import com.cool.store.service.AliyunService; import com.cool.store.service.AliyunService;
import com.cool.store.utils.poi.StringUtils; import com.cool.store.utils.poi.StringUtils;
import com.cool.store.vo.BusinessLicenseInfoVO; import com.cool.store.vo.BusinessLicenseInfoVO;
import com.cool.store.vo.FoodLicenseVO;
import com.cool.store.vo.IdentityCardInfoVO; import com.cool.store.vo.IdentityCardInfoVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@@ -115,17 +121,18 @@ public class AliyunServiceImpl implements AliyunService {
RecognizeBusinessLicenseAdvanceRequest recognizeBusinessLicenseRequest = new RecognizeBusinessLicenseAdvanceRequest() RecognizeBusinessLicenseAdvanceRequest recognizeBusinessLicenseRequest = new RecognizeBusinessLicenseAdvanceRequest()
.setImageURLObject(inputStream); .setImageURLObject(inputStream);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
// RecognizeBusinessLicenseResponse recognizeBusinessLicenseResponse = client.recognizeBusinessLicenseWithOptions(RecognizeBusinessLicenseAdvanceRequest, runtime);
RecognizeBusinessLicenseResponse recognizeBusinessLicenseResponse = client.recognizeBusinessLicenseAdvance(recognizeBusinessLicenseRequest, runtime); RecognizeBusinessLicenseResponse recognizeBusinessLicenseResponse = client.recognizeBusinessLicenseAdvance(recognizeBusinessLicenseRequest, runtime);
log.info("营业执照解析结果:{}", JSONObject.toJSONString(recognizeBusinessLicenseResponse)); log.info("营业执照解析结果:{}", JSONObject.toJSONString(recognizeBusinessLicenseResponse));
RecognizeBusinessLicenseResponseBody.RecognizeBusinessLicenseResponseBodyData result = Optional.ofNullable(recognizeBusinessLicenseResponse).map(o -> o.getBody()).map(o -> o.data).orElse(null); RecognizeBusinessLicenseResponseBody.RecognizeBusinessLicenseResponseBodyData result = Optional.ofNullable(recognizeBusinessLicenseResponse).map(o -> o.getBody()).map(o -> o.data).orElse(null);
if (Objects.nonNull(result)){ if (Objects.nonNull(result)){
String address = result.address; String address = result.address;//住所(经营场所)
String registerNumber = result.registerNumber; String registerNumber = result.registerNumber;
String legalPerson = result.legalPerson;//法人 String legalPerson = result.legalPerson;//法人
String validPeriod = result.validPeriod;//有效期 String validPeriod = result.validPeriod;//有效期
String establishDate = result.establishDate; String establishDate = result.establishDate;
BusinessLicenseInfoVO response = new BusinessLicenseInfoVO(registerNumber,address); String name = result.name;//营业执照名称
String type = result.type;//类型
BusinessLicenseInfoVO response = new BusinessLicenseInfoVO(registerNumber,address,legalPerson,validPeriod,establishDate,name,type);
return response; return response;
} }
return null; return null;
@@ -144,6 +151,56 @@ public class AliyunServiceImpl implements AliyunService {
} }
} }
@Override
public FoodLicenseVO getFoodLicense(String imageUrl) throws ApiException {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
try {
com.aliyun.ocr_api20210707.Client client = new com.aliyun.ocr_api20210707.Client(config);
//非上海区域OSS必须使用流转换后使用
URL url = new URL(imageUrl);
InputStream inputStream = url.openConnection().getInputStream();
com.aliyun.ocr_api20210707.models.RecognizeFoodManageLicenseRequest recognizeFoodManageLicenseRequest = new com.aliyun.ocr_api20210707.models.RecognizeFoodManageLicenseRequest();
// recognizeFoodManageLicenseRequest.setBody(inputStream);
recognizeFoodManageLicenseRequest.setUrl(imageUrl);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
RecognizeFoodManageLicenseResponse recognizeFoodManageLicenseResponse = client.recognizeFoodManageLicenseWithOptions(recognizeFoodManageLicenseRequest,runtime);
log.info("食营解析结果:{}", JSONObject.toJSONString(recognizeFoodManageLicenseResponse));
String result = Optional.ofNullable(recognizeFoodManageLicenseResponse).map(o -> o.getBody()).map(o -> o.data).orElse(null);
if (StringUtils.isNotBlank(result)){
JSONObject data = JSONObject.parseObject(JSON.parseObject(result).get("data").toString());
String operatorName = data.getString("operatorName");//经营者名称
String legalRepresentative = data.getString("legalRepresentative");//法人
String businessAddress = data.getString("businessAddress");//经营场所
String mainBusiness = data.getString("mainBusiness");//主体业态
String businessScope = data.getString("businessScope");//经营项目
String licenceNumber = data.getString("licenceNumber");//许可证编号
FoodLicenseVO foodLicenseVO = new FoodLicenseVO();
foodLicenseVO.setBusinessAddress(businessAddress);
foodLicenseVO.setBusinessScope(businessScope);
foodLicenseVO.setLegalRepresentative(legalRepresentative);
foodLicenseVO.setMainBusiness(mainBusiness);
foodLicenseVO.setLicenceNumber(licenceNumber);
foodLicenseVO.setOperatorName(operatorName);
return foodLicenseVO;
}
return null;
} catch (com.aliyun.tea.TeaException e) {
log.error("食营解析报错TeaException{}", e);
throw new ApiException(e.getMessage());
} catch (MalformedURLException e) {
log.error("食营解析报错MalformedURLException{}", e);
throw new ApiException(e.getMessage());
} catch (IOException e) {
log.error("食营解析报错IOException{}", e);
throw new ApiException(e.getMessage());
} catch (Exception e) {
log.error("食营解析报错Exception{}", e);
throw new ApiException(e.getMessage());
}
}
@Override @Override
public ResponseResult sendMessage(String mobile, SmsCodeTypeEnum codeType) { public ResponseResult sendMessage(String mobile, SmsCodeTypeEnum codeType) {

View File

@@ -6,6 +6,7 @@ import com.cool.store.exception.ServiceException;
import com.cool.store.response.ResponseResult; import com.cool.store.response.ResponseResult;
import com.cool.store.service.AliyunService; import com.cool.store.service.AliyunService;
import com.cool.store.vo.BusinessLicenseInfoVO; import com.cool.store.vo.BusinessLicenseInfoVO;
import com.cool.store.vo.FoodLicenseVO;
import com.cool.store.vo.IdentityCardInfoVO; import com.cool.store.vo.IdentityCardInfoVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@@ -52,4 +53,15 @@ public class OcrController {
throw new ServiceException(ErrorCodeEnum.BUSINESS_LICENSE_PARSE_FAIL); throw new ServiceException(ErrorCodeEnum.BUSINESS_LICENSE_PARSE_FAIL);
} }
} }
@GetMapping(path = "/getFoodBusinessLicense")
@ApiOperation("根据食营证照解析获取数据")
public ResponseResult<FoodLicenseVO> getFoodLicense(@RequestParam(value = "imageUrl")String imageUrl){
try {
FoodLicenseVO businessLicenseInfo = aliyunService.getFoodLicense(imageUrl);
return ResponseResult.success(businessLicenseInfo);
} catch (Exception e) {
throw new ServiceException(ErrorCodeEnum.FOOD_BUSINESS_LICENSE_PARSE_FAIL);
}
}
} }