Commit 59c38dc3 authored by 王向伟's avatar 王向伟

用户综合查询,添加ka调用

parent b3952aee
package cn.quantgroup.customer.model.kaordermapping;
import lombok.Data;
import java.sql.Timestamp;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class LoanOrderMapping {
private Long id;
private String channelOrderNo;
private String channelPaymentNo;
private String applyNo;
private Long loanId;
private Long registeredFrom;
private String orderExtend;
private String businessType;
private Timestamp paymentAt;
private Long qgUserId;
private Timestamp createdAt;
private Timestamp updatedAt;
}
package cn.quantgroup.customer.rest.param.ordermapping;
import lombok.Data;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Data
public class OrderMappingQueryParam {
private Long loanId;
private String channelOrderNo;
private String applyOrderNo;
}
package cn.quantgroup.customer.service;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.rest.param.ordermapping.OrderMappingQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
public interface IKaService {
JsonResult<LoanOrderMapping> findOrderMapping(OrderMappingQueryParam orderMappingQueryParam);
}
package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.exception.BusinessException;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.rest.param.ordermapping.OrderMappingQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IKaService;
import cn.quantgroup.customer.service.http.IHttpService;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;
import static cn.quantgroup.customer.constant.Constant.GSON;
/**
* @author Wang Xiangwei
* @version 2020/3/9
*/
@Slf4j
@Service
public class KaServiceImpl implements IKaService {
@Value("${ka.api.http}")
private String kaSysUrl;
@Autowired
private IHttpService httpService;
@Override
public JsonResult<LoanOrderMapping> findOrderMapping(OrderMappingQueryParam orderMappingQueryParam) {
String logPre = "KaServiceImpl.findOrderMapping";
log.info("{},获得orderMapping orderMappingQueryParam={}",logPre,orderMappingQueryParam);
if(Objects.isNull(orderMappingQueryParam)){
log.error("{} 查询参数为空 orderMappingQueryParam={}",logPre,orderMappingQueryParam);
return JsonResult.buildErrorStateResult("查询参数为空",null);
}
String applyOrderNo = orderMappingQueryParam.getApplyOrderNo();
String channelOrderNo = orderMappingQueryParam.getChannelOrderNo();
Long loanId = orderMappingQueryParam.getLoanId();
String url = kaSysUrl + "/api/order_mapping/get";
try {
Map<String, Object> param = Maps.newHashMap();
if(!Objects.isNull(applyOrderNo)){
param.put("applyOrderNo", applyOrderNo);
}
if(StringUtils.isNotBlank(channelOrderNo)){
param.put("channelOrderNo", channelOrderNo);
}
if(StringUtils.isNotBlank(channelOrderNo)){
param.put("loanId", loanId);
}
String result = httpService.get(url, param);
log.info("{} 请求ka系统返回值:{}",logPre, result);
JsonResult jsonResult = GSON.fromJson(result, JsonResult.class);
if(Objects.isNull(jsonResult) || !jsonResult.isSuccess()){
log.error("{} 查询orderMapping失败 jsonResult={}",logPre,jsonResult);
return JsonResult.buildErrorStateResult("查询orderMapping失败",null);
}
Object data = jsonResult.getData();
LoanOrderMapping loanOrderMapping = GSON.fromJson(data.toString(), LoanOrderMapping.class);
jsonResult.setData(loanOrderMapping);
return jsonResult;
} catch (Exception e) {
log.error("{} 网络通讯异常,orderMappingQueryParam:{},ex:{}", orderMappingQueryParam, ExceptionUtils.getStackTrace(e));
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
}
}
......@@ -5,15 +5,18 @@ import cn.quantgroup.customer.entity.User;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.exception.BusinessException;
import cn.quantgroup.customer.model.Tuple;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.xyqbuser.UserBasicInfo;
import cn.quantgroup.customer.model.xyqbuser.UserCombination;
import cn.quantgroup.customer.repo.UserRepo;
import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery;
import cn.quantgroup.customer.rest.param.ordermapping.OrderMappingQueryParam;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery;
import cn.quantgroup.customer.rest.param.user.UserCombinationParam;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IKaService;
import cn.quantgroup.customer.service.IUserService;
import cn.quantgroup.customer.service.IXyqbService;
import cn.quantgroup.customer.service.http.IHttpService;
......@@ -30,7 +33,6 @@ import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.UserDetails;
......@@ -57,13 +59,15 @@ public class UserServiceImpl implements IUserService {
private final UserSdkImpl userSdk;
private final IXyqbService xyqbService;
private final IKaService kaService;
@Autowired
public UserServiceImpl(UserRepo userRepo, IHttpService httpService, UserSdkImpl userSdk,IXyqbService xyqbService) {
public UserServiceImpl(UserRepo userRepo, IHttpService httpService, UserSdkImpl userSdk, IXyqbService xyqbService, IKaService kaService) {
this.userRepo = userRepo;
this.httpService = httpService;
this.userSdk = userSdk;
this.xyqbService =xyqbService;
this.xyqbService = xyqbService;
this.kaService = kaService;
}
@Override
......@@ -148,7 +152,7 @@ public class UserServiceImpl implements IUserService {
@Override
public JsonResult findUserInfo(UserCombinationParam userCombinationParam) {
final String LOG_PRE = "UserServiceImpl.findUserInfo";
log.info("{} 查询用户信息 userCombinationParam={}",LOG_PRE,userCombinationParam);
log.info("{} 查询用户信息 userCombinationParam={}", LOG_PRE, userCombinationParam);
Tuple<Boolean, String> tuple = validate(userCombinationParam);
if (!tuple.getKey()) {
......@@ -157,47 +161,59 @@ public class UserServiceImpl implements IUserService {
}
//通过userId查询
if (!Objects.isNull(userCombinationParam.getUserId())){
log.info("{} 通过userId查询 userId={}",LOG_PRE,userCombinationParam.getUserId());
if (!Objects.isNull(userCombinationParam.getUserId())) {
log.info("{} 通过userId查询 userId={}", LOG_PRE, userCombinationParam.getUserId());
UserSysResult<XUserDetail> userDetailByUserId = userSdk.getService().findUserDetailByUserId(userCombinationParam.getUserId());
return getUserBasicInfoResult(userDetailByUserId);
}
if(StringUtils.isNotBlank(userCombinationParam.getPhoneNo())){
log.info("{} 通过phoneNo查询 phoneNo={}",LOG_PRE,userCombinationParam.getPhoneNo());
if (StringUtils.isNotBlank(userCombinationParam.getPhoneNo())) {
log.info("{} 通过phoneNo查询 phoneNo={}", LOG_PRE, userCombinationParam.getPhoneNo());
UserSysResult<XUserDetail> userDetailByPhone = userSdk.getService().findUserDetailByPhone(userCombinationParam.getPhoneNo());
return getUserBasicInfoResult(userDetailByPhone);
}
if(StringUtils.isNotBlank(userCombinationParam.getUuid())){
log.info("{} 通过uuid查询 uuid={}",LOG_PRE,userCombinationParam.getUuid());
if (StringUtils.isNotBlank(userCombinationParam.getUuid())) {
log.info("{} 通过uuid查询 uuid={}", LOG_PRE, userCombinationParam.getUuid());
UserSysResult<XUserFullInfo> userFullInfoByUuid = userSdk.getService().findUserFullInfoByUuid(userCombinationParam.getUuid());
Object jsonResultData = getJsonResultData(userFullInfoByUuid);
if(jsonResultData instanceof XUserFullInfo){
if (jsonResultData instanceof XUserFullInfo) {
XUserFullInfo xUserFullInfo = (XUserFullInfo) jsonResultData;
UserSysResult<XUserDetail> userDetailByPhone = userSdk.getService().findUserDetailByPhone(xUserFullInfo.getPhoneNo());
return getUserBasicInfoResult(userDetailByPhone);
}else {
} else {
return (JsonResult) jsonResultData;
}
}
if(!Objects.isNull(userCombinationParam.getLoanId()) || StringUtils.isNotBlank(userCombinationParam.getChannelOrderNo()) || StringUtils.isNotBlank(userCombinationParam.getOrderNo())){
if (!Objects.isNull(userCombinationParam.getLoanId()) || StringUtils.isNotBlank(userCombinationParam.getChannelOrderNo()) || StringUtils.isNotBlank(userCombinationParam.getOrderNo())) {
//通过ka获得userId然后通过userId查询
OrderMappingQueryParam param = new OrderMappingQueryParam();
param.setApplyOrderNo(userCombinationParam.getOrderNo());
param.setChannelOrderNo(userCombinationParam.getChannelOrderNo());
param.setLoanId(userCombinationParam.getLoanId());
JsonResult<LoanOrderMapping> orderMapping = kaService.findOrderMapping(param);
if(!orderMapping.isSuccess()){
log.error("{} 查询用户失败 param={} result={}",LOG_PRE,param,orderMapping);
return orderMapping;
}
Long qgUserId = orderMapping.getData().getQgUserId();
UserSysResult<XUserDetail> userDetailByUserId = userSdk.getService().findUserDetailByUserId(qgUserId);
return getUserBasicInfoResult(userDetailByUserId);
}
if(!Objects.isNull(userCombinationParam.getIdNo())){
if (!Objects.isNull(userCombinationParam.getIdNo())) {
//通过业务系统获得
log.info("{} 通过phoneNo查询 idNo={}", LOG_PRE, userCombinationParam.getIdNo());
return findUserDetailByIdNo(userCombinationParam.getIdNo());
}
return JsonResult.buildErrorStateResult("无有效查询参数",null);
return JsonResult.buildErrorStateResult("无有效查询参数", null);
}
private JsonResult findUserDetailByIdNo(String idNo){
private JsonResult findUserDetailByIdNo(String idNo) {
String url = userSysUrl + "innerapi/user_detail/fuzzyQuery";
try {
Map<String, Object> param = Maps.newHashMap();
......@@ -205,19 +221,19 @@ public class UserServiceImpl implements IUserService {
String result = httpService.post(url, param);
log.info("[user][findUserDetailByIdNo ] 请求业务系统返回值:{}", result);
JsonResult jsonResult = GSON.fromJson(result, JsonResult.class);
if(!Objects.isNull(jsonResult) && jsonResult.isSuccess()){
if (!Objects.isNull(jsonResult) && jsonResult.isSuccess()) {
Object data = jsonResult.getData();
if(data instanceof List){
if (data instanceof List) {
List list = (List) data;
if(list.size() >1){
return JsonResult.buildErrorStateResult("身份证查询返回多条数据,请用其他参数查询",null);
if (list.size() > 1) {
return JsonResult.buildErrorStateResult("身份证查询返回多条数据,请用其他参数查询", null);
}
if (list.size() ==0){
return JsonResult.buildErrorStateResult("不存在相关用户信息",null);
if (list.size() == 0) {
return JsonResult.buildErrorStateResult("不存在相关用户信息", null);
}
Object o = list.get(0);
XUserDetail userDetail = GSON.fromJson(o.toString(),XUserDetail.class);
XUserDetail userDetail = GSON.fromJson(o.toString(), XUserDetail.class);
UserBasicInfo userBasicInfo = new UserBasicInfo();
String createAt = DateUtil.format(userDetail.getCreatedAt(), DateUtil.DATE_FORMAT_1);
userBasicInfo.setCreateAt(createAt);
......@@ -225,8 +241,8 @@ public class UserServiceImpl implements IUserService {
userBasicInfo.setIdNo(userDetail.getIdNo());
userBasicInfo.setName(userDetail.getName());
userBasicInfo.setPhoneNo(userDetail.getPhoneNo());
userBasicInfo.setStatus(userDetail.getEnable()? "正常":"封禁");
return JsonResult.buildSuccessResult(null,userBasicInfo);
userBasicInfo.setStatus(userDetail.getEnable() ? "正常" : "封禁");
return JsonResult.buildSuccessResult(null, userBasicInfo);
}
}
......@@ -236,12 +252,13 @@ public class UserServiceImpl implements IUserService {
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
return JsonResult.buildErrorStateResult("查询用户信息错误",null);
return JsonResult.buildErrorStateResult("查询用户信息错误", null);
}
private JsonResult getUserBasicInfoResult(UserSysResult userSysResult) {
Object data= getJsonResultData(userSysResult);
Object data = getJsonResultData(userSysResult);
UserBasicInfo userBasicInfo = new UserBasicInfo();
if(data instanceof XUserDetail){
if (data instanceof XUserDetail) {
XUserDetail userDetail = (XUserDetail) data;
String createAt = DateUtil.format(userDetail.getCreatedAt(), DateUtil.DATE_FORMAT_1);
userBasicInfo.setCreateAt(createAt);
......@@ -249,27 +266,27 @@ public class UserServiceImpl implements IUserService {
userBasicInfo.setIdNo(userDetail.getIdNo());
userBasicInfo.setName(userDetail.getName());
userBasicInfo.setPhoneNo(userDetail.getPhoneNo());
userBasicInfo.setStatus(userDetail.getEnable()? "正常":"封禁");
}else {
userBasicInfo.setStatus(userDetail.getEnable() ? "正常" : "封禁");
} else {
return (JsonResult) data;
}
return JsonResult.buildSuccessResult(null,userBasicInfo);
return JsonResult.buildSuccessResult(null, userBasicInfo);
}
private Object getJsonResultData(UserSysResult userSysResult) {
String logPre = "UserServiceImpl.getJsonResultData";
log.info("{} 转换为对象 userSysResult={}",logPre,userSysResult);
log.info("{} 转换为对象 userSysResult={}", logPre, userSysResult);
if(Objects.isNull(userSysResult)){
log.error("{} 转换参数为空 userSysResult={}",logPre,userSysResult);
return JsonResult.buildErrorStateResult("远程调用结果为空",null);
if (Objects.isNull(userSysResult)) {
log.error("{} 转换参数为空 userSysResult={}", logPre, userSysResult);
return JsonResult.buildErrorStateResult("远程调用结果为空", null);
}
if(!userSysResult.isSuccess() || Objects.isNull(userSysResult.getData())){
log.error("{} 远程调用失败 userSysResult={}",logPre,userSysResult);
return JsonResult.buildErrorStateResult(userSysResult.getMsg(),userSysResult.getData());
if (!userSysResult.isSuccess() || Objects.isNull(userSysResult.getData())) {
log.error("{} 远程调用失败 userSysResult={}", logPre, userSysResult);
return JsonResult.buildErrorStateResult(userSysResult.getMsg(), userSysResult.getData());
}
return userSysResult.getData();
}
......@@ -339,9 +356,9 @@ public class UserServiceImpl implements IUserService {
@Override
public JsonResult findUserCombination(UserCombinationParam userCombinationParam) {
String logPre = "UserServiceImpl.findUserCombination";
log.info("{},综合查询 userCombinationParam={}",logPre,userCombinationParam);
log.info("{},综合查询 userCombinationParam={}", logPre, userCombinationParam);
JsonResult userInfo = this.findUserInfo(userCombinationParam);
if(!userInfo.isSuccess()){
if (!userInfo.isSuccess()) {
return userInfo;
}
UserBasicInfo userBasicInfo = (UserBasicInfo) userInfo.getData();
......@@ -350,16 +367,16 @@ public class UserServiceImpl implements IUserService {
applyOrderQuery.setOrderNo(userCombinationParam.getOrderNo());
applyOrderQuery.setUserId(userBasicInfo.getUserId());
JsonResult applyOrders = xyqbService.findApplyOrders(applyOrderQuery);
if(!applyOrders.isSuccess()){
if (!applyOrders.isSuccess()) {
return applyOrders;
}
List applyOrderList = (List)applyOrders.getData();
List applyOrderList = (List) applyOrders.getData();
UserCombination userCombination = new UserCombination();
userCombination.setUserInfo(userBasicInfo);
userCombination.setApplyOrderList(applyOrderList);
return JsonResult.buildSuccessResult("",userCombination);
return JsonResult.buildSuccessResult("", userCombination);
}
}
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