Commit beb0581e authored by xiaozhe.chen's avatar xiaozhe.chen

添加还款记录查询接口

parent c3d647ea
......@@ -197,6 +197,21 @@
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>quantgroup-user-sdk</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>brave-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>shutdown-spring-boot-starter</artifactId>
......
package cn.quantgroup.customer.config.rest;
import cn.quantgroup.tech.brave.service.ITechHttpClient;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.DefaultServiceUnavailableRetryStrategy;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.impl.client.*;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.cookie.BestMatchSpecFactory;
import org.apache.http.impl.cookie.BrowserCompatSpec;
import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
import org.apache.http.ssl.SSLContextBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpRequest;
......@@ -26,6 +38,9 @@ import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import static cn.quantgroup.customer.constant.Constant.HTTP;
import static cn.quantgroup.customer.constant.Constant.HTTPS;
......@@ -33,7 +48,14 @@ import static cn.quantgroup.customer.constant.Constant.HTTPS;
@Configuration
public class RestConfig {
@Bean
private static final int SO_TIME_OUT = 60 * 1000;
private static final int TIME_OUT = 15 * 1000;
@Autowired
@Qualifier("techHttpClient")
private ITechHttpClient techHttpClient;
@Bean("commonRestTemplate")
public RestTemplate sslRestTemplate() {
SSLContext sslContext;
try {
......@@ -100,4 +122,50 @@ public class RestConfig {
}
}
@Bean(name = "httpClient")
public CloseableHttpClient httpClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
// socket factory
ConnectionSocketFactory plainSocketFactory = new PlainConnectionSocketFactory();
SSLContext sslContext = new org.apache.http.conn.ssl.SSLContextBuilder().loadTrustMaterial(
null, (x509Certificates, authType) -> true).build();
LayeredConnectionSocketFactory sslSocketFactory =
new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", plainSocketFactory)
.register("https", sslSocketFactory).build();
// cookie specification
Registry<CookieSpecProvider> cookieSpecProviderRegistry = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
.register("easy", httpContext -> new BrowserCompatSpec() {
public void validate(Cookie cookie, CookieOrigin origin) {
}
}).build();
// connection manager
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(10000);
connectionManager.setDefaultMaxPerRoute(1000);
// retry handler
org.apache.http.client.HttpRequestRetryHandler retryHandler = new StandardHttpRequestRetryHandler(3, false);
// keep alive strategy
ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
// httpclient
return techHttpClient.createHttpClientBuilder()
.setConnectionManager(connectionManager)
.setRetryHandler(retryHandler)
.setKeepAliveStrategy(keepAliveStrategy).setDefaultRequestConfig(RequestConfig.custom()
.setConnectTimeout(TIME_OUT)
.setSocketTimeout(SO_TIME_OUT)
.setConnectionRequestTimeout(TIME_OUT)
.build())
.setDefaultCookieSpecRegistry(cookieSpecProviderRegistry).build();
}
}
package cn.quantgroup.customer.exception;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
public class BusinessException extends RuntimeException {
private Long code;
private ErrorCodeEnum type;
public BusinessException() {
super();
}
public BusinessException(ErrorCodeEnum type) {
super(type.getMessage());
this.code = type.getCode();
this.type = type;
}
public BusinessException(Long code, String message) {
super(message);
this.code = code;
}
public BusinessException(String message) {
super(message);
}
public Long getCode() {
return code;
}
public ErrorCodeEnum getType() {
return type;
}
}
package cn.quantgroup.customer.rest;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IRepayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.quantgroup.customer.constant.Constant.GSON;
@Slf4j
@RestController
@RequestMapping("/repay")
public class RepayRest {
private final IRepayService repayService;
@Autowired
public RepayRest(IRepayService repayService) {
this.repayService = repayService;
}
@GetMapping("/repayment/repay_orders")
public JsonResult repayOrders(String phoneNo, String idNo) {
if (StringUtils.isEmpty(phoneNo) && StringUtils.isEmpty(idNo)) {
return JsonResult.buildErrorStateResult(ErrorCodeEnum.PARAM_ERROR.getMessage(), ErrorCodeEnum.PARAM_ERROR.getCode());
}
RepayOrderQuery repayOrderQuery = new RepayOrderQuery();
repayOrderQuery.setPhoneNo(phoneNo);
repayOrderQuery.setIdNo(idNo);
String response = repayService.findRepayOrders(repayOrderQuery);
return GSON.fromJson(response, JsonResult.class);
}
}
package cn.quantgroup.customer.rest.param.repay;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class RepayOrderQuery {
private String phoneNo;
private String idNo;
private Long userId;
}
package cn.quantgroup.customer.service;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
public interface IRepayService {
String findRepayOrders(RepayOrderQuery repayOrderQuery);
}
......@@ -15,4 +15,6 @@ public interface IUserService extends UserDetailsService {
String modifyPhoneFeedback(ModifyPhoneFeedback modifyPhoneFeedback);
String findUuidByIdNo(String idNo);
}
package cn.quantgroup.customer.service;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
public interface IXyqbService {
String findRepayOrders(RepayOrderQuery repayOrderQuery);
}
......@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
......@@ -27,6 +28,7 @@ public class RestTemplateServiceImpl implements IHttpService {
private static final String LEFT_BRACES = "{", RIGHT_BRACES = "}", Q_MARK = "?";
@Autowired
@Qualifier("commonRestTemplate")
private RestTemplate restTemplate;
......
package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.exception.BusinessException;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.service.IRepayService;
import cn.quantgroup.customer.service.IUserService;
import cn.quantgroup.customer.service.IXyqbService;
import cn.quantgroup.user.retbean.XUser;
import cn.quantgroup.user.vo.UserSysResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service("repayService")
public class RepayServiceImpl implements IRepayService {
private final IUserService userService;
private final UserSdkImpl userSdk;
private final IXyqbService xyqbService;
@Autowired
public RepayServiceImpl(IUserService userService, UserSdkImpl userSdk, IXyqbService xyqbService) {
this.userService = userService;
this.userSdk = userSdk;
this.xyqbService = xyqbService;
}
@Override
public String findRepayOrders(RepayOrderQuery repayOrderQuery) {
String phoneNo = repayOrderQuery.getPhoneNo();
String idNo = repayOrderQuery.getIdNo();
if (StringUtils.isEmpty(phoneNo) && StringUtils.isEmpty(idNo)) {
throw new BusinessException(ErrorCodeEnum.PARAM_ERROR);
}
if (StringUtils.isEmpty(phoneNo)) {
String uuid = userService.findUuidByIdNo(idNo);
UserSysResult<XUser> userUserSysResult = userSdk.getService().findUserByUuid(uuid);
if (!userUserSysResult.isSuccess()) {
throw new BusinessException(ErrorCodeEnum.RETURN_ERROR);
}
Long userId = userUserSysResult.getData().getId();
repayOrderQuery.setUserId(userId);
}
return xyqbService.findRepayOrders(repayOrderQuery);
}
}
package cn.quantgroup.customer.service.impl;
import cn.quantgroup.user.IUserSdkService;
import cn.quantgroup.user.UserSdkServiceFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Service
@Slf4j
public class UserSdkImpl {
@Autowired
@Qualifier("httpClient")
private CloseableHttpClient httpClient;
@Value("${passportapi.http}")
private String passportapiHttp;
private IUserSdkService userSdkService;
@PostConstruct
private void init() {
userSdkService = UserSdkServiceFactory.generateSDKService(passportapiHttp, httpClient);
}
public IUserSdkService getService() {
return userSdkService;
}
}
......@@ -8,6 +8,7 @@ import cn.quantgroup.customer.repo.UserRepo;
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.vo.JsonResult;
import cn.quantgroup.customer.service.IUserService;
import cn.quantgroup.customer.service.http.IHttpService;
import cn.quantgroup.riskcontrol.model.AuthenticationUserDetail;
......@@ -105,4 +106,24 @@ public class UserServiceImpl implements IUserService {
throw new NetCommunicationException(ErrorCodeEnum.NET_ERROR.getMessage());
}
}
@Override
public String findUuidByIdNo(String idNo) {
String url = userSysUrl + "/innerapi/fetchUuid";
try {
Map<String, Object> param = Maps.newHashMap();
param.put("idNo", idNo);
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/json");
String result = httpService.post(url, header, param);
log.info("[user][query uuid by idNo ] 请求业务系统返回值:{}", result);
JsonResult jsonResult = GSON.fromJson(result, JsonResult.class);
Object uuid = jsonResult.getData();
return String.valueOf(uuid);
} catch (Exception e) {
log.error("[user][query uuid by idNo ] 网络通讯异常,idNo:{},ex:{}", idNo, ExceptionUtils.getStackTrace(e));
throw new NetCommunicationException(ErrorCodeEnum.NET_ERROR.getMessage());
}
}
}
package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.service.IXyqbService;
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.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;
@Slf4j
@Service("xyqbService")
public class XyqbServiceImpl implements IXyqbService {
@Value("${api.http}")
private String xyqbSysUrl;
private final IHttpService httpService;
@Autowired
public XyqbServiceImpl(IHttpService httpService) {
this.httpService = httpService;
}
@Override
public String findRepayOrders(RepayOrderQuery repayOrderQuery) {
String phoneNo = repayOrderQuery.getPhoneNo();
Long userId = repayOrderQuery.getUserId();
String url = xyqbSysUrl + "/ex/repayment/repay_orders";
Map<String, Object> param = Maps.newHashMap();
if (StringUtils.isNotEmpty(phoneNo)) {
param.put("phoneNo", phoneNo);
}
if (Objects.nonNull(userId)) {
param.put("userId", userId);
}
String response = httpService.get(url, param);
log.info("[xyqb][query repay orders ] param:{},请求业务系统返回值:{}", param, response);
return response;
}
}
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