签署意向协议

This commit is contained in:
guohb
2024-03-25 17:54:42 +08:00
parent 29bbbe5847
commit 43c04a657f
19 changed files with 585 additions and 8 deletions

View File

@@ -0,0 +1,19 @@
package com.cool.store.service;
import com.cool.store.enums.IDCardSideEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.vo.BusinessLicenseInfoVO;
import com.cool.store.vo.IdentityCardInfoVO;
public interface AliyunService {
/**
* ORC识别身份证信息
* @param faceImageUrl
* @param sideEnum
* @return
* @throws ApiException
*/
IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl, IDCardSideEnum sideEnum) throws ApiException;
BusinessLicenseInfoVO getBusinessLicenseInfo(String imageUrl) throws ApiException;
}

View File

@@ -0,0 +1,13 @@
package com.cool.store.service;
import com.cool.store.request.IntentAgreementSubmitRequest;
public interface IntentAgreementService {
/**
* 签署意向协议
* @param request
* @return
*/
boolean submit(IntentAgreementSubmitRequest request);
}

View File

@@ -0,0 +1,136 @@
package com.cool.store.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.ocr20191230.models.*;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.enums.IDCardSideEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.service.AliyunService;
import com.cool.store.utils.poi.StringUtils;
import com.cool.store.vo.BusinessLicenseInfoVO;
import com.cool.store.vo.IdentityCardInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
@Service
@Slf4j
public class AliyunServiceImpl implements AliyunService {
@Value("${aliyun.accessKeyId:null}")
private String accessKeyId;
@Value("${aliyun.accessKeySecret:null}")
private String accessKeySecret;
@Override
public IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl,
IDCardSideEnum sideEnum) throws ApiException {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "ocr.cn-shanghai.aliyuncs.com";
try {
com.aliyun.ocr20191230.Client client = new com.aliyun.ocr20191230.Client(config);
URL url = new URL(faceImageUrl);
InputStream inputStream = url.openConnection().getInputStream();
com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest recognizeIdentityCardAdvanceRequest = new com.aliyun.ocr20191230.models.RecognizeIdentityCardAdvanceRequest()
.setImageURLObject(inputStream)
.setSide(sideEnum.getCode());
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
RecognizeIdentityCardResponse idCardResponse = client.recognizeIdentityCardAdvance(recognizeIdentityCardAdvanceRequest, runtime);
log.info("身份证解析结果:{}", JSONObject.toJSONString(idCardResponse));
RecognizeIdentityCardResponseBody.RecognizeIdentityCardResponseBodyDataFrontResult frontResult = Optional.ofNullable(idCardResponse).map(o -> o.getBody()).map(o -> o.data).map(o -> o.frontResult).orElse(null);
if(Objects.nonNull(frontResult)){
String username = frontResult.name;
String liveAddress = frontResult.address;
String birthdate = frontResult.birthDate;
if(StringUtils.isNotBlank(birthdate)){
birthdate = convertDate(birthdate, "yyyyMMdd");
}
String sex = frontResult.gender;
String idCard = frontResult.IDNumber;
String nation = frontResult.nationality;
IdentityCardInfoVO result = new IdentityCardInfoVO(username, liveAddress, birthdate, sex, idCard, nation);
log.info("身份证解析:{}", JSONObject.toJSONString(result));
return result;
}
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());
}
}
public static String convertDate(String date, String format) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
LocalDate localDate = LocalDate.parse(date, formatter);
return localDate.toString();
} catch (Exception e) {
throw new ServiceException(ErrorCodeEnum.DATA_CONVERT_ERROR);
}
}
@Override
public BusinessLicenseInfoVO getBusinessLicenseInfo(String imageUrl) throws ApiException {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
config.endpoint = "ocr.cn-shanghai.aliyuncs.com";
try {
com.aliyun.ocr20191230.Client client = new com.aliyun.ocr20191230.Client(config);
//非上海区域OSS必须使用流转换后使用
URL url = new URL(imageUrl);
InputStream inputStream = url.openConnection().getInputStream();
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 registerNumber = result.registerNumber;
BusinessLicenseInfoVO response = new BusinessLicenseInfoVO(registerNumber,address);
return response;
}
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());
}
}
}

View File

@@ -0,0 +1,46 @@
package com.cool.store.service.impl;
import com.cool.store.entity.LineInfoDO;
import com.cool.store.entity.SigningBaseInfoDO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.enums.WorkflowSubStageStatusEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.IntentAgreementMapper;
import com.cool.store.mapper.LineInfoMapper;
import com.cool.store.request.IntentAgreementSubmitRequest;
import com.cool.store.service.IntentAgreementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Objects;
@Service
@Slf4j
public class IntentAgreementServiceImpl implements IntentAgreementService {
@Resource
IntentAgreementMapper intentAgreementMapper;
@Resource
LineInfoMapper lineInfoMapper;
@Override
public boolean submit(IntentAgreementSubmitRequest request) {
SigningBaseInfoDO signingBaseInfoDO = request.toSigningBaseInfoDO();
boolean submitStatus = intentAgreementMapper.insert(signingBaseInfoDO);
if (submitStatus){
LineInfoDO lineInfoDO = lineInfoMapper.getByPartnerId(request.getPartnerId());
if (Objects.isNull(lineInfoDO)){
throw new ServiceException(ErrorCodeEnum.INTERVIEW_PARTNER_NOT_EXIST);
}
lineInfoDO.setWorkflowSubStageStatus(WorkflowSubStageStatusEnum.SIGN_INTENT_AGREEMENT_60.getCode());
lineInfoMapper.updateByPrimaryKeySelective(lineInfoDO);
return Boolean.TRUE;
}
return false;
}
}

View File

@@ -46,8 +46,9 @@ public class JoinIntentionServiceImpl extends LineFlowService implements JoinInt
}
lineInfoDO.setWorkflowSubStageStatus(WorkflowSubStageStatusEnum.INTENT_5.getCode());
lineInfoMapper.updateByPrimaryKeySelective(lineInfoDO);
return Boolean.TRUE;
}
return Boolean.TRUE;
return Boolean.FALSE;
}
@Override