|
@@ -2,24 +2,36 @@ package com.hrsk.cloud.eg.infrastructure.loanMannager.threedocking.impl;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.hrsk.cloud.eg.clinet.dto.data.plan.command.EgLoanApiConfigInfoCmd;
|
|
import com.hrsk.cloud.eg.clinet.dto.data.plan.command.EgLoanApiConfigInfoCmd;
|
|
import com.hrsk.cloud.eg.clinet.dto.data.plan.command.PlanCmd;
|
|
import com.hrsk.cloud.eg.clinet.dto.data.plan.command.PlanCmd;
|
|
-import com.hrsk.cloud.eg.clinet.dto.data.user.command.UserBaseInfoCmd;
|
|
|
|
|
|
+import com.hrsk.cloud.eg.clinet.dto.data.user.command.*;
|
|
import com.hrsk.cloud.eg.clinet.vo.DataVo;
|
|
import com.hrsk.cloud.eg.clinet.vo.DataVo;
|
|
|
|
+import com.hrsk.cloud.eg.clinet.vo.OrderResponseVo;
|
|
import com.hrsk.cloud.eg.domain.common.constant.ServerCodeEnums;
|
|
import com.hrsk.cloud.eg.domain.common.constant.ServerCodeEnums;
|
|
|
|
+import com.hrsk.cloud.eg.domain.utils.Md5Util;
|
|
|
|
+import com.hrsk.cloud.eg.domain.utils.SnowflakeIdWorker;
|
|
import com.hrsk.cloud.eg.infrastructure.config.client.HessianUtils;
|
|
import com.hrsk.cloud.eg.infrastructure.config.client.HessianUtils;
|
|
import com.hrsk.cloud.eg.infrastructure.config.client.RetryRestTemplate;
|
|
import com.hrsk.cloud.eg.infrastructure.config.client.RetryRestTemplate;
|
|
import com.hrsk.cloud.eg.infrastructure.loanMannager.threedocking.LoanDockingApi;
|
|
import com.hrsk.cloud.eg.infrastructure.loanMannager.threedocking.LoanDockingApi;
|
|
import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
|
|
import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
|
|
|
|
+import com.hrsk.cloud.eg.infrastructure.utils.DateUtil;
|
|
import com.hrsk.cloud.eg.infrastructure.utils.RedisUtil;
|
|
import com.hrsk.cloud.eg.infrastructure.utils.RedisUtil;
|
|
|
|
+import com.hrsk.cloud.eg.infrastructure.utils.UserUtils;
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
+import org.springframework.scheduling.annotation.AsyncResult;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.crypto.Cipher;
|
|
|
|
+import javax.crypto.spec.IvParameterSpec;
|
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.util.Base64;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -150,4 +162,265 @@ public class BaiYiJinFuCreditService implements LoanDockingApi {
|
|
return ServerCodeEnums.BaiYiJinFu;
|
|
return ServerCodeEnums.BaiYiJinFu;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public OrderResponseVo qualityApply(UserBaseInfoCmd user, PlanCmd planDto, EgLoanApiConfigInfoCmd configInfoCmd) {
|
|
|
|
+ try {
|
|
|
|
+ log.info("佰亿金服开始进件:{}", user.getUserId());
|
|
|
|
+ JSONObject config=JSONObject.parseObject(HessianUtils.deserialize(configInfoCmd.getRequestConfig()).toString());
|
|
|
|
+ XdApplyCmd xdApplyParam = user.getXdApplyParam();
|
|
|
|
+ ApplyInfo applyInfoApi = new ApplyInfo();
|
|
|
|
+ applyInfoApi.setCustomerName(UserUtils.getUserName(user.getRealName(), user.getPoliceSex()));
|
|
|
|
+ applyInfoApi.setMobilePhone(user.getUserMobile());
|
|
|
|
+ applyInfoApi.setLoanamount((double) (xdApplyParam.getBorrowMoney() * 10000));//需求金额
|
|
|
|
+ applyInfoApi.setThirdCode("baiyi"+ SnowflakeIdWorker.nextId());
|
|
|
|
+ applyInfoApi.setThirdSource(config.getString("thirdSource"));
|
|
|
|
+ applyInfoApi.setChannel(config.getString("channel"));
|
|
|
|
+ applyInfoApi.setSource(user.getCompanyCity());//城市
|
|
|
|
+ UserAssetInsuranceInfoCmd xdAssetInsuranceInfo = user.getInsuranceInfo();
|
|
|
|
+ UserAssetHouseInfoCmd houseInfo = user.getHouseInfo();
|
|
|
|
+ UserAssetCarInfoCmd carInfo = user.getCarInfo();
|
|
|
|
+ UserProfessionOfficeWorkersCmd xdProfessionOfficeWorkers = user.getOfficeWorkers();
|
|
|
|
+ UserProfessionBusinessOwnerCmd businessOwner = user.getBusinessOwner();
|
|
|
|
+ UserProfessionSelfEmployedCmd employed = user.getSelfEmployed();
|
|
|
|
+
|
|
|
|
+ applyInfoApi.setHouseflag(houseInfo == null || houseInfo.getHouseType() == null || houseInfo.getHouseType() == 2 ? "1" : "2");//房产
|
|
|
|
+ applyInfoApi.setCarflag(carInfo == null || carInfo.getCarType() == null || carInfo.getCarType() == 1 ? "1" : "2");//车
|
|
|
|
+ applyInfoApi.setInsuranceflag(xdAssetInsuranceInfo == null || xdAssetInsuranceInfo.getInsuranceType() == 1 ? "N" : "Y");//保单
|
|
|
|
+ getSocialSecurity(user, applyInfoApi);//社保//社保
|
|
|
|
+ getProvidentFund(user, applyInfoApi);//公积金
|
|
|
|
+ getMonthlyIncome(xdProfessionOfficeWorkers, businessOwner, employed, user
|
|
|
|
+ , applyInfoApi);//月收入
|
|
|
|
+ if (applyInfoApi.getMonthlyIncome()<=5000){
|
|
|
|
+ applyInfoApi.setMonthlyIncome(8000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ applyInfoApi.setOverdueflag(user.getOverdue()==null|| user.getOverdue()==0?"1":"2");
|
|
|
|
+ applyInfoApi.setSex(user.getPoliceSex().equals("男")?"0":"1");
|
|
|
|
+ applyInfoApi.setLicensenoflag(user.getProfession() != null&&user.getProfession()==5||user.getProfession() != null&&user.getProfession()==2?"2":"1");
|
|
|
|
+ getEducation(user, applyInfoApi);
|
|
|
|
+ if (user.getPoliceBirthBate()!=null) {
|
|
|
|
+ applyInfoApi.setAge(String.valueOf(DateUtil.getAgeByBirth(DateUtil.convertString2Date(user.getPoliceBirthBate(),"yyyy-MM-dd"))));
|
|
|
|
+ } else if (user.getAge() !=null){
|
|
|
|
+ applyInfoApi.setAge(String.valueOf(user.getAge()));
|
|
|
|
+ }
|
|
|
|
+ getCareer(user, applyInfoApi);
|
|
|
|
+ if (xdProfessionOfficeWorkers==null||xdProfessionOfficeWorkers.getSalaryPayment()==null||xdProfessionOfficeWorkers.getSalaryPayment()==1||xdProfessionOfficeWorkers.getSalaryPayment()==2){
|
|
|
|
+ applyInfoApi.setIncomeType("1");
|
|
|
|
+ }else {
|
|
|
|
+ applyInfoApi.setIncomeType("2");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String token = String.valueOf(redisUtil.get(String.format("zudai:token:%s:%s", "baiyi", "baiyitoken")));
|
|
|
|
+ if (StringUtils.isBlank(token)){
|
|
|
|
+ String responseUrl=null;
|
|
|
|
+ String tokenUrl=config.getString("tokenUrl");
|
|
|
|
+ UserTokenInfo userInfo1=new UserTokenInfo();
|
|
|
|
+ userInfo1.setUsername(config.getString("Username"));
|
|
|
|
+ userInfo1.setPassword(config.getString("Password"));
|
|
|
|
+ try{
|
|
|
|
+ responseUrl =httpRestTemplate.restTemplate().postForObject(tokenUrl,userInfo1, String.class);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.error("佰亿金服准入异常,异常信息:{}", e.getMessage(), e);
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(responseUrl);
|
|
|
|
+ if (jsonObject.getInteger("code")==200&&jsonObject.getString("token")!=null){
|
|
|
|
+ token=jsonObject.getString("token");
|
|
|
|
+ redisUtil.set(String.format("zudai:token:%s:%s", "baiyi", "baiyitoken"), jsonObject.getString("token"),3, TimeUnit.HOURS);
|
|
|
|
+ }else {
|
|
|
|
+ return OrderResponseVo.fail("token获取失败",ServerCodeEnums.BaiYiJinFu.getMsg());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject json = new JSONObject() {{
|
|
|
|
+ put("data", AesCbcDemo.encrypt(config.getString("key"),config.getString("iv"),JSON.toJSONString(applyInfoApi)));
|
|
|
|
+ }};
|
|
|
|
+
|
|
|
|
+ String s = JSONObject.toJSONString(json);
|
|
|
|
+ log.info("佰亿金服请求参数:{},加密后:{}", JSON.toJSONString(applyInfoApi), JSON.toJSONString(json));
|
|
|
|
+
|
|
|
|
+ String url = config.getString("applyUrl");
|
|
|
|
+ JSONObject response = null;
|
|
|
|
+ try{
|
|
|
|
+ Map<String, String> head = new HashMap<>();
|
|
|
|
+ head.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
|
+ head.put("Authorization", "Bearer "+token);
|
|
|
|
+ HttpResponse httpResponse = httpRestTemplate.restTemplate().postForObject(url, null, null, head, null, s);
|
|
|
|
+ String responseStr = EntityUtils.toString(httpResponse.getEntity());
|
|
|
|
+ response = JSONObject.parseObject(responseStr);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.error("佰亿金服申请异常,异常信息:{}", e.getMessage(), e);
|
|
|
|
+ }
|
|
|
|
+ log.info("credit createApplyAndOrder BaiYiJinFuCreditService response userId:{}, result:{}",user.getUserId(), response);
|
|
|
|
+ if (response == null) {
|
|
|
|
+ return OrderResponseVo.fail("放回数据为空",ServerCodeEnums.BaiYiJinFu.getMsg());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Integer errorCode = response.getInteger("code");
|
|
|
|
+ if (errorCode == 200) {
|
|
|
|
+ return OrderResponseVo.ok(ServerCodeEnums.BaiYiJinFu.getMsg());
|
|
|
|
+ }
|
|
|
|
+ return OrderResponseVo.fail(response.getString("msg"),ServerCodeEnums.BaiYiJinFu.getMsg());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("佰亿金服申请失败", e);
|
|
|
|
+ return OrderResponseVo.fail("佰亿金服申请失败",ServerCodeEnums.BaiYiJinFu.getMsg());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getSocialSecurity(UserBaseInfoCmd userBasicInfo, ApplyInfo applyInfoApi) {
|
|
|
|
+ if (userBasicInfo.getSocialSecurity() == null || userBasicInfo.getSocialSecurity() == 0) {
|
|
|
|
+ applyInfoApi.setSocialflag("0");
|
|
|
|
+ } else if (userBasicInfo.getSocialSecurity() == 1) {
|
|
|
|
+ applyInfoApi.setSocialflag("4");
|
|
|
|
+ } else {
|
|
|
|
+ applyInfoApi.setSocialflag("5");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getProvidentFund(UserBaseInfoCmd userBasicInfo, ApplyInfo applyInfoApi) {
|
|
|
|
+ if (userBasicInfo.getAccumulation()==null||userBasicInfo.getAccumulation()==0){
|
|
|
|
+ applyInfoApi.setAccumulationfundflag("1");
|
|
|
|
+ }else if (userBasicInfo.getAccumulation()==1){
|
|
|
|
+ applyInfoApi.setAccumulationfundflag("4");
|
|
|
|
+ }else {
|
|
|
|
+ applyInfoApi.setAccumulationfundflag("5");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getEducation(UserBaseInfoCmd userBasicInfo, ApplyInfo applyInfoApi) {
|
|
|
|
+ if (userBasicInfo == null || userBasicInfo.getEducationCode()==-1) {
|
|
|
|
+ applyInfoApi.setEducation("1");
|
|
|
|
+ } else if (userBasicInfo.getEducationCode()==0){
|
|
|
|
+ applyInfoApi.setEducation("1");
|
|
|
|
+ }else if (userBasicInfo.getEducationCode()==1){
|
|
|
|
+ applyInfoApi.setEducation("2");
|
|
|
|
+ }else if (userBasicInfo.getEducationCode()==2){
|
|
|
|
+ applyInfoApi.setEducation("3");
|
|
|
|
+ }else {
|
|
|
|
+ applyInfoApi.setEducation("4");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void getCareer(UserBaseInfoCmd userBasicInfo, ApplyInfo applyInfoApi) {
|
|
|
|
+ if (null == userBasicInfo || userBasicInfo.getProfession() == 1) {
|
|
|
|
+ applyInfoApi.setProfession("民企员工");
|
|
|
|
+ } else if (userBasicInfo.getProfession() == 2) {
|
|
|
|
+ applyInfoApi.setProfession("个体户");
|
|
|
|
+ }else if (userBasicInfo.getProfession() == 3) {
|
|
|
|
+ applyInfoApi.setProfession("电商主");
|
|
|
|
+ } else if (userBasicInfo.getProfession() ==4) {
|
|
|
|
+ applyInfoApi.setProfession("自由职业者");
|
|
|
|
+ } else if (userBasicInfo.getProfession()==5) {
|
|
|
|
+ applyInfoApi.setProfession("企业主");
|
|
|
|
+ }else if (userBasicInfo.getProfession()==6) {
|
|
|
|
+ applyInfoApi.setProfession("其他");
|
|
|
|
+ }else if (userBasicInfo.getProfession()==7) {
|
|
|
|
+ applyInfoApi.setProfession("外企员工");
|
|
|
|
+ }else if (userBasicInfo.getProfession()==8) {
|
|
|
|
+ applyInfoApi.setProfession("公务员");
|
|
|
|
+ }else if (userBasicInfo.getProfession()==9) {
|
|
|
|
+ applyInfoApi.setProfession("事业单位员工");
|
|
|
|
+ }else {
|
|
|
|
+ applyInfoApi.setProfession("国企员工");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //月收入monthly_income
|
|
|
|
+ public static ApplyInfo getMonthlyIncome(UserProfessionOfficeWorkersCmd xdProfessionOfficeWorkers,
|
|
|
|
+ UserProfessionBusinessOwnerCmd businessOwner,
|
|
|
|
+ UserProfessionSelfEmployedCmd employed,
|
|
|
|
+ UserBaseInfoCmd userBasicInfo, ApplyInfo applyInfoApi) {
|
|
|
|
+ if (userBasicInfo == null) {
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+ if (userBasicInfo.getProfession() == 4 || userBasicInfo.getProfession() == 6) {
|
|
|
|
+ Integer moneyIncome = userBasicInfo.getMoneyIncome();
|
|
|
|
+ applyInfoApi.setMonthlyIncome(moneyIncome);
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ } else if (userBasicInfo.getProfession() == 5 || userBasicInfo.getProfession() == 2) {
|
|
|
|
+ if (userBasicInfo.getProfession() == 2) {
|
|
|
|
+ if (employed == null || null == employed.getTurnover()) {
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+ Integer turnover = employed.getTurnover();
|
|
|
|
+ if (turnover == 1 || turnover == 2) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(3000);
|
|
|
|
+ } else if (turnover == 3) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(5000);
|
|
|
|
+ } else if (turnover == 4) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(12000);
|
|
|
|
+ } else if (turnover == 5) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(25000);
|
|
|
|
+ } else if (turnover == 6 || turnover == 7) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(100000);
|
|
|
|
+ }
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+ if (userBasicInfo.getProfession() == 5) {
|
|
|
|
+ if (null == businessOwner || null == businessOwner.getCompanyCommWater()) {
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+ String water = businessOwner.getCompanyCommWater();
|
|
|
|
+ if (water.equals("1")) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(50000);
|
|
|
|
+ } else {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(200000);
|
|
|
|
+ }
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (null==xdProfessionOfficeWorkers||null==xdProfessionOfficeWorkers.getMonthlyIncome()){
|
|
|
|
+ applyInfoApi.setMonthlyIncome(8000);
|
|
|
|
+ }else {
|
|
|
|
+ Integer moneyIncome = xdProfessionOfficeWorkers.getMonthlyIncome();
|
|
|
|
+ if (moneyIncome == 1 || moneyIncome == 2) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(3000);
|
|
|
|
+ } else if (moneyIncome == 3 || moneyIncome == 4) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(5000);
|
|
|
|
+ } else if (moneyIncome == 5) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(8000);
|
|
|
|
+ } else if (moneyIncome == 6) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(12000);
|
|
|
|
+ } else if (moneyIncome == 7) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(25000);
|
|
|
|
+ } else if (moneyIncome == 8 || moneyIncome == 9) {
|
|
|
|
+ applyInfoApi.setMonthlyIncome(100000);
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return applyInfoApi;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static class AesCbcDemo {
|
|
|
|
+
|
|
|
|
+ public static String encrypt(String key, String initVector, String value) throws Exception {
|
|
|
|
+ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
|
|
|
+
|
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
|
|
|
+ cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
|
|
|
|
+
|
|
|
|
+ byte[] encrypted = cipher.doFinal(value.getBytes());
|
|
|
|
+ return Base64.getEncoder().encodeToString(encrypted);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String decrypt(String key, String initVector, String encrypted) throws Exception {
|
|
|
|
+ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
|
|
|
+
|
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
|
|
|
|
+
|
|
|
|
+ byte[] original = cipher.doFinal(Base64.getDecoder().decode(encrypted));
|
|
|
|
+
|
|
|
|
+ return new String(original);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|