diff --git a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java index 8c17a85e9..1759418aa 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java @@ -166,6 +166,8 @@ public enum ErrorCodeEnum { LICENSE_NOT_EXIST(109006, "证照不存在",null), + FOOD_BUSINESS_LICENSE_PARSE_FAIL(109007, "食营证照解析失败", null), + INSERT_OPENING_OPERATION_PLAN_AUDIT_FALSE(103001,"插入运营方案审核信息失败",null), INSERT_OPENING_OPERATION_PLAN_FALSE(103002,"插入运营方案失败",null), SHOP_ID_IS_NULL(103003,"验参shopId失败,为空",null), diff --git a/coolstore-partner-model/src/main/java/com/cool/store/request/SubmitLicenseRequest.java b/coolstore-partner-model/src/main/java/com/cool/store/request/SubmitLicenseRequest.java index 2e5f146b5..10f40e325 100644 --- a/coolstore-partner-model/src/main/java/com/cool/store/request/SubmitLicenseRequest.java +++ b/coolstore-partner-model/src/main/java/com/cool/store/request/SubmitLicenseRequest.java @@ -37,6 +37,9 @@ public class SubmitLicenseRequest { @ApiModelProperty("营业执照经营场所") private String licenseAddress; + @ApiModelProperty("有效期类型 0:长期有效(不用传validity) 1:效期内") + private Integer validityType; + @ApiModelProperty("有效期") private Date validity; @@ -96,32 +99,22 @@ public class SubmitLicenseRequest { licenseTransactDO.setBusinessProject(this.businessProject); licenseTransactDO.setRemark(this.remark); licenseTransactDO.setRemarkUrl(this.remarkUrl); - // Not mapped LicenseTransactDO fields: - // shopId licenseTransactDO.setShopId(this.shopId); - // businessLicense licenseTransactDO.setBusinessLicense(this.licenseName); - // creditCode licenseTransactDO.setCreditCode(this.socialCreditCode); - // creditUrl licenseTransactDO.setCreditUrl(this.licenseUrl); - // validity - licenseTransactDO.setValidity(this.validity); - // idCardPositiveCreditUrl + if (this.validityType == 0){ + licenseTransactDO.setValidity(null); + }else if (this.validityType == 1){ + licenseTransactDO.setValidity(this.validity); + } licenseTransactDO.setIdCardPositiveCreditUrl(this.idCardAndLicense1); - // idCardNegativeCreditUrl licenseTransactDO.setIdCardNegativeCreditUrl(this.idCardAndLicense2); - // foodBusinessLicenseCode licenseTransactDO.setFoodBusinessLicenseCode(this.foodLicenseCode); - // foodLicenseAddress licenseTransactDO.setFoodLicenseAddress(this.businessPremises); - // foodBusinessStartTime licenseTransactDO.setFoodBusinessStartTime(this.foodLicenseStartTime); - // foodBusinessEndTime licenseTransactDO.setFoodBusinessEndTime(this.foodLicenseEndTime); - // foodBusinessLicenseUrl - licenseTransactDO.setFoodBusinessLicenseUrl(this.getFoodLicenseUrl()); - // submitStatus + licenseTransactDO.setFoodBusinessLicenseUrl(this.foodLicenseUrl); licenseTransactDO.setSubmitStatus(this.submitStatus); return licenseTransactDO; } diff --git a/coolstore-partner-model/src/main/java/com/cool/store/response/SubmitLicenseResponse.java b/coolstore-partner-model/src/main/java/com/cool/store/response/SubmitLicenseResponse.java index 0c93646d3..3ad1ba322 100644 --- a/coolstore-partner-model/src/main/java/com/cool/store/response/SubmitLicenseResponse.java +++ b/coolstore-partner-model/src/main/java/com/cool/store/response/SubmitLicenseResponse.java @@ -39,7 +39,7 @@ public class SubmitLicenseResponse { @ApiModelProperty("营业执照经营场所") private String licenseAddress; - @ApiModelProperty("有效期") + @ApiModelProperty("有效期(如果为空则是长期有效)") private Date validity; diff --git a/coolstore-partner-model/src/main/java/com/cool/store/vo/BusinessLicenseInfoVO.java b/coolstore-partner-model/src/main/java/com/cool/store/vo/BusinessLicenseInfoVO.java index 3c192cd9a..07c0268f2 100644 --- a/coolstore-partner-model/src/main/java/com/cool/store/vo/BusinessLicenseInfoVO.java +++ b/coolstore-partner-model/src/main/java/com/cool/store/vo/BusinessLicenseInfoVO.java @@ -11,8 +11,41 @@ public class BusinessLicenseInfoVO { @ApiModelProperty("公司地址") 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) { this.registerNumber = registerNumber; 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; + } } diff --git a/coolstore-partner-model/src/main/java/com/cool/store/vo/FoodLicenseVO.java b/coolstore-partner-model/src/main/java/com/cool/store/vo/FoodLicenseVO.java new file mode 100644 index 000000000..2447bfca5 --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/vo/FoodLicenseVO.java @@ -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; +} diff --git a/coolstore-partner-service/pom.xml b/coolstore-partner-service/pom.xml index 594e90ebf..a6f1d873b 100644 --- a/coolstore-partner-service/pom.xml +++ b/coolstore-partner-service/pom.xml @@ -72,6 +72,11 @@ com.aliyun ocr20191230 + + com.aliyun + ocr_api20210707 + 2.0.7 + org.aspectj aspectjrt diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java b/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java index 410610035..1279fdd48 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/AliyunService.java @@ -5,6 +5,7 @@ import com.cool.store.enums.SmsCodeTypeEnum; import com.cool.store.exception.ApiException; import com.cool.store.response.ResponseResult; import com.cool.store.vo.BusinessLicenseInfoVO; +import com.cool.store.vo.FoodLicenseVO; import com.cool.store.vo.IdentityCardInfoVO; public interface AliyunService { @@ -18,7 +19,7 @@ public interface AliyunService { IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl, IDCardSideEnum sideEnum) throws ApiException; /** - * ORC识别证照 + * ORC识别营业执照 * @param imageUrl * @return * @throws ApiException @@ -33,5 +34,10 @@ public interface AliyunService { */ ResponseResult sendMessage(String mobile, SmsCodeTypeEnum codeType); - + /** + * ORC食营证照解析 + * @param imageUrl + * @return + */ + FoodLicenseVO getFoodLicense(String imageUrl) throws ApiException ; } diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java index 1487178ae..d977c25ac 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/AliyunServiceImpl.java @@ -1,7 +1,12 @@ package com.cool.store.service.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; 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.http.MethodType; 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.utils.poi.StringUtils; import com.cool.store.vo.BusinessLicenseInfoVO; +import com.cool.store.vo.FoodLicenseVO; import com.cool.store.vo.IdentityCardInfoVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -115,17 +121,18 @@ public class AliyunServiceImpl implements AliyunService { RecognizeBusinessLicenseAdvanceRequest recognizeBusinessLicenseRequest = new RecognizeBusinessLicenseAdvanceRequest() .setImageURLObject(inputStream); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); -// RecognizeBusinessLicenseResponse recognizeBusinessLicenseResponse = client.recognizeBusinessLicenseWithOptions(RecognizeBusinessLicenseAdvanceRequest, runtime); RecognizeBusinessLicenseResponse recognizeBusinessLicenseResponse = client.recognizeBusinessLicenseAdvance(recognizeBusinessLicenseRequest, runtime); log.info("营业执照解析结果:{}", JSONObject.toJSONString(recognizeBusinessLicenseResponse)); RecognizeBusinessLicenseResponseBody.RecognizeBusinessLicenseResponseBodyData result = Optional.ofNullable(recognizeBusinessLicenseResponse).map(o -> o.getBody()).map(o -> o.data).orElse(null); if (Objects.nonNull(result)){ - String address = result.address; + String address = result.address;//住所(经营场所) String registerNumber = result.registerNumber; String legalPerson = result.legalPerson;//法人 String validPeriod = result.validPeriod;//有效期 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 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 public ResponseResult sendMessage(String mobile, SmsCodeTypeEnum codeType) { diff --git a/coolstore-partner-web/src/main/java/com/cool/store/controller/webc/OcrController.java b/coolstore-partner-web/src/main/java/com/cool/store/controller/webc/OcrController.java index b635db76a..31a723ee9 100644 --- a/coolstore-partner-web/src/main/java/com/cool/store/controller/webc/OcrController.java +++ b/coolstore-partner-web/src/main/java/com/cool/store/controller/webc/OcrController.java @@ -6,6 +6,7 @@ import com.cool.store.exception.ServiceException; import com.cool.store.response.ResponseResult; import com.cool.store.service.AliyunService; import com.cool.store.vo.BusinessLicenseInfoVO; +import com.cool.store.vo.FoodLicenseVO; import com.cool.store.vo.IdentityCardInfoVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -52,4 +53,15 @@ public class OcrController { throw new ServiceException(ErrorCodeEnum.BUSINESS_LICENSE_PARSE_FAIL); } } + + @GetMapping(path = "/getFoodBusinessLicense") + @ApiOperation("根据食营证照解析获取数据") + public ResponseResult 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); + } + } }