Commit 740d9758 authored by 黎博's avatar 黎博

造数据接口优化

parent e37caaf5
......@@ -8,23 +8,22 @@ import cn.qg.qaplatform.entity.vcc.UserQuotaRecord;
import cn.qg.qaplatform.entity.xyqbuser.User;
import cn.qg.qaplatform.entity.zdata.VccOpenResultVo;
import cn.qg.qaplatform.entity.zdata.VccUserEntity;
import cn.qg.qaplatform.enums.VccStatusEnum;
import cn.qg.qaplatform.process.Vcc;
import cn.qg.qaplatform.service.vcc.AccountService;
import cn.qg.qaplatform.service.vcc.AcsPayOrderService;
import cn.qg.qaplatform.service.vcc.RiskRecordService;
import cn.qg.qaplatform.service.vcc.UserQuotaRecordService;
import cn.qg.qaplatform.service.xyqbUser.UserService;
import cn.qg.qaplatform.service.zdata.vcc.VccDataService;
import cn.qg.qaplatform.service.zdata.risk.RuleEngineService;
import cn.qg.qaplatform.utils.HttpClientUtils;
import cn.qg.qaplatform.utils.JsonResult;
import cn.qg.qaplatform.utils.Result;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -60,30 +59,152 @@ public class VccController {
AcsPayOrderService acsPayOrderService;
@Autowired
VccDataService vccDataService;
RuleEngineService ruleEngineService;
/**
* vcc造数据
* @param namespace 环境
* @param phoneNo 手机号
* @param channel 渠道号
* @param status 状态
* @param status 状态,1-授信成功,2-授信失败,3-开户成功,4-开户失败
* @return
* @throws Exception
*/
@PostMapping("/gen")
public JsonResult genVccUser(@RequestParam(value = "namespace") String namespace,
@RequestParam(value = "phoneNo") String phoneNo,
@RequestParam(value = "channel") String channel,
@RequestParam(value = "status") Integer status) throws Exception {
public Result genVccUser(@RequestParam(value = "namespace") String namespace,
@RequestParam(value = "phoneNo") String phoneNo,
@RequestParam(value = "channel") String channel,
@RequestParam(value = "status") Integer status,
@RequestParam(value = "amount") Integer amount) throws Exception {
if (status !=1 && status !=2 && status !=3 && status !=4) {
return JsonResult.clientFailed("状态值必须是1、2、3、4中的一个!");
return Result.buildErrorStateResult("用户状态错误!", false);
}
String vccChannel;
if (channel.equals("214")) {
vccChannel = "159904";
} else if (channel.equals("217")) {
vccChannel = "159905";
} else {
vccChannel = channel;
}
// 登录
String token;
String uuid;
try {
Map loginResult = Vcc.login(namespace, phoneNo, channel, channel);
token = loginResult.get("token").toString();
uuid = loginResult.get("uuid").toString();
} catch (Exception e) {
e.printStackTrace();
return Result.buildErrorStateResult("登录失败,请检查xyqb_user2服务是否正常", false);
}
SwitchDataSource.dataSourceSwitch(namespace, "xyqb_user");
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("phone_no", phoneNo);
User user = userService.getOne(userQueryWrapper);
// 检查用户是否已有额度
boolean haveQuota = Vcc.checkIfAlreadyHaveQuota(namespace, uuid);
if (haveQuota) {
return Result.buildErrorStateResult("该用户已申请过,请更换新用户申请!", false);
}
// 加入授信黑名单
if (status == 2) {
ruleEngineService.addBlackList(uuid);
log.info("将用户 {} 加入授信黑名单!", uuid);
}
VccOpenResultVo result = vccDataService.makeVccUser(namespace, phoneNo, channel, status);
if (result == null) {
return JsonResult.serverFailed();
VccOpenResultVo vccOpenResultVo = new VccOpenResultVo();
vccOpenResultVo.setPhoneNo(phoneNo);
vccOpenResultVo.setOpenedChannel(channel);
vccOpenResultVo.setUuid(uuid);
vccOpenResultVo.setUserId(String.valueOf(user.getId()));
// credit url
String vccToken;
try {
vccToken = Vcc.creditUrl(namespace, token, vccChannel);
} catch (Exception e) {
e.printStackTrace();
return Result.buildErrorStateResult("vcc_talos报错,造数据失败,请检查vcc_talos", false);
}
// 身份证正面
String uploadFrontResult = Vcc.uploadFrontIdCardNew(namespace, vccToken, uuid, vccChannel);
if (!JsonPath.read(uploadFrontResult, "$.data").toString().equals("true")) {
return Result.buildErrorStateResult("身份证正面上传失败,请查看operator-sys服务日志", false);
}
// 身份证反面
String uploadBackResult = Vcc.uploadBackIdCardNew(namespace, vccToken, uuid, vccChannel);
if (!JsonPath.read(uploadBackResult, "$.data").toString().equals("true")) {
return Result.buildErrorStateResult("身份证反面上传失败,请查看operator-sys服务日志", false);
}
// 放置身份证重复
Vcc.modifyExistIdNo(namespace);
// talos保存用户信息
String saveUserDetailResult = Vcc.saveUserDetails(namespace, token, vccChannel);
if (!JsonPath.read(saveUserDetailResult, "$.data").toString().equals("实名成功")) {
return Result.buildErrorStateResult("保存用户信息失败,请查看spider-center服务日志", false);
}
// 提交ocr
Vcc.submitOcrNew(namespace, vccToken, vccChannel);
// 提交授信
Vcc.submitCredit(namespace, token, vccChannel);
// 授信结果查询
int searchCreditCount = 0;
while (true) {
try {
Thread.sleep(1000);
searchCreditCount++;
Map<String, Object> creditResult = Vcc.searchCreditResult(namespace, token, vccChannel);
if (creditResult.get("status").equals("1") || creditResult.get("status").equals("2")) {
break;
} else if (creditResult.get("status").equals("0") && searchCreditCount == 10) {
String riskNo = Vcc.getRiskNo(namespace, uuid);
Vcc.vccWindControlCreditCallback(namespace, uuid, riskNo, status != 2, amount);
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (status == 1 || status == 2) {
log.info("提交授信成功!");
Thread.sleep(2000);
SwitchDataSource.dataSourceSwitch(namespace, "vcc_talos");
QueryWrapper<Account> accountQueryWrapper = new QueryWrapper<>();
accountQueryWrapper.eq("phone_no", phoneNo);
Account account = accountService.getOne(accountQueryWrapper);
vccOpenResultVo.setMsg(VccStatusEnum.getDescByCode(account.getStatus()));
return Result.buildSuccessResult(vccOpenResultVo);
}
// 人脸识别回调
Vcc.appFaceCallback(namespace, token, vccChannel);
// 基本信息
Vcc.basicInfo(namespace, token, vccChannel);
// 发送验证码
String requestId = Vcc.bindCardSms(namespace, token, vccChannel, "ABC", "6228272537046278993");
// 额度激活
JSONObject quotaActivationResult = Vcc.quotaActivation(namespace, token, vccChannel, "6228272537046278993", requestId);
if (status == 3) {
// 开户结果
JSONObject result = Vcc.openResult(namespace, token, vccChannel);
Map data = (Map) result.get("data");
vccOpenResultVo.setAmount(data.get("amount").toString());
vccOpenResultVo.setEacctNo(data.get("eacctNo").toString());
vccOpenResultVo.setMsg("开户成功");
}
if (status == 4) {
Map data = (Map) quotaActivationResult.get("data");
if (data.get("status").equals("2")) {
vccOpenResultVo.setMsg("开户失败");
} else {
vccOpenResultVo.setMsg("请找开发手动设置结果为开户失败!");
}
}
return JsonResult.success(result);
return Result.buildSuccessResult(vccOpenResultVo);
}
/**
......
package cn.qg.qaplatform.mapper.zdata;
import cn.qg.qaplatform.entity.zdata.VccUserEntity;
import java.util.List;
import java.util.Map;
public interface VccDataMapper {
/**
* 根据状态获取vcc用户
*/
List<VccUserEntity> queryVccDataByStatus(Integer status);
/**
* 查看用户vcc状态
*/
VccUserEntity queryUserVccStatus(String phoneNo);
/**
* 查看vcc风控授信信息
*/
Map<String, Object> getVccRiskRecord(String uuid);
}
......@@ -112,7 +112,7 @@ public class Vcc {
/**
* 身份证正面-namespace
*/
public static void uploadFrontIdCardNew(String namespace, String vccToken, String uuid, String vccChannel) throws IOException {
public static String uploadFrontIdCardNew(String namespace, String vccToken, String uuid, String vccChannel) throws IOException {
String url = "https://auth-" + namespace + ".liangkebang.net/auth-center/h5/api/ocr/auth_sdk.json";
Map<String, Object> headers = new HashMap<>();
headers.put("x-auth-token", vccToken);
......@@ -140,6 +140,7 @@ public class Vcc {
params.put("idCard", JSON.toJSONString(map));
JSONObject result = HttpClientUtils.doPost(url, params, headers);
log.info("上传身份证正面结果:" + result);
return JSON.toJSONString(result);
}
/**
......@@ -174,7 +175,7 @@ public class Vcc {
/**
* 上传身份证反面-namespace
*/
public static void uploadBackIdCardNew(String namespace, String vccToken, String uuid, String vccChannel) throws IOException{
public static String uploadBackIdCardNew(String namespace, String vccToken, String uuid, String vccChannel) throws IOException{
String url = "https://auth-" + namespace + ".liangkebang.net/auth-center/h5/api/ocr/auth_sdk.json";
Map<String, Object> headers = new HashMap<>();
headers.put("x-auth-token", vccToken);
......@@ -198,6 +199,7 @@ public class Vcc {
params.put("idCard", JsonTransUtils.mapToJson(map));
JSONObject result = HttpClientUtils.doPost(url, params, headers);
log.info("上传身份证反面:" + result);
return JSON.toJSONString(result);
}
/**
......@@ -212,7 +214,7 @@ public class Vcc {
/**
* 保存用户信息
*/
public static void saveUserDetails(String namespace, String token, String vccChannel) {
public static String saveUserDetails(String namespace, String token, String vccChannel) {
String url = "https://talos-" + namespace + ".liangkebang.net/vcc/account/save_user_details";
Map<String, Object> headers = new HashMap<>();
Map<String, Object> params = new HashMap<>();
......@@ -223,6 +225,7 @@ public class Vcc {
params.put("idNo", "320101199001040432");
JSONObject result = HttpClientUtils.doPost(url, params, headers);
log.info("保存用户信息:" + result);
return JSON.toJSONString(result);
}
/**
......
package cn.qg.qaplatform.service.zdata.vcc;
import cn.qg.qaplatform.entity.zdata.VccOpenResultVo;
import cn.qg.qaplatform.entity.zdata.VccUserEntity;
import cn.qg.qaplatform.utils.page.PageResult;
import com.alibaba.fastjson.JSONObject;
/**
* Vcc捞数据和造数据
* @author libo
*/
public interface VccDataService {
/**
* vcc造数据
*/
VccOpenResultVo makeVccUser(String namespace, String phoneNo, String openedChannel, Integer status) throws Exception;
/**
* 根据手机号获取用户vcc状态
*/
VccUserEntity queryUserVccStatus(String namespace, String phoneNo);
}
package cn.qg.qaplatform.service.zdata.vcc.impl;
import cn.qg.qaplatform.config.SwitchDataSource;
import cn.qg.qaplatform.enums.VccStatusEnum;
import cn.qg.qaplatform.mapper.zdata.VccDataMapper;
import cn.qg.qaplatform.entity.zdata.VccOpenResultVo;
import cn.qg.qaplatform.entity.zdata.VccUserEntity;
import cn.qg.qaplatform.mapper.zdata.XyqbLoanDataMapper;
import cn.qg.qaplatform.process.Vcc;
import cn.qg.qaplatform.service.zdata.risk.RuleEngineService;
import cn.qg.qaplatform.service.zdata.vcc.VccDataService;
import cn.qg.qaplatform.service.zdata.xyqb.XyqbBasicQueryService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
@Slf4j
public class VccDataServiceImpl implements VccDataService {
@Autowired
VccDataMapper vccDataMapper;
@Autowired
RuleEngineService ruleEngineService;
@Autowired
XyqbBasicQueryService xyqbBasicQueryService;
@Autowired
XyqbLoanDataMapper xyqbLoanDataMapper;
/**
* vcc造数据
* @param namespace 环境
* @param phoneNo 手机号
* @param openedChannel 创建渠道
* @param status 1-授信成功,2-授信失败,3-开户成功,4-开户失败
* @return
* @throws Exception
*/
@Override
public VccOpenResultVo makeVccUser(String namespace, String phoneNo, String openedChannel, Integer status) throws Exception {
VccOpenResultVo vccOpenResultVo = new VccOpenResultVo();
vccOpenResultVo.setPhoneNo(phoneNo);
vccOpenResultVo.setOpenedChannel(openedChannel);
String vccChannel = null;
if (openedChannel.equals("214")) {
vccChannel = "159904";
} else if (openedChannel.equals("217")) {
vccChannel = "159905";
} else {
vccChannel = openedChannel;
}
// 登录
Map loginResult = Vcc.login(namespace, phoneNo, openedChannel, openedChannel);
String token = loginResult.get("token").toString();
String uuid = loginResult.get("uuid").toString();
vccOpenResultVo.setUuid(uuid);
vccOpenResultVo.setUserId(xyqbBasicQueryService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId());
// 加入授信黑名单
if (status == 2) {
ruleEngineService.addBlackList(uuid);
log.info("将用户 {} 加入授信黑名单!", uuid);
}
// 检查用户是否已有额度
boolean haveQuota = Vcc.checkIfAlreadyHaveQuota(namespace, uuid);
if (haveQuota) {
vccOpenResultVo.setMsg("该用户已申请过,请更换新用户申请!");
return vccOpenResultVo;
}
// credit url
String vccToken = Vcc.creditUrl(namespace, token, vccChannel);
// 身份证正面
// Vcc.uploadFrontIdCard(vccToken, uuid, vccChannel);
Vcc.uploadFrontIdCardNew(namespace, vccToken, uuid, vccChannel);
// 身份证反面
// Vcc.uploadBackIdCard(vccToken, uuid, vccChannel);
Vcc.uploadBackIdCardNew(namespace, vccToken, uuid, vccChannel);
// 放置身份证重复
Vcc.modifyExistIdNo(namespace);
// talos保存用户信息
Vcc.saveUserDetails(namespace, token, vccChannel);
// 提交ocr
// Vcc.submitOcr(vccToken, vccChannel);
Vcc.submitOcrNew(namespace, vccToken, vccChannel);
// 提交授信
Vcc.submitCredit(namespace, token, vccChannel);
// 授信结果查询
int searchCreditCount = 0;
while (true) {
try {
Thread.sleep(1000);
searchCreditCount++;
Map<String, Object> creditResult = Vcc.searchCreditResult(namespace, token, vccChannel);
if (creditResult.get("status").equals("1") || creditResult.get("status").equals("2")) {
break;
} else if (creditResult.get("status").equals("0") && searchCreditCount == 10) {
String riskNo = Vcc.getRiskNo(namespace, uuid);
if (status == 2) {
Vcc.vccWindControlCreditCallback(namespace, uuid, riskNo, false, 10000);
} else {
Vcc.vccWindControlCreditCallback(namespace, uuid, riskNo, true, 10000);
}
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (status == 1 || status == 2) {
log.info("提交授信成功!");
Thread.sleep(2000);
VccUserEntity userInfo = queryUserVccStatus(namespace, phoneNo);
vccOpenResultVo.setMsg(VccStatusEnum.getDescByCode(userInfo.getStatus()));
return vccOpenResultVo;
}
// 人脸识别回调
Vcc.appFaceCallback(namespace, token, vccChannel);
// 基本信息
Vcc.basicInfo(namespace, token, vccChannel);
// 发送验证码
String requestId = Vcc.bindCardSms(namespace, token, vccChannel, "ABC", "6228272537046278993");
// 额度激活
JSONObject quotaActivationResult = Vcc.quotaActivation(namespace, token, vccChannel, "6228272537046278993", requestId);
if (status == 3) {
// 开户结果
JSONObject result = Vcc.openResult(namespace, token, vccChannel);
Map data = (Map) result.get("data");
String amount = data.get("amount").toString();
String eacctNo = data.get("eacctNo").toString();
vccOpenResultVo.setAmount(amount);
vccOpenResultVo.setEacctNo(eacctNo);
vccOpenResultVo.setMsg("开户成功");
}
if (status == 4) {
Map data = (Map) quotaActivationResult.get("data");
if (data.get("status").equals("2")) {
vccOpenResultVo.setMsg("开户失败");
} else {
vccOpenResultVo.setMsg("请找开发手动设置结果为开户失败!");
}
}
return vccOpenResultVo;
}
/**
* 根据手机号获取用户vcc状态
* @param namespace 环境
* @param phoneNo 手机号
* @return QueryVccUser实体
*/
@Override
public VccUserEntity queryUserVccStatus(String namespace, String phoneNo) {
SwitchDataSource.dataSourceSwitch(namespace, "vcc_talos");
return vccDataMapper.queryUserVccStatus(phoneNo);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.qg.qaplatform.mapper.zdata.VccDataMapper">
<select id="queryVccDataByStatus" resultType="cn.qg.qaplatform.entity.zdata.VccUserEntity">
select
`phone_no` as phoneNo,
`user_id` as userId,
`uuid`,
`status`,
`registered_from` as registeredFrom,
`next_apply_time` as nextApplyTime,
`created_at` as createdAt
from account
<where>
status = #{status} and `type` = 'xyqb_mall'
</where>
order by id desc
</select>
<select id="queryUserVccStatus" resultType="cn.qg.qaplatform.entity.zdata.VccUserEntity">
select
`phone_no` as phoneNo,
`user_id` as userId,
`uuid`,
`status`,
`registered_from` as registeredFrom,
`next_apply_time` as nextApplyTime,
`created_at` as createdAt
from account
<where>
`phone_no` = #{phoneNo}
</where>
</select>
<select id="getVccRiskRecord" resultType="java.util.Map">
SELECT * FROM `risk_record` where `uuid` = #{uuid} order by id desc limit 1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment