Commit 2b88ae79 authored by 郝彦辉's avatar 郝彦辉

人行报送项目初始化

parents
Pipeline #562 canceled with stages
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.quantgroup</groupId>
<artifactId>renhang-report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>renhang-report</name>
<parent>
<groupId>cn.quantgroup</groupId>
<artifactId>commons-parent</artifactId>
<version>0.2.5.4</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<resource.delimiter>@</resource.delimiter>
<java.version>1.8</java.version>
<fastjson.version>1.2.21</fastjson.version>
<maven.test.skip>true</maven.test.skip>
<mysql.version>5.1.44</mysql.version>
</properties>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources/</directory>
<includes>
<include>
*.properties
</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<!--google-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
<!--db-->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- mybatis 生成器-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!--json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.9</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>quantgroup-user-sdk</artifactId>
<version>1.0.15-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.quantgroup</groupId>
<artifactId>brApi-shaded</artifactId>
<version>201808071146-Release</version>
</dependency>
<!--SpringBoot, Cloud基础的依赖-->
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>commons-spring</artifactId>
</dependency>
<!--暂时是空的.....-->
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>commons-core</artifactId>
</dependency>
<!--优雅停机, 不再强制停机-->
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>shutdown-spring-boot-starter</artifactId>
</dependency>
<!--调用链追踪. 开启吧, 以后的监控,数据统计. 都从这里出数-->
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>brave-spring-boot-starter</artifactId>
</dependency>
<!--全局唯一的IDGenerator, 试运行阶段. 百度开发者+刘志国结合量化派场景, 倾情定制.-->
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>idgenerator-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job-lite-spring-shaded</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>enoch-agent-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
package cn.quantgroup.report;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* Created by Miraculous on 15/7/12.
*/
@Component
public class ApplicationContextHolder implements ApplicationContextAware {
/**
* Spring应用上下文环境
*/
private static ApplicationContext applicationContext;
@Autowired
public ApplicationContextHolder(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
/**
* 获取一个ApplicationContext.
*
* @return ApplicationContext
*/
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
/**
* 实现ApplicationContextAware接口的回调方法,设置上下文环境.
*
* @param applicationContext Spring ApplicationContext上下文
*/
public void setApplicationContext(ApplicationContext applicationContext) {
ApplicationContextHolder.applicationContext = applicationContext;
}
/**
* 根据名称获取一个对象.
*
* @param name bean名称
* @return Object 指定的bean
* @throws BeansException 如果找不到bean
*/
public static <T> T getBean(String name) throws BeansException {
return (T) applicationContext.getBean(name);
}
/**
* 获取名称为name的bean,自动转为所需类型.
*
* @param <T> 需求的bean类型
* @param name bean名称
* @param requiredType 需求的bean类型
* @return 指定类型的bean
* @throws BeansException 如果找不到匹配的类型,或是类型不能被转换,或是bean实例化失败
*/
public static <T> T getBean(String name, Class<T> requiredType) throws BeansException {
return applicationContext.getBean(name, requiredType);
}
/**
* 获取类型为requiredType的对象.
*
* @param <T> 需求的bean类型
* @param requiredType 需求的bean类型
* @return 指定类型的bean
* @throws BeansException 如果找不到匹配的类型
*/
public static <T> T getBean(Class<T> requiredType) throws BeansException {
return applicationContext.getBean(requiredType);
}
/**
* 检测一个bean是否已经被定义.
*
* @param name bean名称
* @return boolean 如果bean已经被定义,则返回true,否则返回false
*/
public static boolean containsBean(String name) {
return applicationContext.containsBean(name);
}
/**
* 判断以给定名字注册的bean定义是一个singleton还是一个prototype.
*
* @param name bean名称
* @return boolean 如果是singleton则返回true
* @throws NoSuchBeanDefinitionException 如果bean名称不存在
*/
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
return applicationContext.isSingleton(name);
}
/**
* 获取给定名字的bean的类型.
*
* @param name bean名称
* @return Class bean类型
* @throws NoSuchBeanDefinitionException 如果bean名称不存在
*/
public static Class getType(String name) throws NoSuchBeanDefinitionException {
return applicationContext.getType(name);
}
/**
* 取出指定bean的别名列表.
*
* @param name bean名称
* @return 如果有别名,返回别名,否则返回空数组.
* @throws NoSuchBeanDefinitionException 如果bean名称不存在
*/
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException {
return applicationContext.getAliases(name);
}
}
package cn.quantgroup.report;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
//@ComponentScan(basePackages = {"cn.quantgroup.report"})
@EnableTransactionManagement
@EnableConfigurationProperties
@EnableCaching
@EnableScheduling
@EnableAsync
@EnableAspectJAutoProxy
@Slf4j
@EnableApolloConfig
@EnableDiscoveryClient
@SpringBootApplication
public class RenhangReportApplication {
public static void main(String[] args) {
JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteEnumUsingToString.getMask();
SpringApplication springApplication = new SpringApplication(RenhangReportApplication.class);
springApplication.addInitializers(new ApolloPropertySourceInitializer());
springApplication.run(args);
log.info(">>>renhang-report start server OK...");
}
}
package cn.quantgroup.report.cmpt;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class CommonAlarmCmpt {
@Value("${isDebug}")
private Boolean isDebug;
private static ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 50, 200,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(200), new ThreadPoolExecutor.DiscardPolicy());
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (pool != null) pool.shutdown();
}));
}
@Value("${alarm.interface.url}")
private String ALARM_INTERFACE_URL;
RequestConfig config = RequestConfig.custom()
.setSocketTimeout(6000)
.setConnectTimeout(6000)
.setConnectionRequestTimeout(6000)
.build();
CloseableHttpClient httpclient = HttpClients.createDefault();
public void alarm(String alarmLevel, String msgTitle, String msgContent) {
if(isDebug) return;
pool.execute(new Runnable() {
@Override
public void run() {
HttpPost httppost = new HttpPost(ALARM_INTERFACE_URL);
httppost.setConfig(config);
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("bizType", "RISK_DATASOURCE"));
params.add(new BasicNameValuePair("alarmLevel", alarmLevel));
params.add(new BasicNameValuePair("msgTitle", msgTitle));
params.add(new BasicNameValuePair("msgContent", msgContent));
CloseableHttpResponse response = null;
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
response = httpclient.execute(httppost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
log.error("告警失败,statusCode : {}", statusCode);
}
} catch (Exception e) {
log.error("告警发送异常", e);
} finally {
if(response != null) {
EntityUtils.consumeQuietly(response.getEntity());
}
IOUtils.closeQuietly(response);
}
}
});
}
public void alarmAtman(String mobile, Long content){
HttpPost httppost = new HttpPost("https://oapi.dingtalk.com/robot/send?access_token=5c787094003bb2bd5ed763dd7afa96f9bf984b4871e2f47369626c493dcb320e");
httppost.setConfig(config);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
String textMsg = "{\"msgtype\":\"text\",\"text\":{\"content\":\"探知数据调用量:"+content+", @"+mobile+" 是不一样的烟火\"},\"at\":{\"atMobiles\":[\""+mobile+"\"],\"isAtAll\":false}}";
StringEntity se = new StringEntity(textMsg, "utf-8");
httppost.setEntity(se);
CloseableHttpResponse response = null;
try{
response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
String result= EntityUtils.toString(response.getEntity(), "utf-8");
System.out.println(result);
}
}catch(Exception e){
log.error("告警发送异常", e);
}finally {
if(response != null) {
EntityUtils.consumeQuietly(response.getEntity());
}
IOUtils.closeQuietly(response);
}
}
}
package cn.quantgroup.report.cmpt;
import cn.quantgroup.report.constant.KeyConstant;
import cn.quantgroup.report.enums.RequestUrlType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Created by Alan on6/14.
*/
@Slf4j
@Component
public class MonitorCmpt {
private static ThreadPoolExecutor pool = new ThreadPoolExecutor(5, 50, 200,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(500), new ThreadPoolExecutor.DiscardPolicy());
private static String[] notAlarm = {
/*RequestUrlType.BaiRongSpecialList_c.name(),
RequestUrlType.QianHaiQueryBlackList.name(),
RequestUrlType.TongDunHitRuleDetail.name(),
RequestUrlType.JDBlacklist.name(),
RequestUrlType.CreditXFraud.name(),
RequestUrlType.ShuMeiOverdue.name(),
RequestUrlType.HaoAnBlackList.name(),
RequestUrlType.BaiDuBlackList.name(),
RequestUrlType.TianXingHuiBlackList.name(),
RequestUrlType.FaHaiJudicial.name(),*/
};
private static List<String> URL_NOT_ALARM = Arrays.asList(notAlarm);
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (pool != null) pool.shutdown();
}));
}
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private CommonAlarmCmpt commonAlarmCmpt;
/**
* 命中率统计
* @param urlType
* @param flag 0:查询失败,1,查询命中
*/
public void statisticHitRate(String urlType, int flag){
pool.execute(new Runnable() {
@Override
public void run() {
try {
String dayKey = KeyConstant.HIT_RATE + KeyConstant.ONE_DAY + urlType + ":" + flag;
String heapKey = KeyConstant.HIT_RATE + KeyConstant.HEAP + urlType + ":" + 0;
redisTemplate.opsForValue().increment(dayKey, 1);
//黑名单不告警
if(URL_NOT_ALARM.contains(urlType)){
return;
}
if (flag == 1) {
redisTemplate.delete(heapKey);
return;
}
Long heapCount = redisTemplate.opsForValue().increment(heapKey, 1);
log.info("三方数据源: {} , 连续未命中次数 : {} ",urlType,heapCount);
if (heapCount >= 15 && (heapCount - 15) % 10 == 0) {
String alarmLevel = "Warn";
if (heapCount == 85 || heapCount == 165) {
alarmLevel = "Emergency";
}
commonAlarmCmpt.alarm(alarmLevel, "三方数据源告警", "数据源【" + urlType + "】查询连续" + heapCount + "次未命中");
}
}catch (Exception e){
log.error("三方数据源统计查询命中率异常, urlType: {} ",urlType ,e);
}
}
});
}
}
/**
*
*/
package cn.quantgroup.report.config.aop;
import java.lang.annotation.*;
/**
*
* @author renfeng
*
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DistributedLock {
}
/**
*
*/
package cn.quantgroup.report.config.aop;
import com.google.common.base.Joiner;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
* 对数据源请求加锁,不包含transactionId(第一个入参), 如:method(transactionId, a, b), 锁 key 为 qry_lock_a_b
*/
@Aspect
@Component
public class DistributedLockAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(DistributedLockAspect.class);
private static final String USER_LOCK = "qry_lock_";
@Autowired
private RedisTemplate redisTemplate;
@Pointcut("@annotation(cn.quantgroup.report.config.aop.DistributedLock)")
private void userQryPointCut() {
}
@Around("userQryPointCut()")
public Object process(ProceedingJoinPoint point) throws Throwable {
String key = null;
Object proceed = null;
try{
String methodName = point.getSignature().getName();
Object[] args = point.getArgs();
if(args.length <= 1){
LOGGER.info("切面获取参数问题, method: {}, args: {}", methodName, args);
proceed = point.proceed();
return proceed;
}
//不包含transactionID的其他参数
Object[] newarr= Arrays.copyOfRange(args, 1, args.length);
key = Joiner.on("_").useForNull("!").join(newarr);
key = new StringBuffer().append(USER_LOCK).append(methodName).append("_").append(key).toString();
boolean flag = true;
int count = 1;
while(!setIfAbsent(key, "1", 3, TimeUnit.SECONDS)){
if(flag) {
LOGGER.info("查询命中锁, key: {}, args: {}", key, args);
flag =false;
}
Thread.sleep(100);
if(count>30){
redisTemplate.delete(key);
}
count++;
}
proceed = point.proceed();
}catch(Exception e){
proceed = point.proceed();
}finally{
if(key != null) {
redisTemplate.delete(key);
}
}
return proceed;
}
public boolean setIfAbsent(String key,String value,long time, TimeUnit timeUnit) {
try{
Boolean setIfAbsent = redisTemplate.opsForValue().setIfAbsent(key, value);
if(setIfAbsent)
redisTemplate.expire(key, time, timeUnit);
return setIfAbsent;
}catch(Exception e){
LOGGER.error("REDIS原子性操作异常!",e);
}
return true;
}
}
/**
*
*/
package cn.quantgroup.report.config.aop;
import java.lang.annotation.*;
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Monitor {
/** 监控类型 */
MonitorType[] value();
}
/**
*
*/
package cn.quantgroup.report.config.aop;
import cn.quantgroup.report.cmpt.CommonAlarmCmpt;
import cn.quantgroup.report.cmpt.MonitorCmpt;
import cn.quantgroup.report.constant.TransactionCodeEnum;
import cn.quantgroup.report.response.TransactionResult;
import cn.quantgroup.report.service.thirdpartymonitor.ThirdpartyApiMonitorService;
import cn.quantgroup.report.utils.StringUtil;
import cn.quantgroup.report.enums.RequestUrlType;
import cn.quantgroup.report.response.GlobalResponse;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 1.监控数据源
* 2.统一结果处理
*/
@Slf4j
@Aspect
@Component
public class MonitorAspect {
protected static ExecutorService dbLogPool = new ThreadPoolExecutor(20,50,200, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
@Autowired
private ThirdpartyApiMonitorService thirdpartyApiMonitorService;
@Autowired
private CommonAlarmCmpt iMonitorAlarmService;
@Autowired
protected MonitorCmpt monitorCmpt;
@Pointcut("@annotation(cn.quantgroup.report.config.aop.Monitor)")
private void userQryPointCut() {
}
@Around("userQryPointCut()")
public Object process(ProceedingJoinPoint point) throws Throwable {
log.info("enter MonitorAspect point : {}", point);
long begin = System.currentTimeMillis();
Object result = point.proceed();
long timeConsume = System.currentTimeMillis()- begin;
dbLogPool.execute(()-> {
try {
Signature sig = point.getSignature();
if (!(sig instanceof MethodSignature)) {
log.warn("process msig :{}", sig);
return;
}
MethodSignature msig = (MethodSignature) sig;
Object target = point.getTarget();
Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());
Monitor annotation = currentMethod.getAnnotation(Monitor.class);
MonitorType[] monitorTypes = annotation.value();
if (!(result instanceof GlobalResponse)) return;
GlobalResponse response = (GlobalResponse) result;
log.info("handle response : {}" , StringUtil.shortPrintLog(response.toString()));
Arrays.stream(monitorTypes).forEach(o -> {
try {
switch (o) {
case FEE:
handleFee(response);
break;
case EXCEPTION:
handleException(response, point.getArgs(), timeConsume);
break;
case RESULT:
handleResult(response);
break;
case HIT:
handleHitStat(response);
break;
}
}catch (Exception e){
log.error("处理结果异常", e);
}
});
}catch (Exception e){
log.error("统一处理异常", e);
}
});
return result;
}
/**
* 统计查询命中情况并告警
* @param response
*/
private void handleHitStat(GlobalResponse response) {
log.info("handleHitStat start transactionId {}", response.getTransactionId());
List<TransactionResult> transactionResults = response.getTransactionResult();
transactionResults.stream().forEach(o -> {
TransactionCodeEnum tansactionCode = o.getTansactionCode();
if (TransactionCodeEnum.SuccessAndMiss.equals(tansactionCode)) {
monitorCmpt.statisticHitRate(o.getUrlType().name(), 0);
} else if(TransactionCodeEnum.SuccessAndHit.equals(tansactionCode)){
monitorCmpt.statisticHitRate(o.getUrlType().name(), 1);
}
});
}
/**
* 处理查询结果,记录查询
*/
private void handleResult(GlobalResponse response) {
String transactionId = response.getTransactionId();
log.info("handleResult start transactionId {}", transactionId);
List<TransactionResult> transactionResults = response.getTransactionResult();
for (TransactionResult transactionResult : transactionResults) {
RequestUrlType urlType = transactionResult.getUrlType();
TransactionCodeEnum tansactionCode = transactionResult.getTansactionCode();
if(StringUtils.isNotBlank(response.getUuid())) {
thirdpartyApiMonitorService.saveTransactionLog(urlType, transactionId, response.getUuid(), tansactionCode);
} else if(StringUtils.isNotBlank(response.getIdentity())) {
thirdpartyApiMonitorService.saveTransactionLogByIdentifyNumber(urlType, transactionId, response.getIdentity(), tansactionCode);
}else if(StringUtils.isNotBlank(response.getPhone())) {
thirdpartyApiMonitorService.saveTransactionLogByPhone(urlType, transactionId, response.getPhone(), tansactionCode);
} else {
thirdpartyApiMonitorService.saveTransactionLog(urlType, transactionId, null, tansactionCode);
}
}
}
/**
* 处理异常,统一告警
*/
private void handleException(GlobalResponse response, Object[] args, long timeConsume) {
log.info("handleception start transactionId {}, url_type, timeConsume {}", response.getTransactionId(), timeConsume, response.getTransactionResult());
List<TransactionResult> transactionResult = response.getTransactionResult();
transactionResult.stream().forEach(o -> {
TransactionCodeEnum tansactionCode = o.getTansactionCode();
if(TransactionCodeEnum.Fail.equals(tansactionCode)){
int code = response.getCode();
String error = response.getError();
boolean isReadCache = (boolean) args[args.length-1];
if(!isReadCache){
iMonitorAlarmService.alarm("WARN","数据源告警 : " + o.getUrlType().getUrlName(),"code : " + code + "; msg : " + error + " args : " + Arrays.toString(args));
}else{
log.info("handleException is ReadCache: {} ", JSON.toJSONString(args));
}
} else {
//超时告警
if(timeConsume > 60000){
iMonitorAlarmService.alarm("WARN","数据源调用超时 : " + o.getUrlType().getUrlName(),JSON.toJSONString(args)+"耗时 : " + timeConsume + "ms");
}
}
});
}
/**
* record fee
*/
private void handleFee(GlobalResponse response) {
// log.info("handleFee response transactionId: {}" , response.getTransactionId());
// if(response.getIsBilling()){
// List<TransactionResult> transactionResult = response.getTransactionResult();
// transactionResult.stream().forEach(o -> {
// thirdpartyApiMonitorService.recordCost(o.getUrlType(), o.getUrlType().getSourceName());
// }
// );
// }
}
}
package cn.quantgroup.report.config.aop;
public enum MonitorType {
/** 监控所有异常 */
EXCEPTION,
/** 监控费用 */
FEE,
/** 监控结果 */
RESULT,
/** 监控命中情况 */
HIT
}
package cn.quantgroup.report.config.datasource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
/**
* Created by suh on 2018/1/15.
*/
@Configuration
@EnableAsync
public class ExecutorConfig {
private int corePoolSize = 2;
private int maxPoolSize = 10;
private int queueCapacity = 50;
@Bean(name = "DianHuaBangCallBack")
public Executor DianHuaBangCallBack() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("DianHuaBangCallBack-");
executor.initialize();
return executor;
}
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
}
package cn.quantgroup.report.config.datasource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.JedisPoolConfig;
import java.util.HashSet;
import java.util.Set;
/**
* Created by ocean on 2017/5/27.
*/
@Configuration
public class RedisConfig {
@Value("${risk.data.redis.defaultExpiration}")
private Long defaultExpiration;
@Value("${risk.redis.master.host}")
private String masterHost;
@Value("${risk.redis.master.port}")
private int masterPort;
@Value("${risk.redis.master.name}")
private String masterName;
@Value("${risk.redis.sentinel1.host}")
private String sentinel1Host;
@Value("${risk.redis.sentinel1.port}")
private int sentinel1port;
@Value("${risk.redis.sentinel2.host}")
private String sentinel2Host;
@Value("${risk.redis.sentinel2.port}")
private int sentinel2port;
@Value("${risk.redis.sentinel3.host}")
private String sentinel3Host;
@Value("${risk.redis.sentinel3.port}")
private int sentinel3port;
private RedisConnectionFactory generateDevConnectionFactory() {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(masterHost);
factory.setPort(masterPort);
factory.setUsePool(true);
factory.setConvertPipelineAndTxResults(true);
JedisPoolConfig poolConfig = generatePoolConfig();
factory.setPoolConfig(poolConfig);
factory.afterPropertiesSet();
return factory;
}
private RedisConnectionFactory generateReleaseConnectionFactory() {
RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration();
RedisNode master = new RedisNode(masterHost, masterPort);
master.setName(masterName);
Set<RedisNode> sentinels = new HashSet<>();
RedisNode sentinel1 = new RedisNode(sentinel1Host, sentinel1port);
RedisNode sentinel2 = new RedisNode(sentinel2Host, sentinel2port);
RedisNode sentinel3 = new RedisNode(sentinel3Host, sentinel3port);
sentinels.add(sentinel1);
sentinels.add(sentinel2);
sentinels.add(sentinel3);
sentinelConfiguration.setMaster(master);
sentinelConfiguration.setSentinels(sentinels);
JedisPoolConfig poolConfig = generatePoolConfig();
JedisConnectionFactory factory = new JedisConnectionFactory(sentinelConfiguration, poolConfig);
factory.setHostName(masterHost);
factory.setPort(masterPort);
factory.setTimeout(10000);
factory.setUsePool(true);
factory.setConvertPipelineAndTxResults(true);
factory.afterPropertiesSet();
return factory;
}
private JedisPoolConfig generatePoolConfig() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMinIdle(20);
poolConfig.setMaxTotal(300);
poolConfig.setMaxWaitMillis(5000);
poolConfig.setTestOnBorrow(true);
return poolConfig;
}
@Bean(name = "redisConnectionFactory")
RedisConnectionFactory factory() {
if (StringUtils.isEmpty(masterName)) {
return generateDevConnectionFactory();
} else {
return generateReleaseConnectionFactory();
}
}
@Bean(name = "redisTemplate")
public RedisTemplate<String, Object> redisTemplate(
RedisConnectionFactory factory) {
final RedisTemplate<String, Object> template = new RedisTemplate<>();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
JdkSerializationRedisSerializer jdkSerializationRedisSerializer =
new JdkSerializationRedisSerializer();
template.setEnableTransactionSupport(false);
template.setKeySerializer(stringRedisSerializer);
template.setHashKeySerializer(stringRedisSerializer);
template.setValueSerializer(jdkSerializationRedisSerializer);
template.setDefaultSerializer(jdkSerializationRedisSerializer);
template.setConnectionFactory(factory);
return template;
}
@Bean(name = "stringRedisTemplate")
public RedisTemplate<String, String> stringRedisTemplate(
RedisConnectionFactory factory) {
final RedisTemplate<String, String> template = new RedisTemplate<>();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
template.setEnableTransactionSupport(false);
template.setKeySerializer(stringRedisSerializer);
template.setHashKeySerializer(stringRedisSerializer);
template.setValueSerializer(stringRedisSerializer);
template.setDefaultSerializer(stringRedisSerializer);
template.setConnectionFactory(factory);
return template;
}
@Bean(name = "cacheManager")
public CacheManager cacheManager(RedisTemplate<String, Object> redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
cacheManager.setDefaultExpiration(defaultExpiration);
cacheManager.setUsePrefix(true);
return cacheManager;
}
}
package cn.quantgroup.report.config.datasource.baihang;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Import(BaiHangDataSourcePreperties.class)
@Configuration
@Slf4j
@MapperScan(basePackages = BaiHangDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "baihangSqlSessionFactory")
public class BaiHangDataSourceConfig {
static final String PACKAGE = "cn.quantgroup.report.mapper.baihang";
@Value("${baihang.mapper-locations}")
private String mapperLocations;
@Value("${baihang.type-aliases-package}")
private String typeAliasesPackage;
@Value("${config-location}")
private String configLocation;
@Autowired
private BaiHangDataSourcePreperties baiHangDataSourcePreperties;
@Bean(name = "baihangDataSource")
@Primary
public DataSource baihangDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(baiHangDataSourcePreperties.getJdbcUrl());
log.info("百行征信数据库地址:{}", baiHangDataSourcePreperties.getJdbcUrl());
config.setPassword(baiHangDataSourcePreperties.getPassword());
config.setUsername(baiHangDataSourcePreperties.getUsername());
config.setMaximumPoolSize(baiHangDataSourcePreperties.getMaxPoolSize());
config.setMinimumIdle(baiHangDataSourcePreperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
@Bean(name = "baihangTransactionManager")
@Primary
public DataSourceTransactionManager baihangTransactionManager(@Qualifier("baihangDataSource") DataSource baihangDataSource) {
return new DataSourceTransactionManager(baihangDataSource);
}
@Bean(name = "baihangSqlSessionFactory")
@Primary
public SqlSessionFactory baihangSqlSessionFactory(@Qualifier("baihangDataSource") DataSource baihangDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(baihangDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver()
.getResource(configLocation));
return sessionFactory.getObject();
}
@Bean(name = "baihangSqlSessionTemplate")
@Primary
public SqlSessionTemplate baihangSqlSessionTemplate(@Qualifier("baihangSqlSessionFactory") SqlSessionFactory baihangSqlSessionFactory) throws Exception {
return new SqlSessionTemplate(baihangSqlSessionFactory);
}
}
package cn.quantgroup.report.config.datasource.baihang;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Setter
@Getter
@Configuration
public class BaiHangDataSourcePreperties {
@Value("${db.driver}")
private String driverClass;
@Value("${baihang.db.minPoolSize}")
private int minPoolSize;
@Value("${baihang.db.maxPoolSize}")
private int maxPoolSize;
@Value("${data.source.baihang.jdbcUrl}")
private String jdbcUrl;
//private String jdbcUrl = "jdbc:mysql://172.20.6.29:4010/rc_real_time_data_pool?useUnicode=true&characterEncoding=UTF8&useSSL=false";
//private String jdbcUrl = "jdbc:mysql://172.20.6.21:4010/rc_real_time_data_pool?useUnicode=true&characterEncoding=UTF8&useSSL=false";
@Value("${data.source.baihang.username}")
private String username;
@Value("${data.source.baihang.password}")
private String password;
}
package cn.quantgroup.report.config.datasource.history;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Import(XyqbHistoryDataSourcePreperties.class)
@Configuration
@Slf4j
@MapperScan(basePackages = XyqbHistoryDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "xyqbHistorySqlSessionFactory")
public class XyqbHistoryDataSourceConfig {
static final String PACKAGE = "cn.quantgroup.report.mapper.history";
//@Value("${baihang.mapper-locations}")
private String mapperLocations = "classpath:cn/quantgroup/report/mapper/history/*.xml";
//@Value("${baihang.type-aliases-package}")
private String typeAliasesPackage = "cn.quantgroup.report.mapper.history";
@Value("${config-location}")
private String configLocation;
@Autowired
private XyqbHistoryDataSourcePreperties xyqbHistoryDataSourcePreperties;
@Bean(name = "xyqbHistoryDataSource")
public DataSource xyqbHistoryDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(xyqbHistoryDataSourcePreperties.getJdbcUrl());
log.info("xyqb历史数据库地址:{}", xyqbHistoryDataSourcePreperties.getJdbcUrl());
config.setPassword(xyqbHistoryDataSourcePreperties.getPassword());
config.setUsername(xyqbHistoryDataSourcePreperties.getUsername());
config.setMaximumPoolSize(xyqbHistoryDataSourcePreperties.getMaxPoolSize());
config.setMinimumIdle(xyqbHistoryDataSourcePreperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
@Bean(name = "xyqbHistoryTransactionManager")
public DataSourceTransactionManager xyqbHistoryTransactionManager(@Qualifier("xyqbHistoryDataSource") DataSource xyqbHistoryDataSource) {
return new DataSourceTransactionManager(xyqbHistoryDataSource);
}
/* @Bean(name = "xyqbHistorySqlSessionFactory")
public SqlSessionFactory xyqbHistorySqlSessionFactory(@Qualifier("xyqbHistoryDataSource") DataSource xyqbHistoryDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(xyqbHistoryDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver()
.getResource(configLocation));
return sessionFactory.getObject();
}*/
/*
@Bean(name = "xyqbHistorySqlSessionTemplate")
public SqlSessionTemplate xyqbHistorySqlSessionTemplate(@Qualifier("xyqbHistorySqlSessionFactory") SqlSessionFactory xyqbHistorySqlSessionFactory) throws Exception {
return new SqlSessionTemplate(xyqbHistorySqlSessionFactory);
}*/
@Bean(name = "xyqbHistoryJdbcTemplate")
public JdbcTemplate primaryJdbcTemplate(@Qualifier("xyqbHistoryDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
package cn.quantgroup.report.config.datasource.history;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Setter
@Getter
@Configuration
public class XyqbHistoryDataSourcePreperties {
@Value("${db.driver}")
private String driverClass;
@Value("${baihang.db.minPoolSize}")
private int minPoolSize;
@Value("${baihang.db.maxPoolSize}")
private int maxPoolSize;
//@Value("${data.source.baihang.jdbcUrl}")
//private String jdbcUrl="jdbc:mysql://172.20.6.29:4010/rc_real_time_data_pool?useUnicode=true&characterEncoding=UTF8&useSSL=false";
private String jdbcUrl = "jdbc:mysql://172.20.6.21:4010/rc_real_time_data_pool?useUnicode=true&characterEncoding=UTF8&useSSL=false";
//@Value("${data.source.baihang.username}")
private String username="xyqb_history_w";
//@Value("${data.source.baihang.password}")
private String password="KDb18asPu6iEz5lg";
}
package cn.quantgroup.report.config.datasource.master;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* Desc:
* User: HaiNan.Wang
* Date: 2017/5/2
*/
@Import(RiskDatasourceProperties.class)
@Configuration
@MapperScan(basePackages = RiskDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory")
public class RiskDataSourceConfig {
static final String PACKAGE = "cn.quantgroup.report.mapper.master";
@Value("${master.mapper-locations}")
private String mapperLocations;
@Value("${master.type-aliases-package}")
private String typeAliasesPackage;
@Value("${config-location}")
private String configLocation;
@Value("${db.driver:com.mysql.jdbc.Driver}")
private String driverClass;
@Autowired
private RiskDatasourceProperties repaymentPlanProperties;
@Bean(name = "masterDataSource")
public DataSource masterDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(repaymentPlanProperties.getRiskDatasourceJdbcUrl());
config.setPassword(repaymentPlanProperties.getRiskDatasourcePassword());
config.setUsername(repaymentPlanProperties.getRiskDatasourceUsername());
config.setMaximumPoolSize(repaymentPlanProperties.getMaxPoolSize());
config.setMinimumIdle(repaymentPlanProperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
@Bean(name = "masterTransactionManager")
public DataSourceTransactionManager repaymentPlanDataSourceTransactionManager(@Qualifier("masterDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "masterSqlSessionFactory")
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(masterDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver()
.getResource(configLocation));
return sessionFactory.getObject();
}
@Bean(name = "masterSqlSessionTemplate")
public SqlSessionTemplate masterSqlSessionTemplate(@Qualifier("masterSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "riskDatasourceJdbcTemplate")
public JdbcTemplate primaryJdbcTemplate(@Qualifier("masterDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
package cn.quantgroup.report.config.datasource.master;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* Desc:
* User: HaiNan.Wang
* Date: 2017/5/2
*/
@Getter
@Setter
@Configuration
public class RiskDatasourceProperties {
@Value("${db.driver}")
private String driverClass;
@Value("${db.minPoolSize}")
private int minPoolSize;
@Value("${db.maxPoolSize}")
private int maxPoolSize;
/**
* repaymentplan
*/
@Value("${db.risk_datasource.url}")
private String riskDatasourceJdbcUrl;
@Value("${db.risk_datasource.username}")
private String riskDatasourceUsername;
@Value("${db.risk_datasource.password}")
private String riskDatasourcePassword;
}
package cn.quantgroup.report.config.datasource.tidbrisk;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* -----------------------------------------------------------------------------<br>
* 描述: tidb中call_record日志表 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.12.30 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Import(TidbRiskDatasourceProperties.class)
@Configuration
@Slf4j
@MapperScan(basePackages = TidbRiskDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "tidbRiskSqlSessionFactory")
public class TidbRiskDataSourceConfig {
static final String PACKAGE = "cn.quantgroup.report.mapper.tidbrisk";
//@Value("${tidb.risk_datasource.mapper-locations}")
private String mapperLocations="classpath:cn/quantgroup/report/mapper/tidbrisk/*.xml";//resources *.xml
//@Value("${tidb.risk_datasource.type-aliases-package}")
private String typeAliasesPackage="cn.quantgroup.report.domain.tidbrisk";//实体pojo
@Value("${config-location}")
private String configLocation;
@Autowired
private TidbRiskDatasourceProperties tidbRiskDatasourceProperties;
@Bean(name = "tidbRiskDataSource")
public DataSource tidbRiskDataSource() {
HikariConfig config = new HikariConfig();
log.info("tidb.risk_datasource数据库地址:{}",tidbRiskDatasourceProperties.getTidbRiskDatasourceJdbcUrl());
config.setJdbcUrl(tidbRiskDatasourceProperties.getTidbRiskDatasourceJdbcUrl());
config.setPassword(tidbRiskDatasourceProperties.getTidbRiskDatasourcePassword());
config.setUsername(tidbRiskDatasourceProperties.getTidbRiskDatasourceUsername());
config.setMaximumPoolSize(tidbRiskDatasourceProperties.getMaxPoolSize());
config.setMinimumIdle(tidbRiskDatasourceProperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
@Bean(name = "tidbRiskTransactionManager")
public DataSourceTransactionManager tidbRiskTransactionManager(@Qualifier("tidbRiskDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "tidbRiskSqlSessionFactory")
public SqlSessionFactory tidbRiskSqlSessionFactory(@Qualifier("tidbRiskDataSource") DataSource tidbRiskDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(tidbRiskDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver()
.getResource(configLocation));
return sessionFactory.getObject();
}
@Bean(name = "tidbRiskSqlSessionTemplate")
public SqlSessionTemplate tidbRiskSqlSessionTemplate(@Qualifier("tidbRiskSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
@Bean(name = "tidbRiskJdbcTemplate")
public JdbcTemplate tidbRiskJdbcTemplate(@Qualifier("tidbRiskDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
package cn.quantgroup.report.config.datasource.tidbrisk;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* -----------------------------------------------------------------------------<br>
* 描述: tidb中call_record日志表 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.12.30 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Getter
@Setter
@Configuration
public class TidbRiskDatasourceProperties {
@Value("${db.driver}")
private String driverClass;
@Value("${db.minPoolSize}")
private int minPoolSize;
@Value("${db.maxPoolSize}")
private int maxPoolSize;
/**
* tidb.risk_datasource
*/
@Value("${db.tidb.risk_datasource.fullurl}")
private String tidbRiskDatasourceJdbcUrl;
//private String tidbRiskDatasourceJdbcUrl="jdbc:mysql://fengkong-tidb.quantgroups.com:4010/risk_datasource?useUnicode=true&characterEncoding=UTF8";
@Value("${db.tidb.risk_datasource.username}")
private String tidbRiskDatasourceUsername;
//private String tidbRiskDatasourceUsername="risk_datasource_w";
@Value("${db.tidb.risk_datasource.password}")
private String tidbRiskDatasourcePassword;
//private String tidbRiskDatasourcePassword="50GjQLd6hUOSeTMB";
}
package cn.quantgroup.report.config.datasource.xyqbuser;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* Desc:
* User: HaiNan.Wang
* Date: 2017/5/2
*/
@Import(XyqbUserDatasourceProperties.class)
@Configuration
@Slf4j
@MapperScan(basePackages = XyqbUserDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "xyqbUserSqlSessionFactory")
public class XyqbUserDataSourceConfig {
static final String PACKAGE = "cn.quantgroup.report.mapper.xyqbuser";
@Value("${xyqb_user.mapper-locations}")
private String mapperLocations;
@Value("${xyqb_user.type-aliases-package}")
private String typeAliasesPackage;
@Value("${config-location}")
private String configLocation;
@Autowired
private XyqbUserDatasourceProperties xyqbUserDatasourceProperties;
@Bean(name = "xyqbUserDataSource")
public DataSource xyqbUserDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(xyqbUserDatasourceProperties.getJdbcUrl());
log.info("数据库地址:{}", xyqbUserDatasourceProperties.getJdbcUrl());
config.setPassword(xyqbUserDatasourceProperties.getPassword());
config.setUsername(xyqbUserDatasourceProperties.getUsername());
config.setMaximumPoolSize(xyqbUserDatasourceProperties.getMaxPoolSize());
config.setMinimumIdle(xyqbUserDatasourceProperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(config);
}
@Bean(name = "xyqbUserTransactionManager")
public DataSourceTransactionManager xyqbUserTransactionManager(@Qualifier("xyqbUserDataSource") DataSource xyqbUserDataSource) {
return new DataSourceTransactionManager(xyqbUserDataSource);
}
@Bean(name = "xyqbUserSqlSessionFactory")
public SqlSessionFactory xyqbUserSqlSessionFactory(@Qualifier("xyqbUserDataSource") DataSource xyqbUserDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(xyqbUserDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver()
.getResource(configLocation));
return sessionFactory.getObject();
}
@Bean(name = "xyqbUserSqlSessionTemplate")
public SqlSessionTemplate xyqbUserSqlSessionTemplate(@Qualifier("xyqbUserSqlSessionFactory") SqlSessionFactory xyqbUserSqlSessionFactory) throws Exception {
return new SqlSessionTemplate(xyqbUserSqlSessionFactory);
}
}
package cn.quantgroup.report.config.datasource.xyqbuser;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* Desc:
* User: HaiNan.Wang
* Date: 2017/5/2
*/
@Getter
@Setter
@Configuration
public class XyqbUserDatasourceProperties {
@Value("${db.driver}")
private String driverClass;
@Value("${db.minPoolSize}")
private int minPoolSize;
@Value("${db.maxPoolSize}")
private int maxPoolSize;
@Value("${db.xyqb_user.url}")
private String jdbcUrl;
@Value("${db.xyqb_user.username}")
private String username;
@Value("${db.xyqb_user.password}")
private String password;
}
package cn.quantgroup.report.config.filter;
import cn.quantgroup.report.fastjson.CustomValueFilter;
import com.google.common.collect.Sets;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ValueFilterConfig {
@Bean("qianHaiMaskedValueFilter")
public CustomValueFilter qianHaiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("idNo", "idType", "name"));
}
@Bean("jdMaskedValueFilter")
public CustomValueFilter jdMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("mobile", "c_mobile", "address", "cust_id"));
}
@Bean("creditXMaskedValueFilter")
public CustomValueFilter creditXMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("id", "user_name", "mobile_number", "identity_number"));
}
@Bean("baiRongMaskedValueFilter")
public CustomValueFilter baiRongMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("id", "name", "cell", "bank_id"));
}
@Bean("shuMeiMaskedValueFilter")
public CustomValueFilter shuMeiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("phone", "imei", "idfa", "name", "prcid", "cardid"));
}
@Bean("tongDunMaskedValueFilter")
public CustomValueFilter tongDunMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("account_name", "id_number", "account_mobile"));
}
@Bean("zhiMaMaskedValueFilter")
public CustomValueFilter zhiMaMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("address", "bankCard", "certNo", "bank_card", "cert_no", "mobile"));
}
@Bean("qCloudMaskedValueFilter")
public CustomValueFilter qCloudMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("idNumber", "phoneNumber", "name","uid","userIp"));
}
@Bean("zhengXin91MaskedValueFilter")
public CustomValueFilter zhengXin91MaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("realName", "idCard"));
}
@Bean("haoAnMaskedValueFilter")
public CustomValueFilter haoAnMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "id", "appkey", "phone"));
}
@Bean("baiDuMaskedValueFilter")
public CustomValueFilter baiDuMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "identity", "appkey", "phone", "sp_no"));
}
@Bean("intelliCreditMaskedValueFilter")
public CustomValueFilter intelliCreditMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "pid", "mobile"));
}
@Bean("baiQiShiMaskedValueFilter")
public CustomValueFilter baiQiShiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "identity","phone","verifyKey","partnerId"));
}
@Bean("dianHuaBangMaskedValueFilter")
public CustomValueFilter dianHuaBangMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("phone"));
}
@Bean("rong360MaskedValueFilter")
public CustomValueFilter rong360MaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("orderNo"));
}
@Bean("unionPayMaskedValueFilter")
public CustomValueFilter unionPayMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("bankCardNo","name","identityNo","phone"));
}
@Bean("chengAnMaskedValueFilter")
public CustomValueFilter chengAnMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name","idCard","mobiel"));
}
@Bean("shengDunMaskedValueFilter")
public CustomValueFilter shengDunMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name","identityNumber","phone"));
}
@Bean("xinYanMaskedValueFilter")
public CustomValueFilter xinYanMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name","identity","phone","bankCard"));
}
@Bean("elevenBeiMaskedValueFilter")
public CustomValueFilter elevenBeiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("identity"));
}
@Bean("tianXingHuiMaskedValueFilter")
public CustomValueFilter tianXingHuiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name","identity","phone"));
}
@Bean("zhongChengXinMaskedValueFilter")
public CustomValueFilter zhongChengXinMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name","identityNumber"));
}
@Bean("jiGuangMaskedValueFilter")
public CustomValueFilter jiGuangMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name","id_number","phone"));
}
@Bean("kaNiuMaskedValueFilter")
public CustomValueFilter kaNiuMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name"));
}
@Bean("shuChuangMaskedValueFilter")
public CustomValueFilter shuChuangMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("mobile"));
}
@Bean("faHaiMaskedValueFilter")
public CustomValueFilter faHaiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "idCard"));
}
@Bean("tianChuangMaskedValueFilter")
public CustomValueFilter tianChuangMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "identity", "phone"));
}
@Bean("tanZhiMaskedValueFilter")
public CustomValueFilter tanZhiMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "identity", "phone"));
}
@Bean("jiAoMaskedValueFilter")
public CustomValueFilter jiAoMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "idCard"));
}
@Bean("bingJianMaskedValueFilter")
public CustomValueFilter bingJianMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "id", "phone", "bankCard"));
}
@Bean("anLiangMaskedValueFilter")
public CustomValueFilter anLiangMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "idCard", "mobile", "bankCard"));
}
@Bean("zhiShuMaskedValueFilter")
public CustomValueFilter zhiShuMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("name", "idCard", "mobile"));
}
@Bean("ficoMaskedValueFilter")
public CustomValueFilter ficoMaskedValueFilter() {
return new CustomValueFilter(Sets.newHashSet("mobile", "idCard"));
}
}
\ No newline at end of file
/**
*
*/
package cn.quantgroup.report.config.http;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.NoHttpResponseException;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.net.ssl.*;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* @author guowei.wei
* @time 2018-05-30 10:11
*/
@Configuration
public class HttpClientConfig {
@Bean(name = "httpClient")
public CloseableHttpClient httpClient() throws NoSuchAlgorithmException, KeyManagementException {
/**
* 忽略证书
*/
HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier(){
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
/**
* 创建TrustManager
*/
X509TrustManager xtm = new X509TrustManager(){
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() { return null; }
public boolean isServerTrusted(
X509Certificate[] certs) {
return true;
}
public boolean isClientTrusted(
X509Certificate[] certs) {
return true;
}
};
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, new TrustManager[]{xtm}, new SecureRandom());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,ignoreHostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslsf)
.build();
// connection manager
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(10000);
connectionManager.setDefaultMaxPerRoute(1000);
HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() {
@Override
public boolean retryRequest(IOException arg0, int retryTimes, HttpContext arg2) {
if (retryTimes >= 2)
return false;
if (arg0 instanceof UnknownHostException || arg0 instanceof ConnectTimeoutException
|| !(arg0 instanceof SSLException) || arg0 instanceof NoHttpResponseException || arg0 instanceof InterruptedIOException)
return true;
HttpClientContext clientContext = HttpClientContext.adapt(arg2);
HttpRequest request = clientContext.getRequest();
if (!(request instanceof HttpEntityEnclosingRequest)) // 如果请求被认为是幂等的,那么就重试。即重复执行不影响程序其他效果的
return true;
return false;
}
};
// keep alive strategy
ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
// httpclient
return HttpClients.custom()
.setConnectionManager(connectionManager)
.setRetryHandler(retryHandler)
.setKeepAliveStrategy(keepAliveStrategy)
.build();
}
}
package cn.quantgroup.report.constant;/**
* -----------------------------------------------------------------------------<br>
* 描述: <br>
* 作者: Administrator <br>
* 时间: 2019.11.14 10:56 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
/**
* -----------------------------------------------------------------------------<br>
* 描述: <br>
* 作者:yanhui.Hao <br>
* 时间:2019.11.14 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public class BaiHangHistoryConstant {
public static final int MAX_COMMIT_COUT = 24000;//大于2万条会出现事务提交过长报错
public static final String SQL_COMMONE_TEMPLATE_HISTORY = "INSERT xyqb_i_loan_a_m_history_bak " +
" select * from xyqb_i_loan_application_manifest_history b " +
" where b.funding_corp_id in (420,520,580,650,670,810,240,640,700) " +
" and b.created_at >= '##STARTTIME##' and b.created_at < '##ENDTIME##'; ";
//报送查询 b.loan_paid_at<@t2 公司打款时间
public static final String SQL_COMMONE_TEMPLATE_PLAN = "INSERT xyqb_i_repayment_plan_bak " +
"select a.* from xyqb_i_repayment_plan a " +
" join xyqb_i_loan_a_m_history_bak b " +
" on a.loan_application_history_id = b.loan_application_history_id " +
"where b.created_at >= '##STARTTIME##' and b.created_at < '##ENDTIME##'; ";
//报送查询 a.repaid_at>=@t2 还款时间
//---------------------根据id去同步---------------------------
public static final String SQL_COMMONE_TEMPLATE_HISTORY_BAK_MAX_ID = "select MAX(b.id) as bakMaxId from xyqb_i_loan_a_m_history_bak b; ";
public static final String SQL_COMMONE_TEMPLATE_HISTORY_MAX_ID = " select MAX(b2.id) from xyqb_i_loan_application_manifest_history b2 " +
" where b2.funding_corp_id in (420,520,580,650,670,810,240,640,700) ";
//借款清单表xyqb_i_loan_application_manifest_history
public static final String SQL_COMMONE_TEMPLATE_HISTORY_SYN_COUNT = "select count(b.id) from xyqb_i_loan_application_manifest_history b " +
" where b.funding_corp_id in (420,520,580,650,670,810,240,640,700) " +
" and b.id > ##BAKMAXID## AND b.id <= ##NEWMAXID## ;";
public static final String SQL_COMMONE_TEMPLATE_HISTORY_SYN_DATA = "REPLACE INTO xyqb_i_loan_a_m_history_bak " + //"INSERT xyqb_i_loan_a_m_history_bak "
" select b.* from xyqb_i_loan_application_manifest_history b " +
" where b.funding_corp_id in (420,520,580,650,670,810,240,640,700) " +
" and b.id > ##STARTID## ";//AND b.id <= ##ENDID##
//还款计划表还款计划表xyqb_i_repayment_plan
public static final String SQL_COMMONE_TEMPLATE_PLAN_SYN_COUNT = "select count(a.id) from xyqb_i_repayment_plan a " +
" join xyqb_i_loan_a_m_history_bak b on a.loan_application_history_id = b.loan_application_history_id " +
" where b.id > ##BAKMAXID## AND b.id <= ##NEWMAXID## ;";
public static final String SQL_COMMONE_TEMPLATE_PLAN_SYN_DATA = "REPLACE INTO xyqb_i_repayment_plan_bak " + //"INSERT xyqb_i_repayment_plan_bak "
"select a.* from xyqb_i_repayment_plan a " +
" join xyqb_i_loan_a_m_history_bak b on a.loan_application_history_id = b.loan_application_history_id " +
" where b.id > ##STARTID## ";//AND b.id <= ##ENDID##
public static final String SQL_TEMPLATE_HISTORY_P2P = "REPLACE INTO xyqb_i_loan_a_m_history_p2p_bak " +
" select * from xyqb_i_loan_application_manifest_history b " +
" where b.funding_corp_id in (210,540) " +
" and b.loan_paid_at >= '##STARTTIME##' and b.loan_paid_at < '##ENDTIME##'; ";
public static final String SQL_TEMPLATE_PLAN_P2P = "REPLACE INTO xyqb_i_repayment_plan_p2p_bak " +
" select a.* from xyqb_i_repayment_plan a " +
" join xyqb_i_loan_a_m_history_p2p_bak b on a.loan_application_history_id = b.loan_application_history_id " +
" where b.loan_paid_at >= '##STARTTIME##' and b.loan_paid_at < '##ENDTIME##'; ";
}
package cn.quantgroup.report.constant;
/**
* Created by Alan on 2018/6/14.
*/
public class KeyConstant {
public static final String PROJECT_NAME = "risk_datasource:";
public static final String STAT = PROJECT_NAME + "stat:";
public static final String ONE_DAY = "one_day:";
public static final String ONE_HOUR = "one_hour:";
public static final String HEAP = "heap:";
public static final String HIT_RATE = STAT + "hit_rate:";
}
package cn.quantgroup.report.constant;
public enum TransactionCodeEnum {
SuccessAndHit("请求成功且命中", 1001),
SuccessAndMiss("请求成功且未命中", 1002),
Fail("请求失败", 1003),
HitInHbase("命中HBase", 1004);
private String name;
private int code;
TransactionCodeEnum(String name, int code){
this.name = name;
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
package cn.quantgroup.report.controller;
import cn.quantgroup.report.response.GlobalResponse;
import cn.quantgroup.report.service.cache.CacheService;
import cn.quantgroup.report.service.DataSourceCacheConfigService;
import cn.quantgroup.report.service.common.CommonQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping(value = "/cache")
public class CacheController {
@Autowired
private CacheService cacheService;
@Autowired
private DataSourceCacheConfigService cacheConfigService;
@Autowired
private CommonQueryService commonQueryService;
@Autowired
private RedisTemplate redisTemplate;
@RequestMapping("/clear_huadao_token")
public GlobalResponse clearHuadaoToken(){
try{
redisTemplate.delete("NEW_HUADAO_QUERY_TOKEN_KEY");
log.info("清除华道缓存token成功");
return GlobalResponse.generate("清除华道缓存token成功");
}catch(Exception e){
log.info("清除华道缓存token异常");
return GlobalResponse.generate("清除华道缓存token异常");
}
}
@RequestMapping("/get_huadao_token")
public GlobalResponse getHuadaoToken(){
try{
String token = String.valueOf(redisTemplate.opsForValue().get("NEW_HUADAO_QUERY_TOKEN_KEY"));
log.info("获取华道缓存token结果, token : {} ", token);
return GlobalResponse.generate(token);
}catch(Exception e){
log.info("获取华道缓存token异常");
return GlobalResponse.generate("获取华道缓存token异常");
}
}
@RequestMapping("/reload")
public GlobalResponse reload(){
try{
cacheConfigService.init();
log.info("刷新数据源缓存时间完成");
return GlobalResponse.generate("Ok");
}catch(Exception e){
log.info("刷新数据源缓存时间异常", e);
return GlobalResponse.generate(e.getMessage());
}
}
@RequestMapping("/config/clear")
public GlobalResponse clearConfigCache(String configName) {
try{
cacheService.clearCache(configName);
log.info("刷新缓存配置成功, configName: {} ", configName);
return GlobalResponse.generate("OK");
}catch (Exception e){
log.error("刷新缓存异常, {} , {} , {} ", configName, e.getMessage(), e);
return GlobalResponse.generate(e.getMessage());
}
}
@RequestMapping("/lock/clear")
public GlobalResponse clearLock(String lockName) {
try{
cacheService.clearLock(lockName);
return GlobalResponse.generate("OK");
}catch (Exception e){
log.error("{}", e.getMessage(), e);
return GlobalResponse.generate(e.getMessage());
}
}
}
package cn.quantgroup.report.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* @Author fengjunkai
*/
@Slf4j
@RestController
@RequestMapping("/")
public class CheckController {
private static Map<String,String> map = new ConcurrentHashMap<>();
@ResponseBody
@RequestMapping(value="check")
public ResponseEntity<String> check(){
if(map!=null && map.size()>0){
return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
}else{
return new ResponseEntity<String>(HttpStatus.OK);
}
}
@ResponseBody
@RequestMapping(value="/online")
public Map<String, String> online(){
log.info("应用上线,流量开始切入....");
map.clear();
return responseOk();
}
@ResponseBody
@RequestMapping(value="/offline")
public Map<String, String> offline(){
log.info("应用下线,流量不再切入....");
map.put("status", "offline");
return responseOk();
}
@ResponseBody
@RequestMapping(value="/test")
public Map<String, String> test() {
log.info("CheckController测试!map = {}", map);
return ImmutableMap.of("code", "0", "msg", JSON.toJSONString(map));
}
public static Map<String, String> responseOk() {
return ImmutableMap.of("code", "0", "msg", "ok");
}
@RequestMapping("/getuuid")
public String getUuid(String param){
return UUID.nameUUIDFromBytes(param.getBytes()).toString();
}
}
package cn.quantgroup.report.controller;
import com.netflix.discovery.DiscoveryManager;
import com.netflix.discovery.EurekaClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author fengjunkai
*/
@Slf4j
@RestController
@RequestMapping("/")
public class DiscoveryManagerController {
@Autowired
@Qualifier("eurekaClient")
private EurekaClient eurekaClient;
@RequestMapping("clientShutdown")
public void clientShutdown(){
try{
eurekaClient.shutdown();
log.info("百行报送项目通知eureka下线成功");
}catch(Exception e){
log.error("百行报送项目通知eureka下线异常", e);
}
}
@RequestMapping("test1")
public String test(){
try {
log.info("开始执行");
Thread.sleep(10000);
log.info("执行结束");
} catch (InterruptedException e) {
e.printStackTrace();
}
return "hello world !!!";
}
}
package cn.quantgroup.report.controller;
import cn.quantgroup.report.response.GlobalResponse;
import cn.quantgroup.report.service.common.CommonQueryService;
import cn.quantgroup.report.service.manualTool.CleanningTransactionLogService;
import cn.quantgroup.report.service.manualTool.ManualToolService;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping(value = "/manualtool")
public class ManualToolController {
@Autowired
private ManualToolService manualToolService;
@Autowired
private CommonQueryService queryService;
@Autowired
private CleanningTransactionLogService cleanningTransactionLogService;
@RequestMapping("/send/baihang")
public String sendBaihang(String p1,String p2,String p3,String p4,String p5,String secretKey, String isSend,String errorCode, String isProduct, String sendIncludeType) {
try{
Map<String,String> resultMap = manualToolService.sendBaiHangData(p1,p2,p3,p4,p5,secretKey,isSend,errorCode, isProduct, sendIncludeType);
return JSON.toJSONString(resultMap);
}catch (Exception e){
log.error("众信利民助贷模式To百行征信手动报送异常, {} , {} ", e.getMessage(), e);
return "众信利民助贷模式To百行征信手动报送异常";
}
}
/**
* 描述: 放款信息 D2 <br/>
* 参数: [jsonFile] <br/>
* 返回值: GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.27 <br/>
*/
@RequestMapping("/build/d2")
public GlobalResponse buildLoanInfoD2(String jsonFile) {
try{
return manualToolService.buildLoanInfoD2(jsonFile);
}catch (Exception e){
log.error("百行征信手动报送异常, {} , {} ", e.getMessage(), e);
return GlobalResponse.generate(e.getMessage());
}
}
@RequestMapping("/dealWithExcelData")
public GlobalResponse dealWithExcelData(String filePath,String type){
return manualToolService.dealWithExcelData(filePath,type);
}
@RequestMapping("/removeD3LoanIdChunfu")
public String remove_D3_loanId_chunfu(String oldDataFile, String cfLoanIdLogFile, String newFileName, String rmIdFileName,String rmPhoneFileName){
return manualToolService.remove_D3_loanId_chunfu(oldDataFile,cfLoanIdLogFile,newFileName,rmIdFileName,rmPhoneFileName);
}
@RequestMapping("/checkD3loanIdInD2")
public String check_D3loanId_InD2(String d3LoanIdFile, String d2File, String inFileName, String notInFileName){
return manualToolService.check_D3loanId_InD2(d3LoanIdFile,d2File,inFileName,notInFileName);
}
@RequestMapping("/checkD2loanIdInD3WanJie")
public String check_D2loanId_InD3WanJie(String d3LoanIdFile, String d2File, String notWJFileName){
return manualToolService.check_D2loanId_InD3WanJie(d3LoanIdFile,d2File,notWJFileName);
}
@RequestMapping("/newD3ReplaceReqId")
public String newD3ReplaceReqId(String newD3FilePath, String newD3FileNames, String oldD3ReqIdFile, String mapNotEmptyFile){
manualToolService.newD3ReplaceReqId(newD3FilePath,newD3FileNames,oldD3ReqIdFile,mapNotEmptyFile);
return "调用结束";
}
@RequestMapping("/d2_saveLog")
public String d2_saveLog(String d2JsonFileName,String reqIdFileName,String no_reqId_start, String isHaveRecordId){
manualToolService.d2_saveLog(d2JsonFileName,reqIdFileName,no_reqId_start,isHaveRecordId);
return "d2_saveLog调用结束";
}
@RequestMapping("/d3_saveLog")
public String d3_saveLog(String d3FilePath, String d3JsonFileNames, String reqIdLogName, String no_reqId_start, String isHaveRecordId){
manualToolService.d3_saveLog(d3FilePath,d3JsonFileNames,reqIdLogName,no_reqId_start,isHaveRecordId);
return "d3_saveLog调用结束";
}
@RequestMapping("/synCallRecordNew")
public String synCallRecordNew(String newYnrTime,String isExecuteOnce){
cleanningTransactionLogService.synCallRecordNew(newYnrTime,isExecuteOnce);
return "synCallRecordNew调度完成";
}
@RequestMapping("/checkCallRecordCF")
public String checkCallRecordCF(String newYnrTime,String isExecuteOnce){
cleanningTransactionLogService.checkCallRecordCF(newYnrTime,isExecuteOnce);
return "checkCallRecordCF调度完成";
}
@RequestMapping("/checkTransactionLogCF")
public String checkTransactionLogCF(String newYnrTime,String isExecuteOnce){
cleanningTransactionLogService.checkTransactionLogCF(newYnrTime,isExecuteOnce);
return "checkTransactionLogCF调度完成";
}
@RequestMapping("/checkCallRecordCFByTransactionLog")
public String checkCallRecordCFByTransactionLog(String newYnrTime,String isExecuteOnce){
cleanningTransactionLogService.checkCallRecordCFByTransactionLog(newYnrTime,isExecuteOnce);
return "checkCallRecordCFByTransactionLog调度完成";
}
@RequestMapping("/checkCallRecordCFByTransactionLog2")
public String checkCallRecordCFByTransactionLog2(String newYnrTime,String isExecuteOnce){
cleanningTransactionLogService.checkCallRecordCFByTransactionLog2(newYnrTime,isExecuteOnce);
return "checkCallRecordCFByTransactionLog2调度完成";
}
@RequestMapping("/deleteTidbCallRecordCF")
public String deleteTidbCallRecordCF(String cfFileName, String bakFileName){
cleanningTransactionLogService.deleteTidbCallRecordCF(cfFileName,bakFileName);
return "deleteTidbCallRecordCF调度完成";
}
@RequestMapping("/deleteRedisKey")
public Map<String,Object> deleteRedisKey(String key1, String key2, String key3){
try{
manualToolService.deleteRedisKey(key1, key2, key3);
return ImmutableMap.of("code", 0, "msg", "手动删除redisKey成功");
}catch(Exception e){
return ImmutableMap.of("code", 1, "msg", "手动设置redisKey异常");
}
}
@RequestMapping("/getRedisVal")
public String getRedisVal(String key){
try{
return manualToolService.getRedisVal(key);
}catch(Exception e){
return "获取redis值异常";
}
}
}
package cn.quantgroup.report.controller.external;
import cn.quantgroup.report.service.baihang.BaiHangQueryService;
import cn.quantgroup.report.service.common.CommonQueryService;
import cn.quantgroup.report.utils.IdUtils;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* Created by fengjunkai on 2018/8/13 0013 下午 4:48
**/
@Slf4j
@RestController
@RequestMapping(value = "/ex/common", method = RequestMethod.POST)
public class CommonSourceController {
@Autowired
private CommonQueryService queryService;
@Autowired
private BaiHangQueryService baiHangQueryService;
@RequestMapping("/query")
public Object commonQuery(String source_types, String uuid, String name, String phone, String identity, String backDate, String business_type, String order_id, boolean isReadCache){
Object object = queryService.commonQuery(source_types, uuid, name, phone, identity, backDate, business_type, order_id, isReadCache);
return object;
}
/**
* -----------------------------------------------------------------------------<br>
* 描 述: 百行个人征信报告查询 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.05.13 16:53 <br>
* 最后修改人: <br>
* 最后修改时间: 2020.05.13 16:53 <br>
* 入参说明: [transactionId, uuid, identity, phone, name, queryReason, loanId] <br>
* 出参说明: java.lang.String <br>
* -----------------------------------------------------------------------------
*/
@RequestMapping("/zxlmbh/persionCreditReport")
public String persionCreditReport(String key, String transactionId, String uuid, String identity, String phone, String name, String queryReason, String loanId) {
Map<String, Object> resultMap = null;
if(StringUtils.isEmpty(key) || !"b5140fb2-2c85-4b5a-abcf-3e97528014db".equals(key)){
resultMap = ImmutableMap.of("code", "301", "msg", "权限参数不能为空!");
}
if (StringUtils.isAnyBlank(identity, name, queryReason)) {
resultMap = ImmutableMap.of("code", "301", "msg", "业务参数不能为空!");
}else{
if (StringUtils.isEmpty(transactionId)) {
transactionId = IdUtils.getUuid();
}
resultMap = baiHangQueryService.queryBaiHangQ1OfZxlm(transactionId, uuid, identity, phone, name, queryReason, loanId);
}
return JSON.toJSONString(resultMap);
}
}
package cn.quantgroup.report.controller.external;
import cn.quantgroup.report.job.SynLoanInfoHistoryTask;
import cn.quantgroup.report.response.GlobalResponse;
import cn.quantgroup.report.service.baihang.BaiHangZhuDaiService;
import cn.quantgroup.report.service.manualTool.ManualToolService;
import cn.quantgroup.report.utils.ReadOrWriteTxt;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 北京众信利民信息技术有限公司 助贷模式To百行征信报送<br>
* 作者:yanhui.Hao <br>
* 时间:2019.11.20 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@RestController
@RequestMapping("/zhudai/re_send")
public class ExZhuDaiBaiHangReSendController {
private static final Logger log = LoggerFactory.getLogger(ExZhuDaiBaiHangReSendController.class);
@Autowired
BaiHangZhuDaiService baiHangZhuDaiService;
@Autowired
private SynLoanInfoHistoryTask synLoanInfoHistoryTask;
@Autowired
private ManualToolService manualToolService;
@RequestMapping("/manual/synTable/historyAndplan")
public String historyAndplan(String p3,String secretKey){
if(manualToolService.checkSecretKey(p3,secretKey)){
//增量同步history和plan表数据
synLoanInfoHistoryTask.syn_historyAndplan_by_id();
return "historyAndplan任务调度完成";
}else{
return "historyAndplan任务调度失败,参数错误";
}
}
//存量整理公共方法
@RequestMapping("/manual/build/zhuDaiStockSyn")
public String zhuDaiStockSyn(String type, String startDate, String noEndDate, String d3Type,String isNotHaveReqID) {
//d3Type=0 还款,type=1 逾期
if (StringUtils.isAnyBlank(type, startDate, noEndDate)) {
return "参数为空";
}
startDate=startDate+"T00:00:00";
noEndDate = noEndDate+"T00:00:00";
baiHangZhuDaiService.zhuDaiStockSyn(type, startDate, noEndDate, d3Type,isNotHaveReqID);
return "请求type=" + type + ",startDate=" + startDate + ",noEndDate=" + noEndDate + ",调度结束";
}
//存量异步整理停止方法
@RequestMapping("/manual/build/zhuDaiStockStop")
public String zhuDaiStockStop(String type,String value) {
if (StringUtils.isAnyBlank(type)) {
return "参数为空";
}
boolean val = false;
if(StringUtils.isNotBlank(value) && "true".equals(value)){
val = true;
}
return baiHangZhuDaiService.zhuDaiStockStop(type,val);
}
//文件报送压缩加密、解密
@RequestMapping("/manual/dealWithFileCry")
public String dealWithFileCry(String filePath, String type) {
try {
//"2019-05-07T00:00:00"
if (StringUtils.isAnyBlank(filePath,type)) {
return "参数为空";
}
if ("zip".equalsIgnoreCase(type)) {
return baiHangZhuDaiService.fileUploadClient(filePath);
} else if ("unzip".equalsIgnoreCase(type)) {
return baiHangZhuDaiService.fileUploadValidationClient(filePath);
} else {
return "其他未知类型type=" + type;
}
} catch (Exception e) {
log.error("dealWithFileCry异常, {} , {} ", e.getMessage(), e);
return e.getMessage();
}
}
//---------------------------------------------------------------------
/**
* 描述: 手动重新报送部分申请A1逻辑问题数据 <br/>
* 参数: [] <br/>
* 返回值: cn.quantgroup.report.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.29 <br/>
*/
@RequestMapping("/manual/buquan/mainApplySend")
public String mainApplySend(){
try{
return baiHangZhuDaiService.sendHandApplyToBaiHang(true,null);
//return GlobalResponse.generate("百行征信助贷模式手动报送D2数据成功");
}catch(Exception e){
log.error("众信利民助贷模式手动报送A1申请异常", e);
//return GlobalResponse.generate("百行征信助贷模式手动报送A1数据失败");
return "众信利民助贷模式手动报送A1数据失败";
}
}
/**
* 描述: 手动重新报送部分放款D2逻辑问题数据 <br/>
* 参数: [] <br/>
* 返回值: cn.quantgroup.report.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.29 <br/>
*/
@RequestMapping("/manual/buquan/mainLoanInfoSend")
public String mainLoanInfoSend(String isSaveLogBean){
try{
return baiHangZhuDaiService.sendHandLoaInfoReportToBaiHang2(true,null,isSaveLogBean);
//return GlobalResponse.generate("百行征信助贷模式手动报送D2数据成功");
}catch(Exception e){
log.error("众信利民助贷模式手动报送D2放款异常", e);
//return GlobalResponse.generate("百行征信助贷模式手动报送D2数据失败");
return "众信利民助贷模式手动报送D2数据失败";
}
}
/**
* 描述: 手动报送部分还款D3逻辑问题数据 <br/>
* 参数: [] <br/>
* 返回值: cn.quantgroup.report.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.29 <br/>
*/
@RequestMapping("/manual/buquan/mainRepaymentLoanInfo")
public String mainRepaymentLoanInfo(){
try{
return baiHangZhuDaiService.sendHandRepaymentReportToBaiHang1(true,null);
//return GlobalResponse.generate("百行征信助贷模式手动报送D3数据成功");
}catch(Exception e){
log.error("众信利民助贷模式手动报送D3还款异常", e);
//return GlobalResponse.generate("百行征信助贷模式手动报送D3数据失败");
return "众信利民助贷模式手动报送D3还款数据失败";
}
}
/**
* 描述: 因数据同步失败,根据报送时间天,手动调用,报送一整天所有数据 <br/>
* 参数: [] <br/>
* 返回值: cn.quantgroup.report.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.29 <br/>
*/
@RequestMapping("/manual/scheduledSend")
public String scheduledSend(String type, String startDate, String endDate) {
try {
//"2019-05-07T00:00:00"
if (StringUtils.isAnyBlank(type, startDate, endDate)) {
return "参数为空";
}
if (startDate.length() != 19 || endDate.length() != 19 || !startDate.contains("T") || !endDate.contains("T")) {
log.warn("日期格式有误, startDate : {} , endDate : {} ", startDate, endDate);
return "日期格式有误";
}
String startnyr = LocalDateTime.parse(startDate).format(DateTimeFormatter.ISO_DATE);
String endnyr = LocalDateTime.parse(endDate).format(DateTimeFormatter.ISO_DATE);
if ("A1".equalsIgnoreCase(type)) {
//贷款申请信息(A1)
baiHangZhuDaiService.sendZhuDaiApplyToBaiHang(startnyr, endnyr);
} else if ("D2".equalsIgnoreCase(type)) {
//非循环贷款账户数据信息(D2)
baiHangZhuDaiService.sendZhuDaiLoanToBaiHang(startnyr, endnyr);
} else if ("D3".equalsIgnoreCase(type)) {
//非循环贷款贷后数据信息(D3)
baiHangZhuDaiService.sendZhuDaiRepaymentToBaiHang(startnyr, endnyr);
} else {
return "其他未知类型type=" + type;
}
} catch (Exception e) {
log.error("dataTuoMin异常, {} , {} ", e.getMessage(), e);
return e.getMessage();
}
return type + "手动报送结束";
}
//---------------------------------------------------------------------------
//test1.场景测试 数据进行脱敏
/* @RequestMapping("/test/dataTuoMin")
public String dataTuoMin(String type,String jsonFilePath) {
try{
return baiHangZhuDaiService.dataTuoMin(type,jsonFilePath);
}catch (Exception e){
log.error("dataTuoMin异常, {} , {} ", e.getMessage(), e);
return e.getMessage();
}
}*/
//test2.接口测试 手动调用
@RequestMapping("/test/apiSend")
public String apiSend(String type,String startDate, String endDate) {
try{
return baiHangZhuDaiService.apiSend(type,startDate,endDate);
}catch (Exception e){
log.error("dataTuoMin异常, {} , {} ", e.getMessage(), e);
return e.getMessage();
}
}
//test
@RequestMapping("/test/bulidD3")
public String bulidD3(String type,String jsonFile) {
try{
return baiHangZhuDaiService.build_stockRepayMentInfoZhuDai(jsonFile);
}catch (Exception e){
log.error("bulidD3异常, {} , {} ", e.getMessage(), e);
return e.getMessage();
}
}
//test
@RequestMapping("/test/bulidD2")
public GlobalResponse bulidD2(String jsonFile){
try{
String sourceStr = FileUtils.readFileToString(new File(jsonFile), "utf-8");
JSONObject sourceJson = JSON.parseObject(sourceStr);
JSONArray recordsJsonArr = sourceJson.getJSONArray("RECORDS");
List<String> lineList = new ArrayList<>(recordsJsonArr.size());
for(int i=0; i<recordsJsonArr.size(); i++){
lineList.add(recordsJsonArr.get(i).toString());
}
baiHangZhuDaiService.sendHandLoaInfoReportToBaiHang(false,lineList);
return GlobalResponse.generate("百行征信助贷模式手动报送D2数据成功");
}catch(Exception e){
log.error("百行征信助贷模式报送放款异常", e);
return GlobalResponse.generate("百行征信助贷模式手动报送D2数据失败");
}
}
//test
@RequestMapping("/test/bulidA1")
public GlobalResponse bulidA1(String jsonFile){
try{
List<String> lineList = ReadOrWriteTxt.readTxtList("D:\\用户目录\\Downloads\\A1_M.txt");
System.out.println("lineList:"+lineList.size());
baiHangZhuDaiService.build_A1(lineList);
return GlobalResponse.generate("百行征信助贷模式手动报送D2数据成功");
}catch(Exception e){
log.error("百行征信助贷模式报送放款异常", e);
return GlobalResponse.generate("百行征信助贷模式手动报送D2数据失败");
}
}
}
package cn.quantgroup.report.domain.baihang;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 申请贷款信息
*
* @Author fengjunkai
* @Date 2019-03-26 14:32
*/
@Data
public class ApplyLoanInfo {
private String reqID;
private String uploadTs;
private String name;
private String pid;
private String mobile;
private String queryReason;
private String guaranteeType;
private String loanPurpose;
private String customType;
private String applyAmount;
private String loanId;
}
package cn.quantgroup.report.domain.baihang;
import java.math.BigDecimal;
import lombok.Data;
/**
* 申请贷款信息
*
* @Author fengjunkai
* @Date 2019-03-26 14:32
*/
@Data
public class ApplyLoanInfoZhuDai {
private String reqID;
private String opCode;//操作代码A-增加 M-修改
private String uploadTs;
private int isFinTechAgencyBusiness;//是否是助贷业务 N
private String applyDate;
private String applyId;
private int applyType;
private String name;
private int idType;
private String pid;
private String mobile;
private String emailAddress; //电子邮箱
private int eduBackground;//学历
private int degree;//学位
private int guaranteeType;//信贷业务担保类型
private int loanPurpose;//贷款用途 Y/N
private int customType; //客户类型
private BigDecimal applyAmount; //申请贷款金额
private String businessOrgCreditCode;//业务发生机构代码 Y/N
//private String homeAddress; //N
//private String homePhone; //N
//private String workName; //N
//private String workAddress; //N
//private String workPhone; //N
//private String idAddress; //N
//private String mailAddress; //N
private int livingCondition;//居住状况
private int marriageStatus; //婚姻状况
private String spouseName;//配偶姓名 Y/N
//private Integer spouseIdType;
//private String spousePid;
//private String spouseMobile;
//private String spouseWorkName;
//private String firstContactsName; //第一联系人姓名 Y/N
//private Integer firstContactsRelationship;
//private Integer firstContactsIdType;
//private String firstContactsPid;
//private String firstContactsMobile; //第一联系人手机号码 Y/N
//private String firstContactsTelephone;
//private String firstContactsWorkName;
//private String secondContactsName;//第二联系人姓名 Y/N
//private Integer secondContactsRelationship;
//private Integer secondContactsIdType;
//private String secondContactsPid;
//private String secondContactsMobile;//第二联系人手机号码 Y/N
//private String secondContactsTelephone;
//private String secondContactsWorkName;
//device;
//deviceType;
//imei;
//mac;
//ipAddress;
//osName;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Builder;
import lombok.Data;
/**
* @Author fengjunkai
* @Date 2019-04-24 15:46
*/
@Builder
@Data
public class BaiHangName {
private String loanId;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
/**
* @Author fengjunkai
* @Date 2019-04-24 15:46
*/
@Data
public class BaiHangNameResult {
private String name;
private String mobile;
private String pid;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Builder;
import lombok.Data;
/**
* @Author fengjunkai
* @Date 2019-04-20 13:30
*/
@Data
@Builder
public class BaiHangRepayment {
private String sendDate;
private String loanId;
private int termNo;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Builder;
import lombok.Data;
/**
* @Author fengjunkai
* @Date 2019-07-12 18:44
*/
@Builder
@Data
public class BaiHangThreeElements {
private String name;
private String idCard;
private String phone;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Builder;
import lombok.Data;
/**
* @Author fengjunkai
* @Date 2019-04-16 16:29
*/
@Builder
@Data
public class BaiHangTimeRecord {
private String startTime;
private String endTime;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Builder;
import lombok.Data;
/**
* @Author fengjunkai
* @Date 2019-04-16 20:11
*/
@Builder
@Data
public class BaiHangUpDateRecord {
private String enable;
private String recordId;
private String opCode;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 放款-资金合作方信息
*
* @Author fengjunkai
* @Date 2019-03-26 14:49
*/
@Data
public class FinTechAgencyBusinessZhuDai implements Serializable {
private static final long serialVersionUID = 7293591774673907983L;
private String institutionalFundingPartner; //资金合作方名称
private String institutionalFundingPartnerID; //资金合作方代码
private String relationID; //助贷机构与资金合作方的关联码
private String institutionalFundingPartnerLoanID; //资金合作方贷款/授信账户编号 N
private String orderID; //助贷业务贷款订单编号
private BigDecimal preCreditLimit; //预授信额度 N
}
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 放款用户信息
*
* @Author fengjunkai
* @Date 2019-03-26 14:49
*/
@Data
public class LoanInfoZhuDai extends FinTechAgencyBusinessZhuDai implements Serializable {
private static final long serialVersionUID = 7293591774673907983L;
private String reqID; //记录唯一ID
private String opCode; //操作代码A-增加 M-修改
private String uploadTs; //记录生成时间 ISO 8601格式 LocalDateTime生成 2016-03-08T10:03:10
//businessOrgCreditCod 业务发生机构代码 Y/N 实际开展本信贷业务的机构的代码。
private String name; //姓名
private String pid; //身份证好
private String mobile; //手机号
private String loanId; //贷款编号
//originalLoanId
private int guaranteeType; //贷款担保类型
private int loanPurpose; //借款用途
private String applyDate;// 贷款申请时间
private String accountOpenDate; //账户开立时间
private String issueDate; //贷款放款时间
private String dueDate; //贷款到期日期 YYYY-MM-DD
private BigDecimal loanAmount; //贷款金额
private int totalTerm; //还款总期数
private int targetRepayDateType; //账单日类型
private int termPeriod;//每期还款周期
private String firstRepaymentDate; //首次应还款日期 YYYY-MM-DD
private int gracePeriod; //宽限日
private String targetRepayDateList; //账单日列表
private String recordId;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 放款用户信息
*
* @Author fengjunkai
* @Date 2019-03-26 14:49
*/
@Data
public class LoanInfoZhuDaiVo implements Serializable {
private static final long serialVersionUID = 7293591774673907983L;
private String reqID; //记录唯一ID
private String opCode; //操作代码A-增加 M-修改
private String uploadTs; //记录生成时间 ISO 8601格式 LocalDateTime生成 2016-03-08T10:03:10
private String name; //姓名
private String pid; //身份证好
private String mobile; //手机号
private String loanId; //贷款编号
//originalLoanId
private int guaranteeType; //贷款担保类型
private int loanPurpose; //借款用途
private String applyDate;// 贷款申请时间
private String accountOpenDate; //账户开立时间
private String issueDate; //贷款放款时间
private String dueDate; //贷款到期日期 YYYY-MM-DD
private BigDecimal loanAmount; //贷款金额
private int totalTerm; //还款总期数
private int targetRepayDateType; //账单日类型
private int termPeriod;//每期还款周期
private String firstRepaymentDate; //首次应还款日期 YYYY-MM-DD
private int gracePeriod; //宽限日
private String targetRepayDateList; //账单日列表
private FinTechAgencyBusinessZhuDai finTechAgencyBusiness; //资金合作方信息
//可以为空
/*"device": {
"deviceType": 1,
"imei": "ABCDEFG12345678",
"mac": "ABCD12345678",
"ipAddress": "139.129.1.54",
"osName": 2
}*/
}
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 还款用户信息
*
* @Author fengjunkai
* @Date 2019-03-26 15:13
*/
@Data
public class RepaymentInfoZhuDai implements Serializable {
private static final long serialVersionUID = 8722959335665582382L;
private String reqID; //记录唯一标示
private String opCode; //操作CODE a-增加 m-修改
private String uploadTs; //记录生成时间 ISO 8601
private String loanId; //贷款ID
private String name;
private String pid;
private String mobile;
private int termNo; //当前还款期数
private String termStatus; //本期还款状态
private String targetRepaymentDate; //本期应还款日 YYYY-MM-DD
private String realRepaymentDate; //实际还款日期ISO 8601 Y/N
private BigDecimal plannedPayment; //本期计划应还款金额
private BigDecimal targetRepayment; //本期剩余应还款金额
private BigDecimal realRepayment; // 本次还款金额
private String overdueStatus; //当前逾期天数
private String statusConfirmAt;//本期还款状态确认时间
private BigDecimal overdueAmount; //当前逾期总金额
private BigDecimal remainingAmount; //贷款余额
private int loanStatus; //本笔贷款状态
//businessOrgCreditCode 业务发生机构代码string Y/N
private String recordId;
}
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 还款用户信息
*
* @Author fengjunkai
* @Date 2019-03-26 15:13
*/
@Data
public class RepaymentLoanInfoLog implements Serializable {
private static final long serialVersionUID = 8722959335665582382L;
private String reqID; //记录唯一标示
private String opCode; //操作CODE a-增加 m-修改
private String uploadTs; //记录生成时间 ISO 8601
private String loanId; //贷款ID
private String name;
private String pid;
private String mobile;
private int termNo; //当前还款期数
private String termStatus; //本期还款状态
private String targetRepaymentDate; //本期应还款日 YYYY-MM-DD
private String realRepaymentDate; //实际还款日期ISO 8601
private BigDecimal plannedPayment; //本期计划应还款金额
private BigDecimal targetRepayment; //本期剩余应还款金额
private BigDecimal realRepayment; // 本次还款金额
private String overdueStatus; //当前逾期天数
private String statusConfirmAt;//本期还款状态确认时间
private BigDecimal overdueAmount; //当前逾期总金额
private BigDecimal remainingAmount; //贷款余额
private int loanStatus; //本笔贷款状态
private String recordId;
private Long id;
private Integer enable;
private String createdAt;
private String updatedAt;
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AccountPO implements Serializable{
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column account.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column account.source_name
*
* @mbg.generated
*/
private String sourceName;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column account.blance
*
* @mbg.generated
*/
private BigDecimal blance;
private BigDecimal thershold;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column account.status
*
* @mbg.generated
*/
private String status;
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiRequestLogPO implements Serializable{
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_request_log_201805.id
*
* @mbg.generated
*/
private Long id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_request_log_201805.url_type
*
* @mbg.generated
*/
private String urlType;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_request_log_201805.res_code
*
* @mbg.generated
*/
private String resCode;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_request_log_201805.res_msg
*
* @mbg.generated
*/
private String resMsg;
private String hitFlag;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_request_log_201805.time_elapse
*
* @mbg.generated
*/
private Integer timeElapse;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_request_log_201805.create_time
*
* @mbg.generated
*/
private Date createTime;
/**
* yyyymm --- 201805
*/
private String suffix;
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @Author fengjunkai
*/
@Data
public class CallRecord1 implements Serializable {
private static final long serialVersionUID = 3380282142711506937L;
private String transactionId;
private String uuid;
private String urlType;
private String code;
private Timestamp created_at;
private Timestamp updated_at;
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* Created by suh on 2018/3/28.
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonWithBillingApiRequestEvent {
private String userId;
private Date timeCreated;
private String responseCode;
private String responseMessage;
private Integer mills;
private String requestUrlType;
private String isBilling;
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CostRecordPO implements Serializable {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.source_name
*
* @mbg.generated
*/
private String sourceName;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.url_type
*
* @mbg.generated
*/
private String urlType;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.invoke_times
*
* @mbg.generated
*/
private Integer invokeTimes;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.cost
*
* @mbg.generated
*/
private BigDecimal cost;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.balance
*
* @mbg.generated
*/
private BigDecimal balance;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column cost_record.create_time
*
* @mbg.generated
*/
private Date createTime;
/**
* yyyymm --- 201805
*/
private String suffix;
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Builder
@Data
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class DataPriceConfigPO implements Serializable {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.source_name
*
* @mbg.generated
*/
private String sourceName;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.data_type
*
* @mbg.generated
*/
private String dataType;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.url_type
*
* @mbg.generated
*/
private String urlType;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.price
*
* @mbg.generated
*/
private BigDecimal price;
private Integer frequency;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.status
*
* @mbg.generated
*/
private String status;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column data_price_config.create_time
*
* @mbg.generated
*/
private Date createTime;
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @Author fengjunkai
* @Date 2019-06-19 14:07
*/
@Data
public class DataSourceCacheConfig implements Serializable {
private static final long serialVersionUID = -8145976034591357518L;
private String productType;
private String productName;
private Integer productCacheTime;
private Integer productTestCacheTime;
private String dataSourceName;
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 三方数据源项目通过uuid白名单将返回500的转换成400配置表 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.10.22 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DsSpecialUserHandle {
private Long id;//主键id
private String methodName;//三方数据源实际方法名
private String serviceName;//三方数据源实际service名称
private String uuid;//用户的uuid
private Boolean enable; //数据是否可用, 默认1 true
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* Created by suh on 2018/3/28.
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ElevenBeiApiRequestEvent {
private String identity;
private Date timeCreated;
private String responseCode;
private String responseMessage;
private Integer mills;
private String requestUrlType;
private String isBilling;
}
package cn.quantgroup.report.domain.master;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
@Data
@NoArgsConstructor
public class IntelliCreditLoanIssue {
private Long id;
private String name;
private String pid;
private String mobile;
private String loanType;
private Long accountOpenDate;
private Long applyDate;
private Long issueDate;
private BigDecimal loanAmount;
private Long loanId;
private Integer totalTerm;
private Long firstRepaymentDate;
private Integer termPeriod;
private Integer planCount;
private Integer status;
private Date timeCreated;
private String device;
@Builder
public IntelliCreditLoanIssue(Long id, String name, String pid, String mobile, String loanType, Long accountOpenDate, Long applyDate, Long issueDate, BigDecimal loanAmount, Long loanId, Integer totalTerm, Long firstRepaymentDate, Integer termPeriod, Integer planCount, Integer status, String device) {
this.name = name;
this.pid = pid;
this.mobile = mobile;
this.loanType = loanType;
this.accountOpenDate = accountOpenDate;
this.applyDate = applyDate;
this.issueDate = issueDate == null ? 0l : issueDate;
this.loanAmount = loanAmount == null ? BigDecimal.ZERO : loanAmount;
this.loanId = loanId;
this.totalTerm = totalTerm == null ? 0 : totalTerm;
this.firstRepaymentDate = firstRepaymentDate == null ? 0 : firstRepaymentDate;
this.termPeriod = termPeriod == null ? 0 : termPeriod;
this.planCount = planCount == null ? 0 : planCount;
this.status = status;
this.timeCreated = new Date();
this.device = device;
}
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IntelliCreditLoanTrace {
private Long id;
private Long loanId;
private Long repaymentPlanId;
private Integer termNo;
private String termStatus;
private Long targetRepaymentDate;
private Long realRepaymentDate;
private BigDecimal targetRepayment;
private BigDecimal realRepayment;
private Long statusConfirmAt;
private String overdueStatus;
private Integer status;
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@NoArgsConstructor
public class IntelliCreditRequestEvent {
private Long id;
private String uuid;
private Date timeCreated;
private Integer httpCode;
private String responseMessage;
private Integer mills;
@Builder
public IntelliCreditRequestEvent(Long id, String uuid, Integer httpCode, String responseMessage, Integer mills) {
this.uuid = uuid;
this.id = id;
this.httpCode = httpCode;
this.responseMessage = responseMessage;
this.mills = mills;
this.timeCreated = new Date();
}
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class JdApiRequestEvent {
private Long id;
private String uuid;
private Date timeCreated;
private String responseCode;
private String responseMessage;
private String businessCode;
private Integer mills;
private String requestUrlType;
}
\ No newline at end of file
package cn.quantgroup.report.domain.master;
import lombok.Data;
import java.io.Serializable;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 百行报送逾期还款白名单表 <br>
* 作者:yanhui.Hao <br>
* 时间:2020.02.05 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Data
//@Builder
public class RepaymentLoanWhiteList implements Serializable {
private static final long serialVersionUID = 8722959335665582382L;
private Long id;
private String pid;
private String mobile;
private String loanId; //贷款ID
private Integer type; //报送业务类型(1:广达小贷;2:众信利民助贷)
private Integer enable; //是否可用,0:不可用;1:可用
private String createdAt;
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TransactionLogPO implements Serializable {
private String transactionId;
private String uuid;
private String urlType;
private Integer code;
private Date timeCreated;
}
package cn.quantgroup.report.domain.master;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* Created by suh on 2018/2/11.
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UnionPayApiRequestEvent {
private String bankCardNo;
private Date timeCreated;
private Integer mills;
private String businessCode;
private String requestUrlType;
}
package cn.quantgroup.report.domain.sdk;
import lombok.Data;
import java.io.Serializable;
@Data
public class SdkUser implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private String idNo;
private String name;
private String phoneNo;
private Long registerFrom;
private String uuid;
/**phoneNo md5加密 2019.10.10*/
private String phoneNoMd5;
/**idNo md5加密 2019.10.10*/
private String idNoMd5;
}
package cn.quantgroup.report.domain.tidbrisk;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 调用日志实体bean <br>
* 作者:yanhui.Hao <br>
* 时间:2019.12.30 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Setter
@Getter
@Builder
public class CallRecord2 {
private String channelType;//数据源调用批次号
private String requestUrl;//数据源调用批次号
private String channelId;//渠道号, 融360-333, 国美-159843
private String transactionId;//数据源调用批次号
private String uuid;//用户uuid
private String urlType;//数据源, QCloud43Md5AntiFraud-腾讯43版反欺诈模型分
private Integer code;//1001:请求成功且命中;1002:请求成功且未命中;1003:请求失败;1004:命中HBase;
//private String createdAt;//创建时间
}
package cn.quantgroup.report.domain.tidbrisk;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 调用日志实体bean <br>
* 作者:yanhui.Hao <br>
* 时间:2019.12.30 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CallRecord3 implements Serializable {
private String channelType;//数据源调用批次号
private String requestUrl;//数据源调用批次号
private String channelId;//渠道号, 融360-333, 国美-159843
private String transactionId;//数据源调用批次号
private String uuid;//用户uuid
private String urlType;//数据源, QCloud43Md5AntiFraud-腾讯43版反欺诈模型分
private Integer code;//1001:请求成功且命中;1002:请求成功且未命中;1003:请求失败;1004:命中HBase;
private Timestamp createdAt;
private Timestamp updatedAt;
private Long id;
}
package cn.quantgroup.report.domain.xyqbuser;
import lombok.Data;
import java.util.Date;
@Data
public class User {
private Long id;
private String phoneNo;
private String uuid;
private Date createdAt;
}
\ No newline at end of file
package cn.quantgroup.report.domain.xyqbuser;
import lombok.Data;
import java.util.Date;
@Data
public class UserDetail {
private Long id;
private Long userId;
private String phoneNo;
private String name;
private String idNo;
private Integer idType;
private Boolean isAuthenticated;
private Integer gender;
private String email;
private String qq;
private Date createdAt;
private Date updatedAt;
}
\ No newline at end of file
package cn.quantgroup.report.enums;
public enum RequestUrlType {
CreditCardRecord("信用卡", "信用卡消费记录"), //信用卡消费记录
BaiHangPersionalCreditReport("百行征信", "百行个人征信报告"),
BaiHangCreditReport("百行征信", "百行个人征信报告"),
LhpBlackListLevel("量化派", "量化派数据产品输出黑名等级"),
;
private String sourceName;
private String urlName;
RequestUrlType(String sourceName, String urlName) {
this.sourceName = sourceName;
this.urlName = urlName;
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public String getUrlName() {
return urlName;
}
public void setUrlName(String urlName) {
this.urlName = urlName;
}
}
\ No newline at end of file
/*
* Copyright 2014-present Miyou tech inc. All Rights Reserved.
*/
package cn.quantgroup.report.error;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.SocketTimeoutException;
import java.util.Arrays;
public class QGException extends RuntimeException {
private static final Logger LOGGER = LoggerFactory.getLogger(QGException.class);
public QGExceptionType qgExceptionType;
public boolean isToastFormat = false;
public String detail;
public QGException(String detail, QGExceptionType qgExceptionType, Object... args) {
super(detail);
try {
if (StringUtils.isNoneBlank(qgExceptionType.frontEndToastTemplate)) {
isToastFormat = true;
initException(String.format(qgExceptionType.frontEndToastTemplate, args), qgExceptionType);
} else {
initException(qgExceptionType);
}
} catch (Exception e) {
LOGGER.error("format front end toast err, " + qgExceptionType + ", args: " + Arrays.toString(args), e);
initException(QGExceptionType.COMMON_SERVER_ERROR);
}
}
public QGException(QGExceptionType qgExceptionType, Object... args) {
super(qgExceptionType.text);
try {
if (StringUtils.isNoneBlank(qgExceptionType.frontEndToastTemplate)) {
isToastFormat = true;
initException(String.format(qgExceptionType.frontEndToastTemplate, args), qgExceptionType);
} else {
initException(qgExceptionType);
}
} catch (Exception e) {
LOGGER.error("format front end toast err, " + qgExceptionType + ", args: " + Arrays.toString(args), e);
initException(QGExceptionType.COMMON_SERVER_ERROR);
}
}
public QGException(String detail, Throwable cause, QGExceptionType qgExceptionType) {
super(detail, cause);
this.initException(detail, qgExceptionType);
}
public QGException(String detail, QGExceptionType qgExceptionType) {
super(detail);
initException(detail, qgExceptionType);
}
public QGException(QGExceptionType qgExceptionType) {
super(qgExceptionType.text);
initException(qgExceptionType);
}
public QGException(Throwable cause, QGExceptionType qgExceptionType, Object... args) {
super(qgExceptionType.text, cause);
try {
if (StringUtils.isNoneBlank(qgExceptionType.frontEndToastTemplate)) {
isToastFormat = true;
initException(String.format(qgExceptionType.frontEndToastTemplate, args), qgExceptionType);
} else {
initException(qgExceptionType);
}
} catch (Exception e) {
LOGGER.error("format front end toast err, " + qgExceptionType + ", args: " + Arrays.toString(args), e);
initException(QGExceptionType.COMMON_SERVER_ERROR);
}
}
public static QGException wrap(Throwable e) {
return wrap(e, QGExceptionType.COMMON_SERVER_ERROR);
}
public static QGException wrap(Throwable e, QGExceptionType exceptionType) {
if (e instanceof QGException) {
return (QGException) e;
}
if (e instanceof SocketTimeoutException)
return new QGException(QGExceptionType.COMMON_THIRD_PARTY_TIMEOUT);
return new QGException(e, exceptionType);
}
public static QGException wrap(Throwable e, QGExceptionType exceptionType, Object... args) {
if (e instanceof QGException) {
return (QGException) e;
}
if (e instanceof SocketTimeoutException)
return new QGException(QGExceptionType.COMMON_THIRD_PARTY_TIMEOUT);
return new QGException(e, exceptionType, args);
}
private void initException(QGExceptionType QGExceptionType) {
this.initException(QGExceptionType.text, QGExceptionType);
}
private void initException(String detail, QGExceptionType QGExceptionType) {
this.qgExceptionType = QGExceptionType;
this.detail = detail;
}
}
\ No newline at end of file
/*
* Copyright 2014-present Miyou tech inc. All Rights Reserved.
*/
package cn.quantgroup.report.error;
import lombok.extern.slf4j.Slf4j;
/**
* 系统使用Exception来进行Error Code处理。如果LogType为Error,
* 代表这种Error不应该返回给客户端,应该统一打印出服务器端错误;
* 如果是WARNING的话,就将对应的Exception Text返回给客户端。
*/
@Slf4j
public enum QGExceptionType {
COMMON_SERVER_ERROR(1001, "系统异常,请稍后再试"),
COMMON_ILLEGAL_STATE(1002, "断言错误"),
COMMON_ILLEGAL_PARAM_TOAST(1003, "参数异常", "%s"),
COMMON_AUTH_ERROR(1004, "系统异常,请稍后再试"),
COMMON_ILLEGAL_PARAM(1010, "参数异常"),
COMMON_THIRD_PARTY_TIMEOUT(1011, "第三方服务超时"),
COMMON_INVALID_PARAM(1012, "参数错误"),
COMMON_ID_INVALID(1013, "id数据非法"),
COMMON_STRING_PARAM_GREATER_THAN_LENGTH(1014, "参数的长度过长", "%s的长度不能大于%s"),
COMMON_STRING_PARAM_IS_ALL_NULL(1015, "参数不能为空", "%s不能为空"),
COMMON_STRING_PARAM_IS_NULL(1016, "参数不能同时为空", "%s不能同时为空"),
COMMON_THIRD_PARTY_ERROR(1017, "第三方服务报错", "第三方服务报错,错误编码:%s,错误提示:%s"),
COMMON_QIAN_HAI_API_INNER_ERROR(1023, "前海服务接口出错", "%s"),
COMMON_QIAN_HAI_API_CALL_FAIL(1024, "前海服务调用失败", "%s"),
//1025
// COMMON_JD_API_CALL_FAIL(1026, "jd服务调用失败"),
COMMON_JD_API_RET_ERROR(1027, "jd服务调用失败", "错误编码:%s,错误提示:%s"),
COMMON_TIMES_GREATER_THAN_MAX_IN_TIME_QUANTUM(1028, "操作频率太快了", "一定时间[%s]秒内,[%s]的操作次数过多,当前为%s,允许的最大值为%s"),
COMMON_TIMES_GREATER_THAN_ONE_TIME_IN_TIME_QUANTUM(1029, "指定时间内操作重复", "一定时间[%s]秒内,[%s]被重复操作,当前为操作次数%s"),
COMMON_DISALLOW_CONCURRENT_EXECUTION(1030, "操作重复", "[%s]被重复操作,当前为操作次数%s"),
COMMON_BAI_RONG_API_CALL_FAIL(1031, "百融服务调用失败", "百融服务调用失败,错误编码:%s,错误提示:%s"),
COMMON_BAI_RONG_LOGIN_FAIL(1033, "百融授权失败", "%s"),
COMMON_CREDIT_X_API_CALL_FAIL(1034, "CreditX服务调用失败", "CreditX服务调用失败,错误编码:%s,错误提示:%s"),
COMMON_SHU_MEI_API_CALL_FAIL(1035, "数美服务调用失败", "数美服务调用失败,错误编码:%s,错误提示:%s"),
// COMMON_Q_CLOUD_API_CALL_FAIL(1036, "qcloud服务调用失败"),
COMMON_91_ZHENG_XIN_API_CALL_FAIL(1037, "91征信服务调用失败"),
COMMON_91_OPERATION_BEYOND_LIMIT(1038, "91征信服务调用过于频繁失败"),
COMMON_GE_TUI_UUID_INVALID(1039, "uuid不能为空"),
COMMON_GE_TUI_UUID_INFO_NOT_EXIST(1040, "用户设备信息不存在"),
COMMON_GE_TUI_API_CALL_FAIL(1041, "个推服务调用失败"),
COMMON_GE_TUI_AUTH_CALL_FAIL(1042, "个推授权调用失败"),
COMMON_HAO_AN_API_CALL_FAIL(1043,"号安服务调用失败", "%s"),
COMMON_BAI_DU_API_CALL_FAIL(1044,"百度服务调用失败"),
COMMON_INTELLI_CREDIT_API_CALL_FAIL(1045,"中智信服务调用失败", "%s"),
COMMON_INTELLI_CREDIT_LOAN_ID_NOT_NULL(1046, "借款id不能为空"),
COMMON_INTELLI_CREDIT_USER_INVALID(1047, "用户不存在"),
COMMON_INTELLI_CREDIT_USER_DETAIL_INVALID(1048, "用户详情信息不存在"),
COMMON_BAI_QI_SHI_API_CALL_FAIL(1049,"白骑士服务调用失败"),
COMMON_THIRD_PART_CALL_FAIL(1050,"第三方服务调用失败"),
COMMON_RONG360_API_CALL_FAIL(1051,"融360服务调用失败", "%s"),
COMMON_CHENGAN_API_CALL_FAIL(1052,"诚安服务调用失败"),
COMMON_SHENGDUN_API_CALL_FAIL(1053,"晟顿服务调用失败", "%s"),
COMMON_XINYAN_API_CALL_FAIL(1054,"新顏服务调用失败", "%s"),
COMMON_TIANXINGHUI_API_CALL_FAIL(1055,"天行汇服务调用失败", "%s"),
COMMON_ZHONGCHENGXIN_API_CALL_FAIL(1056,"中诚信服务调用失败"),
COMMON_DIAN_HUA_BANG_API_CALL_FAIL(1057,"电话邦服务调用失败", "%s"),
COMMON_BLACK_APPID_IS_NULL(1058,"黑名单appid不能为空"),
COMMON_BLACK_APPID_IS_WRONG(1059,"黑名单appid不正确"),
COMMON_BLACK_TIMESTAMP_IS_NULL(1060,"黑名单timeunit为空"),
COMMON_BLACK_TIMESTAMP_IS_INVALID(1061,"黑名单timeunit超时"),
COMMON_BLACK_PHONE_IS_NULL(1062,"黑名单手机号为空"),
COMMON_BLACK_TOKEN_IS_NULL(1063,"黑名单token为空"),
COMMON_BLACK_TOKEN_IS_INVALID(1064,"黑名单token无效"),
COMMON_CHANNEL_IS_INVALID(1065,"无效的来源渠道"),
COMMON_BLACK_APPID_IS_INVALID(1066,"APPID无效"),
COMMON_USER_CENTER_NOT_FOUND(1067,"用户中心未查询到当前用户", "用户中心未查询到当前用户: %s"),
COMMON_FA_HAI_RESULT_ERROR(1068,"法海服务返回结果异常当前用户","法海服务返回结果异常当前用户:%s"),
COMMON_JI_AO_API_CALL_FAIL(1069,"集奥服务调用失败","%s"),
COMMON_JI_AO_API_RET_ERROR(1070,"集奥服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_TIAN_CHUANG_API_CALL_FAIL(1071,"天创服务调用失败", "%s"),
COMMON_TIAN_CHUANG_API_RET_ERROR(1072,"天创服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_SHU_CHUANG_API_CALL_FAIL(1073,"数创服务调用失败", "%s"),
COMMON_SHU_CHUANG_API_RET_ERROR(1074,"数创服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_ELEVEN_BEI_API_CALL_FAIL(1075,"十一呗服务调用失败"),
COMMON_ELEVEN_BEI_API_RET_ERROR(1076,"十一呗服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_HAO_AN_API_RET_ERROR(1077,"号安服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_TONG_DUN_API_CALL_FAIL(1078,"同盾服务调用失败", "%s"),
COMMON_TONG_DUN_API_RET_ERROR(1079,"号安服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_XIN_YAN_API_CALL_FAIL(1080,"新颜服务调用失败"),
COMMON_XIN_YAN_API_RET_ERROR(1081,"新颜服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_DIAN_HUA_BANG_API_RET_ERROR(1082,"电话邦服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_BAI_RONG_PERC_API_CALL_FAIL(1083,"百融个人资质服务调用失败", "%s"),
COMMON_BAI_RONG_PERC_API_RET_ERROR(1084,"百融个人资质调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_BAI_RONG_RULE_APPLY_API_CALL_FAIL(1085,"百融个人资质服务调用失败", "%s"),
COMMON_BAI_RONG_RULE_APPLY_API_RET_ERROR(1086,"百融个人资质调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_BAI_RONG_WHITE_LIST_API_CALL_FAIL(1087,"百融白名单服务调用失败", "%s"),
COMMON_BAI_RONG_WHITE_LIST_API_RET_ERROR(1088,"百融白名单服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_KA_NIU_WHITE_LIST_API_CALL_FAIL(1089,"卡牛服务调用失败", "%s"),
COMMON_KA_NIU_WHITE_LIST_API_RET_ERROR(1090,"卡牛服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_TIANXINGHUI_API_RET_ERROR(1091,"天行汇服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_QIAN_HAI_API_RET_ERROR(1092,"前海服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_SHENG_DUN_API_RET_ERROR(1093,"晟顿服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_Q_CLOUD_API_CALL_ERROR(1094, "qcloud服务调用异常", "错误编码:%s,错误提示:%s"),
COMMON_Q_CLOUD_API_CALL_RESULT_ERROR(1095, "qcloud服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_BING_JIAN_API_CALL_FAIL(1096,"冰鉴服务调用失败","接口:%s ;%s"),
COMMON_BING_JIAN_API_RET_ERROR(1097,"冰鉴服务调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_BAI_RONG_STRATEGY_API_CALL_FAIL(1098,"百融服务调用失败", "接口:%s ;%s"),
COMMON_BAI_RONG_STRATEGY_API_RET_ERROR(1099,"百融调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
//1100
COMMON_AN_LIANG_API_CALL_FAIL(1101,"安粮服务调用失败", "接口:%s ;%s"),
COMMON_AN_LIANG_API_RET_ERROR(1102,"安粮调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_ZHI_SHU_API_CALL_FAIL(1103,"智数服务调用失败", "接口:%s ;%s"),
COMMON_ZHI_SHU_API_RET_ERROR(1104,"智数调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_GE_TUI_NEW_API_CALL_FAIL(1105,"个推服务调用失败", "接口:%s ;%s"),
COMMON_GE_TUI_NEW_API_RET_ERROR(1106,"个推调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_FICO_API_CALL_FAIL(1107,"FICO服务调用失败", "接口:%s ;%s"),
COMMON_FICO_API_RET_ERROR(1108,"FICO调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_QICHACHA_API_CALL_FAIL(1109,"企查查服务调用失败", "接口:%s ;%s"),
COMMON_QICHACHA_API_RET_ERROR(1110,"企查查调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_JI_GUANG_API_CALL_FAIL(1111,"极光服务调用失败", "接口:%s ;%s"),
COMMON_JI_GUANG_API_RET_ERROR(1112,"极光调用结果异常", "接口:%s ;错误编码:%s,错误提示:%s"),
COMMON_TAN_ZHI_API_RET_ERROR(1113,"探知数据报告服务调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_ANLIANG_RESULT_DATA_NULL_RET_ERROR(1114,"安粮返回结果为空", "错误编码:%s,错误提示:%s"),
COMMON_ZHONGCHENGXIN_PHONECHECK_API_CALL_FAIL(1115,"中诚信手机实名校验服务调用失败"),
COMMON_ZHONGCHENGXIN_BANKCARDCHECK_API_CALL_FAIL(1116,"中诚信银行卡四要素校验服务调用失败"),
COMMON_ZHICHENGAFU_API_CALL_FAIL(1117,"至诚阿福欺诈甄别", "错误编码:%s, 错误提示:%s"),
COMMON_LIANGJINGJING_V2_API_CALL_FAIL(1118,"量京京V2联合建模"),
COMMON_MOXIERISK_API_CALL_FAIL(1119,"魔蝎申请准入报告查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_MOXIERISK_API_RESULT_UNKNOW(1120,"魔蝎申请准入报告返回结果查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_SUANHUARISK_API_CALL_FAIL(1121,"算话风险过滤服务调用失败", "错误编码:%s, 错误提示:%s"),
////COMMON_PINTAI_API_CALL_FAIL(1061,"品钛线上现金分期场景分服务调用失败", "错误编码:%s, 错误提示:%s"),
COMMON_TONGDUNLOAN_API_CALL_FAIL(1122,"同盾信贷保镖智信分查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_MOXIERISK_API_V2_CALL_FAIL(1123,"魔蝎申请准入报告查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_JI_AO_API_REGISTER_TIME_ERROR(1124,"集奥手机号在网时长查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_JI_AO_API_STOP_ENGINE_TIME_ERROR(1125,"集奥近3个月停机次数查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_JI_AO_API_IS_IN_BLACK_LIST_ERROR(1126,"集奥手机号是否在黑名单查询异常", "错误编码:%s, 错误提示:%s"),
COMMON_PAIPAIXIN_CASH_LOAN_ERROR(1127,"拍拍贷-拍拍信现金分期模型查询异常", "错误编码:%s, 错误提示:%s"),
////COMMON_PINTAI_CREDIT_V1_API_CALL_FAIL(1128,"品钛信用评估分V1服务调用失败", "错误编码:%s, 错误提示:%s"),
////COMMON_PINTAI_CREDIT_V2_API_CALL_FAIL(1068,"品钛信用评估分V2服务调用失败", "错误编码:%s, 错误提示:%s"),
COMMON_SUANHUARISK_API_CALL_RESULT_IS_NULL_FAIL(1129,"算话风险过滤服务返回结果为空" ),
COMMON_PAIPAIXIN_CASH_LOAN_RESULT_IS_NULL_ERROR(1130,"拍拍贷-拍拍信现金分期模型返回结果为空"),
COMMON_YOUMENG_LOAN_SCORE_ERROR(1131,"友盟小额分", "错误编码:%s, 错误提示:%s"),
COMMON_FAHAI_ERROR(1132,"法海司法", "错误编码:%s, 错误提示:%s"),
COMMON_JINRONG_360_CREDIT_SCORE_ERROR(1133,"360金融统一信用分调用失败", "错误编码:%s, 错误提示:%s"),
COMMON_BAIHANG_CREDIT_REPORT_ERROR(1134,"百行征信查询失败", "错误编码:%s, 错误提示:%s"),
COMMON_HUADAO_MODEL_ERROR(1135,"华道联合建模", "错误编码:%s, 错误提示:%s"),
COMMON_HUADAO_MODEL_GET_QUERY_TOKEN_ERROR(1136,"华道联合建模获取请求token失败", "错误编码:%s, 错误提示:%s"),
////COMMON_TENCENT_AUDIFRAUD_RISK_SCORE_RESULT_ERROR(1137,"腾讯天御反欺诈风险分请求结果异常", "错误编码:%s, 错误提示:%s"),
////COMMON_DIANHUABANG_THREEELEMENTS_CHECK_RESULT_ERROR(1077,"电话邦三要素核验异常", "错误编码:%s, 错误提示:%s"),
COMMON_CASH_LOAN_SCORE_RESULT_ERROR(1138,"集奥线上现金分期评分异常", "错误编码:%s, 错误提示:%s"),
COMMON_ZHONGCHENGXIN_PHONE_REGISTER_TIME_API_CALL_FAIL(1139,"中诚信手机号在网时长服务调用失败"),
// xyqb user
XYQB_USER_NOT_EXSIT(2001, "用户不存在"),
XYQB_USER_NOT_MATCH(2002, "用户不匹配"),
COMMON_THIRD_PART_CALL_EXCEPTION(3001,"第三方服务调用异常", "异常信息:%s"),
//
COMMON_MI_GUAN_API_CALL_FAIL(1140,"获取蜜罐报告接口调用失败","%s"),
COMMON_MI_GUAN_API_RET_ERROR(1141,"获取蜜罐报告接口调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_FACEID_API_CALL_FAIL(1142,"FaceID风控多头API调用失败","%s"),
COMMON_FACEID_API_RET_ERROR(1143,"FaceID风控多头API调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_MuJin_API_CALL_FAIL(1144,"木槿科技借贷风险名单API调用失败","%s"),
COMMON_MuJin_API_RET_ERROR(1145,"木槿科技借贷风险名单API调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_RongHui_API_CALL_FAIL(1146,"融慧量化派定制化模型API调用失败","%s"),
COMMON_RongHui_API_RET_ERROR(1147,"融慧量化派定制化模型API调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_DIANHUABANG_THREEELEMENTS_CHECK_RESULT_FAIL(1148,"电话邦三要素核验调用失败","%s"),
COMMON_DIANHUABANG_THREEELEMENTS_CHECK_RESULT_ERROR(1149,"电话邦三要素核验异常", "错误编码:%s, 错误提示:%s"),
COMMON_DIANHUABANG_CALLACCNETDURTIME_THREEELEMENTS_API_CALL_FAIL(1150,"电话邦手机号在网时长调用失败","%s"),
COMMON_DIANHUABANG_CALLACCNETDURTIME_THREEELEMENTS_API_RET_ERROR(1151,"电话邦手机号在网时长异常", "错误编码:%s, 错误提示:%s"),
COMMON_PINTAI_API_CALL_FAIL(1152,"品钛线上现金分期场景分服务调用失败", "%s"),
COMMON_PINTAI_API_RET_ERROR(1153,"品钛线上现金分期场景分服务调用异常", "错误编码:%s, 错误提示:%s"),
COMMON_PINTAI_CREDIT_V2_API_CALL_FAIL(1154,"品钛信用评估分V2服务调用失败", "%s"),
COMMON_PINTAI_CREDIT_V2_API_RET_ERROR(1155,"品钛信用评估分V2服务调用异常", "错误编码:%s, 错误提示:%s"),
COMMON_PengRui_API_CALL_FAIL(1156,"鹏芮风控黑名单调用失败","%s"),
COMMON_PengRui_API_RET_ERROR(1157,"鹏芮风控黑名单调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_LhpBlackListLevel_FAIL(1158,"量化派数据产品输出黑名等级查询失败","%s"),
COMMON_LhpBlackListLevel_ERROR(1159,"量化派数据产品输出黑名等级查询异常", "错误编码:%s,错误提示:%s"),
COMMON_TENCENT_AUDIFRAUD_RISK_SCORE_RESULT_FAIL(1160,"腾讯天御反欺诈风险分请求失败","%s"),
COMMON_TENCENT_AUDIFRAUD_RISK_SCORE_RESULT_ERROR(1161,"腾讯天御反欺诈风险分请求结果异常", "错误编码:%s, 错误提示:%s"),
COMMON_PINTAI_CREDIT_V1_API_CALL_FAIL(1166,"品钛信用评估分V1服务调用失败", "%s"),
COMMON_PINTAI_CREDIT_V1_API_ERROR(1167,"品钛信用评估分V1服务调用结果异常", "错误编码:%s, 错误提示:%s"),
COMMON_ZhongHuJinThreeElement_API_FAIL(1162,"中互金运营商三要素核验API调用失败","%s"),
COMMON_ZhongHuJinThreeElement_API_ERROR(1163,"中互金运营商三要素核验API调用结果异常", "错误编码:%s,错误提示:%s"),
COMMON_ZhongHuJinWholeIn_API_FAIL(1164,"中互金在网时长核验API调用失败","%s"),
COMMON_ZhongHuJinWholeIn_API_ERROR(1165,"中互金在网时长核验API调用结果异常", "错误编码:%s,错误提示:%s"),
/** !!!!!!!!!!!!!!!!备注:以后code增加依次类推,请不要重复!!!!!!!!!!!!!! */
;
public int code;
public String text;
public String frontEndToastTemplate;
QGExceptionType(int code, String text) {
this.code = code;
this.text = text;
this.frontEndToastTemplate = text;
}
QGExceptionType(int code, String text, String frontEndToastTemplate) {
this.code = code;
this.text = text;
this.frontEndToastTemplate = frontEndToastTemplate;
}
public static QGExceptionType fromCode(int code) {
for (QGExceptionType exceptionType : QGExceptionType.values()) {
if (exceptionType.code == code) {
return exceptionType;
}
}
return null;
}
@Override
public String toString() {
return "error_code: " + code + ", text: " + text + ", frontEndToastTemplate: " + frontEndToastTemplate;
}
}
package cn.quantgroup.report.error;
public class QGPreconditions {
private QGPreconditions() {
}
public static void checkArgument(boolean expression) {
checkArgument(expression, QGExceptionType.COMMON_ILLEGAL_PARAM);
}
public static void checkArgument(boolean expression, Object errorMessage) {
checkArgument(expression, QGExceptionType.COMMON_ILLEGAL_PARAM, errorMessage);
}
public static void checkArgument(boolean expression,
String errorMessageTemplate, Object... errorMessageArgs) {
checkArgument(expression, QGExceptionType.COMMON_ILLEGAL_PARAM, errorMessageTemplate, errorMessageArgs);
}
public static void checkArgument(boolean expression, QGExceptionType exceptionType) {
if (!expression) {
throw new QGException(exceptionType);
}
}
public static void checkArgument(boolean expression, QGExceptionType exceptionType, Object... errorMessage) {
if (!expression) {
throw new QGException(exceptionType, errorMessage);
}
}
}
package cn.quantgroup.report.fastjson;
import cn.quantgroup.report.utils.MaskedUtils;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.google.common.base.Joiner;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class CustomValueFilter implements ValueFilter {
private final Set<String> Masked_KEYS;
public CustomValueFilter(Set<String> masked_KEYS) {
Masked_KEYS = masked_KEYS;
}
@Override
public Object process(Object o, String s, Object o1) {
if (Masked_KEYS == null || o1 == null || StringUtils.isBlank(s) || !Masked_KEYS.contains(s)) {
return o1;
}
if (o1 instanceof String[]) {
List<String> maskedStrings = Arrays.stream(((String[]) o1)).map(string -> MaskedUtils.buildMaskedCommonString(string)).collect(Collectors.toList());
return Joiner.on(",").join(maskedStrings);
}
return MaskedUtils.buildMaskedCommonString(o1 instanceof String ? ((String) o1) : o1.toString());
}
}
\ No newline at end of file
package cn.quantgroup.report.job;
import cn.quantgroup.report.service.baihang.BaiHangZhuDaiService;
import cn.quantgroup.report.service.baihang.constant.Constant;
import cn.quantgroup.report.utils.dingtalk.DingTalk;
import com.google.common.base.Stopwatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 量化派助贷模式(非循环贷) -
* (贷款申请/放款/还款(逾期)三类实时批量数据)-To百行报送<br>
* 每日凌晨5点报送 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.10.25 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Component
public class QuantGroupZhuDaiReportToBaiHang {
private static final Logger log = LoggerFactory.getLogger(QuantGroupZhuDaiReportToBaiHang.class);
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private BaiHangZhuDaiService baiHangZhuDaiService;
@Autowired
private SynLoanInfoHistoryTask synLoanInfoHistoryTask;
@Autowired
private DingTalk dingTalk;
@Async
@Scheduled(cron = "0 0 05 * * ?")
public void startZhuDaiReport(){
if(increment()){
redisTemplate.expire(Constant.QG_ZHU_DAI_REPORT_LOCK_KEY, 10, TimeUnit.SECONDS);
Stopwatch stopwatch = Stopwatch.createStarted();
boolean tableIsSyn = synLoanInfoHistoryTask.syn_historyAndplan_by_id();
if(tableIsSyn){
try{
//yyyy-MM-dd
String startnyr = LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ISO_DATE);
String endnyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
log.info("量化派-助贷模式报送贷款信息开始, newTime: {} , startnyr: {} , endnyr: {} ", LocalDateTime.now(), startnyr, endnyr);
String msg_A1 = baiHangZhuDaiService.sendZhuDaiApplyToBaiHang(startnyr,endnyr); //生产 助贷-贷款申请 报送T+1 暂时先不报送C1 因为百行还没有开放查询接口
dingTalk.talk("Info","报送"+startnyr+"申请A1结束",msg_A1);
if(msg_A1.indexOf("[false]")!=-1){
dingTalk.talk_ToUser("申请A1报送失败", "报送"+startnyr+"申请A1有部分失败,请尽快手动处理!");
}
String msg_D2 = baiHangZhuDaiService.sendZhuDaiLoanToBaiHang(startnyr,endnyr); //生产 助贷-放款信息 报送T+1
dingTalk.talk("Info","报送"+startnyr+"放款D2结束",msg_D2);
if(msg_D2.indexOf("[false]")!=-1){
dingTalk.talk_ToUser("放款D2报送失败", "报送"+startnyr+"放款D2有部分失败,请尽快手动处理!");
}
String msg_D3 =baiHangZhuDaiService.sendZhuDaiRepaymentToBaiHang(startnyr,endnyr); //生产 助贷-还款&逾期信息 报送T+1
dingTalk.talk("Info","报送"+startnyr+"还款D3结束",msg_D3);
if(msg_D3.indexOf("[false]")!=-1){
dingTalk.talk_ToUser("还款D3报送失败", "报送"+startnyr+"还款D3有部分失败,请尽快手动处理!");
}
log.info("量化派-助贷模式报送贷款信息结束, newTime: {}, 耗时: {} , msg: {} ", LocalDateTime.now(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), (msg_A1 + msg_D2 + msg_D3));
}catch (Exception e){
log.error("量化派-助贷模式报送贷款信息异常, newTime: {}, 耗时: {} ", LocalDateTime.now(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS), e);
dingTalk.talk("Error","报送服务内部异常", e);
dingTalk.talk_ToUser("数据报送异常", "报送服务内部异常,请尽快手动处理!");
}
}else{
log.error("量化派-助贷模式报送贷款信息失败, 原因是同步历史表数据返回false, 请尽快人工处理, newTime: {} ", LocalDateTime.now());
}
}
}
public Boolean increment(){
Long increment = redisTemplate.opsForValue().increment(Constant.QG_ZHU_DAI_REPORT_LOCK_KEY, 1);
return increment <= 1;
}
}
package cn.quantgroup.report.job;
import cn.quantgroup.report.service.baihang.BaiHangZhuDaiService;
import cn.quantgroup.report.service.manualTool.ManualToolService;
import cn.quantgroup.report.utils.dingtalk.DingTalk;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Enumeration;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 一些繁琐的日正常工作task<br>
* 作者:yanhui.Hao <br>
* 时间:2020.03.11 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Component
public class RoutineWorkTask {
private static final Logger log = LoggerFactory.getLogger(RoutineWorkTask.class);
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private DingTalk dingTalk;
@Autowired
private ManualToolService manualToolService;
@Autowired
BaiHangZhuDaiService baiHangZhuDaiService;
/**
* 百行报送工程RoutineWorkTask锁key
*/
public static final String ROUTINE_WORK_BH_LOCK_KEY_1 = "ROUTINE_WORK_BH_LOCK_KEY_1";
public static final String ROUTINE_WORK_BH_LOCK_KEY_2 = "ROUTINE_WORK_BH_LOCK_KEY_2";
public static final String ZXLM_A1_INTERFACE_SEND = "ZXLM_A1_INTERFACE_SEND";
public static final String ZXLM_D2_INTERFACE_SEND = "ZXLM_D2_INTERFACE_SEND";
public static final String ZXLM_D3_INTERFACE_SEND = "ZXLM_D3_INTERFACE_SEND";
//百行反馈日志(今天反馈日志是昨天05:00报送的),但最近百行反馈日志一直延迟,-1代表向前推一天,既昨天
@Value("${baihang.backLog.delay.day}")
public String BACKLOG_DELAY_DAY;
@Async
@Scheduled(cron = "0 0 18 * * ?")
public void downloadLog() {
//if (increment(ROUTINE_WORK_BH_LOCK_KEY_1)) {
// redisTemplate.expire(ROUTINE_WORK_BH_LOCK_KEY_1, 10, TimeUnit.SECONDS);
String ip = getServerIp();
if (StringUtils.isNotEmpty(ip) && (StringUtils.equalsAnyIgnoreCase(ip, "172.21.10.8", "172.17.0.122"))) {
Stopwatch stopwatch = Stopwatch.createStarted();
//yyyyMMdd
//2020.03.19 本来今天查看今天的反馈日志(今天反馈日志是昨天05:00报送的),但最近百行反馈日志一直延迟1天
String newDatenyr = getNewDatenyr();
log.info("下载(众信利民助贷)百行反馈日志开始>>>>>>>>, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr);
//指定只有172.21.10.8服务器
//String downloadUrl = "http://172.21.10.8:9021/manualtool/send/baihang?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
String p1 = "L0hNMklnTjNPenA1aDdqSHpreld1UT09";
String p2 = "UTg1UFN4SjN3TThuVXFIVEFUUFR0QT09";
String p3 = "Mm12NTBKU1JkVFE3MjlCK3RnZTNRdz09";
String p4 = "MmJJMzNUQVRMSXQ4V3VDbUswZGNlUT09";
String p5 = newDatenyr;
String secretKey = "UY1I5dHb3iq/DtEAm1f3yu7emYzlSvpFNPkxpOMSegqYJ08M2drTtNiqLyaxjbERWR0yS5CHPKpHwGjTXWHP3DEEDfXX4LhRtmiN1LIpZPdl87YWpDJ1qg07EN671JcY406oPbh7KsHFO0I0B32Hee1iZanKL4tzqmgF4dvsUNs=";
String isSend = "false";//不自动报送
String sendIncludeType = "D2,D3";//不不自动报送,该参数没有用
String isProduct = "true";
String errorCode = "D3_035,";//以后发现其他错误code,可以追加
try {
Stopwatch stopwatch1 = Stopwatch.createStarted();
Map<String, String> resultMap = manualToolService.sendBaiHangData(p1, p2, p3, p4, p5, secretKey, isSend, errorCode, isProduct, sendIncludeType);
log.info("下载&处理众信利民助贷反馈日志结束, result: {} , 耗时: {} ", JSONObject.toJSONString(resultMap), stopwatch1.stop().elapsed(TimeUnit.MILLISECONDS));
if (resultMap != null) {
String success = resultMap.get("success");
String alarm = resultMap.get("alarm");
String isEmpty = resultMap.get("isEmpty");
if (StringUtils.isNotEmpty(success)) {
if (StringUtils.isNotEmpty(isEmpty)) {
//dingTalk.talk("Info", "下载&处理" + newDatenyr + "(ZXLM助贷)百行反馈日志结束", success);
if(StringUtils.isNotEmpty(alarm)){
//Thread.sleep(500);
dingTalk.talk_ToUser("下载"+newDatenyr+"(ZXLM助贷)百行反馈主日志文件不存在", "下载反馈主日志文件不存在,请注意确认或和百行联系!");
}else{
dingTalk.talk("Info", "下载&处理" + newDatenyr + "(ZXLM助贷)百行反馈日志结束——[OK]", success);
}
log.info("下载(众信利民助贷)百行反馈日志结束<<<<<<<<, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return;
} else {
dingTalk.talk("Info", "下载&处理" + newDatenyr + "(ZXLM助贷)百行反馈日志结束", success + "——[10分钟后将会自动重新报送,若有问题请及时停止!]");
String json_sq_A1 = resultMap.get("json_sq_A1");
if (StringUtils.isNotEmpty(json_sq_A1) && "true".equals(json_sq_A1)) {
setRedisValStr(ZXLM_A1_INTERFACE_SEND);
}
String json_fk_D2 = resultMap.get("json_fk_D2");
if (StringUtils.isNotEmpty(json_fk_D2) && "true".equals(json_fk_D2)) {
setRedisValStr(ZXLM_D2_INTERFACE_SEND);
}
String json_hk_D3 = resultMap.get("json_hk_D3");
if (StringUtils.isNotEmpty(json_hk_D3) && "true".equals(json_hk_D3)) {
setRedisValStr(ZXLM_D3_INTERFACE_SEND);
}
log.info("下载(众信利民助贷)百行反馈日志结束<<<<<<<<, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return;
}
}
}
} catch (Exception e) {
log.error("下载(众信利民助贷)百行反馈日志异常<<<<<<<<, newDatenyr: {} ", newDatenyr, e);
//dingTalk.talk("Error", "下载&处理(ZXLM助贷)百行反馈日志系统异常", "(" + newDatenyr + ") 异常信息:" + e.toString());
dingTalk.talk_ToUser("下载&处理(ZXLM助贷)百行反馈日志系统异常", "(" + newDatenyr + ") 日常处理ZXLM助贷反馈日志系统异常,请尽快手动处理!!!");
return;
}
dingTalk.talk_ToUser("下载(众信利民助贷)百行反馈日志未知异常", "下载 (" + newDatenyr + ") 反馈日志失败,请尽快手动处理!");
log.info("下载(众信利民助贷)百行反馈日志结束<<<<<<<<, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
@Async
@Scheduled(cron = "0 10 18 * * ?")
public void sendBaoSong() {
//if (increment(ROUTINE_WORK_BH_LOCK_KEY_2)) {
// redisTemplate.expire(ROUTINE_WORK_BH_LOCK_KEY_2, 10, TimeUnit.SECONDS);
String ip = getServerIp();
if (StringUtils.isNotEmpty(ip) && (StringUtils.equalsAnyIgnoreCase(ip, "172.21.10.8", "172.17.0.122"))) {
Stopwatch stopwatch = Stopwatch.createStarted();
//yyyyMMdd
String newDatenyr = getNewDatenyr();
//指定只有172.21.10.8服务器 172.21.10.8:9021
//String send_A1_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainApplySend?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
//String send_D2_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainLoanInfoSend?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
//String send_D3_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainRepaymentLoanInfo?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
log.info("众信利民助贷-百行重新报送开始>>>>>>>>, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr);
if (getRedisValStr(ZXLM_A1_INTERFACE_SEND)) {
try {
redisTemplate.delete(ZXLM_A1_INTERFACE_SEND);
String result = baiHangZhuDaiService.sendHandApplyToBaiHang(true, null);
log.info("众信利民助贷-百行重新报送A1结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result);
dingTalk.talk("Info", "ZXLM助贷-重新报送 A1 结束", "(" + newDatenyr + ")" + result);
Thread.sleep(3 * 1000);//3秒
} catch (Exception e) {
log.error("(众信利民助贷)重新报送A1异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e);
dingTalk.talk_ToUser("ZXLM助贷-重新报送 A1 异常", "(" + newDatenyr + ") A1报送异常,请尽快查看处理!");
}
}
if (getRedisValStr(ZXLM_D2_INTERFACE_SEND)) {
try {
redisTemplate.delete(ZXLM_D2_INTERFACE_SEND);
String result = baiHangZhuDaiService.sendHandLoaInfoReportToBaiHang2(true, null, "true");
log.info("众信利民助贷-百行重新报送D2结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result);
dingTalk.talk("Info", "ZXLM助贷-重新报送 D2 结束", "(" + newDatenyr + ")" + result);
Thread.sleep(10 * 1000);//10秒
} catch (Exception e) {
log.error("(众信利民助贷)重新报送D2异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e);
dingTalk.talk_ToUser("ZXLM助贷-重新报送 D2 异常", "(" + newDatenyr + ") D2报送异常,请尽快查看处理!");
}
}
if (getRedisValStr(ZXLM_D3_INTERFACE_SEND)) {
try {
redisTemplate.delete(ZXLM_D3_INTERFACE_SEND);
String result = baiHangZhuDaiService.sendHandRepaymentReportToBaiHang1(true, null);
log.info("众信利民助贷-百行重新报送D3结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result);
dingTalk.talk("Info", "ZXLM助贷-重新报送 D3 结束", "(" + newDatenyr + ")" + result);
} catch (Exception e) {
log.error("(众信利民助贷)重新报送D3异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e);
dingTalk.talk_ToUser("ZXLM助贷-重新报送 D3 异常", "(" + newDatenyr + ") D3报送异常,请尽快查看处理!");
}
}
log.info("众信利民助贷-百行重新报送结束<<<<<<<<, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
private Boolean increment(String key) {
Long increment = redisTemplate.opsForValue().increment(key, 1);
return increment <= 1;
}
private void setRedisValStr(String key) {
try {
redisTemplate.opsForValue().set(key, "true", 15, TimeUnit.MINUTES);
} catch (Exception e) {
log.error("Redis中set值异常, key: {} ", key, e);
}
}
private boolean getRedisValStr(String key) {
String value = null;
try {
value = redisTemplate.opsForValue().get(key);
} catch (Exception e) {
log.error("Redis中get值异常, key: {} ", key, e);
}
if (StringUtils.isNotEmpty(value) && "true".equals(value)) {
return true;
} else {
return false;
}
}
private static String getServerIp() {
try {
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress ip = (InetAddress) addresses.nextElement();
if (ip != null
&& ip instanceof Inet4Address
&& !ip.isLoopbackAddress() // loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255
&& ip.getHostAddress().indexOf(":") == -1) {
log.info("本机的IP = " + ip.getHostAddress());
return ip.getHostAddress();
}
}
}
} catch (Exception e) {
log.error("获取本地ip异常", e);
}
return null;
}
private String getNewDatenyr() {
int bakDay = 0;
if (StringUtils.isNotBlank(BACKLOG_DELAY_DAY)) {
try {
bakDay = Integer.parseInt(BACKLOG_DELAY_DAY);
} catch (Exception e) {
log.error("数字转换异常, BACKLOG_DELAY_DAY: {} ", BACKLOG_DELAY_DAY, e);
}
}
//yyyy-MM-dd
String newDatenyr = null;
if (bakDay != 0) {
newDatenyr = LocalDateTime.now().plusDays(bakDay).format(DateTimeFormatter.ISO_DATE);
} else {
newDatenyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
}
newDatenyr = newDatenyr.replace("-", "");
return newDatenyr;
}
}
package cn.quantgroup.report.job;
import cn.quantgroup.report.constant.BaiHangHistoryConstant;
import cn.quantgroup.report.service.baihang.constant.Constant;
import cn.quantgroup.report.utils.dingtalk.DingTalk;
import com.google.common.base.Stopwatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 量化派助贷模式(非循环贷) -
* (贷款申请/放款/还款(逾期)三类实时批量数据)-To百行报送<br>
* 每日凌晨5点报送 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.10.25 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Component
public class SynLoanInfoHistoryTask {
private static final Logger log = LoggerFactory.getLogger(SynLoanInfoHistoryTask.class);
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private JdbcTemplate xyqbHistoryJdbcTemplate;
@Autowired
private DingTalk dingTalk;
private static AtomicBoolean SYN_Stop = new AtomicBoolean(false);
@Async
/*@Scheduled(cron = "0 0 05 * * ?")*/ //2019.11.15 15:25
public void startHistoryDateCopy(){
if(increment()){
redisTemplate.expire(Constant.XYQB_HISTORY_DAI_REPORT_LOCK_KEY, 10, TimeUnit.SECONDS);
Stopwatch stopwatch = Stopwatch.createStarted();
//yyyy-MM-dd
//String startnyr = LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ISO_DATE);
//String endnyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
log.info("量化派-同步表xyqb_i_loan_application_manifest_history数据开始, newTime: {} ", LocalDateTime.now());
//将xyqb_i_loan_application_manifest_history表的数据,同步到xyqb_i_repayment_plan_bak
//syn_history_by_CreatedAt();
//将xyqb_i_repayment_plan表的数据,同步到xyqb_i_loan_a_m_history_bak
//syn_plan_by_CreatedAt();
syn_historyAndplan_by_id();
////syn_history_p2p_bak();
////syn_plan_p2p_bak();
log.info("量化派-同步表xyqb_i_loan_application_manifest_history数据结束, endTime: {}, 耗时: {} ", LocalDateTime.now(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
private Boolean increment(){
Long increment = redisTemplate.opsForValue().increment(Constant.XYQB_HISTORY_DAI_REPORT_LOCK_KEY, 1);
return increment <= 1;
}
@Deprecated
private void syn_history_by_CreatedAt(){
LocalDateTime erlyDate = LocalDateTime.parse("2016-08-23T00:00:00");//2016-08-23T16:29:10
LocalDateTime endDate = LocalDateTime.parse("2019-11-01T00:00:00");//2019-11-11 12:32:08
int counter = 0;
while (true) {
Stopwatch startwatch = Stopwatch.createStarted();
if (SYN_Stop.get()) {
log.error("同步xyqb_i_loan_application_manifest_history数据查询STOP, D3_Stop: {} , endTime: {} ", SYN_Stop.get(), erlyDate.plusDays(counter).format(DateTimeFormatter.ISO_DATE));
break;
}
counter++;
if (erlyDate.plusDays(counter).compareTo(endDate) > 0) {
break;
}
String starTime = erlyDate.plusDays(counter - 1).format(DateTimeFormatter.ISO_DATE);
String endTime = erlyDate.plusDays(counter).format(DateTimeFormatter.ISO_DATE);
try {
String tmp_sql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_HISTORY;
tmp_sql = tmp_sql.replace("##STARTTIME##",starTime);
tmp_sql = tmp_sql.replace("##ENDTIME##",endTime);
int upCount = xyqbHistoryJdbcTemplate.update(tmp_sql);
log.info("同步xyqb_i_loan_application_manifest_history数据结束,startTime: {} , 耗时:{} , updateCount: {} ", starTime, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms", upCount);
}catch (Exception e){
log.error("同步xyqb_i_loan_application_manifest_history数据异常, startTime: {} , endTime: {} , counter: {} ", starTime, endTime,counter, e);
}
}
}
@Deprecated
private void syn_plan_by_CreatedAt(){
LocalDateTime erlyDate = LocalDateTime.parse("2016-08-23T00:00:00");//2016-08-23T16:29:10
LocalDateTime endDate = LocalDateTime.parse("2019-11-01T00:00:00");//2019-11-11 12:32:08
int counter = 0;
while (true) {
Stopwatch startwatch = Stopwatch.createStarted();
if (SYN_Stop.get()) {
log.error("同步xyqb_i_repayment_plan数据查询STOP, D3_Stop: {} , endTime: {} ", SYN_Stop.get(), erlyDate.plusDays(counter).format(DateTimeFormatter.ISO_DATE));
break;
}
counter++;
if (erlyDate.plusDays(counter).compareTo(endDate) > 0) {
break;
}
String starTime = erlyDate.plusDays(counter - 1).format(DateTimeFormatter.ISO_DATE);
String endTime = erlyDate.plusDays(counter).format(DateTimeFormatter.ISO_DATE);
try {
String tmp_sql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_PLAN;
tmp_sql = tmp_sql.replace("##STARTTIME##",starTime);
tmp_sql = tmp_sql.replace("##ENDTIME##",endTime);
int upCount = xyqbHistoryJdbcTemplate.update(tmp_sql);
log.info("同步xyqb_i_repayment_plan数据结束,startTime: {} , 耗时:{} , updateCount: {} ", starTime, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms", upCount);
}catch (Exception e){
log.error("同步xyqb_i_repayment_plan数据异常, startTime: {} , endTime: {} , counter: {} ", starTime, endTime,counter, e);
}
}
}
private boolean syn_history_by_id(long bakMaxId,long newMaxId){
String count_sql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_HISTORY_SYN_COUNT;
count_sql = count_sql.replace("##BAKMAXID##",""+bakMaxId);
count_sql = count_sql.replace("##NEWMAXID##",""+newMaxId);//防止查询的过程中再增长
Integer count = xyqbHistoryJdbcTemplate.queryForObject(count_sql,Integer.class);
if(count==null){
log.error("表xyqb_i_loan_application_manifest_history查询增量count为Null.");
dingTalk.talk("Warn","同步[借款清单]数据失败","查询增量count为Null,请尽快处理!"+" bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
dingTalk.talk_ToUser("借款清单同步失败", "同步[借款清单]表查询增量count为Null,停止T+1报送!发现问题,请及时处理!");
return false;
}
//小于2万条,可以commit
if(count.intValue() <= BaiHangHistoryConstant.MAX_COMMIT_COUT){
Stopwatch startwatch = Stopwatch.createStarted();
String inset_sql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_HISTORY_SYN_DATA;
inset_sql = inset_sql.replace("##STARTID##",""+bakMaxId);
int update = xyqbHistoryJdbcTemplate.update(inset_sql);
log.info("增量同步xyqb_i_loan_application_manifest_history表结束, bakMaxId: {} , count: {} , 插入条数: {} , 耗时: {} ", bakMaxId, count, update, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms");
dingTalk.talk("Info","同步[借款清单]数据成功","实际条数: "+update +", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
return true;
}else{
//大于2万条会报事务太长,需要分页插入
int id_limit_count = (int) (newMaxId - bakMaxId);
int page = id_limit_count / BaiHangHistoryConstant.MAX_COMMIT_COUT;
int mode = id_limit_count % BaiHangHistoryConstant.MAX_COMMIT_COUT;
if(mode!=0){
page = page+1;
}
int totalUpdate = 0;
for (int p=0 ; p < page; p++){
Stopwatch startwatch = Stopwatch.createStarted();
long startId = bakMaxId + p * BaiHangHistoryConstant.MAX_COMMIT_COUT;
long endId = bakMaxId + (p+1) * BaiHangHistoryConstant.MAX_COMMIT_COUT;
if( endId > newMaxId){
endId = newMaxId;
}
String tmpInsertSql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_HISTORY_SYN_DATA;
tmpInsertSql = tmpInsertSql.replace("##STARTID##",""+startId);
tmpInsertSql = tmpInsertSql + (" AND b.id <="+endId+" ;");
int update = xyqbHistoryJdbcTemplate.update(tmpInsertSql);
totalUpdate+=update;
log.info("增量同步xyqb_i_loan_application_manifest_history表页数page["+p+"], startId: {} , endId: {} , 插入条数: {} , 耗时: {} ", startId, endId, update, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms");
}
log.info("增量同步xyqb_i_loan_application_manifest_history表结束, bakMaxId: {} , newMaxId: {} , ID差: {} , count: {} , totalUpdate: {} , page: {} , mode: {} ", bakMaxId, newMaxId, (newMaxId-bakMaxId), count, totalUpdate, page, mode);
if(totalUpdate==count){
dingTalk.talk("Info","同步[借款清单]数据成功","实际条数(分页): "+totalUpdate+", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
return true;
}else{
dingTalk.talk("Warn","同步[借款清单]数据失败","查询条数: "+count+",实际条数="+totalUpdate+", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
dingTalk.talk_ToUser("借款清单同步异常", "同步[借款清单]数据失败,停止T+1报送!发现问题,请及时处理!");
return false;
}
}
}
private boolean syn_plan_by_id(long bakMaxId,long newMaxId){
String count_sql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_PLAN_SYN_COUNT;
count_sql = count_sql.replace("##BAKMAXID##",""+bakMaxId);
count_sql = count_sql.replace("##NEWMAXID##",""+newMaxId);//防止查询的过程中再增长
Integer count = xyqbHistoryJdbcTemplate.queryForObject(count_sql,Integer.class);
if(count==null){
log.error("表xyqb_i_repayment_plan查询增量count为Null.");
dingTalk.talk("Warn","同步[还款计划]数据失败","查询增量count为Null,请尽快处理!" + ", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
dingTalk.talk_ToUser("还款计划同步失败", "同步[还款计划]表查询增量count为Null,停止T+1报送!发现问题,请及时处理!");
return false;
}
//小于2万条,可以commit
if(count.intValue() <= BaiHangHistoryConstant.MAX_COMMIT_COUT){
Stopwatch startwatch = Stopwatch.createStarted();
String inset_sql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_PLAN_SYN_DATA;
inset_sql = inset_sql.replace("##STARTID##",""+bakMaxId);
int update = xyqbHistoryJdbcTemplate.update(inset_sql);
log.info("增量同步xyqb_i_repayment_plan表结束, bakMaxId: {} , count: {} , 插入条数: {} , 耗时: {} ", bakMaxId, count, update, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms");
dingTalk.talk("Info","同步[还款计划]数据成功","实际条数: "+update +", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
return true;
}else{
//大于2万条会报事务太长,需要分页插入
//xyqb_i_repayment_plan表目前发现有24期的,也就是说xyqb_i_loan_a_m_history_bak关联最大会出现24条
int PLAN_MAX_COMMIT_COUT = BaiHangHistoryConstant.MAX_COMMIT_COUT / 24;
int id_limit_count = (int) (newMaxId - bakMaxId);
int page = id_limit_count / PLAN_MAX_COMMIT_COUT;
int mode = id_limit_count % PLAN_MAX_COMMIT_COUT;
if(mode!=0){
page = page+1;
}
int totalUpdate = 0;
for (int p=0 ; p < page; p++){
Stopwatch startwatch = Stopwatch.createStarted();
long startId = bakMaxId + p * PLAN_MAX_COMMIT_COUT;
long endId = bakMaxId + (p+1) * PLAN_MAX_COMMIT_COUT;
if( endId > newMaxId){
endId = newMaxId;
}
String tmpInsertSql = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_PLAN_SYN_DATA;
tmpInsertSql = tmpInsertSql.replace("##STARTID##",""+startId);
tmpInsertSql = tmpInsertSql + (" AND b.id <="+endId+" ;");
int update = xyqbHistoryJdbcTemplate.update(tmpInsertSql);
totalUpdate+=update;
log.info("增量同步xyqb_i_repayment_plan表页数page["+p+"], startId: {} , endId: {} , 插入条数: {} , 耗时: {} ", startId, endId, update, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms");
}
log.info("增量同步xyqb_i_repayment_plan表结束, bakMaxId: {} , newMaxId: {} , ID差: {} , count: {} , totalUpdate: {} , page: {} , mode: {} ", bakMaxId, newMaxId, (newMaxId-bakMaxId), count, totalUpdate, page, mode);
if(totalUpdate==count){
dingTalk.talk("Info","同步[还款计划]数据成功","实际条数(分页): "+totalUpdate + ", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
return true;
}else{
dingTalk.talk("Warn","同步[还款计划]数据失败","查询条数: "+count+",实际条数="+totalUpdate + ", bakMaxId: "+bakMaxId+", newMaxId: "+newMaxId);
dingTalk.talk_ToUser("还款计划同步异常", "同步[还款计划]数据失败,停止T+1报送!发现问题,请及时处理!");
return false;
}
}
}
public boolean syn_historyAndplan_by_id(){
Stopwatch startwatch = Stopwatch.createStarted();
try {
String tmp_sql1 = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_HISTORY_BAK_MAX_ID;
Long bakMaxId = xyqbHistoryJdbcTemplate.queryForObject(tmp_sql1,Long.class);
String tmp_sql2 = BaiHangHistoryConstant.SQL_COMMONE_TEMPLATE_HISTORY_MAX_ID;
Long newMaxId = xyqbHistoryJdbcTemplate.queryForObject(tmp_sql2,Long.class);
//2019.11.15 13:37 bakMaxId: 1857710 , newMaxId: 13732716 , count: 1062175 , 差:11875006 , 总插入条数: 1062174 , page: 594
//bakMaxId = 1857710L;
//newMaxId = 13732716L;
if(bakMaxId!=null && bakMaxId.longValue() >= 0L && newMaxId!=null && newMaxId.longValue() >= 0L){
//同步到xyqb_i_loan_a_m_history_bak表-------------------------------
boolean table_history = syn_history_by_id(bakMaxId.longValue(), newMaxId.longValue());
if(table_history){
//同步到xyqb_i_repayment_plan_bak表
boolean table_plan = syn_plan_by_id(bakMaxId.longValue(), newMaxId.longValue());
if(table_plan){
log.info("ALL增量同步history&plan表数据结束, nowTime: {} ", LocalDateTime.now(), startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms");
return true;
}else{
log.error("All增量同步[xyqb_i_repayment_plan_bak]表数据失败,请尽快处理! nowTime: {} , bakMaxId: {} , newMaxId: {} ",LocalDateTime.now(), bakMaxId, newMaxId);
////dingTalk.talk("Warn","同步[还款计划]数据失败","同步xyqb_i_repayment_plan_bak表数据失败,请尽快处理! newMaxId:"+newMaxId+",newMaxId="+newMaxId);
}
}else{
log.error("增量同步[xyqb_i_loan_a_m_history_bak]表数据失败,请尽快处理! nowTime: {} , bakMaxId: {} , newMaxId: {} ",LocalDateTime.now(), bakMaxId, newMaxId);
////dingTalk.talk("Warn","同步[借款清单]数据失败","同步xyqb_i_loan_a_m_history_bak表数据失败,请尽快处理! newMaxId:"+newMaxId+",newMaxId="+newMaxId);
}
//-------------------------------
}else {
log.error("增量同步xyqb_i_repayment_plan数据-历史id为空,停止同步! nowTime: {} , bakMaxId: {} , newMaxId: {} ",LocalDateTime.now(), bakMaxId, newMaxId);
dingTalk.talk("Warn","同步临时表数据失败","查询数据历史bakMaxId或newMaxId为空.");
dingTalk.talk_ToUser("数据同步异常2", "查询数据历史bakMaxId或newMaxId为空,停止T+1报送!发现问题,请及时处理!");
}
}catch (Exception e){
log.error("增量同步history和plan表数据异常, nowTime: {} ", LocalDateTime.now(), e);
dingTalk.talk("Error","同步history和plan表数据异常",e);
dingTalk.talk_ToUser("数据同步异常1", "同步history和plan表数据异常,停止T+1报送!发现问题,请及时处理!");
}
return false;
}
/**
* 描述: 将xyqb_i_loan_application_manifest_history表的数据
* 同步到xyqb_i_loan_a_m_history_p2p_bak表<br/>
* 参数: [] <br/>
* 返回值: boolean <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.12.17 <br/>
*/
private void syn_history_p2p_bak(){
LocalDateTime erlyDate = LocalDateTime.parse("2016-11-01T00:00:00");
LocalDateTime endDate = LocalDateTime.parse("2019-01-01T00:00:00");
int counter = 0;
while (true) {
Stopwatch startwatch = Stopwatch.createStarted();
counter++;
if (erlyDate.plusDays(counter).compareTo(endDate) > 0) {
break;
}
String starTime = erlyDate.plusDays(counter - 1).format(DateTimeFormatter.ISO_DATE);
String endTime = erlyDate.plusDays(counter).format(DateTimeFormatter.ISO_DATE);
try {
String tmp_sql = BaiHangHistoryConstant.SQL_TEMPLATE_HISTORY_P2P;
tmp_sql = tmp_sql.replace("##STARTTIME##",starTime);
tmp_sql = tmp_sql.replace("##ENDTIME##",endTime);
int upCount = xyqbHistoryJdbcTemplate.update(tmp_sql);
log.info("同步xyqb_i_loan_a_m_history_p2p_bak数据结束, startTime: {} , 耗时: {} , updateCount: {} ", starTime, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms", upCount);
}catch (Exception e){
log.error("同步xyqb_i_loan_a_m_history_p2p_bak数据异常, startTime: {} , endTime: {} , counter: {} ", starTime, endTime,counter, e);
}
}
}
/**
* 描述: 将xyqb_i_repayment_plan表的数据同步到xyqb_i_repayment_plan_p2p_bak表 <br/>
* 参数: [] <br/>
* 返回值: void <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.12.17 <br/>
*/
private void syn_plan_p2p_bak(){
LocalDateTime erlyDate = LocalDateTime.parse("2016-11-01T00:00:00");
LocalDateTime endDate = LocalDateTime.parse("2019-10-25T00:00:00");
int counter = 0;
while (true) {
Stopwatch startwatch = Stopwatch.createStarted();
counter++;
if (erlyDate.plusDays(counter).compareTo(endDate) > 0) {
break;
}
String starTime = erlyDate.plusDays(counter - 1).format(DateTimeFormatter.ISO_DATE);
String endTime = erlyDate.plusDays(counter).format(DateTimeFormatter.ISO_DATE);
try {
String tmp_sql = BaiHangHistoryConstant.SQL_TEMPLATE_PLAN_P2P;
tmp_sql = tmp_sql.replace("##STARTTIME##",starTime);
tmp_sql = tmp_sql.replace("##ENDTIME##",endTime);
int upCount = xyqbHistoryJdbcTemplate.update(tmp_sql);
log.info("同步xyqb_i_repayment_plan_p2p_bak数据结束, startTime: {} , 耗时: {} , updateCount: {} ", starTime, startwatch.stop().elapsed(TimeUnit.MILLISECONDS)+".ms", upCount);
}catch (Exception e){
log.error("同步xyqb_i_repayment_plan_p2p_bak数据异常, startTime: {} , endTime: {} , counter: {} ", starTime, endTime,counter, e);
}
}
}
}
package cn.quantgroup.report.mapper.baihang;
import cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai;
import cn.quantgroup.report.domain.baihang.BaiHangTimeRecord;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 贷款申请信息查询mapper <br>
* 作者:yanhui.Hao <br>
* 时间:2019.11.06 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Repository
public interface ApplyLoanInfoMapper {
//广达小贷-申请实时
//List<ApplyLoanInfo> findApplyLoanInfo();
//广达小贷-申请存量
//List<ApplyLoanInfo> findStockApplyLoanInfo();
/**
* 描述: 百行-助贷申请存量数据 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.23 <br/>
*/
@Deprecated
List<ApplyLoanInfoZhuDai> queryStockApplyLoanInfoZhuDai(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 1.1百行助贷-非联合贷 实时申请 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<ApplyLoanInfoZhuDai> findRealTimeApplyLoanZhuDai(BaiHangTimeRecord timeRecord);
/**
* 描述: 1.2百行助贷-联合贷 实时申请 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<ApplyLoanInfoZhuDai> findRealTimeApplyLoanZhuDaiLh(BaiHangTimeRecord timeRecord);
}
package cn.quantgroup.report.mapper.baihang;
import cn.quantgroup.report.domain.baihang.BaiHangTimeRecord;
import cn.quantgroup.report.domain.baihang.LoanInfoZhuDai;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 放款信息查询
*
* @Author fengjunkai
* @Date 2019-03-26 15:26
*/
@Repository
public interface LoanInfoMapper {
//报送实时放款数据(广达百行征信报送)
//List<LoanInfoZhuDai> findLoanInfo();
//List<LoanInfoZhuDai> findLoanInfoByTime(BaiHangTimeRecord baiHangTimeRecord);
//List<LoanInfoZhuDai> stockLoanInfo();
/**
* 描述: 根据loan_application_history_id查询xyqb_i_repayment_plan表最晚还款日 <br/>
* 参数: loan_application_history_id <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.11.06 <br/>
*/
List<String> findTargetRepaymentDayList(String reqId);
/**
* 描述: 根据order_no查询 loan_application_history_id <br/>
* 参数: orderNoArray<br/>
* 返回值: String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.24 <br/>
*/
List<String> findHistoryIdByOrderNo(String[] orderNoArray);
/**
* 描述: 根据loan_application_history_id查询手动报送的bean <br/>
* 参数: loanApplicationHistoryId <br/>
* 返回值: LoanInfoZhuDai <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.25 <br/>
*/
LoanInfoZhuDai findLoanInfoD2ByHistoryId(String loanApplicationHistoryId);
/**
* 描述: 百行-助贷放款存量数据 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.23 <br/>
*/
@Deprecated
List<LoanInfoZhuDai> queryStockLoanInfoZhuDai(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 2.1百行助贷-非联合贷 实时放款数据 <br/>
* 参数: <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<LoanInfoZhuDai> findRealTimeLoanInfoZhuDai(BaiHangTimeRecord timeRecord);
/**
* 描述: 2.2百行助贷-联合贷 实时放款数据 <br/>
* 参数: <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<LoanInfoZhuDai> findRealTimeLoanInfoZhuDaiLh(BaiHangTimeRecord timeRecord);
}
package cn.quantgroup.report.mapper.baihang;
import cn.quantgroup.report.domain.baihang.BaiHangTimeRecord;
import cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 还款信息查询
*
* @Author fengjunkai
* @Date 2019-03-26 15:27
*/
@Repository
public interface RepaymentLoanInfoMapper {
//实时还款(广达百行征信报送)
//List<RepaymentInfoZhuDai> findRepayMentLoanInfo(BaiHangTimeRecord baiHangTimeRecord);
//实时逾期还款(广达百行征信报送)
//List<RepaymentInfoZhuDai> findRepayMentLoanInfoOverdue(BaiHangTimeRecord baiHangTimeRecord);
///List<RepaymentInfoZhuDai> findStockRepayMentLoanInfo(BaiHangTimeRecord baiHangTimeRecord);
//List<RepaymentInfoZhuDai> findStockRepayMentLoanInfoOverdue(BaiHangTimeRecord baiHangTimeRecord);
//BaiHangNameResult findName(BaiHangName baiHangName);
/**
* 描述: 百行-助贷逾期还款存量数据 整理 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.23 <br/>
*/
@Deprecated
List<RepaymentInfoZhuDai> queryStockRepayMentInfoOverdueZhuDai(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 百行-助贷还款存量数据 整理 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.23 <br/>
*/
@Deprecated
List<RepaymentInfoZhuDai> queryStockRepayMentInfoZhuDai(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 3.1百行助贷-非联合贷 实时还款 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<RepaymentInfoZhuDai> findRealTimeRepayMentInfo(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 3.2百行助贷-联合贷 实时还款 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<RepaymentInfoZhuDai> findRealTimeRepayMentInfoLh(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 4.1百行助贷-非联合贷 实时逾期还款 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<RepaymentInfoZhuDai> findRealTimeRepayMentOverdue(BaiHangTimeRecord baiHangTimeRecord);
/**
* 描述: 4.2百行助贷-联合贷 实时逾期还款 <br/>
* 参数: 日期 BaiHangTimeRecord: startTime和endsTime <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.28 <br/>
*/
List<RepaymentInfoZhuDai> findRealTimeRepayMentOverdueLh(BaiHangTimeRecord baiHangTimeRecord);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.AccountPO;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface AccountPOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table account
*
* @mbg.generated
*/
int insert(AccountPO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table account
*
* @mbg.generated
*/
int insertSelective(AccountPO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table account
*
* @mbg.generated
*/
List<AccountPO> selectByExample(AccountPO example);
void updateByParams(AccountPO example);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.ApiRequestLogPO;
import org.springframework.stereotype.Repository;
@Repository
public interface ApiRequestLogPOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_request_log_201805
*
* @mbg.generated
*/
int insert(ApiRequestLogPO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_request_log_201805
*
* @mbg.generated
*/
int insertSelective(ApiRequestLogPO record);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.baihang.ApplyLoanInfo;
import cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai;
import cn.quantgroup.report.domain.baihang.LoanInfoZhuDai;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 贷款申请信息查询mapper
*
* @Author fengjunkai
* @Date 2019-03-26 15:25
*/
@Repository
public interface ApplyLoanInfoDbMapper {
void saveApplyLoanInfoRecordLog(ApplyLoanInfo applyLoanInfo);
List<ApplyLoanInfo> findAll();
/**
* 描述: 根据loan_application_history_id查询手动报送的申请bean <br/>
* 参数: loanApplicationHistoryId <br/>
* 返回值: ApplyLoanInfoZhuDai <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.25 <br/>
*/
ApplyLoanInfoZhuDai findApplyInfoA1ByHistoryId(String loanApplicationHistoryId);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.CommonWithBillingApiRequestEvent;
import org.springframework.stereotype.Repository;
/**
* Created by suh on 2017/11/6.
*/
@Repository
public interface CommonApiReqestEventMapper {
int insert(CommonWithBillingApiRequestEvent event);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.CostRecordPO;
import org.springframework.stereotype.Repository;
@Repository
public interface CostRecordPOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table cost_record
*
* @mbg.generated
*/
int insert(CostRecordPO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table cost_record
*
* @mbg.generated
*/
int insertSelective(CostRecordPO record);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.DataPriceConfigPO;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface DataPriceConfigPOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table data_price_config
*
* @mbg.generated
*/
List<DataPriceConfigPO> queryByParams(DataPriceConfigPO dataPriceConfigPO);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table data_price_config
*
* @mbg.generated
*/
int insert(DataPriceConfigPO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table data_price_config
*
* @mbg.generated
*/
int insertSelective(DataPriceConfigPO record);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.DataSourceCacheConfig;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-06-19 14:05
*/
@Repository
public interface DataSourceCacheConfigMapper {
List<DataSourceCacheConfig> findAllCacheConfig();
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.DsSpecialUserHandle;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by suh on 2017/11/6.
*/
@Repository
public interface DsSpecialUserHandleMapper {
int insert(DsSpecialUserHandle event);
List<DsSpecialUserHandle> selectAllByEnable();
int updateNotEnableByParams(DsSpecialUserHandle record);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.ElevenBeiApiRequestEvent;
import org.springframework.stereotype.Repository;
/**
* Created by suh on 2017/11/6.
*/
@Repository
public interface ElevenBeiApiReqestEventMapper {
int insert(ElevenBeiApiRequestEvent event);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.IntelliCreditLoanIssue;
import java.util.List;
public interface IntelliCreditLoanIssueMapper {
int insert(IntelliCreditLoanIssue record);
int insertSelective(IntelliCreditLoanIssue record);
IntelliCreditLoanIssue selectByPrimaryKey(Long id);
List<IntelliCreditLoanIssue> selectUndoneByBeginId(Long id);
int updateByPrimaryKeySelective(IntelliCreditLoanIssue record);
int updateByPrimaryKeyWithBLOBs(IntelliCreditLoanIssue record);
int updateByPrimaryKey(IntelliCreditLoanIssue record);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.IntelliCreditLoanTrace;
public interface IntelliCreditLoanTraceMapper {
int insert(IntelliCreditLoanTrace record);
int insertSelective(IntelliCreditLoanTrace record);
IntelliCreditLoanTrace selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(IntelliCreditLoanTrace record);
int updateByPrimaryKey(IntelliCreditLoanTrace record);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.IntelliCreditRequestEvent;
import org.springframework.stereotype.Repository;
@Repository
public interface IntelliCreditRequestEventMapper {
int insert(IntelliCreditRequestEvent record);
int insertSelective(IntelliCreditRequestEvent record);
IntelliCreditRequestEvent selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(IntelliCreditRequestEvent record);
int updateByPrimaryKey(IntelliCreditRequestEvent record);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord;
import cn.quantgroup.report.domain.baihang.LoanInfoZhuDai;
import org.springframework.stereotype.Repository;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 放款信息查询 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.11.06 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Repository
public interface LoanInfoDbMapper {
void saveLoanInfoRecordLog(LoanInfoZhuDai loanInfo);
void updateCurrentRecordEnableFalce(BaiHangUpDateRecord baiHangUpDateRecord);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.baihang.BaiHangRepayment;
import cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord;
import cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai;
import cn.quantgroup.report.domain.baihang.RepaymentLoanInfoLog;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 还款信息查询 <br>
* 作者:yanhui.Hao <br>
* 时间:2019.11.06 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Repository
public interface RepaymentLoanInfoDbMapper {
void saveRepaymentLoanInfoLog(RepaymentInfoZhuDai repaymentLoanInfo);
void updateCurrentRecordEnableFalse(BaiHangUpDateRecord baiHangUpDateRecord);
RepaymentInfoZhuDai findLastOne(BaiHangRepayment baiHangRepayment);
/**
* 描述: 根据recordId查询op_code=A的 <br/>
* 参数: <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.24 <br/>
*/
List<RepaymentLoanInfoLog> findByD3RecordId(String[] recordIdArray);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.RepaymentLoanWhiteList;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 百行报送逾期还款白名单表 <br>
* 作者:yanhui.Hao <br>
* 时间:2020.02.05 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Repository
public interface RepaymentLoanWhiteListMapper {
RepaymentLoanWhiteList findRepaymentLoanWhiteListOne(@Param("loanId")String loanId, @Param("type")int type);
}
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.TransactionLogPO;
import org.springframework.stereotype.Repository;
@Repository
public interface TransactionLogPOMapper {
int insert(TransactionLogPO transactionLogPO);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.master;
import cn.quantgroup.report.domain.master.UnionPayApiRequestEvent;
import org.springframework.stereotype.Repository;
/**
* Created by suh on 2018/2/11.
*/
@Repository
public interface UnionPayApiRequestEventMapper {
int insert(UnionPayApiRequestEvent event);
}
package cn.quantgroup.report.mapper.tidbrisk;
import cn.quantgroup.report.domain.tidbrisk.CallRecord2;
import org.springframework.stereotype.Repository;
@Repository
public interface CallRecordMapper {
/**
* 描述: call_record表
* 迁移至fengkong-tidb.quantgroups.com的risk_datasource库<br/>
* 参数: <br/>
* 返回值: <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.12.30 <br/>
*/
int insertCallRecord(CallRecord2 callRecord);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.xyqbuser;
import cn.quantgroup.report.domain.xyqbuser.UserDetail;
import java.util.List;
public interface UserDetailMapper {
UserDetail selectByPrimaryKey(Long id);
UserDetail selectByUserId(Long userId);
List<UserDetail> selectByIdentityNumber(String identityNumber);
}
\ No newline at end of file
package cn.quantgroup.report.mapper.xyqbuser;
import cn.quantgroup.report.domain.xyqbuser.User;
public interface UserMapper {
User selectByPrimaryKey(Long id);
User selectByUuid(String uuid);
}
\ No newline at end of file
package cn.quantgroup.report.response;
import cn.quantgroup.report.error.QGException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
/**
* Created by yanminmin on 2017/3/24.
*/
@ControllerAdvice({"cn.quantgroup.report"})
@Slf4j
public class GlobalControllerHandler {
// 定义全局异常处理,value属性可以过滤拦截条件,此处拦截所有的Exception
@ExceptionHandler(value = Exception.class)
@ResponseBody
public GlobalResponse exception(Exception ex, WebRequest request) {
return new GlobalResponse(QGException.wrap(ex));
}
}
package cn.quantgroup.report.response;
import cn.quantgroup.report.constant.TransactionCodeEnum;
import cn.quantgroup.report.enums.RequestUrlType;
import cn.quantgroup.report.error.QGException;
import cn.quantgroup.report.error.QGExceptionType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
@Data
public class GlobalResponse {
private int code;
private String error;
private String transactionId;
private Object body;
@JsonIgnore
private Boolean isBilling = false;
@JsonIgnore
private String uuid;
@JsonIgnore
private String identity;
@JsonIgnore
private String phone;
@JsonIgnore
private List<TransactionResult> transactionResult = new ArrayList<>();
public GlobalResponse() {
}
private GlobalResponse(Object object) {
body = object;
code = 0;
error = "";
}
public GlobalResponse(Object code, String error) {
if (code instanceof String && StringUtils.isNumeric(((String) code))) {
this.code = Integer.parseInt(((String) code));
} else {
this.code = QGExceptionType.COMMON_SERVER_ERROR.code;
}
this.error = error;
}
public GlobalResponse(QGException ex) {
code = ex.qgExceptionType.code;
error = StringUtils.isNotBlank(ex.detail) ? ex.detail : ex.qgExceptionType.text;
}
public static GlobalResponse generate(Object o) {
return new GlobalResponse(o);
}
public static GlobalResponse builder(String transactionId, Object o) {
GlobalResponse response;
if(o instanceof QGException){
response = new GlobalResponse((QGException)o);
} else {
response = new GlobalResponse(o);
}
response.setTransactionId(transactionId);
return response;
}
public GlobalResponse addTransactionResult(RequestUrlType urlType, TransactionCodeEnum code){
transactionResult.add(new TransactionResult(urlType, code));
return this;
}
public GlobalResponse addTransactionResult(List<TransactionResult> transactionResults){
transactionResult.addAll(transactionResults);
return this;
}
public GlobalResponse addUuid(String uuid){
this.uuid = uuid;
return this;
}
public GlobalResponse addPhone(String phone){
this.phone = phone;
return this;
}
public GlobalResponse addIdentity(String identity){
this.identity = identity;
return this;
}
public GlobalResponse isBilling(boolean isBilling){
this.isBilling = isBilling;
return this;
}
}
package cn.quantgroup.report.response;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
/**
* Created by suh on 2017/12/18.
*/
@Data
public class RiskHttpResponse {
private int code;
private JSONObject jsonObject;
public RiskHttpResponse(JSONObject jsonObject,int code){
this.jsonObject = jsonObject;
this.code = code;
}
public RiskHttpResponse(){}
}
package cn.quantgroup.report.response;
import cn.quantgroup.report.constant.TransactionCodeEnum;
import cn.quantgroup.report.enums.RequestUrlType;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class TransactionResult {
private RequestUrlType urlType;
private TransactionCodeEnum tansactionCode;
}
package cn.quantgroup.report.service;
import cn.quantgroup.report.cmpt.MonitorCmpt;
import cn.quantgroup.report.enums.RequestUrlType;
import cn.quantgroup.report.service.thirdpartymonitor.ThirdpartyApiMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.*;
/**
* Created by Alan on 2018/5/29.
*/
@Service
public class AbstractBaseService {
protected static ThreadPoolExecutor pool = new ThreadPoolExecutor(20, 500, 2000,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(5000), new ThreadPoolExecutor.DiscardPolicy());
protected static ExecutorService dbLogPool = Executors.newCachedThreadPool();
@Autowired
protected MonitorCmpt monitorCmpt;
@Autowired
protected DataSourceCacheConfigService cacheConfigService;
static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (pool != null) pool.shutdown();
if (dbLogPool != null) pool.shutdown();
}));
}
protected void saveLog(ThirdpartyApiMonitorService thirdpartyApiMonitorService, RequestUrlType urlType, Long start, Long end, String buscode, String message, String hitFlag) {
final String code = buscode;
final String msg = message;
final int millsElapse = (int)(end-start);
final String flag = hitFlag;
pool.execute(()->thirdpartyApiMonitorService.saveLog(urlType, code, msg, flag, millsElapse));
}
}
package cn.quantgroup.report.service;
/**
* Created by fengjunkai on 2018/8/13 0013 下午 5:30
**/
public interface CommonSuperService {
}
package cn.quantgroup.report.service;
import cn.quantgroup.report.domain.master.DataSourceCacheConfig;
import cn.quantgroup.report.mapper.master.DataSourceCacheConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* 数据源缓存配置
*
* @Author fengjunkai
* @Date 2019-06-19 14:53
*/
@Slf4j
@Service
public class DataSourceCacheConfigService {
private Map<String, Integer> allDataSourceCacheConfigMap = new ConcurrentHashMap();
private Map<String, Integer> allDataSourceTestCacheConfigMap = new ConcurrentHashMap();
@Autowired
private DataSourceCacheConfigMapper dataSourceCacheConfigMapper;
@PostConstruct
private void initDataSourceCacheConfig() {
init();
}
public void init() {
allDataSourceCacheConfigMap.clear();
allDataSourceTestCacheConfigMap.clear();
List<DataSourceCacheConfig> allCacheConfig = dataSourceCacheConfigMapper.findAllCacheConfig();
allDataSourceCacheConfigMap = allCacheConfig.stream().collect(Collectors.toMap(DataSourceCacheConfig::getProductType, DataSourceCacheConfig::getProductCacheTime));
allDataSourceTestCacheConfigMap = allCacheConfig.stream().collect(Collectors.toMap(DataSourceCacheConfig::getProductType, DataSourceCacheConfig::getProductTestCacheTime));
}
public Integer getCacheTime(String productType) {
Integer cacheTime = allDataSourceCacheConfigMap.get(productType);
return cacheTime == null ? 1 : cacheTime;
}
public Integer getTestCacheTime(String productType) {
Integer testCacheTime = allDataSourceTestCacheConfigMap.get(productType);
return testCacheTime == null ? 1 : testCacheTime;
}
}
package cn.quantgroup.report.service.baihang;
import cn.quantgroup.report.service.AbstractBaseService;
import cn.quantgroup.report.service.CommonSuperService;
import cn.quantgroup.report.service.baihang.util.Base64;
import cn.quantgroup.report.service.http.IHttpService;
import cn.quantgroup.report.utils.IdUtils;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: 百行个人征信报告查询 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.05.13 16:01 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Slf4j
@Service
public class BaiHangQueryService extends AbstractBaseService implements CommonSuperService {
//@Value("${baihang.zhudai.Q1.account.name}")
private String baiHangQ1AccountName = "BJZXLM_A0001";
//@Value("${baihang.zhudai.Q1.password}")
private String haiHangQ1Password = "msvo%t4cxb#i262g";
//@Value("${baihang.zhudai.Q1.requestUrl}")
private String baihangQ1requestUrl = "https://zxpt.baihangcredit.com:8443/api/v1/credit/query";
@Autowired
private IHttpService iHttpService;
/**
* -----------------------------------------------------------------------------<br>
* 描 述: 百行个人征信报告(zxlm实体:贷前/贷中/贷后)查询公共方法 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.05.13 15:58 <br>
* 最后修改人: <br>
* 最后修改时间: 2020.05.13 15:58 <br>
* 入参说明: [transactionId, uuid, identity, phone, name, queryReason, loanId] <br>
* 出参说明: java.util.Map<java.lang.String,java.lang.String> <br>
* -----------------------------------------------------------------------------
*/
public Map<String, Object> queryBaiHangQ1OfZxlm(String transactionId, String uuid, String identity, String phone, String name, String queryReason, String loanId) {
/*查询原因(queryReason)
1 授信审批 机构在批核贷款、授信额度时填报的原因
2 贷中管理 机构在实际放款前如果需要再次查询,填写贷中管理
3 贷后管理 机构在贷款放款或循环贷款额度批核后,在业务存续期间,定期开展贷后风险管理时查询
4 个人查询 信息主体本人查询征信报告时填报
5 异议处理 百行征信或机构为处理异议处理时查询
6 担保查询 机构审核担保人资质而查询征信报告时填写
7 特约商户实名审查 适用于特约商户实名审查时填写
8 重要人员资信审查 适用于法定代表人、负责人、高管等资信审查时填写
9 其他人员资信审查 适用于出资方或关联方等资信审查时填写*/
log.info("众信利民-百行个人征信报告查询入参, name: {} , identity: {} , queryReason: {} , uuid: {} ", name, identity, queryReason, uuid);
if (!",1,2,3,4,5,6,7,8,9,".contains("," + queryReason + ",")) {
return ImmutableMap.of("code", "301", "msg", "参数不正确!");
}
Long startTime = System.currentTimeMillis();
long cost = 0;
try {
JSONObject applyLoanInfo = new JSONObject();
applyLoanInfo.put("reqID", transactionId);//记录唯一标识
applyLoanInfo.put("name", BaiHangZhuDaiService.interfaceUploadClient(name));
applyLoanInfo.put("idType", 1);//证件类型
applyLoanInfo.put("pid", BaiHangZhuDaiService.interfaceUploadClient(identity));
applyLoanInfo.put("creditRptVersion", 1);//信用报告版本 1:机构简版
applyLoanInfo.put("queryReason", queryReason);//查询原因
if ("2".equals(queryReason) || "3".equals(queryReason)) {
//ERR_30039: 查询原因是“2-贷中管理”、“3-贷后管理”时,应填写“贷款/授信账户编号”
applyLoanInfo.put("loanId", loanId);
}
//String resultStr = iHttpService.postBaiHang(baihangQ1requestUrl, getHeader(), JSON.toJSONString(applyLoanInfo));
String resultStr = "{\"homeInfo\":[{\"homeAddress\":\"福建省龙岩**********\",\"date\":\"2020-02-27\"},{\"homeAddress\":\"福建省宁化县济村**********\",\"date\":\"2020-02-27\"},{\"homeAddress\":\"福建省龙岩**********\",\"date\":\"2020-01-25\"}],\"nonRevolvingLoan\":{\"D180\":{\"applyTenantCount\":-1,\"loanCount\":0,\"loanAmount\":0.0,\"loanTenantCount\":0,\"maxLoanAmount\":0.0,\"averageLoanAmount\":0.0,\"overdueLoanCount\":0,\"compensationCount\":0,\"compensationTimes\":0,\"compensationAmount\":0.0},\"D30\":{\"applyTenantCount\":-1,\"loanCount\":0,\"loanAmount\":0.0,\"loanTenantCount\":0,\"maxLoanAmount\":0.0,\"averageLoanAmount\":0.0,\"overdueLoanCount\":0,\"compensationCount\":0,\"compensationTimes\":0,\"compensationAmount\":0.0},\"D360\":{\"applyTenantCount\":-1,\"loanCount\":0,\"loanAmount\":0.0,\"loanTenantCount\":0,\"maxLoanAmount\":0.0,\"averageLoanAmount\":0.0,\"overdueLoanCount\":0,\"compensationCount\":0,\"compensationTimes\":0,\"compensationAmount\":0.0},\"D90\":{\"applyTenantCount\":-1,\"loanCount\":0,\"loanAmount\":0.0,\"loanTenantCount\":0,\"maxLoanAmount\":0.0,\"averageLoanAmount\":0.0,\"overdueLoanCount\":0,\"compensationCount\":0,\"compensationTimes\":0,\"compensationAmount\":0.0},\"summary\":{\"loanCount\":0,\"openLoanCount\":0,\"remainingAmount\":0.0,\"remainingOverdueLoanCount\":0,\"remainingOverdueAmount\":0.0,\"remainingMaxOverdueStatus\":\"N\",\"overdueCount\":0,\"maxOverdueStatus\":\"N\",\"lastCompensationDate\":\"\"}},\"personalProfile\":{\"pid\":\"558b1bea81d43b64739f4a10ad225fa71af86c9139ec78b6e236edc31eff9d70\",\"idType\":1,\"name\":\"3c2388015a362992a4d8a9dcf8157cd56a7e6a33b29e7ae4739f5b259c89783c\",\"mobileCount\":0},\"queryHistory\":[{\"tenantType\":\"-\",\"tenantName\":\"鹰潭市信江广达小额贷款股份有限公司\",\"userId\":\"YTXJGD_C0001\",\"date\":\"2020-04-12\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-03-24\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-03-06\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-02-27\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-02-27\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-02-26\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-02-26\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"鹰潭市信江广达小额贷款股份有限公司\",\"userId\":\"YTXJGD_C0001\",\"date\":\"2020-02-26\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-01-30\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-01-28\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-01-25\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2020-01-25\",\"reason\":1},{\"tenantType\":\"-\",\"tenantName\":\"*\",\"userId\":\"*\",\"date\":\"2019-12-22\",\"reason\":1}],\"reportHeader\":{\"reportId\":\"BH2005081653168406987864\",\"reportTime\":\"2020-05-08T16:53:16\",\"queryResult\":1},\"revolvingLoan\":{\"D180\":{\"applyTenantCount\":-1,\"revolvingCompensationCount\":0,\"revolvingCompensationTimes\":0,\"revolvingCompensationAmount\":0.0,\"lendingAmount\":0.0,\"creditLimitSum\":0.0,\"overdueAccountCount\":0,\"accountCount\":0},\"D30\":{\"applyTenantCount\":-1,\"revolvingCompensationCount\":0,\"revolvingCompensationTimes\":0,\"revolvingCompensationAmount\":0.0,\"lendingAmount\":0.0,\"creditLimitSum\":0.0,\"overdueAccountCount\":0,\"accountCount\":0},\"D360\":{\"applyTenantCount\":-1,\"revolvingCompensationCount\":0,\"revolvingCompensationTimes\":0,\"revolvingCompensationAmount\":0.0,\"lendingAmount\":0.0,\"creditLimitSum\":0.0,\"overdueAccountCount\":0,\"accountCount\":0},\"D90\":{\"applyTenantCount\":-1,\"revolvingCompensationCount\":0,\"revolvingCompensationTimes\":0,\"revolvingCompensationAmount\":0.0,\"lendingAmount\":0.0,\"creditLimitSum\":0.0,\"overdueAccountCount\":0,\"accountCount\":0},\"summary\":{\"remainingAmount\":0.0,\"remainingOverdueAmount\":0.0,\"remainingMaxOverdueStatus\":\"N\",\"overdueCount\":0,\"maxOverdueStatus\":\"N\",\"revolvingLastCompensationDate\":\"\",\"creditLimitSum\":0.0,\"accountCount\":0,\"validAccountCount\":0,\"maxCreditLimitPerTenant\":0.0,\"remainingOverdueAccountCount\":0}},\"workInfo\":[{\"workName\":\"福建华维环保科*****\",\"workAddress\":\"\",\"date\":\"2020-02-27\"}]}";
cost = System.currentTimeMillis() - startTime;
log.info("众信利民-百行个人征信报告查询结束, transactionId: {} , uuid: {} , identity: {} , phone: {} , name: {} , queryReason: {} , loanId: {} , result: {} , 耗时: {} ",
transactionId, uuid, identity, phone, name, queryReason, loanId, resultStr, cost);
//失败的情况 {"errorCode":"ERR_20003","errorMessage":"decrypt failed"}
if (StringUtils.isNotBlank(resultStr)) {
return ImmutableMap.of("code", "200", "msg", "众信利民-百行个人征信报告查询成功", "data", resultStr);
} else {
return ImmutableMap.of("code", "999", "msg", "众信利民-百行个人征信报告查询失败,返回结果为空!");
}
} catch (Exception e) {
cost = System.currentTimeMillis() - startTime;
log.error("众信利民-百行个人征信报告查询异常, transactionId: {} , uuid: {} , identity: {} , phone: {} , name: {} , queryReason: {} , loanId: {} , 耗时: {} ",
transactionId, uuid, identity, phone, name, queryReason, loanId, cost, e);
return ImmutableMap.of("code", "500", "msg", "众信利民-百行个人征信报告查询异常["+e.toString()+"]");
}
}
private Map<String, String> getHeader() {
Map<String, String> headerMap = new HashMap<>();
headerMap.put("Authorization", "Basic " + Base64.byteArrayToBase64((baiHangQ1AccountName + ":" + haiHangQ1Password).getBytes()));
headerMap.put("Content-Type", "application/json");
return headerMap;
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
package cn.quantgroup.report.service.baihang.client;
import cn.quantgroup.report.service.baihang.response.FileUploadResponse;
import cn.quantgroup.report.service.baihang.response.FileUploadValidationResponse;
import cn.quantgroup.report.service.baihang.util.BHRSAUtils;
import cn.quantgroup.report.service.baihang.util.BHZipUtil;
import cn.quantgroup.report.service.baihang.request.FileUploadRequest;
import cn.quantgroup.report.service.baihang.request.FileUploadValidationRequest;
import cn.quantgroup.report.service.baihang.util.BHAESUtil;
import cn.quantgroup.report.service.baihang.util.Base64;
import java.io.*;
/**
* @Author fengjunkai
* @Date 2019-03-27 19:58
*/
public class BhFileCreditApiClient {
//RSA公钥
private static java.security.PublicKey rsa_public_key = null;
//RSA私钥
private static java.security.PrivateKey rsa_private_key = null;
//AES密钥
private static String aes_key = null;
/**
* 初始化
* @param rsa_public_key
* @param aes_key
*/
public void init(java.security.PublicKey rsa_public_key,String aes_key){
if(this.rsa_public_key == null){
this.rsa_public_key = rsa_public_key;
}
if(this.aes_key == null){
this.aes_key = aes_key;
}
}
/**
* 初始化
* @param rsa_public_key
*/
public void init(java.security.PublicKey rsa_public_key){
if(this.rsa_public_key == null){
this.rsa_public_key = rsa_public_key;
}
}
/**
* 初始化
* @param rsa_private_key
*/
public void init(java.security.PrivateKey rsa_private_key){
if(this.rsa_private_key == null){
this.rsa_private_key = rsa_private_key;
}
}
/**
* 文件压缩和加密
* @param req
* @return
*/
public FileUploadResponse execute(FileUploadRequest req){
FileUploadResponse response = new FileUploadResponse();
File srcFile = new File(req.getDataFile());
if(!srcFile.exists()){
response.setSuccess(false);
response.setErrorMessage("待压缩加密的文件不存在");
return response;
}
if(req.getTargetFilePath().equals("")){
req.setTargetFilePath(srcFile.getParent());
}
File zipFile = null;
FileInputStream in = null;
PrintWriter pw = null;
try{
//压缩后的zip数据文件
zipFile = new File(req.getTargetFilePath()+ File.separator +srcFile.getName().substring(0,srcFile.getName().lastIndexOf("."))+".zip");
//压缩文件
response = BHZipUtil.zipFile(new File(req.getDataFile()),zipFile);
//压缩失败
if(!response.isSuccess()){
return response;
}
//设置压缩加密后的文件路径
response.setEncryptFilePath(req.getTargetFilePath());
//设置压缩加密后的文件名
response.setEncryptFileName(srcFile.getName().substring(0,srcFile.getName().lastIndexOf("."))+".cry");
//压缩文件
File encryptFile = new File(response.getEncryptFilePath()+ File.separator +response.getEncryptFileName());
if(encryptFile.exists()){
encryptFile.delete();
}
pw = new PrintWriter(new FileWriter(encryptFile,true));
//初始化RSA公钥
BHRSAUtils.init(rsa_public_key, null);
//RSA加密
byte[] bytes = BHRSAUtils.encryptData(aes_key.getBytes());
String aes_key_str = Base64.byteArrayToBase64(bytes);
//将ASE密钥加密后放入加密文件的第一行
pw.println(aes_key_str);
//将压缩文件的数据报文加密后放入加密文件
in = new FileInputStream(zipFile);
int len;
byte[] buf = new byte[1024];
while ((len = in.read(buf)) > 0) {
pw.println(Base64.byteArrayToBase64(BHAESUtil.encryptData(aes_key, buf)));
}
pw.flush();
}catch (Exception e) {
response.setSuccess(false);
response.setErrorMessage(e.getMessage());
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
if (pw != null)
pw.close();
if(zipFile.exists()){
zipFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
/**
* 文件解密和解压
* @param req
* @return
*/
public FileUploadValidationResponse execute(FileUploadValidationRequest req){
FileUploadValidationResponse response = new FileUploadValidationResponse();
File srcFile = new File(req.getDataFile());
if(!srcFile.exists()){
response.setSuccess(false);
response.setErrorMessage("待解密解压的文件不存在");
return response;
}
if(req.getTargetFilePath().equals("")){
req.setTargetFilePath(srcFile.getParent());
}
File zipFile = null;
FileOutputStream out = null;
BufferedReader br = null;
try{
//解密后的压缩文件
zipFile = new File(req.getTargetFilePath()+ File.separator +srcFile.getName().substring(0,srcFile.getName().lastIndexOf("."))+".zip");
response.setDecryptFilePath(req.getTargetFilePath());
response.setDecryptFileName(srcFile.getName().substring(0,srcFile.getName().lastIndexOf("."))+".txt");
if(zipFile.exists()){
zipFile.delete();
}
out = new FileOutputStream(zipFile);
br = new BufferedReader(new FileReader(srcFile));
//加密文件的第一行为AES密钥经过RSA加密后的报文
String aes_key_encrypt = br.readLine();
if(aes_key_encrypt==null || aes_key_encrypt.equals("")){
response.setSuccess(false);
response.setErrorMessage("待解密解压的文件内容不符合规范");
return response;
}
BHRSAUtils.init(null, rsa_private_key);
//AES密钥明文
String aes_key_str = new String(BHRSAUtils.decryptData(Base64.base64ToByteArray(aes_key_encrypt)));
String str = br.readLine();
while(str!=null){
out.write(BHAESUtil.decryptData(aes_key_str, Base64.base64ToByteArray(str)));
str = br.readLine();
}
out.flush();
out.close();
FileUploadResponse fileUploadResponse = BHZipUtil.unzipFile(zipFile,req.getTargetFilePath());
response.setSuccess(fileUploadResponse.isSuccess());
response.setErrorMessage(fileUploadResponse.getErrorMessage());
}catch (Exception e) {
response.setSuccess(false);
response.setErrorMessage(e.getMessage());
e.printStackTrace();
} finally {
try {
if (out != null)
out.close();
if (br != null)
br.close();
if(zipFile.exists()){
zipFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
}
package cn.quantgroup.report.service.baihang.client;
import cn.quantgroup.report.service.baihang.response.InterfaceUploadValidationResponse;
import cn.quantgroup.report.service.baihang.util.BHRSAUtils;
import cn.quantgroup.report.service.baihang.request.InterfaceUploadRequest;
import cn.quantgroup.report.service.baihang.request.InterfaceUploadValidationRequest;
import cn.quantgroup.report.service.baihang.response.InterfaceUploadResponse;
import cn.quantgroup.report.service.baihang.util.Base64;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-03-27 16:50
*/
public class BhInterfaceCreditApiClient {
private static final String CHARSET = "UTF-8";
//RSA公钥
private static java.security.PublicKey rsa_public_key = null;
//RSA私钥
private static java.security.PrivateKey rsa_private_key = null;
//AES密钥
private static String aes_key = null;
/**
* 初始化
* @param rsa_public_key
* @param aes_key
*/
public void init(java.security.PublicKey rsa_public_key,String aes_key){
if(this.rsa_public_key == null){
this.rsa_public_key = rsa_public_key;
}
if(this.aes_key == null){
this.aes_key = aes_key;
}
}
/**
* 初始化
* @param rsa_public_key
*/
public void init(java.security.PublicKey rsa_public_key){
if(this.rsa_public_key == null){
this.rsa_public_key = rsa_public_key;
}
}
/**
* 初始化
* @param rsa_private_key
*/
public void init(java.security.PrivateKey rsa_private_key){
if(this.rsa_private_key == null){
this.rsa_private_key = rsa_private_key;
}
}
/**
* 接口数据加密
* @param req
* @return
*/
public InterfaceUploadResponse execute(InterfaceUploadRequest req){
InterfaceUploadResponse response = new InterfaceUploadResponse();
try{
BHRSAUtils.init(rsa_public_key, null);
List<String> datas = req.getData();
for(int i=0;i<datas.size();i++){
byte[] bytes = BHRSAUtils.encryptData(datas.get(i).getBytes(CHARSET));
response.addEncryptData(Base64.byteArrayToBase64(bytes));
}
}catch(Exception e){
response.setSuccess(false);
response.setErrorMessage(e.getMessage());
e.printStackTrace();
}
return response;
}
/**
* 接口数据解密
* @param req
* @return
*/
public InterfaceUploadValidationResponse execute(InterfaceUploadValidationRequest req){
InterfaceUploadValidationResponse response = new InterfaceUploadValidationResponse();
try{
BHRSAUtils.init(null, rsa_private_key);
List<String> datas = req.getData();
for(int i=0;i<datas.size();i++){
byte[] bytes = BHRSAUtils.decryptData(Base64.base64ToByteArray(datas.get(i)));
response.addDecryptData(new String(bytes,CHARSET));
}
}catch(Exception e){
response.setSuccess(false);
response.setErrorMessage(e.getMessage());
e.printStackTrace();
}
return response;
}
}
package cn.quantgroup.report.service.baihang.constant;
public class Constant {
/** 量化派助贷模式-(贷款申请/放款/还款(逾期)三类实时数据)-To百行报送 */
public static final String QG_ZHU_DAI_REPORT_LOCK_KEY = "QG_ZHU_DAI_REPORT_LOCK_KEY";
public static final String XYQB_HISTORY_DAI_REPORT_LOCK_KEY = "XYQB_HISTORY_DAI_REPORT_LOCK_KEY";
}
package cn.quantgroup.report.service.baihang.request;
/**
* @Author fengjunkai
* @Date 2019-03-27 20:00
*/
public class FileUploadRequest {
/**
* 原始数据文件
*/
private String dataFile = "";
/**
* 密文文件输出路径
*/
private String targetFilePath = "";
public String getDataFile() {
return dataFile;
}
public void setDataFile(String dataFile) {
this.dataFile = dataFile;
}
public String getTargetFilePath() {
return targetFilePath;
}
public void setTargetFilePath(String targetFilePath) {
this.targetFilePath = targetFilePath;
}
}
package cn.quantgroup.report.service.baihang.request;
/**
* @Author fengjunkai
* @Date 2019-03-27 20:00
*/
public class FileUploadValidationRequest
{
/**
* 压缩加密数据文件
*/
private String dataFile = "";
/**
* 解密解压文件输出路径
*/
private String targetFilePath = "";
public String getDataFile() {
return dataFile;
}
public void setDataFile(String dataFile) {
this.dataFile = dataFile;
}
public String getTargetFilePath() {
return targetFilePath;
}
public void setTargetFilePath(String targetFilePath) {
this.targetFilePath = targetFilePath;
}
}
package cn.quantgroup.report.service.baihang.request;
import java.util.ArrayList;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-03-27 16:51
*/
public class InterfaceUploadRequest {
/*
* 待加密的数据集合
*/
private List<String> data = new ArrayList<String>();
public List<String> getData() {
return data;
}
public void setData(List<String> data) {
this.data = data;
}
public void addData(String str){
this.data.add(str);
}
}
package cn.quantgroup.report.service.baihang.request;
import java.util.ArrayList;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-03-27 16:55
*/
public class InterfaceUploadValidationRequest {
/*
* 待解密的数据集合
*/
private List<String> data = new ArrayList<String>();
public List<String> getData() {
return data;
}
public void setData(List<String> data) {
this.data = data;
}
public void addData(String str){
this.data.add(str);
}
}
package cn.quantgroup.report.service.baihang.response;
/**
* @Author fengjunkai
* @Date 2019-03-27 19:59
*/
public class FileUploadResponse {
/*
* 是否成功
*/
public boolean isSuccess = true;
/*
* 错误信息
*/
private String errorMessage = "";
/*
* 压缩加密后的文件路径
*/
private String encryptFilePath = "";
/*
* 压缩加密后的文件名
*/
private String encryptFileName = "";
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getEncryptFilePath() {
return encryptFilePath;
}
public void setEncryptFilePath(String encryptFilePath) {
this.encryptFilePath = encryptFilePath;
}
public String getEncryptFileName() {
return encryptFileName;
}
public void setEncryptFileName(String encryptFileName) {
this.encryptFileName = encryptFileName;
}
}
package cn.quantgroup.report.service.baihang.response;
/**
* @Author fengjunkai
* @Date 2019-03-27 20:00
*/
public class FileUploadValidationResponse {
/*
* 是否成功
*/
public boolean isSuccess = true;
/*
* 错误信息
*/
private String errorMessage = "";
/*
* 解密解压后的文件路径
*/
private String decryptFilePath = "";
/*
* 解密解压后的文件名
*/
private String decryptFileName = "";
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getDecryptFilePath() {
return decryptFilePath;
}
public void setDecryptFilePath(String decryptFilePath) {
this.decryptFilePath = decryptFilePath;
}
public String getDecryptFileName() {
return decryptFileName;
}
public void setDecryptFileName(String decryptFileName) {
this.decryptFileName = decryptFileName;
}
}
package cn.quantgroup.report.service.baihang.response;
import java.util.ArrayList;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-03-27 16:52
*/
public class InterfaceUploadResponse {
/*
* 是否成功
*/
public boolean isSuccess = true;
/*
* 错误信息
*/
private String errorMessage = "";
/*
* 加密后的数据集合
*/
private List<String> encryptData = new ArrayList<String>();
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public List<String> getEncryptData() {
return this.encryptData;
}
public void setEncryptData(List<String> encryptData) {
this.encryptData = encryptData;
}
public void addEncryptData(String str) {
this.encryptData.add(str);
}
}
package cn.quantgroup.report.service.baihang.response;
import java.util.ArrayList;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-03-27 16:58
*/
public class InterfaceUploadValidationResponse {
/*
* 是否成功
*/
public boolean isSuccess = true;
/*
* 错误信息
*/
private String errorMessage = "";
/*
* 解密后的数据集合
*/
private List<String> decryptData = new ArrayList<String>();
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public List<String> getDecryptData() {
return decryptData;
}
public void setDecryptData(List<String> decryptData) {
this.decryptData = decryptData;
}
public void addDecryptData(String str){
this.decryptData.add(str);
}
}
package cn.quantgroup.report.service.baihang.util;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
/**
* @Author fengjunkai
* @Date 2019-03-27 20:04
*/
public class BHAESUtil {
private static Cipher encryptCipher = null;
private static Cipher decryptCipher = null;
public static void initEncryptCipher(String aes_key) throws Exception {
if(encryptCipher == null){
//1.构造密钥生成器,指定为AES算法,不区分大小写
KeyGenerator kgen = KeyGenerator.getInstance("AES");//
//2.利用用户密码作为随机数初始化出
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG" );
secureRandom.setSeed(aes_key.getBytes());
kgen.init(128, secureRandom);
//3.产生原始对称密钥
SecretKey secretKey = kgen.generateKey();
//4.获得原始对称密钥的字节数组
byte[] enCodeFormat = secretKey.getEncoded();
//5.根据字节数组生成AES密钥
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
//6.根据指定算法AES自成密码器
encryptCipher = Cipher.getInstance("AES");
//7.初始化密码器
encryptCipher.init(Cipher.ENCRYPT_MODE, key);
}
}
public static void initDecryptCipher(String aes_key) throws Exception {
if(decryptCipher == null){
//1.构造密钥生成器,指定为AES算法,不区分大小写
KeyGenerator kgen = KeyGenerator.getInstance("AES");// 创建AES的Key生产者
//2.利用用户密码作为随机数初始化出
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG" );
secureRandom.setSeed(aes_key.getBytes());
kgen.init(128, secureRandom);
//3.产生原始对称密钥
SecretKey secretKey = kgen.generateKey();// 根据用户密码,生成一个密钥
//4.获得原始对称密钥的字节数组
byte[] enCodeFormat = secretKey.getEncoded();// 返回基本编码格式的密钥
//5.根据字节数组生成AES密钥
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");// 转换为AES专用密钥
//6.根据指定算法AES自成密码器
decryptCipher = Cipher.getInstance("AES");// 创建密码器
//7.初始化密码器
decryptCipher.init(Cipher.DECRYPT_MODE, key);// 初始化为解密模式的密码器
}
}
/**
* AES加密字符串
*
* @param content
* 需要被加密的字符串
* @return 密文
*/
public static synchronized byte[] encryptData(String aes_key,byte[] data) throws Exception{
initEncryptCipher(aes_key);
//获取加密内容的字节数组(这里要设置为utf-8)不然内容中如果有中文和英文混合中文就会解密为乱码
//byte[] byteContent = content.getBytes("utf-8");
//加密:将数据加密
byte[] result = encryptCipher.doFinal(data);
return result;
}
/**
* 解密AES加密过的字符串
*
* @param content
* AES加密过过的内容
* @return 明文
*/
public static synchronized byte[] decryptData(String aes_key,byte[] data) throws Exception{
initDecryptCipher(aes_key);
//解密:将数据解密
byte[] resultByte = decryptCipher.doFinal(data);
return resultByte; // 明文
}
}
package cn.quantgroup.report.service.baihang.util;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
/**
* 百行RSA加密工具
*
* @Author fengjunkai
* @Date 2019-03-27 15:17
*/
public class BHRSAUtils {
//加密算法
public static final String DEFAULT_ENCRYPT_ALGORITHM = "RSA";
//RSA公钥
private static java.security.PublicKey rsa_public_key = null;
//RSA私钥
private static java.security.PrivateKey rsa_private_key = null;
private static Cipher encryptCipher = null;
private static Cipher decryptCipher = null;
/**
* 加载RSAPrivateKey
* @param fileName
* @return
* @throws NoSuchAlgorithmException
* @throws IOException
* @throws InvalidKeySpecException
*/
public static PrivateKey readRSAPrivateKey(String fileName) throws NoSuchAlgorithmException, IOException,
InvalidKeySpecException {
InputStream isr = BHRSAUtils.class.getResourceAsStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(isr));
StringBuilder builder = new StringBuilder();
boolean inKey = false;
for (String line = br.readLine(); line != null; line = br.readLine()) {
line = line.trim();
if (!inKey) {
if (line.startsWith("-----BEGIN ") && line.endsWith(" PRIVATE KEY-----")) {
inKey = true;
}
continue;
} else {
if (line.startsWith("-----END ") && line.endsWith(" PRIVATE KEY-----")) {
inKey = false;
break;
}
builder.append(line);
}
}
br.close();
isr.close();
byte[] keyBytes = Base64.base64ToByteArray((builder.toString()));
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey key = kf.generatePrivate(spec);
return key;
}
/**
* 加载RSAPublicKey
* @param fileName
* @return
* @throws NoSuchAlgorithmException
* @throws IOException
* @throws InvalidKeySpecException
*/
public static PublicKey readRSAPublicKey(String fileName)
throws NoSuchAlgorithmException, IOException,
InvalidKeySpecException {
InputStream isr = BHRSAUtils.class.getResourceAsStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(isr));
StringBuilder builder = new StringBuilder();
boolean inKey = false;
for (String line = br.readLine(); line != null; line = br.readLine()) {
line = line.trim();
if (!inKey) {
if (line.startsWith("-----BEGIN ") && line.endsWith(" PUBLIC KEY-----")) {
inKey = true;
}
continue;
} else {
if (line.startsWith("-----END ") && line.endsWith(" PUBLIC KEY-----")) {
inKey = false;
break;
}
builder.append(line);
}
}
br.close();
isr.close();
byte[] keyBytes = Base64.base64ToByteArray((builder.toString()));
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
PublicKey key = kf.generatePublic(spec);
return key;
}
/**
* 初始化
* @param publicKey
* @param privateKey
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
* @throws InvalidKeyException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
*/
public static void init(java.security.PublicKey publicKey,java.security.PrivateKey privateKey) throws NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
if(rsa_public_key == null && publicKey != null){
rsa_public_key = publicKey;
encryptCipher = Cipher.getInstance(DEFAULT_ENCRYPT_ALGORITHM);
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
}
if(rsa_private_key == null && privateKey != null){
rsa_private_key = privateKey;
decryptCipher = Cipher.getInstance(DEFAULT_ENCRYPT_ALGORITHM);
decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
}
}
/**
* 加密数据
* @param dataToEncrypt
* @return
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
* @throws InvalidKeyException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
*/
public static synchronized byte[] encryptData(byte[] dataToEncrypt) throws NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
return encryptCipher.doFinal(dataToEncrypt);
}
/**
* 解密数据
* @param data
* @return
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
* @throws InvalidKeyException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
*/
public static synchronized byte[] decryptData(byte[] data) throws NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
return decryptCipher.doFinal(data);
}
}
package cn.quantgroup.report.service.baihang.util;
import cn.quantgroup.report.service.baihang.response.FileUploadResponse;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet;
import java.io.File;
/**
* @Author fengjunkai
* @Date 2019-03-27 20:01
*/
public class BHZipUtil {
/**
* 编码格式
*/
public final static String encoding = "UTF-8";
/**
* 压缩文件
* @param srcfile(待压缩文件,必须是后缀为txt的文件,不能是文件夹)
* @param targetFile(压缩后的文件,必须是后缀为zip的文件,不能是文件夹)
* @return
*/
public static FileUploadResponse zipFile(File srcFile,File targetFile) {
FileUploadResponse response = new FileUploadResponse();
if(srcFile==null || targetFile==null){
response.setSuccess(false);
response.setErrorMessage("待压缩文件或压缩后的文件不能为空!");
return response;
}
if(!srcFile.exists() || srcFile.isDirectory()){
response.setSuccess(false);
response.setErrorMessage("待压缩文件不存在或不能是文件夹!");
return response;
}
if(!srcFile.getName().endsWith(".txt") || !targetFile.getName().endsWith(".zip")){
response.setSuccess(false);
response.setErrorMessage("待压缩文件后缀必须为txt,压缩后的文件后缀必须为zip!");
return response;
}
if(targetFile.exists()){
targetFile.delete();
}
Project proj = new Project();
FileSet fileSet = new FileSet();
fileSet.setProject(proj);
fileSet.setFile(srcFile);
Zip zip = new Zip();
zip.setProject(proj);
zip.setDestFile(targetFile);
zip.addFileset(fileSet);
zip.setEncoding(encoding);
zip.execute();
return response;
}
/**
* 解压文件
* @param zipfile(压缩文件,必须是后缀为zip的文件,不能是文件夹)
* @param unzipFilePath(解压后文件的相对路径)
* @return
*/
public static FileUploadResponse unzipFile(File zipFile, String unzipFilePath) {
FileUploadResponse response = new FileUploadResponse();
if(!zipFile.exists()){
response.setSuccess(false);
response.setErrorMessage("压缩文件不存在!");
return response;
}
if(!zipFile.getName().endsWith(".zip")){
response.setSuccess(false);
response.setErrorMessage("压缩文件后缀必须为zip");
return response;
}
Project proj = new Project();
Expand expand = new Expand();
expand.setProject(proj);
expand.setTaskType("unzip");
expand.setTaskName("unzip");
expand.setEncoding(encoding);
expand.setSrc(zipFile);
expand.setDest(new File(unzipFilePath));
expand.execute();
return response;
}
}
package cn.quantgroup.report.service.baihang.util;
/**
* @Author fengjunkai
* @Date 2019-03-27 15:19
*/
public class Base64 {
/**
* Translates the specified byte array into a Base64 string as per
* Preferences.put(byte[]).
*/
public static String byteArrayToBase64(byte[] a){
return byteArrayToBase64(a, false);
}
/**
* Translates the specified byte array into an "aternate representation"
* Base64 string. This non-standard variant uses an alphabet that does not
* contain the uppercase alphabetic characters, which makes it suitable for
* use in situations where case-folding occurs.
*/
public static String byteArrayToAltBase64(byte[] a){
return byteArrayToBase64(a, true);
}
private static String byteArrayToBase64(byte[] a, boolean alternate){
int aLen = a.length;
int numFullGroups = aLen / 3;
int numBytesInPartialGroup = aLen - 3 * numFullGroups;
int resultLen = 4 * ((aLen + 2) / 3);
StringBuffer result = new StringBuffer(resultLen);
char[] intToAlpha = (alternate ? intToAltBase64 : intToBase64);
// Translate all full groups from byte array elements to Base64
int inCursor = 0;
for(int i = 0; i < numFullGroups; i++){
int byte0 = a[inCursor++] & 0xff;
int byte1 = a[inCursor++] & 0xff;
int byte2 = a[inCursor++] & 0xff;
result.append(intToAlpha[byte0 >> 2]);
result.append(intToAlpha[(byte0 << 4) & 0x3f | (byte1 >> 4)]);
result.append(intToAlpha[(byte1 << 2) & 0x3f | (byte2 >> 6)]);
result.append(intToAlpha[byte2 & 0x3f]);
}
// Translate partial group if present
if(numBytesInPartialGroup != 0){
int byte0 = a[inCursor++] & 0xff;
result.append(intToAlpha[byte0 >> 2]);
if(numBytesInPartialGroup == 1){
result.append(intToAlpha[(byte0 << 4) & 0x3f]);
result.append("==");
}else{
// assert numBytesInPartialGroup == 2;
int byte1 = a[inCursor++] & 0xff;
result.append(intToAlpha[(byte0 << 4) & 0x3f | (byte1 >> 4)]);
result.append(intToAlpha[(byte1 << 2) & 0x3f]);
result.append('=');
}
}
// assert inCursor == a.length;
// assert result.length() == resultLen;
return result.toString();
}
/**
* This array is a lookup table that translates 6-bit positive integer index
* values into their "Base64 Alphabet" equivalents as specified in Table 1
* of RFC 2045.
*/
private static final char intToBase64[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
/**
* This array is a lookup table that translates 6-bit positive integer index
* values into their "Alternate Base64 Alphabet" equivalents. This is NOT
* the real Base64 Alphabet as per in Table 1 of RFC 2045. This alternate
* alphabet does not use the capital letters. It is designed for use in
* environments where "case folding" occurs.
*/
private static final char intToAltBase64[] = {'!', '"', '#', '$', '%', '&', '\'', '(', ')', ',', '-',
'.', ':', ';', '<', '>', '@', '[', ']', '^', '`', '_', '{', '|', '}', '~', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '?'};
/**
* Translates the specified Base64 string (as per Preferences.get(byte[]))
* into a byte array.
*
* @throw IllegalArgumentException if <tt>s</tt> is not a valid Base64
* string.
*/
public static byte[] base64ToByteArray(String s){
return base64ToByteArray(s, false);
}
/**
* Translates the specified "aternate representation" Base64 string into a
* byte array.
*
* @throw IllegalArgumentException or ArrayOutOfBoundsException if
* <tt>s</tt> is not a valid alternate representation Base64 string.
*/
public static byte[] altBase64ToByteArray(String s){
return base64ToByteArray(s, true);
}
private static byte[] base64ToByteArray(String s, boolean alternate){
byte[] alphaToInt = (alternate ? altBase64ToInt : base64ToInt);
int sLen = s.length();
int numGroups = sLen / 4;
if(4 * numGroups != sLen)
throw new IllegalArgumentException("String length must be a multiple of four.");
int missingBytesInLastGroup = 0;
int numFullGroups = numGroups;
if(sLen != 0){
if(s.charAt(sLen - 1) == '='){
missingBytesInLastGroup++;
numFullGroups--;
}
if(s.charAt(sLen - 2) == '=')
missingBytesInLastGroup++;
}
byte[] result = new byte[3 * numGroups - missingBytesInLastGroup];
char[] a = s.toCharArray();
// Translate all full groups from base64 to byte array elements
int inCursor = 0, outCursor = 0;
for(int i = 0; i < numFullGroups; i++){
int ch0 = base64toInt(a[inCursor++], alphaToInt);
int ch1 = base64toInt(a[inCursor++], alphaToInt);
int ch2 = base64toInt(a[inCursor++], alphaToInt);
int ch3 = base64toInt(a[inCursor++], alphaToInt);
result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
result[outCursor++] = (byte) ((ch2 << 6) | ch3);
}
// Translate partial group, if present
if(missingBytesInLastGroup != 0){
int ch0 = base64toInt(a[inCursor++], alphaToInt);
int ch1 = base64toInt(a[inCursor++], alphaToInt);
result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
if(missingBytesInLastGroup == 1){
int ch2 = base64toInt(a[inCursor++], alphaToInt);
result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
}
}
// assert inCursor == s.length()-missingBytesInLastGroup;
// assert outCursor == result.length;
return result;
}
/**
* Translates the specified character, which is assumed to be in the
* "Base 64 Alphabet" into its equivalent 6-bit positive integer.
*
* @throw IllegalArgumentException or ArrayOutOfBoundsException if c is not
* in the Base64 Alphabet.
*/
private static int base64toInt(char c, byte[] alphaToInt){
int result = alphaToInt[c];
if(result < 0)
throw new IllegalArgumentException("Illegal character " + c);
return result;
}
/**
* This array is a lookup table that translates unicode characters drawn
* from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into
* their 6-bit positive integer equivalents. Characters that are not in the
* Base64 alphabet but fall within the bounds of the array are translated to
* -1.
*/
private static final byte base64ToInt[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1,
-1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51};
/**
* This array is the analogue of base64ToInt, but for the nonstandard
* variant that avoids the use of uppercase alphabetic characters.
*/
private static final byte altBase64ToInt[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7,
8, -1, 62, 9, 10, 11, -1, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 12, 13, 14, -1, 15, 63, 16, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 17, -1, 18, 19, 21, 20, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 22, 23, 24, 25};
}
package cn.quantgroup.report.service.baihang.util;
import cn.quantgroup.report.service.baihang.response.FileUploadResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TuoMinUtils {
private static char getRandomChar() {
String str = "";
int hightPos; //
int lowPos;
Random random = new Random();
hightPos = (176 + Math.abs(random.nextInt(39)));
lowPos = (161 + Math.abs(random.nextInt(93)));
byte[] b = new byte[2];
b[0] = (Integer.valueOf(hightPos)).byteValue();
b[1] = (Integer.valueOf(lowPos)).byteValue();
try {
str = new String(b, "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("错误");
}
return str.charAt(0);
}
private static String getRandomNum(int length) {
StringBuffer buff = new StringBuffer();
Random random = new Random();
for (int i=0;i<length;i++){
// 返回一个0~(指定数-1)之间的随机值
int ran = random.nextInt(10);
buff.append(ran);
}
return buff.toString();
}
public static String random_name(String name) {
/*姓名脱敏
保证为汉字,如张三丰脱敏为张无忌、张艺兴,均符合要求。
避免使用张某、赵某等,容易出现编码校验失败问题。*/
return name.substring(0,1)+getRandomChar()+getRandomChar();
}
public static String random_idcard(String idcard) {
/*身份证脱敏
需满足以下条件:
1.身份证前两位数字(即省份代码)需为以下34个数字之一:11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82
2.身份证中的年月日需为现实中存在的日期
如360822198305022623脱敏:*/
return idcard.substring(0,2) + getRandomNum(4) + idcard.substring(6,14) + getRandomNum(4);
}
public static String random_mobile(String mobile) {
return mobile.substring(0,3) + getRandomNum(4) + mobile.substring(7,11);
}
public static boolean checkEmail(String email) {
//电子邮件
if(StringUtils.isBlank(email)){
return false;
}
String regex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9]+(-[a-z0-9]+)?\\.)+[a-z]{2,}$";
//"^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"
//"^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"
//"^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"
boolean b1 = Pattern.compile(regex).matcher(email).matches(); //email.matches(email);
String ends = "";
if(email.contains("@")){
ends = email.substring(email.lastIndexOf("@"), email.length());
}
boolean b2 = Pattern.compile("\\s+").matcher(ends).find();;
String regex2 =".*[A-Z]+.*"; //"[A-Z]*"
boolean b3 = Pattern.compile(regex2).matcher(ends).matches();
return b1 && !b2 && !b3;
}
//判断Email合法性
public static boolean isEmail(String email) {
if (email == null)
return false;
String rule = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
Pattern pattern = Pattern.compile(rule);
Matcher matcher = pattern.matcher(email);
if (matcher.matches())
return true;
else
return false;
}
public static void main(String[] args) {
//System.out.println(random_name("郝彦辉"));
// System.out.println(random_idcard("622726198911100236"));
// System.out.println(random_mobile("18010105506"));
/* String readAddr = "E:\\桌面_工作\\数据备份\\201911061315贷款申请关联用户.json";
String writeAddr = "E:\\桌面_工作\\数据备份\\201911061315用户脱敏.txt";
try {
long log_stUtc = System.currentTimeMillis();
String sourceStr = FileUtils.readFileToString(new File(readAddr), "utf-8");
JSONObject sourceJson = JSON.parseObject(sourceStr);
JSONArray recordsJsonArr = sourceJson.getJSONArray("RECORDS");
System.out.println("总条数:"+recordsJsonArr.size());
for (int i = 0; i < recordsJsonArr.size(); i++) {
System.out.println("第:"+i);
JSONObject jsonObj = recordsJsonArr.getJSONObject(i);
try {
String name = jsonObj.getString("name");
String pid = jsonObj.getString("pid");
String mobile = jsonObj.getString("mobile");
StringBuffer out = new StringBuffer();
out.append(pid);
out.append("=");
out.append(random_idcard(pid));
out.append(",");
out.append(random_mobile(mobile));
out.append(",");
out.append(random_name(name));
out.append("\n");
FileUtils.write(new File(writeAddr), out , "utf-8", true);
}catch (Exception e){
System.err.println("Error 第:"+i+",pid="+jsonObj.getString("pid"));
}
}
System.out.println("脱敏结束, 耗时: "+((System.currentTimeMillis()-log_stUtc)/1000)+".s");
} catch (IOException e) {
e.printStackTrace();
}
*/
String email = "630226318@QQ.COM";
//String email = "294603191@qq.c0m";
//String email = "139@139.com13902502392";
//System.out.println(checkEmail(email));
//System.out.println(isEmail(email));
System.out.println(checkEmail("630226318@qq.com"));
System.out.println(checkEmail("630226318@QQ.C OM"));
System.out.println(checkEmail("630226318@QQ.COM"));
System.out.println(checkEmail("139@139.com13902502392"));
System.out.println(checkEmail("294603191@qq.c0m"));
}
}
package cn.quantgroup.report.service.cache;
/**
* Created by Alan on 2018/5/29.
*/
public interface CacheService {
void clearLock(String lockName);
void clearCache(String configName);
}
package cn.quantgroup.report.service.cache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
/**
* Created by Alan on 2018/5/29.
*/
@Service
@Slf4j
public class CacheServiceImpl implements CacheService{
@Autowired
private RedisTemplate redisTemplate;
@Override
public void clearLock(String lockName) {
RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
connection.del(lockName.getBytes());
connection.close();
}
@Override
public void clearCache(String configName) {
redisTemplate.delete(configName);
}
}
package cn.quantgroup.report.service.common;
import cn.quantgroup.report.ApplicationContextHolder;
import cn.quantgroup.report.constant.TransactionCodeEnum;
import cn.quantgroup.report.response.GlobalResponse;
import cn.quantgroup.report.service.CommonSuperService;
import cn.quantgroup.report.service.common.model.CommonParams;
import cn.quantgroup.report.utils.IdUtils;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
/**
* Created by fengjunkai on 2018/8/31 0031 上午 11:51
**/
@Slf4j
@Service
public class CommonQueryService implements CommonSuperService {
private ThreadPoolExecutor TASK_POOL = new ThreadPoolExecutor(50, 1000, 200L, TimeUnit.MILLISECONDS, new SynchronousQueue<>());
@Deprecated
public Object commonQuery(String source_types, String inUuid, String name, String phone, String identity, String backDate, String business_type, String order_id, boolean isReadCache) {
log.info("三方数据源统一查询接口, 入参, inUuid: {} ,sourceType:{}, businessType:{} , orderId:{}, isReadCache: {} ", inUuid, source_types, business_type, order_id, isReadCache);
String transactionId = IdUtils.getUuid();
Map<String, Object> resultMap = new ConcurrentHashMap<>();
try {
if (StringUtils.isAnyBlank(source_types, inUuid) && StringUtils.isBlank(name) && StringUtils.isBlank(phone) && StringUtils.isBlank(identity)) {
return ImmutableMap.of("transactionId", transactionId, "code", 201, "message", "参数不能为空" + "sourceType:" + source_types);
}
CommonParams commonParams = null;
String uuid = "";
Map<String, String> mapping = new ConcurrentHashMap<>();
CountDownLatch countDownLatch = new CountDownLatch(mapping.size());
CommonParams params = commonParams;
mapping.forEach((methodName, serviceName) -> {
log.info("TASK_POOL ActiveCount : {} , Task Queue size : {} ", TASK_POOL.getActiveCount(), TASK_POOL.getQueue().size());
TASK_POOL.execute(() -> {
try {
String serviceNameO1 = serviceName.split(":")[0];
String keysO1 = serviceName.split(":")[1];
execute(transactionId, serviceNameO1, methodName, resultMap, params, keysO1, backDate, isReadCache);
} catch (Exception e) {
log.error("三方数据源统一查询接口, 异常, uuid: {} , sourceType:{}, keys:{}", uuid, serviceName.split(":")[0], serviceName.split(":")[1], e);
} finally {
countDownLatch.countDown();
}
});
});
countDownLatch.await(60, TimeUnit.SECONDS);
if (resultMap.size() > 0) {
return ImmutableMap.of("code", 200, "message", "查询成功", "data", resultMap);
} else {
return ImmutableMap.of("code", 500, "message", "查询异常", "data", resultMap);
}
} catch (Exception e) {
return ImmutableMap.of("code", 500, "message", "查询异常", "data", resultMap);
}
}
private void execute(String transactionId, String serviceName, String methodName, Map<String, Object> resultMap, CommonParams userFullInfo, String keys, String backDate, boolean isReadCache) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
String uuid = userFullInfo.getUuid();
CommonSuperService superService = ApplicationContextHolder.getBean(serviceName);
Object resultObject = superService.getClass().getMethod(methodName, String.class, String.class, String.class, String.class, String.class, boolean.class)
.invoke(superService, transactionId, userFullInfo.getIdNo(), userFullInfo.getPhoneNo(), userFullInfo.getName(), uuid, isReadCache);
GlobalResponse globalResponse = (GlobalResponse) resultObject;
Object object = globalResponse.getBody();
boolean flag = globalResponse.getTransactionResult().stream().filter(o -> (o != null) && TransactionCodeEnum.Fail.equals(o.getTansactionCode())).count() > 0;
if (object != null) {
JSONObject jsonObject = (JSONObject) object;
Integer riskScore = jsonObject.getIntValue("riskScore");
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("value", riskScore);
bodyMap.put("state", 200);
resultMap.put("tencent_risk_ riskScore", bodyMap);
} else {
/* if (flag && !isReadCache) {
putErrorBodyByserviceName(uuid, resultMap, serviceName, methodName);
} else if (flag && isReadCache) {
putTestErrorBody(resultMap, serviceName);
} else {
put400Body(resultMap, serviceName);
}*/
}
}
}
\ No newline at end of file
package cn.quantgroup.report.service.common.model;
import cn.quantgroup.report.domain.sdk.SdkUser;
public class CommonParams {
private SdkUser sdkUser;
public CommonParams(){}
public CommonParams(SdkUser sdkUser) {
this.sdkUser = sdkUser;
}
private String idNo;
private String name;
private String phoneNo;
private String uuid;
private String bankCard;
/**phoneNo md5加密 2019.10.10*/
private String phoneNoMd5;
/**idNo md5加密 2019.10.10*/
private String idNoMd5;
public SdkUser getSdkUser() {
return sdkUser;
}
public void setSdkUser(SdkUser sdkUser) {
this.sdkUser = sdkUser;
}
public String getIdNo() {
if(idNo == null) {
return sdkUser.getIdNo();
}
return idNo;
}
public void setIdNo(String idNo) {
this.idNo = idNo;
}
public String getName() {
if(name == null) {
return sdkUser.getName();
}
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNo() {
if(phoneNo == null) {
return sdkUser.getPhoneNo();
}
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getUuid() {
if(uuid == null) {
return sdkUser.getUuid();
}
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getBankCard() {
return bankCard;
}
public void setBankCard(String bankCard) {
this.bankCard = bankCard;
}
//add by 2019.10.10 增加md5加密字段
public String getPhoneNoMd5() {
if(phoneNoMd5 == null) {
return sdkUser.getPhoneNoMd5();
}
return phoneNoMd5;
}
public void setPhoneNoMd5(String phoneNoMd5) {
this.phoneNoMd5 = phoneNoMd5;
}
public String getIdNoMd5() {
if(idNoMd5 == null) {
return sdkUser.getIdNoMd5();
}
return idNoMd5;
}
public void setIdNoMd5(String idNoMd5) {
this.idNoMd5 = idNoMd5;
}
}
package cn.quantgroup.report.service.http;
import java.util.Map;
/**
* @author guowei.wei
* @time 2018-05-30 10:11
*/
public interface IHttpService {
/**
* Http Get
*
* @param uri
* @return
*/
String get(String uri);
Map<String,String> getMap(String uri,String interfaceType, Object... args);
String get(String uri, int timeOut);
<T> T get(String uri, Class<T> classOfT);
/**
* Http Get
*
* @param uri
* @param parameters
* @return
*/
String get(String uri, Map<String, String> parameters);
/**
* Http Get
*
* @param uri
* @param headers
* @param parameters
* @return
*/
String get(String uri, Map<String, String> headers, Map<String, String> parameters);
/**
* Http GetMap
* @param uri
* @param headers
* @param parameters
* @param interfaceType
* @return
*/
Map<String,String> getMap(String uri, Map<String, String> headers, Map<String, String> parameters,String interfaceType, Object... args);
/**
* Http Post
*
* @param uri
* @return
*/
String post(String uri);
/**
* Http Post
*
* @param uri
* @param parameters
* @return
*/
String post(String uri, Map<String, String> parameters);
/**
* Http Post
*
* @param uri
* @param headers
* @param parameters
* @return
*/
String post(String uri, Map<String, String> headers, Map<String, String> parameters);
public String post(String uri, Map<String, String> parameters, boolean isLog);
public String postCommon(String uri, Map<String, String> headers, String jsonParams, Map<String, String> responseHeaders, String interfaceType) ;
public Map<String,String> postJsonMap(String uri, Map<String, String> headers, String jsonParams,Map<String, String> responseHeaders,String interfaceType, Object... args) ;
public String postObj(String uri, Map<String, Object> parameters);
public String postObj(String uri, Map<String, String> headers, Map<String, Object> parameters) ;
/**
* 不需要返回结果的请求
* @param url
* @param parameters
* @return
*/
public int postNoResponse(String url, Map<String, String> parameters);
public void exceptionAlarm(String interfaceType,String uri,String exception, Object... args);
public void timeOutAndCodeAlarm(long startTime,long endTime,String interfaceType,String uri,String statusCode,String reason, Object... args);
public void alarm(long startTime,long endTime,String interfaceType,String uri,String statusCode,String reason, Object... args);
String postCommon(String uri, Map<String, String> headers, String json);
String postCommonAllResult(String uri, Map<String, String> headers, String json);
String postCommonAllResultSoap(String uri, Map<String, String> headers, String json);
String postBaiHang(String uri, Map<String, String> headers, String json);
}
package cn.quantgroup.report.service.http.impl;
import cn.quantgroup.report.cmpt.CommonAlarmCmpt;
import cn.quantgroup.report.error.QGException;
import cn.quantgroup.report.error.QGExceptionType;
import cn.quantgroup.report.service.http.IHttpService;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Predicates;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
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.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.*;
/**
* @author guowei.wei
* @time 2018-05-30 10:11
*/
@Service
public class HttpServiceImpl implements IHttpService {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpServiceImpl.class);
private static final int TIME_OUT_60 = 60 * 1000;
private static final int TIME_OUT_20 = 20 * 1000;
private static final int TIME_OUT_15 = 15 * 1000;
public static final String responseContentKey = "responseContentKey";
public static final String statusCodeKey = "statusCodeKey";
public static final String consumeTimeKey = "consumeTimeKey";
@Autowired
@Qualifier("httpClient")
private CloseableHttpClient httpClient;
@Autowired
private CommonAlarmCmpt commonAlarmCmpt;
@Override
public String get(String uri) {
return get(uri, null, null);
}
@Override
public Map<String,String> getMap(String uri,String interfaceType, Object... args) {
return getMap(uri, null, null,interfaceType,args);
}
@Override
public String get(String uri,int timeOut) {
return doHttp(RequestBuilder.get(), uri, null, null,true,timeOut);
}
@Override
public <T> T get(String uri, Class<T> classOfT) {
String s = get(uri, null, null);
return new Gson().fromJson(s,classOfT);
}
@Override
public String get(String uri, Map<String, String> parameters) {
return get(uri, null, parameters);
}
@Override
public String get(String uri, Map<String, String> headers, Map<String, String> parameters) {
return doHttp(RequestBuilder.get(), uri, headers, parameters,true,TIME_OUT_20);
}
@Override
public Map<String,String> getMap(String uri, Map<String, String> headers, Map<String, String> parameters,String interfaceType, Object... args) {
return doHttpMap(RequestBuilder.get(), uri, headers, parameters,false,TIME_OUT_20,interfaceType,args);
}
@Override
public String post(String uri) {
return post(uri, null, null);
}
@Override
public String post(String uri, Map<String, String> parameters) {
return post(uri, null, parameters);
}
@Override
public String post(String uri, Map<String, String> parameters,boolean isLog) {
return doHttp(RequestBuilder.post(), uri, null, parameters,isLog,TIME_OUT_20);
}
@Override
public String post(String uri, Map<String, String> headers, Map<String, String> parameters) {
return doHttp(RequestBuilder.post(), uri, headers, parameters,true,TIME_OUT_20);
}
@Override
public String postCommon(String uri, Map<String, String> headers, String jsonParams, Map<String, String> responseHeaders, String interfaceType) {
return doJsonHttp(RequestBuilder.post(),uri,headers,jsonParams,responseHeaders,interfaceType);
}
@Override
public Map<String,String> postJsonMap(String uri, Map<String, String> headers, String jsonParams,Map<String, String> responseHeaders,String interfaceType, Object... args) {
return doJsonHttpMap(RequestBuilder.post(),uri,headers,jsonParams,responseHeaders,interfaceType,args);
}
@Override
public String postObj(String uri, Map<String, Object> parameters) {
return postObj(uri, null, parameters);
}
@Override
public String postObj(String uri, Map<String, String> headers, Map<String, Object> parameters) {
return doObjectHttp(RequestBuilder.post(),uri,headers,parameters);
}
@Override
public int postNoResponse(String url, Map<String, String> parameters){
return doHttpNoResponse(RequestBuilder.post(),url,null,parameters);
}
private int doHttpNoResponse(RequestBuilder requestBuilder,String uri, Map<String, String> headers, Map<String, String> parameters){
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,TIME_OUT_15);
this.setHeader(requestBuilder, headers);
this.setParameter(requestBuilder, parameters);
httpResponse = httpClient.execute(requestBuilder.build());
int statusCode = httpResponse.getStatusLine().getStatusCode();
if(statusCode==200){
httpEntity = httpResponse.getEntity();
}else{
LOGGER.info("HTTP请求失败, uri:{},parameters:{},响应码:{}", uri,parameters,statusCode);
}
return statusCode;
} catch (Exception e) {
LOGGER.error("HTTP请求异常, uri:{},parameters:{}", uri,parameters, e);
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
return 808;
}
/**
* Send Http
*
* @param requestBuilder
* @param uri
* @param headers
* @param parameters
* @return
*/
public String doHttp(RequestBuilder requestBuilder, String uri, Map<String, String> headers, Map<String, String> parameters,boolean isLog,int timeOut) {
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,timeOut);
this.setHeader(requestBuilder, headers);
this.setParameter(requestBuilder, parameters);
long startTime = System.currentTimeMillis();
httpResponse = httpClient.execute(requestBuilder.build());
long endTime = System.currentTimeMillis();
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
try{
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
}catch (Exception e){}
if(isLog)
LOGGER.info("{}, uri:{},parameters:{},response:{},statusCode:{}", method, uri, parameters,response,statusCode);
return response;
} catch (Exception e) {
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, parameters, e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url: "+uri);
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
public String postCommon(RequestBuilder requestBuilder, String uri, Map<String, String> headers, String parameters, boolean isLog, int timeOut) {
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,timeOut);
this.setHeader(requestBuilder, headers);
this.setParameter(requestBuilder, parameters);
httpResponse = httpClient.execute(requestBuilder.build());
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
}
if(isLog)
LOGGER.info("{}, uri:{},parameters:{},response:{},statusCode:{}", method, uri, parameters,response,statusCode);
return response;
} catch (Exception e) {
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, parameters, e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url: "+uri);
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
public String postCommonAllResult(RequestBuilder requestBuilder, String uri, Map<String, String> headers, String parameters, boolean isLog, int timeOut) {
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,timeOut);
this.setHeader(requestBuilder, headers);
this.setParameter(requestBuilder, parameters);
httpResponse = httpClient.execute(requestBuilder.build());
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
// if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
// }
if(isLog)
LOGGER.info("{}, uri:{},parameters:{},response:{},statusCode:{}", method, uri, parameters,response,statusCode);
return response;
} catch (Exception e) {
LOGGER.error("第三方API请求异常 {}, uri:{}, parameters:{}", method, uri, parameters, e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url: "+uri);
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
public String postCommonAllResultSoap(RequestBuilder requestBuilder, String uri, Map<String, String> headers, String parameters, boolean isLog, int timeOut) {
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,timeOut);
this.setHeader(requestBuilder, headers);
this.setParameter(requestBuilder, parameters);
httpResponse = httpClient.execute(requestBuilder.build());
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
// if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
// }
if(isLog)
LOGGER.info("{}, uri:{},parameters:{},response:{},statusCode:{}", method, uri, parameters,response,statusCode);
return response;
} catch (Exception e) {
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, parameters, e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url: "+uri);
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
/**
* Send Http
*
* @param requestBuilder
* @param uri
* @param headers
* @param parameters
* @return
*/
public Map<String,String> doHttpMap(RequestBuilder requestBuilder, String uri, Map<String, String> headers, Map<String, String> parameters,boolean isLog,int timeOut,String interfaceType, Object... args) {
Map<String,String> map = new LinkedHashMap<>();
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,timeOut);
this.setParameter(requestBuilder, parameters);
this.setHeader(requestBuilder, headers);
long startTime = System.currentTimeMillis();
httpResponse = httpClient.execute(requestBuilder.build());
long endTime = System.currentTimeMillis();
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
String params = "";
if(args.length > 0){
params = ";参数:"+Arrays.toString(args);
}
if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
} else {
//状态码不为200,报警
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常", ";地址:"+uri+";状态码:"+statusCode+params);
}
long consumeTime = endTime - startTime;
//超过10秒,报警
if(consumeTime >TIME_OUT_15){
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求耗时"+consumeTime/1000+"秒", ";地址:"+uri+";状态码:"+statusCode+params);
}
map.put(statusCodeKey,statusCode+"");
map.put(responseContentKey,response);
map.put(consumeTimeKey,(endTime-startTime)+"");
// if(isLog)
// LOGGER.info("{}, uri:{},parameters:{},response:{},statusCode:{}", method, uri, parameters,response,statusCode);
return map;
} catch (Exception e) {
if(parameters == null || parameters.size() == 0){
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常", ";地址:"+uri+";异常信息:"+e.getMessage()+";参数:"+ Arrays.toString(args));
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, Arrays.toString(args), e);
} else {
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常", ";地址:"+uri+";异常信息:"+e.getMessage()+";参数:"+ JSONObject.toJSONString(parameters));
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, parameters, e);
}
return null;
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
/**
* Send Http
*
* @param requestBuilder
* @param uri
* @param headers
* @param parameters
* @return
*/
public String doObjectHttp(RequestBuilder requestBuilder, String uri, Map<String, String> headers, Map<String, Object> parameters) {
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,TIME_OUT_20);
this.setHeader(requestBuilder, headers);
this.setParameter2(requestBuilder, parameters);
httpResponse = httpClient.execute(requestBuilder.build());
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
}
LOGGER.info("{}, uri:{}, parameters:{},response:{}", method, uri, parameters,response);
return response;
} catch (Exception e) {
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, parameters, e);
return null;
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
/**
* Send Http
*
* @param requestBuilder
* @param uri
* @param headers
* @param jsonParams
* @return
*/
public String doJsonHttp(RequestBuilder requestBuilder, String uri, Map<String, String> headers, String jsonParams,Map<String, String> responseHeaders,String interfaceType) {
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,TIME_OUT_20);
this.setParameter(requestBuilder, jsonParams);
this.setHeader(requestBuilder, headers);
if(responseHeaders != null && responseHeaders.size() > 0){
for(Map.Entry<String,String> resHea : responseHeaders.entrySet()){
httpResponse.setHeader(resHea.getKey(),resHea.getValue());
}
}
long startTime = System.currentTimeMillis();
httpResponse = httpClient.execute(requestBuilder.build());
long endTime = System.currentTimeMillis();
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, CharEncoding.UTF_8);
} else {
response = statusCode+"";
}
return response;
} catch (Exception e) {
LOGGER.error("{}, uri:{}, ", method, uri, e);
return null;
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
/**
* Send Http
*
* @param requestBuilder
* @param uri
* @param headers
* @param jsonParams
* @return
*/
public Map<String,String> doJsonHttpMap(RequestBuilder requestBuilder, String uri, Map<String, String> headers, String jsonParams,Map<String, String> responseHeaders,String interfaceType,Object... args) {
Map<String,String> map = new LinkedHashMap<>();
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
String params = "";
if(args.length > 0){
params = ";参数:"+Arrays.toString(args);
}
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,TIME_OUT_20);
this.setParameter(requestBuilder, jsonParams);
this.setHeader(requestBuilder, headers);
// if(responseHeaders != null && responseHeaders.size() > 0){
// for(Map.Entry<String,String> resHea : responseHeaders.entrySet()){
// httpResponse.addHeader(resHea.getKey(),resHea.getValue());
// }
// }
long startTime = System.currentTimeMillis();
httpResponse = httpClient.execute(requestBuilder.build());
long endTime = System.currentTimeMillis();
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, CharEncoding.UTF_8);
} else {
//状态码不为200,报警
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常", ";地址:"+uri+";状态码:"+statusCode+params);
}
long consumeTime = endTime - startTime;
//超过10秒,报警
if(consumeTime >TIME_OUT_15){
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求耗时"+consumeTime/1000+"秒", ";地址:"+uri+";状态码:"+statusCode+params);
}
map.put(statusCodeKey,statusCode+"");
map.put(responseContentKey,response);
map.put(consumeTimeKey,(endTime-startTime)+"");
return map;
} catch (Exception e) {
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常", ";地址:"+uri+";异常信息:"+e.getMessage()+params);
LOGGER.error("{}, uri:{}, params:{}", method, uri,params, e);
return null;
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
/**
* Set Parameter
*
* @param requestBuilder
* @param parameters
*/
private void setParameter(RequestBuilder requestBuilder, Map<String, String> parameters) {
if (MapUtils.isNotEmpty(parameters)) {
parameters = Maps.filterValues(parameters, Predicates.notNull());
Set<Map.Entry<String, String>> entrys = parameters.entrySet();
/************** Get 请求 **************/
if (requestBuilder.getMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) {
for (Map.Entry<String, String> entry : entrys) {
requestBuilder.addParameter(entry.getKey(), entry.getValue());
}
}
/************** Post 请求 **************/
else {
List<NameValuePair> valuePairs = new ArrayList<>();
for (Map.Entry<String, String> entry : entrys) {
valuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
try {
requestBuilder.setEntity(new UrlEncodedFormEntity(valuePairs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
/**
* Set Parameter
*
* @param requestBuilder
* @param parameters Map<String, Object>
*/
private void setParameter2(RequestBuilder requestBuilder, Map<String, Object> parameters) {
if (MapUtils.isNotEmpty(parameters)) {
parameters = Maps.filterValues(parameters, Predicates.notNull());
Set<Map.Entry<String, Object>> entrys = parameters.entrySet();
/************** Get 请求 **************/
if (requestBuilder.getMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) {
for (Map.Entry<String, Object> entry : entrys) {
requestBuilder.addParameter(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
}
/************** Post 请求 **************/
else {
List<NameValuePair> valuePairs = new ArrayList<>();
for (Map.Entry<String, Object> entry : entrys) {
valuePairs.add(new BasicNameValuePair(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())));
}
try {
requestBuilder.setEntity(new UrlEncodedFormEntity(valuePairs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
/**
* Set Parameter
*
* @param requestBuilder
* @param jsonParams
*/
private void setParameter(RequestBuilder requestBuilder, String jsonParams) {
if (StringUtils.isNotEmpty(jsonParams)) {
StringEntity stringEntity = new StringEntity(jsonParams, CharEncoding.UTF_8);
stringEntity.setContentType("application/json; charset=utf-8");
requestBuilder.setEntity(stringEntity);
}
}
/**
* Set Header
*
* @param requestBuilder
* @param headers
*/
private void setHeader(RequestBuilder requestBuilder, Map<String, String> headers) {
requestBuilder.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36")
.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6")
.setHeader("Connection", "keep-alive");
if (MapUtils.isNotEmpty(headers)) {
headers = Maps.filterValues(headers, Predicates.notNull());
Set<Map.Entry<String, String>> entrys = headers.entrySet();
for (Map.Entry<String, String> entry : entrys) {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
}
}
/**
* Request config
*
* @return
*/
private void setConfig(RequestBuilder requestBuilder,int timeOut) {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeOut)
.setSocketTimeout(timeOut)
.setConnectionRequestTimeout(timeOut)
.build();
requestBuilder.setConfig(config);
}
@Override
public void exceptionAlarm(String interfaceType,String uri,String exception, Object... args) {
try {
if(StringUtils.isNotBlank(exception)){
String params = "";
if(args.length > 0){
params = ";参数:"+Arrays.toString(args);
}
String name = uri.startsWith("http") ? "地址:" : "接口:";
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常",name+uri+";异常原因:"+exception+params);
}
} catch (Exception e) {
LOGGER.error("报警异常, interfaceType:{},uri:{}",interfaceType, uri, e);
}
}
@Override
public void timeOutAndCodeAlarm(long startTime,long endTime,String interfaceType,String uri,String statusCode,String reason, Object... args) {
try {
String name = uri.startsWith("http") ? "地址:" : "接口:";
String params = "";
if(args.length > 0){
params = ";参数:"+Arrays.toString(args);
}
long consumeTime = endTime - startTime;
//超过10秒,报警
String statusC = StringUtils.isBlank(statusCode) ? "" : ";状态码:"+statusCode;
if(consumeTime >TIME_OUT_15){
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求耗时"+consumeTime/1000+"秒", name+uri+statusC+params);
}
if(StringUtils.isNotBlank(statusCode) && !"200".equals(statusCode)){
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求异常", name+uri+statusC+params);
}
if(StringUtils.isNotBlank(reason)){
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType+"请求失败", name+uri+";返回内容"+reason+params);
}
} catch (Exception e) {
LOGGER.error("报警异常, interfaceType:{},uri:{}",interfaceType, uri, e);
}
}
@Override
public void alarm(long startTime,long endTime,String interfaceType,String uri,String statusCode,String reason, Object... args) {
try {
String name = uri.startsWith("http") ? "地址:" : "接口:";
String params = "";
if(args.length > 0){
params = ";参数:"+Arrays.toString(args);
}
long consumeTime = endTime - startTime;
String statusC = StringUtils.isBlank(statusCode) ? "" : ";状态码:"+statusCode+",";
//请求异常
commonAlarmCmpt.alarm("Warn", "三方数据源"+interfaceType, name+uri+params+statusC+reason+";耗时:"+consumeTime/1000+"秒");
} catch (Exception e) {
LOGGER.error("报警异常, interfaceType:{},uri:{}",interfaceType, uri, e);
}
}
@Override
public String postCommon(String uri, Map<String, String> headers, String json) {
return postCommon(RequestBuilder.post(), uri, headers, json,true,TIME_OUT_20);
}
@Override
public String postCommonAllResult(String uri, Map<String, String> headers, String json) {
return postCommonAllResult(RequestBuilder.post(), uri, headers, json,true,TIME_OUT_60);
}
@Override
public String postCommonAllResultSoap(String uri, Map<String, String> headers, String json) {
return postCommonAllResultSoap(RequestBuilder.post(), uri, headers, json,true,TIME_OUT_20);
}
@Override
public String postBaiHang(String uri, Map<String, String> headers, String json) {
return postBaiHangComm(RequestBuilder.post(), uri, headers, json,true,TIME_OUT_20 );
}
public String postBaiHangComm(RequestBuilder requestBuilder, String uri, Map<String, String> headers, String parameters, boolean isLog, int timeOut){
String method = requestBuilder.getMethod();
HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null;
try {
requestBuilder.setUri(uri);
this.setConfig(requestBuilder,timeOut);
this.setHeader(requestBuilder, headers);
this.setParameter(requestBuilder, parameters);
httpResponse = httpClient.execute(requestBuilder.build());
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = null;
// if(statusCode==200){
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity, "UTF-8");
// }
if(isLog)
LOGGER.info("{}, uri:{},parameters:{},response:{},statusCode:{}", method, uri, parameters,response,statusCode);
return response;
} catch (Exception e) {
LOGGER.error("{}, uri:{}, parameters:{}", method, uri, parameters, e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url: "+uri);
} finally {
EntityUtils.consumeQuietly(httpEntity);
IOUtils.closeQuietly(httpResponse);
}
}
}
package cn.quantgroup.report.service.manualTool;
import cn.quantgroup.report.domain.master.CallRecord1;
import cn.quantgroup.report.domain.master.TransactionLogPO;
import cn.quantgroup.report.domain.tidbrisk.CallRecord3;
import cn.quantgroup.report.utils.JdbcUtils;
import cn.quantgroup.report.utils.ReadOrWriteTxt;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* -----------------------------------------------------------------------------<br>
* 描述: <br>
* 作者:yanhui.Hao <br>
* 时间:2019.12.31 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Slf4j
@Service
public class CleanningTransactionLogService {
@Autowired
private JdbcTemplate riskDatasourceJdbcTemplate;
@Autowired
private JdbcTemplate tidbRiskJdbcTemplate;
@Autowired
@Qualifier("tidbRiskDataSource")
private DataSource tidbRiskDataSource;
/* @Resource(name = "tidbRiskDataSource")
private DataSource tidbRiskDataSource2;*/
public static void main(String[] args) {
// LocalDateTime now = LocalDateTime.now();
try {
Stopwatch stopwatch = Stopwatch.createStarted();
Map<String, String> map = new HashMap<>();
Map<String, String> map1 = new HashMap<>();
for (int i = 0; i < 500000; i++) {
map.put(new StringBuffer(String.valueOf(i)).append(String.valueOf(i)).append(String.valueOf(i)).append(String.valueOf(i)).toString(), String.valueOf(i));
}
for (int i = 0; i < 500000; i++) {
map1.put(new StringBuffer(String.valueOf(i)).append(String.valueOf(i)).append(String.valueOf(i)).append(String.valueOf(i)).toString(), String.valueOf(i));
}
System.out.println(stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
e.printStackTrace();
}
}
/* @Async
public void start() {
try {
String tmpTime = "2019-11-23";
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(tmpTime).getTime()).toLocalDateTime();
for (int i = 0; i < 800; i++) {
String startTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i + 1).format(DateTimeFormatter.ISO_DATE);
String sql = "select * from transaction_log where time_created > '" + endTime + "' and time_created < '" + startTime + "'";
Stopwatch queryStopwatch = Stopwatch.createStarted();
List<TransactionLogPO> transactionLogPOList = riskDatasourceJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(TransactionLogPO.class));
log.info("transactionLog查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(transactionLogPOList) ? 0 : transactionLogPOList.size(), sql, queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isEmpty(transactionLogPOList)) {
log.info("查询数据为空跳过");
continue;
}
Map<String, TransactionLogPO> transactionLogPOMap = new HashMap<>();
Map<String, CallRecord1> callRecord1Map = new HashMap<>();
Stopwatch stopwatch = Stopwatch.createStarted();
for (int tran = 0; tran < transactionLogPOList.size(); tran++) {
TransactionLogPO transactionLogPO = transactionLogPOList.get(tran);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transactionLogPO.getTimeCreated());
String key = new StringBuffer(transactionLogPO.getTransactionId()).append(StringUtils.isNotBlank(transactionLogPO.getUuid()) ? transactionLogPO.getUuid() : "").append(transactionLogPO.getUrlType()).append(transactionLogPO.getCode()).append(format).toString();
// System.out.println(key);
transactionLogPOMap.put(key, transactionLogPO);
}
log.info("transactionLog 组装数据完成 查询大小: {} , 组装后大小: {} , 耗时: {} ", transactionLogPOList.size(), transactionLogPOMap.size(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch callRStopwatch = Stopwatch.createStarted();
String sql1 = "select * from call_record where created_at > '" + endTime + "' and created_at < '" + startTime + "' order by created_at desc;";
List<CallRecord1> queryResult = riskDatasourceJdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(CallRecord1.class));
log.info("callRecord查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), sql1, callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
CallRecord1 callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(callRecord1.getCreated_at().getTime()));
String key = new StringBuffer(callRecord1.getTransactionId()).append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "").append(callRecord1.getUrlType()).append(callRecord1.getCode()).append(format).toString();
callRecord1Map.put(key, callRecord1);
}
log.info("callRecord 组装数据完成 查询大小: {} , 组装后大小: {} , 耗时: {} ", queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, TransactionLogPO>> iterator = transactionLogPOMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, TransactionLogPO> next = iterator.next();
String key = next.getKey();
if (callRecord1Map.containsKey(key)) {
iterator.remove();
}
}
log.info("去重 组装数据完成 查询大小: {} , 组装后大小: {} , 耗时: {} ", queryResult.size(), transactionLogPOMap.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
if (transactionLogPOMap.size()>0) {
List<CallRecord1> callRecord1s = new ArrayList<>();
Stopwatch stopwatch1222 = Stopwatch.createStarted();
transactionLogPOMap.forEach((k, v)->{
TransactionLogPO transactionLogPO = v;
CallRecord1 callRecord1 = new CallRecord1();
callRecord1.setCode(String.valueOf(transactionLogPO.getCode()));
callRecord1.setUrlType(transactionLogPO.getUrlType());
callRecord1.setTransactionId(transactionLogPO.getTransactionId());
callRecord1.setUuid(transactionLogPO.getUuid());
Timestamp time = new Timestamp(transactionLogPO.getTimeCreated().getTime());
callRecord1.setCreated_at(time);
callRecord1.setUpdated_at(time);
callRecord1s.add(callRecord1);
if (callRecord1s.size() > 0 && callRecord1s.size() % 1000 == 0) {
Stopwatch stopwatch1 = Stopwatch.createStarted();
JdbcUtils.prepareBatchUpdateExecuteTransactionid("INSERT INTO `call_record` (`transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?)", callRecord1s);
callRecord1s.clear();
log.info("插入数据完成, 耗时: {}", stopwatch1.stop().elapsed(TimeUnit.MILLISECONDS));
}
});
if (callRecord1s.size() > 0) {
JdbcUtils.prepareBatchUpdateExecuteTransactionid("INSERT INTO `call_record` (`transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?)", callRecord1s);
}
log.info("一天数据插入完成, 大小: {} , 耗时: {} ", transactionLogPOMap.size(), stopwatch1222.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
log.info("完事");
} catch (Exception e) {
log.error("清洗数据异常", e);
}
}*/
// @Async
// public void start() {
//
// try {
// String tmpTime = "2019-12-21";
// SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
// LocalDateTime now = new Timestamp(simpleDateFormat1.parse(tmpTime).getTime()).toLocalDateTime();
// for (int i = 0; i < 800; i++) {
// String startTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
// String endTime = now.minusDays(i + 1).format(DateTimeFormatter.ISO_DATE);
// String sql = "select * from transaction_log where time_created > '"+ endTime +"' and time_created < '"+startTime+"'";
// Stopwatch queryStopwatch = Stopwatch.createStarted();
// List<TransactionLogPO> transactionLogPOList = riskDatasourceJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(TransactionLogPO.class));
// log.info("查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(transactionLogPOList)?0:transactionLogPOList.size(), sql, queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
// if(CollectionUtils.isEmpty(transactionLogPOList)){
// log.info("查询数据为空跳过");
// continue;
// }
// Stopwatch oneStopwatch = Stopwatch.createStarted();
// List<CallRecord1> callRecord1s = new ArrayList<>();
// for (int j = 0; j < transactionLogPOList.size(); j++) {
// try{
// TransactionLogPO transactionLogPO = transactionLogPOList.get(j);
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// String d = simpleDateFormat.format(transactionLogPO.getTimeCreated());
// String sql1 = "";
// if(StringUtils.isNotBlank(transactionLogPO.getUuid())){
// sql1 = "select * from call_record where transaction_id = '"+transactionLogPO.getTransactionId()+"' and uuid = '" + transactionLogPO.getUuid() + "' and url_type = '" + transactionLogPO.getUrlType() + "' and code = '" + transactionLogPO.getCode() + "' and created_at = '"+d+"';";
// }else{
// sql1 = "select * from call_record where transaction_id = '"+transactionLogPO.getTransactionId()+"' and url_type = '" + transactionLogPO.getUrlType() + "' and code = '" + transactionLogPO.getCode() + "' and created_at = '"+d+"';";;
// }
// List<CallRecord1> queryResult = riskDatasourceJdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(CallRecord1.class));
// if(CollectionUtils.isEmpty(queryResult)){
//// log.info("查询结果不为空,重新插入 sql: {} , resutl: {} ", sql1, JSON.toJSONString(queryResult));
// CallRecord1 callRecord1 = new CallRecord1();
// callRecord1.setCode(String.valueOf(transactionLogPO.getCode()));
// callRecord1.setUrlType(transactionLogPO.getUrlType());
// callRecord1.setTransactionId(transactionLogPO.getTransactionId());
// callRecord1.setUuid(transactionLogPO.getUuid());
// Timestamp time = new Timestamp(transactionLogPO.getTimeCreated().getTime());
// callRecord1.setCreated_at(time);
// callRecord1.setUpdated_at(time);
//
// callRecord1s.add(callRecord1);
// if(callRecord1s.size()>0 && callRecord1s.size()%1000==0){
// Stopwatch stopwatch = Stopwatch.createStarted();
// JdbcUtils.prepareBatchUpdateExecuteTransactionid("INSERT INTO `call_record` (`transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?)", callRecord1s);
// callRecord1s.clear();
// log.info("插入数据完成, 耗时: {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
// }
// }else{
// log.info("命中原有数据不插入");
// }
//
// }catch(Exception e){
// log.error("清洗插入callRecord异常", e);
// }
//
// }
// if(callRecord1s.size()>0){
// JdbcUtils.prepareBatchUpdateExecuteTransactionid("INSERT INTO `call_record` (`transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?)", callRecord1s);
// log.info("插入数据完成1, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, transactionLogPOList.size(), oneStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
// }
//
// }
// log.info("完事");
// } catch (Exception e) {
// log.error("清洗数据异常", e);
// }
// }
/*
@Async
public void synCallRecord(String newYnrTime) {//yyyy-MM-dd
try {
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(newYnrTime).getTime()).toLocalDateTime();
//开始时间 2018-10-17 11:30:39
//结束时间 2019-12-31 10:36:34
//相差440天
for (int i = 0; i < 500; i++) {
String startTime = now.minusDays(i+1).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
String TRANSACTION_SQL = "select transaction_id, uuid, url_type, code, time_created " +
" from transaction_log where time_created >= '" + startTime + "' and time_created < '" + endTime + "'";
Stopwatch queryStopwatch = Stopwatch.createStarted();
List<TransactionLogPO> transactionLogPOList = riskDatasourceJdbcTemplate.query(TRANSACTION_SQL, new BeanPropertyRowMapper<>(TransactionLogPO.class));
log.info("transactionLog查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(transactionLogPOList) ? 0 : transactionLogPOList.size(), TRANSACTION_SQL, queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isEmpty(transactionLogPOList)) {
log.info("查询数据为空跳过, startTime: {} , endTime: {} ",startTime, endTime);
continue;
}
Map<String, TransactionLogPO> transactionLogPOMap = new HashMap<>();
Stopwatch stopwatch = Stopwatch.createStarted();
for (int tran = 0; tran < transactionLogPOList.size(); tran++) {
TransactionLogPO transactionLogPO = transactionLogPOList.get(tran);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transactionLogPO.getTimeCreated());
String key = new StringBuffer(transactionLogPO.getTransactionId())
.append(StringUtils.isNotBlank(transactionLogPO.getUuid()) ? transactionLogPO.getUuid() : "")
.append(transactionLogPO.getUrlType())
.append(transactionLogPO.getCode())
.append(format).toString();
transactionLogPOMap.put(key, transactionLogPO);
}
log.info("transactionLog组装数据完成, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, transactionLogPOList.size(), transactionLogPOMap.size(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch callRStopwatch = Stopwatch.createStarted();
String CALL_SQL = "select request_url, channel_type, channel_id, transaction_id, uuid, url_type, code, created_at, updated_at " +
" from call_record where created_at >= '" + startTime + "' and created_at < '" + endTime + "' order by created_at desc;";
List<CallRecord1> queryResult = riskDatasourceJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(CallRecord1.class));
log.info("callRecord查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), CALL_SQL, callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Map<String, CallRecord1> callRecord1Map = new HashMap<>();
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
CallRecord1 callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(callRecord1.getCreated_at().getTime()));
String key = new StringBuffer(callRecord1.getTransactionId())
.append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "")
.append(callRecord1.getUrlType())
.append(callRecord1.getCode())
.append(format).toString();
callRecord1Map.put(key, callRecord1);
}
log.info("callRecord组装数据完成, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, TransactionLogPO>> iterator = transactionLogPOMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, TransactionLogPO> next = iterator.next();
String key = next.getKey();
if (callRecord1Map.containsKey(key)) {
iterator.remove();
}
}
log.info("去重组装数据完成, startTime: {} , callRecord查询大小: {} , 组装后transactionLogPOMap大小: {} , 耗时: {} ", startTime, queryResult.size(), transactionLogPOMap.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
if (transactionLogPOMap.size()>0) {
List<CallRecord1> callRecord1s = new ArrayList<>();
Stopwatch stopwatch1222 = Stopwatch.createStarted();
transactionLogPOMap.forEach((k, v)->{
TransactionLogPO transactionLogPO = v;
//c.request_url, c.channel_type, c.channel_id
CallRecord1 callRecord1 = new CallRecord1();
callRecord1.setCode(String.valueOf(transactionLogPO.getCode()));
callRecord1.setUrlType(transactionLogPO.getUrlType());
callRecord1.setTransactionId(transactionLogPO.getTransactionId());
callRecord1.setUuid(transactionLogPO.getUuid());
Timestamp time = new Timestamp(transactionLogPO.getTimeCreated().getTime());
callRecord1.setCreated_at(time);
callRecord1.setUpdated_at(time);
callRecord1s.add(callRecord1);
if (callRecord1s.size() > 0 && callRecord1s.size() % 1000 == 0) {
Stopwatch stopwatch1 = Stopwatch.createStarted();
JdbcUtils.prepareBatchUpdateExecuteTransactionid("INSERT INTO `call_record` (`transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?)", callRecord1s);
callRecord1s.clear();
log.info("插入数据完成, 耗时: {}", stopwatch1.stop().elapsed(TimeUnit.MILLISECONDS));
}
});
if (callRecord1s.size() > 0) {
JdbcUtils.prepareBatchUpdateExecuteTransactionid("INSERT INTO `call_record` (`transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?)", callRecord1s);
}
log.info("一天数据插入完成, 大小: {} , 耗时: {} ", transactionLogPOMap.size(), stopwatch1222.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
log.info("完事");
} catch (Exception e) {
log.error("清洗数据异常", e);
}
}
*/
@Async
public void synCallRecordNew(String newYnrTime, String isExecuteOnce) {//yyyy-MM-dd
try {
boolean executeOnce = false;
if(StringUtils.isNotEmpty(isExecuteOnce) && "true".equals(isExecuteOnce)){
executeOnce = true;
}
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(newYnrTime).getTime()).toLocalDateTime();
//开始时间 2018-10-17 11:30:39
//结束时间 2019-12-31 10:36:34
//相差440天
for (int i = 0; i < 500; i++) {
String startTime = now.minusDays(i+1).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
String TRANSACTION_SQL = "select request_url, channel_type, channel_id, transaction_id, uuid, url_type, code, created_at, updated_at " +
" from call_record where created_at >= '" + startTime + "' and created_at < '" + endTime + "'";
Stopwatch queryStopwatch = Stopwatch.createStarted();
List<CallRecord3> transactionLogPOList = riskDatasourceJdbcTemplate.query(TRANSACTION_SQL, new BeanPropertyRowMapper<>(CallRecord3.class));
log.info("transactionLog查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(transactionLogPOList) ? 0 : transactionLogPOList.size(), TRANSACTION_SQL, queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isEmpty(transactionLogPOList)) {
log.info("查询数据为空跳过, startTime: {} , endTime: {} ",startTime, endTime);
continue;
}
Map<String, CallRecord3> transactionLogPOMap = new HashMap<>();
Stopwatch stopwatch = Stopwatch.createStarted();
for (int tran = 0; tran < transactionLogPOList.size(); tran++) {
CallRecord3 transactionLogPO = transactionLogPOList.get(tran);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transactionLogPO.getCreatedAt());
String key = new StringBuffer(transactionLogPO.getTransactionId())
.append(StringUtils.isNotBlank(transactionLogPO.getUuid()) ? transactionLogPO.getUuid() : "")
.append(transactionLogPO.getUrlType())
.append(transactionLogPO.getCode())
.append(format).toString();
transactionLogPOMap.put(key, transactionLogPO);
}
log.info("transactionLog组装数据完成, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, transactionLogPOList.size(), transactionLogPOMap.size(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch callRStopwatch = Stopwatch.createStarted();
String CALL_SQL = "select transaction_id, uuid, url_type, code, created_at " +
" from call_record where created_at >= '" + startTime + "' and created_at < '" + endTime + "' order by created_at desc;";
List<CallRecord1> queryResult = tidbRiskJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(CallRecord1.class));
log.info("callRecord查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), CALL_SQL, callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Map<String, CallRecord1> callRecord1Map = new HashMap<>();
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
CallRecord1 callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(callRecord1.getCreated_at().getTime()));
String key = new StringBuffer(callRecord1.getTransactionId())
.append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "")
.append(callRecord1.getUrlType())
.append(callRecord1.getCode())
.append(format).toString();
callRecord1Map.put(key, callRecord1);
}
log.info("callRecord组装数据完成, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, CallRecord3>> iterator = transactionLogPOMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, CallRecord3> next = iterator.next();
String key = next.getKey();
if (callRecord1Map.containsKey(key)) {
iterator.remove();
}
}
log.info("去重组装数据完成, startTime: {} , callRecord查询大小: {} , 组装后transactionLogPOMap大小: {} , 耗时: {} ", startTime, queryResult.size(), transactionLogPOMap.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
if (transactionLogPOMap.size()>0) {
List<CallRecord3> callRecord3List = new ArrayList<>();
Stopwatch stopwatch1222 = Stopwatch.createStarted();
AtomicInteger pageNum = new AtomicInteger();
String INSERT_SQL = "INSERT INTO `call_record` (`request_url`, `channel_type`, `channel_id`, `transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ";
transactionLogPOMap.forEach((k, v)->{
callRecord3List.add(v);
if (callRecord3List.size() > 0 && callRecord3List.size() % 1000 == 0) {
Stopwatch stopwatch1 = Stopwatch.createStarted();
JdbcUtils.batchUpdateExecuteCallRecord(tidbRiskDataSource,INSERT_SQL, callRecord3List);
callRecord3List.clear();
pageNum.getAndIncrement();
log.info("插入数据完成, pageNum: {} , 耗时: {} ", pageNum.get(), stopwatch1.stop().elapsed(TimeUnit.MILLISECONDS));
}
});
if (callRecord3List.size() > 0) {
JdbcUtils.batchUpdateExecuteCallRecord(tidbRiskDataSource,INSERT_SQL, callRecord3List);
pageNum.getAndIncrement();
}
log.info("一天数据插入完成, startTime: {} , pageNum: {} , 大小: {} , 耗时: {} ",startTime, pageNum.get(), transactionLogPOMap.size(), stopwatch1222.stop().elapsed(TimeUnit.MILLISECONDS));
}else{
log.info("一天数据插入完成, startTime: {} , transactionLogPOMap size is Empty!",startTime);
}
if(executeOnce){
log.info("一天数据插入完成, newYnrTime: {} , isExecuteOnce: {} , startTime: {} , endTime: {} ,",newYnrTime, isExecuteOnce, startTime, endTime);
break;
}
}
log.info("----All清洗数据结束----");
} catch (Exception e) {
log.error("清洗数据异常", e);
}
}
/**
* 描述: 检测tidb的call_record表数据是否有重复数据 <br/>
* 参数: [newYnrTime, isExecuteOnce] <br/>
* 返回值: void <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2020.01.02 <br/>
*/
@Async
public void checkCallRecordCF(String newYnrTime, String isExecuteOnce) { //yyyy-MM-dd
try {
boolean executeOnce = false;
if(StringUtils.isNotEmpty(isExecuteOnce) && "true".equals(isExecuteOnce)){
executeOnce = true;
}
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(newYnrTime).getTime()).toLocalDateTime();
//开始时间 2018-10-17 11:30:39
//结束时间 2019-12-31 10:36:34
//相差440天
for (int i = 0; i < 500; i++) {
String startTime = now.minusDays(i+1).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
Stopwatch callRStopwatch = Stopwatch.createStarted();
String CALL_SQL = "select transaction_id, uuid, url_type, code, created_at " +
" from call_record where created_at >= '" + startTime + "' and created_at < '" + endTime + "'";
List<CallRecord1> queryResult = tidbRiskJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(CallRecord1.class));
log.info("checkCallRecordCF检测重复callRecord查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), CALL_SQL, callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Map<String, Integer> callRecord1Map = new HashMap<>();
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
CallRecord1 callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(callRecord1.getCreated_at().getTime()));
String key = new StringBuffer(callRecord1.getTransactionId()).append(",")
.append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "").append(",")
.append(callRecord1.getUrlType()).append(",")
.append(callRecord1.getCode()).append(",")
.append(format).toString();
if(callRecord1Map.containsKey(key)){
callRecord1Map.put(key, callRecord1Map.get(key).intValue()+1);
}else{
callRecord1Map.put(key, 1);
}
}
log.info("checkCallRecordCF检测重复callRecord组装数据完成, startTime: {} , 查询List大小: {} , 组装后Map大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, Integer>> iterator = callRecord1Map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> next = iterator.next();
String key = next.getKey();
Integer value = next.getValue();
if (value!=null && value.intValue() >1 ) {
log.info("checkCallRecordCF检测重复发现有重复数据, startTime: {} , 重复次数value: {} , key: {} ", startTime, value, key);
}else{
iterator.remove();
}
}
log.info("checkCallRecordCF检测重复数据结束, startTime: {} , 查询List大小: {} , 过滤后callRecord1Map大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
if(executeOnce){
log.info("checkCallRecordCF检测重复一天数据完成, newYnrTime: {} , isExecuteOnce: {} , startTime: {} , endTime: {} ,",newYnrTime, isExecuteOnce, startTime, endTime);
break;
}
}
log.info("----checkCallRecordCF---All检测重复数据结束----");
} catch (Exception e) {
log.error("checkCallRecordCF检测重复数据异常", e);
}
}
@Async
public void checkTransactionLogCF(String newYnrTime, String isExecuteOnce) { //yyyy-MM-dd
try {
boolean executeOnce = false;
if(StringUtils.isNotEmpty(isExecuteOnce) && "true".equals(isExecuteOnce)){
executeOnce = true;
}
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(newYnrTime).getTime()).toLocalDateTime();
//开始时间 2018-10-17 11:30:39
//结束时间 2019-12-31 10:36:34
//相差440天
for (int i = 0; i < 500; i++) {
String startTime = now.minusDays(i+1).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
Stopwatch callRStopwatch = Stopwatch.createStarted();
String CALL_SQL = "select transaction_id, uuid, url_type, code, time_created " +
" from transaction_log t where t.time_created >= '" + startTime + "' and t.time_created < '" + endTime + "'";
List<TransactionLogPO> queryResult = riskDatasourceJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(TransactionLogPO.class));
log.info("checkTransactionLogCF检测重复transaction_log查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), CALL_SQL, callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Map<String, Integer> callRecord1Map = new HashMap<>();
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
TransactionLogPO callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(callRecord1.getTimeCreated());
String key = new StringBuffer(callRecord1.getTransactionId()).append(",")
.append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "").append(",")
.append(callRecord1.getUrlType()).append(",")
.append(callRecord1.getCode()).append(",")
.append(format).toString();
if(callRecord1Map.containsKey(key)){
callRecord1Map.put(key, callRecord1Map.get(key).intValue()+1);
}else{
callRecord1Map.put(key, 1);
}
}
log.info("checkTransactionLogCF检测重复transaction组装数据完成, startTime: {} , 查询List大小: {} , 组装后Map大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, Integer>> iterator = callRecord1Map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> next = iterator.next();
String key = next.getKey();
Integer value = next.getValue();
if (value!=null && value.intValue() >1 ) {
log.info("checkTransactionLogCF检测重复发现有重复数据, startTime: {} , 重复次数value: {} , key: {} ", startTime, value, key);
}else{
iterator.remove();
}
}
log.info("checkTransactionLogCF检测重复数据结束, startTime: {} , 查询List大小: {} , 过滤后transaction Map大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
if(executeOnce){
log.info("checkTransactionLogCF检测重复一天数据完成, newYnrTime: {} , isExecuteOnce: {} , startTime: {} , endTime: {} ,",newYnrTime, isExecuteOnce, startTime, endTime);
break;
}
}
log.info("----checkTransactionLogCF---All检测重复数据结束----");
} catch (Exception e) {
log.error("checkTransactionLogCF检测重复数据异常", e);
}
}
@Async
public void checkCallRecordCFByTransactionLog(String newYnrTime, String isExecuteOnce) {//yyyy-MM-dd
try {
boolean executeOnce = false;
if(StringUtils.isNotEmpty(isExecuteOnce) && "true".equals(isExecuteOnce)){
executeOnce = true;
}
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(newYnrTime).getTime()).toLocalDateTime();
//开始时间 2018-10-17 11:30:39
//结束时间 2019-12-31 10:36:34
//相差440天
for (int i = 0; i < 500; i++) {
String startTime = now.minusDays(i+1).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
String TRANSACTION_SQL = "select transaction_id, uuid, url_type, code, time_created " +
" from transaction_log where time_created >= '" + startTime + "' and time_created < '" + endTime + "'";
Stopwatch queryStopwatch = Stopwatch.createStarted();
List<TransactionLogPO> transactionLogPOList = riskDatasourceJdbcTemplate.query(TRANSACTION_SQL, new BeanPropertyRowMapper<>(TransactionLogPO.class));
log.info("transactionLog查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(transactionLogPOList) ? 0 : transactionLogPOList.size(), TRANSACTION_SQL, queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isEmpty(transactionLogPOList)) {
log.info("查询数据为空跳过, startTime: {} , endTime: {} ",startTime, endTime);
continue;
}
Map<String, TransactionLogPO> transactionLogPOMap = new HashMap<>();
Stopwatch stopwatch = Stopwatch.createStarted();
for (int tran = 0; tran < transactionLogPOList.size(); tran++) {
TransactionLogPO transactionLogPO = transactionLogPOList.get(tran);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transactionLogPO.getTimeCreated());
String key = new StringBuffer(transactionLogPO.getTransactionId()).append(",")
.append(StringUtils.isNotBlank(transactionLogPO.getUuid()) ? transactionLogPO.getUuid() : "").append(",")
.append(transactionLogPO.getUrlType()).append(",")
.append(transactionLogPO.getCode()).append(",")
.append(format).toString();
transactionLogPOMap.put(key, transactionLogPO);
}
log.info("transactionLog组装数据完成, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, transactionLogPOList.size(), transactionLogPOMap.size(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch callRStopwatch = Stopwatch.createStarted();
String CALL_SQL = "select transaction_id, uuid, url_type, code, created_at " +
" from call_record where created_at >= '" + startTime + "' and created_at < '" + endTime + "' order by created_at desc;";
List<CallRecord1> queryResult = tidbRiskJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(CallRecord1.class));
log.info("callRecord查询数据结束, startTime: {} , endTime: {} , size: {} , sql: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), CALL_SQL, callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Map<String, CallRecord1> callRecord1Map = new HashMap<>();
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
CallRecord1 callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(callRecord1.getCreated_at().getTime()));
String key = new StringBuffer(callRecord1.getTransactionId()).append(",")
.append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "").append(",")
.append(callRecord1.getUrlType()).append(",")
.append(callRecord1.getCode()).append(",")
.append(format).toString();
callRecord1Map.put(key, callRecord1);
}
log.info("callRecord组装数据完成, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, TransactionLogPO>> iterator = transactionLogPOMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, TransactionLogPO> next = iterator.next();
String key = next.getKey();
if (callRecord1Map.containsKey(key)) {
iterator.remove();
}
}
log.info("去重组装数据完成, startTime: {} , callRecord查询大小: {} , 组装后transactionLogPOMap大小: {} , 耗时: {} ", startTime, queryResult.size(), transactionLogPOMap.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
if (transactionLogPOMap.size()>0) {
Stopwatch stopwatch1222 = Stopwatch.createStarted();
AtomicInteger countNum = new AtomicInteger();
transactionLogPOMap.forEach((k, v)->{
countNum.getAndIncrement();
log.info("检测transactionLogPOMap不为空, startTime: {} , ST: {} , mapkey: {} ",startTime, countNum.get(), k);
});
log.info("一天数据插入完成, startTime: {} , countNum: {} , Map大小: {} , 耗时: {} ",startTime, countNum.get(), transactionLogPOMap.size(), stopwatch1222.stop().elapsed(TimeUnit.MILLISECONDS));
}else{
log.info("一天数据插入完成, startTime: {} , transactionLogPOMap size is Empty!",startTime);
}
if(executeOnce){
log.info("一天数据插入完成, newYnrTime: {} , isExecuteOnce: {} , startTime: {} , endTime: {} ,",newYnrTime, isExecuteOnce, startTime, endTime);
break;
}
}
log.info("----All清洗数据结束----");
} catch (Exception e) {
log.error("清洗数据异常", e);
}
}
@Async
public void checkCallRecordCFByTransactionLog2(String newYnrTime, String isExecuteOnce) {//yyyy-MM-dd
try {
boolean executeOnce = false;
if(StringUtils.isNotEmpty(isExecuteOnce) && "true".equals(isExecuteOnce)){
executeOnce = true;
}
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
LocalDateTime now = new Timestamp(simpleDateFormat1.parse(newYnrTime).getTime()).toLocalDateTime();
//开始时间 2018-10-17 11:30:39
//结束时间 2019-12-31 10:36:34
//相差440天
for (int i = 0; i < 500; i++) {
String startTime = now.minusDays(i+1).format(DateTimeFormatter.ISO_DATE);
String endTime = now.minusDays(i).format(DateTimeFormatter.ISO_DATE);
String TRANSACTION_SQL = "select transaction_id, uuid, url_type, code, time_created " +
" from transaction_log where time_created >= '" + startTime + "' and time_created < '" + endTime + "'";
Stopwatch queryStopwatch = Stopwatch.createStarted();
List<TransactionLogPO> transactionLogPOList = riskDatasourceJdbcTemplate.query(TRANSACTION_SQL, new BeanPropertyRowMapper<>(TransactionLogPO.class));
log.info("transactionLog查询数据结束CCFByT, startTime: {} , endTime: {} , size: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(transactionLogPOList) ? 0 : transactionLogPOList.size(), queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isEmpty(transactionLogPOList)) {
log.info("查询数据为空跳过CCFByT, startTime: {} , endTime: {} ",startTime, endTime);
continue;
}
Map<String, TransactionLogPO> transactionLogPOMap = new HashMap<>();
Stopwatch stopwatch = Stopwatch.createStarted();
for (int tran = 0; tran < transactionLogPOList.size(); tran++) {
TransactionLogPO transactionLogPO = transactionLogPOList.get(tran);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(transactionLogPO.getTimeCreated());
String key = new StringBuffer(transactionLogPO.getTransactionId()).append(",")
.append(StringUtils.isNotBlank(transactionLogPO.getUuid()) ? transactionLogPO.getUuid() : "").append(",")
.append(transactionLogPO.getUrlType()).append(",")
.append(transactionLogPO.getCode()).append(",")
.append(format).toString();
transactionLogPOMap.put(key, transactionLogPO);
}
log.info("transactionLog REMOVE数据完成CCFByT, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, transactionLogPOList.size(), transactionLogPOMap.size(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch callRStopwatch = Stopwatch.createStarted();
String CALL_SQL = "select transaction_id, uuid, url_type, code, created_at " +
" from call_record where created_at >= '" + startTime + "' and created_at < '" + endTime + "' order by created_at desc;";
List<CallRecord1> queryResult = tidbRiskJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(CallRecord1.class));
log.info("callRecord查询数据结束CCFByT, startTime: {} , endTime: {} , size: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(queryResult) ? 0 : queryResult.size(), callRStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Map<String, CallRecord1> callRecord1Map = new HashMap<>();
if (CollectionUtils.isNotEmpty(queryResult)) {
Stopwatch callStopwatch = Stopwatch.createStarted();
for (int call = 0; call < queryResult.size(); call++) {
CallRecord1 callRecord1 = queryResult.get(call);
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(callRecord1.getCreated_at().getTime()));
String key = new StringBuffer(callRecord1.getTransactionId()).append(",")
.append(StringUtils.isNotBlank(callRecord1.getUuid()) ? callRecord1.getUuid() : "").append(",")
.append(callRecord1.getUrlType()).append(",")
.append(callRecord1.getCode()).append(",")
.append(format).toString();
callRecord1Map.put(key, callRecord1);
}
log.info("callRecord组装数据完成CCFByT, startTime: {} , 查询大小: {} , 组装后大小: {} , 耗时: {} ", startTime, queryResult.size(), callRecord1Map.size(), callStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
Stopwatch delStopwatch = Stopwatch.createStarted();
Iterator<Map.Entry<String, TransactionLogPO>> iterator = transactionLogPOMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, TransactionLogPO> next = iterator.next();
String key = next.getKey();
if (callRecord1Map.containsKey(key)) {
iterator.remove();
callRecord1Map.remove(key);
}
}
log.info("去相同据完成CCFByT, startTime: {} , callRecord1Map大小: {} , transactionLogPOMap大小: {} , 耗时: {} ", startTime, callRecord1Map.size(), transactionLogPOMap.size(), delStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
String path = "/home/quant_group/baihang-report/logs/transaction_call/";
if (transactionLogPOMap.size()>0) {
Stopwatch stopwatch1222 = Stopwatch.createStarted();
AtomicInteger countNum = new AtomicInteger();
transactionLogPOMap.forEach((k, v)->{
countNum.getAndIncrement();
try {
FileUtils.write(new File(path +"transaction_start_"+startTime+".txt"), k+"\r\n", "UTF-8", true);
} catch (IOException e) {
e.printStackTrace();
}
});
log.info("写入transaction_log多出的数据结束CCFByT, startTime: {} , countNum: {} , Map大小: {} , 耗时: {} ",startTime, countNum.get(), transactionLogPOMap.size(), stopwatch1222.stop().elapsed(TimeUnit.MILLISECONDS));
}else{
log.info("写入transaction_log多出的数据结束CCFByT, startTime: {} , transactionLogPOMap size is Empty!",startTime);
}
if (callRecord1Map.size()>0) {
Stopwatch stopwatch3 = Stopwatch.createStarted();
AtomicInteger countNum3 = new AtomicInteger();
callRecord1Map.forEach((key, v)->{
countNum3.getAndIncrement();
try {
FileUtils.write(new File(path +"callRecord_start_"+startTime+".txt"), key+"\r\n", "UTF-8", true);
} catch (IOException e) {
e.printStackTrace();
}
});
log.info("写入call_record多出的数据结束CCFByT, startTime: {} , countNum: {} , Map大小: {} , 耗时: {} ",startTime, countNum3.get(), callRecord1Map.size(), stopwatch3.stop().elapsed(TimeUnit.MILLISECONDS));
}else{
log.info("写入call_record多出的数据结束CCFByT, startTime: {} , transactionLogPOMap size is Empty!",startTime);
}
if(executeOnce){
log.info("比较数据完成CCFByT, newYnrTime: {} , isExecuteOnce: {} , startTime: {} , endTime: {} ,",newYnrTime, isExecuteOnce, startTime, endTime);
break;
}
}
log.info("----All比较数据完成CCFByT----");
} catch (Exception e) {
log.error("比较数据异常CCFByT", e);
}
}
@Async
public void deleteTidbCallRecordCF(String cfFileName, String bakFileName) {
try {
List<String> tidbCallRecordCFList = ReadOrWriteTxt.readTxtList(cfFileName);
log.info("读取文件cfFileName: {} , tidbCallRecordCFList大小:{} ",cfFileName,tidbCallRecordCFList.size());
for (int i = 0; i < tidbCallRecordCFList.size(); i++) {
//ee86810a076d45d58a5d87d7cfc60e8f,032f14da-b905-4a1c-9c38-9db3dd0b1304,ZhiChengAFuAntiFraud,1004,2019-12-24 21:48:53
log.info("删除重复数据ST:"+i);
String[] arry = tidbCallRecordCFList.get(i).trim().split(",");
Stopwatch callRStopwatch = Stopwatch.createStarted();
String DELETE_CALL_SQL = "delete from call_record where id=##ID## AND transaction_id ='##TRANSACTION_ID##';";
String CALL_SQL = "select * from call_record where transaction_id ='" + arry[0] + "' and uuid ='" + arry[1] +"'"
+" and url_type ='" + arry[2] + "' and code ='" +arry[3]+ "'; ";
List<CallRecord3> queryResult = tidbRiskJdbcTemplate.query(CALL_SQL, new BeanPropertyRowMapper<>(CallRecord3.class));
int size = (queryResult!=null ? queryResult.size(): 0);
if(queryResult!=null && queryResult.size()==2){
CallRecord3 bean1 = queryResult.get(0);
CallRecord3 bean2 = queryResult.get(1);
int second = Math.abs(bean1.getCreatedAt().compareTo(bean2.getCreatedAt()));
if(second <=3){
if(StringUtils.isEmpty(bean1.getRequestUrl()) && StringUtils.isEmpty(bean1.getChannelId())
&& ( StringUtils.isNotEmpty(bean2.getRequestUrl()) || StringUtils.isNotEmpty(bean2.getChannelId())
|| StringUtils.isNotEmpty(bean2.getChannelType())
)){
String sql = DELETE_CALL_SQL.replace("##ID##", ""+bean1.getId());
sql = sql.replace("##TRANSACTION_ID##", bean1.getTransactionId());
try {
FileUtils.write(new File(bakFileName), JSON.toJSONString(bean1)+"\r\n", "UTF-8", true);
int update =tidbRiskJdbcTemplate.update(sql);
log.info("删除bean1成功, sql: {} ,update: {} ",sql,update);
} catch (Exception e) {
log.error("删除bean1数据是不, sql: {} ",sql, e);
}
}else if(StringUtils.isEmpty(bean2.getRequestUrl()) && StringUtils.isEmpty(bean2.getChannelId())
&& (StringUtils.isNotEmpty(bean1.getRequestUrl()) || StringUtils.isNotEmpty(bean1.getChannelId())
|| StringUtils.isNotEmpty(bean1.getChannelType())
)){
String sql = DELETE_CALL_SQL.replace("##ID##", ""+bean2.getId());
sql = sql.replace("##TRANSACTION_ID##", bean2.getTransactionId());
try {
FileUtils.write(new File(bakFileName), JSON.toJSONString(bean2)+"\r\n", "UTF-8", true);
int update = tidbRiskJdbcTemplate.update(sql);
log.info("删除bean2成功, sql: {} , update: {} ",sql,update);
} catch (Exception e) {
log.error("删除bean2数据是不, sql: {} ",sql, e);
}
}else {
log.info("查询call_record表,发现其他情况, param: {} , List: {} ", tidbCallRecordCFList.get(i), (queryResult!=null ? JSON.toJSONString(queryResult): "null") );
}
}else{
log.info("查询call_record表,相差时间大于3秒, param: {} , List: {} ", tidbCallRecordCFList.get(i), (queryResult!=null ? JSON.toJSONString(queryResult): "null") );
}
}else{
log.info("查询call_record表,list大小不为2, param: {} , size: {} , List: {} ", tidbCallRecordCFList.get(i), size, (queryResult!=null ? JSON.toJSONString(queryResult): "null") );
}
}
log.info("----删除bean数据完成----");
} catch (Exception e) {
log.error("删除bean数据异常", e);
}
}
}
package cn.quantgroup.report.service.manualTool;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.regex.Pattern;
/**
* -----------------------------------------------------------------------------<br>
* 描述: <br>
* 作者: Administrator <br>
* 时间: 2020.04.05 15:37 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public class HomeWork {
public static void main(String[] args) {
//1、输入两个数a和b,输出a+b
Object num_a = "9999999999999999999999999999999999999999999999999999999999999999999999999999999999";
Object num_b = "1.01";
Object result = aAddb(num_a, num_b);
System.out.println(num_a + " + " + num_b + " = " +result.toString());
//2、从目录A下打开文件test.txt,读取全10个字符并输出
String filePath = "C:\\Users\\Administrator\\Desktop\\助贷\\2020-01-06_07\\test.txt";
String str_10 = null;
str_10 = readTxt10char1(filePath);
System.out.printf(str_10);
str_10 = readTxt10char2(filePath);
System.out.printf(str_10);
str_10 = readTxt10char3(filePath);
System.out.printf(str_10);
}
public static Object aAddb(Object a, Object b) {
if (null == a || StringUtils.isBlank(a.toString().trim())) {
System.out.println("参数a不能为空!");
return null;
}
if (null == b || StringUtils.isBlank(b.toString().trim())) {
System.out.println("参数b不能为空!");
return null;
}
String str_a = a.toString().trim();
String str_b = b.toString().trim();
if (!isInteger(str_a) && !isDouble(str_a)) {
System.out.println("参数a不是数值类型!");
return null;
}
if (!isInteger(str_b) && !isDouble(str_b)) {
System.out.println("参数b不是数值类型!");
return null;
}
if (isDouble(str_a) || isDouble(str_b)) {
//if(str_a.split("[.]")[0].length()>=18 || str_b.split("[.]")[0].length()>=18){
BigDecimal bigDecimal_a = new BigDecimal(str_a);
BigDecimal bigDecimal_b = new BigDecimal(str_b);
return bigDecimal_a.add(bigDecimal_b);
/*}else {
double d_a = Double.parseDouble(str_a);
double d_b = Double.parseDouble(str_b);
return d_a + d_b;
}*/
} else {
//Long.MAX_VALUE 9223372036854775807
if (str_a.length() >= 18 || str_b.length() >= 18) {
BigInteger big_a = new BigInteger(str_a);
BigInteger big_b = new BigInteger(str_b);
return big_a.add(big_b);
} else {
long l_a = Long.parseLong(str_a);
long l_b = Long.parseLong(str_b);
return l_a + l_b;
}
}
}
/**
* -----------------------------------------------------------------------------<br>
* 描述: 获取文件前10个字符,(按行去取,中文看做1个字符)<br>
* 作者:yanhui.Hao <br>
* 时间:2020.04.05 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public static String readTxt10char1(String txtPath) {
File file = new File(txtPath);
FileInputStream fileInputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
if (file.isFile() && file.exists()) {
try {
fileInputStream = new FileInputStream(file);
inputStreamReader = new InputStreamReader(fileInputStream, "GBK");
bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer sb = new StringBuffer();
String text = null;
while ((text = bufferedReader.readLine()) != null) {
sb.append(text);
if (sb.length() >= 10) {
break;
}
}
if(sb.length()>=10){
return sb.substring(0, 10);
}else{
return sb.substring(0, sb.length());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
bufferedReader.close();
inputStreamReader.close();
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
/**
* -----------------------------------------------------------------------------<br>
* 描述: 获取文件前10个字符,(按行读取,把中文看做2个字符)<br>
* 作者:yanhui.Hao <br>
* 时间:2020.04.05 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public static String readTxt10char2(String txtPath) {
File file = new File(txtPath);
FileInputStream fileInputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
if (file.isFile() && file.exists()) {
try {
fileInputStream = new FileInputStream(file);
inputStreamReader = new InputStreamReader(fileInputStream, "GBK");
bufferedReader = new BufferedReader(inputStreamReader);
byte[] byte10 = new byte[10];
int copy_index = 0;
String text = null;
while ((text = bufferedReader.readLine()) != null) {
byte[] tmp = text.getBytes("GBK");
if (tmp.length >= 10) {
System.arraycopy(tmp, 0, byte10, 0, 10);
break;
} else {
if (copy_index + tmp.length >= 10) {
System.arraycopy(tmp, 0, byte10, copy_index, 10 - copy_index);
copy_index = 10;
break;
} else {
System.arraycopy(tmp, 0, byte10, copy_index, tmp.length);
copy_index += tmp.length;
}
}
}
String str = new String(byte10, "GBK");
return str;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
bufferedReader.close();
inputStreamReader.close();
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
/**
* -----------------------------------------------------------------------------<br>
* 描述: 获取文件前10个字符,(按字节读取,把中文看做2个字符)<br>
* 作者:yanhui.Hao <br>
* 时间:2020.04.05 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public static String readTxt10char3(String txtPath) {
File file = new File(txtPath);
FileInputStream fileInputStream = null;
if (file.isFile() && file.exists()) {
try {
fileInputStream = new FileInputStream(file);
/* byte[] byte10 = new byte[10];
int read = fileInputStream.read(byte10);
if(read>0){
String str = new String(byte10, "GBK");
System.out.println(str);
return str;
}*/
//byte[] byte_10 = new byte[10];
byte[] byte_10 = getByte10(fileInputStream, 0, null, 0);
String str = new String(byte_10, "GBK");
return str;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
//判断整数(int)
private static boolean isInteger(String str) {
if (null == str || "".equals(str)) {
return false;
}
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
//判断浮点数(double和float)
private static boolean isDouble(String str) {
if (null == str || "".equals(str)) {
return false;
}
Pattern pattern = Pattern.compile("^[-\\+]?\\d*[.]\\d+$");
boolean isDouble = pattern.matcher(str).matches();
if (!isDouble) {
try {
BigDecimal test_bigDecimal = new BigDecimal(str);
isDouble = true;
} catch (Exception e) {
}
}
return isDouble;
}
private static byte[] getByte10(FileInputStream fileInputStream, int start, byte[] byte_10, int index) {
if(byte_10==null){
byte_10 = new byte[10];
}
try {
int length = 8;
byte[] byte_tmp = new byte[length];
int read = fileInputStream.read(byte_tmp, 0, length);
int i1 = fileInputStream.hashCode();
start += length;
if (read > 0) {
//"\r" 回车键 13 ; "\n" 换行键 10
for (int i = 0; i < read; i++) {
if (byte_tmp[i] != 10 && byte_tmp[i] != 13) {
if (index >= 10) {
break;
} else {
byte_10[index] = byte_tmp[i];
index++;
}
}
}
if (index < 10) {
return getByte10(fileInputStream, start, byte_10, index);
} else {
return byte_10;
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.toString());
}
byte[] byte_tmp = new byte[index];
System.arraycopy(byte_10, 0, byte_tmp, 0, byte_tmp.length);
return byte_tmp;
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
package cn.quantgroup.report.service.manualTool;
import com.jcraft.jsch.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import java.io.*;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j
public class ShellUtils {
// 字符编码默认是utf-8
public static final String DEFAULT_CHART = "UTF-8";
public static final String CHANNEL_TYPE_EXEC = "exec";
public static final String CHANNEL_TYPE_SHELL = "shell";
public static final String CHANNEL_TYPE_SFTP = "sftp";
private static final String DEFAULT_CHANNEL_TYPE = CHANNEL_TYPE_EXEC;
private static final Integer DEFAULT_PORT = 22;// 默认连接端口
private String ip;
private int port;
private String userName;
private String userPwd;
private static final JSch jsch = new JSch();// session构造器
private Session session = null;
private ChannelShell channelShell = null;
private ChannelExec channelExec = null;
private ChannelSftp channelSftp = null;
private InputStream inputStream = null;
private OutputStream outputStream = null;
private BufferedReader in = null;
public static Lock LOCK = new ReentrantLock(); // 注意这个地方
public ShellUtils(String ip, String username, String password) throws Exception {
this.ip = ip;
this.userName = username;
this.userPwd = password;
this.port = DEFAULT_PORT;
}
public ShellUtils(String ip, int port, String username, String password) throws Exception {
this.ip = ip;
this.userName = username;
this.userPwd = password;
this.port = port;
}
public Boolean login() {
boolean flg = false;
try {
session = jsch.getSession(this.userName, this.ip, this.port);
log.info("shellUtils login init session ok!");
session.setPassword(this.userPwd);
session.setConfig("StrictHostKeyChecking", "no");// 去掉连接确认的
session.connect(30000);
flg = true;
log.info("shellUtils login session.connect ok!");
} catch (JSchException e) {
e.printStackTrace();
log.error("shellUtils login error JSchException!", e);
}
return flg;
}
public void initChannel(String channelName) throws JSchException {
if (StringUtils.isBlank(channelName)) {
throw new JSchException();
}
try {
if (CHANNEL_TYPE_EXEC.equals(channelName)) {
this.channelExec = (ChannelExec) session.openChannel(this.CHANNEL_TYPE_EXEC);
this.channelExec.connect();
log.info("shellUtils openChannel >" + channelName + " channel ok!");
this.inputStream = channelExec.getInputStream();
this.outputStream = channelExec.getOutputStream();
log.info("shellUtils channel >" + channelName + " get inputStream & outputStream ok!");
} else if (CHANNEL_TYPE_SHELL.equals(channelName)) {
this.channelShell = (ChannelShell) session.openChannel(this.CHANNEL_TYPE_SHELL);
this.channelShell.connect();
log.info("shellUtils openChannel >" + channelName + " channel ok!");
this.inputStream = channelShell.getInputStream();
this.outputStream = channelShell.getOutputStream();
log.info("shellUtils channel >" + channelName + " get inputStream & outputStream ok!");
} else if (CHANNEL_TYPE_SFTP.equals(channelName)) {
this.channelSftp = (ChannelSftp) session.openChannel(this.CHANNEL_TYPE_SFTP);
this.channelSftp.connect();
log.info("shellUtils openChannel >" + channelName + " channel ok!");
this.inputStream = channelSftp.getInputStream();
this.outputStream = channelSftp.getOutputStream();
log.info("shellUtils channel >" + channelName + " get inputStream & outputStream ok!");
} else {
this.channelExec = (ChannelExec) session.openChannel(this.DEFAULT_CHANNEL_TYPE);
this.channelExec.connect();
log.info("shellUtils openChannel >" + channelName + " channel ok!");
this.inputStream = channelExec.getInputStream();
this.outputStream = channelExec.getOutputStream();
log.info("shellUtils channel >" + channelName + " get inputStream & outputStream ok!");
}
} catch (JSchException e) {
e.printStackTrace();
log.error("initChannel方法出现JSchException异常!", e);
} catch (IOException e) {
e.printStackTrace();
log.error("initChannel方法出现IOException异常!", e);
}
}
/**
* 释放IO
*/
public void ioclose() {
try {
if (this.inputStream != null) {
this.inputStream.close();
}
if (this.outputStream != null) {
this.outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
log.error("shellUtils ioclose error!", e);
}
}
/**
* 关闭通道
*/
public void closeChannelShell() {
try {
this.in.close();
if (this.channelShell != null) {
this.channelShell.disconnect();
}
if (this.session != null) {
this.session.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
log.error("shellUtils closeChannelShell error!", e);
}
}
public void execute(List<String> cmdList, boolean appendLast) {
// this.LOCK.lock();
synchronized (this.outputStream) {
///System.out.println("execute start." + cmdList.toString().replace("\n\r", "|"));
try {
if (this.outputStream == null) {
this.outputStream = channelShell.getOutputStream();
}
for (String cmd : cmdList) {
this.outputStream.write(cmd.getBytes());
}
if (appendLast) {
this.outputStream.write("echo '++CMD LAST++' \n\r".getBytes());
}
this.outputStream.flush();
Thread.sleep(4000);
} catch (IOException e) {
e.printStackTrace();
log.error("shellUtils execute error IOException!", e);
} catch (InterruptedException e) {
e.printStackTrace();
log.error("shellUtils execute error InterruptedException! ", e);
} finally {
// this.LOCK.unlock();
log.info("shellUtils execute end.");
}
}
}
public String outCmdResult() {
try {
this.LOCK.lock();
if (this.inputStream == null) {
this.inputStream = this.channelShell.getInputStream();
}
if (this.in == null) {
this.in = new BufferedReader(new InputStreamReader(this.inputStream, DEFAULT_CHART));
}
} catch (IOException e) {
e.printStackTrace();
log.error("shellUtils outCmdResult error IOException!", e);
} finally {
this.LOCK.unlock();
}
synchronized (this.in) {
StringBuffer buff = new StringBuffer();
try {
log.info("shellUtils outCmdResult >>>>>>>inputStream start.");
while (in.ready()) {
String line = in.readLine();
buff.append("\n");
buff.append(line);
if (line.startsWith("[") && line.contains("@") && line.contains("]# ")) {
//不打印
} else {
if (StringUtils.isNotBlank(line)) {
//System.out.println(line);
//多余输出不打印
if(line.startsWith("download_baihang:")){
log.info(line);
}
}
}
if (line.equals("++CMD LAST++")) {
break;
}
}
Thread.sleep(1000);
log.info("shellUtils outCmdResult >>>>>>>inputStream end.");
} catch (IOException e) {
e.printStackTrace();
log.error("shellUtils outCmdResult error IOException!", e);
} catch (InterruptedException e) {
e.printStackTrace();
log.error("shellUtils outCmdResult error InterruptedException!", e);
}
return buff.toString();
}
}
public String getResult() {
synchronized (this.inputStream) {
try {
if (this.inputStream == null) {
this.inputStream = this.channelShell.getInputStream();
}
} catch (IOException e) {
e.printStackTrace();
log.error("shellUtils getResult error IOException!", e);
}
}
synchronized (this.in) {
StringBuffer buff = new StringBuffer();
try {
if (this.in == null) {
this.in = new BufferedReader(new InputStreamReader(this.inputStream, DEFAULT_CHART));
}
log.info("shellUtils getResult >>>>>>>inputStream start.");
Thread.sleep(1000);
while (in.ready()) {
String line = in.readLine();
//System.out.println(line);
/* if (line.startsWith("[") && line.contains("@") && line.contains("]# ")) {
//不打印
} else {
if (StringUtils.isNotBlank(line)) {
//多余日志不打印
//log.info(line);
}
}*/
if ("++CMD LAST++".equals(line)) {
break;
} else {
if (line.startsWith("{\"reqID\":")) {
if (buff.length() == 0) {
buff.append("[");
buff.append(line.trim());
} else {
buff.append(",");
buff.append(line.trim());
}
}
}
}
if (buff.toString().startsWith("[") && !buff.toString().endsWith("]")) {
buff.append("]");
}
Thread.sleep(1000);
log.info("shellUtils getResult >>>>>>>inputStream end.");
} catch (IOException e) {
e.printStackTrace();
log.error("shellUtils getResult error IOException!", e);
} catch (InterruptedException e) {
e.printStackTrace();
log.error("shellUtils getResult error InterruptedException!", e);
}
return buff.toString();
}
}
}
package cn.quantgroup.report.service.thirdpartymonitor;
public class HBaseConfig {
public final static ThreadLocal<Boolean> readHBaseFirst = new ThreadLocal<Boolean>() {
public Boolean initialValue() {
return true;
}
};
public static void disableReadHBaseFirst() {
readHBaseFirst.set(false);
}
public static void enableReadHBaseFirst() {
readHBaseFirst.set(true);
}
}
package cn.quantgroup.report.service.thirdpartymonitor;
import cn.quantgroup.report.error.QGExceptionType;
import cn.quantgroup.report.error.QGPreconditions;
import cn.quantgroup.report.utils.ClockUtils;
//import com.lkb.data.hbase.utils.RowKeyTool;
import lombok.Builder;
import lombok.Data;
/*import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;*/
@Data
public class ThirdPartyBean {
/* public static final TableName TABLE_NAME = TableName.valueOf("third-party-info");
public static final byte[] COLUMN_FAMILY = Bytes.toBytes("f");
public static final byte[] ID_NO = Bytes.toBytes("i");
public static final byte[] DATA_SOURCE = Bytes.toBytes("s");
public static final byte[] REQUEST_TIME = Bytes.toBytes("t");
public static final byte[] REQUEST_MESSAGE = Bytes.toBytes("q");
public static final byte[] RESPONSE_MESSAGE = Bytes.toBytes("p");
private String id;
private String requestTime;
private String datasource;
private String request;
private String response;
@Builder
public ThirdPartyBean(String id, String datasource, String request, String response) {
this.id = id;
this.datasource = datasource; //urltype
this.request = request;
this.response = response;
this.requestTime = ClockUtils.hBaseDateTimeStringFromTimestamp(ClockUtils.now());
}
public byte[] findRowKey() {
QGPreconditions.checkArgument(this.id != null && datasource != null, QGExceptionType.COMMON_STRING_PARAM_IS_NULL);
byte[] prefix = RowKeyTool.getMD5Prefix(id, 4);
QGPreconditions.checkArgument(prefix != null, QGExceptionType.COMMON_STRING_PARAM_IS_NULL);
return Bytes.add(prefix, RowKeyTool.createRowKeyField(id), Bytes.toBytes("|" + datasource));
}
public Put generatePut() {
byte[] rk = findRowKey();
Put put = new Put(rk);
put.addColumn(COLUMN_FAMILY, ID_NO, Bytes.toBytes(id));
put.addColumn(COLUMN_FAMILY, DATA_SOURCE, Bytes.toBytes(datasource));
put.addColumn(COLUMN_FAMILY, REQUEST_TIME, Bytes.toBytes(requestTime));
put.addColumn(COLUMN_FAMILY, REQUEST_MESSAGE, Bytes.toBytes(request));
put.addColumn(COLUMN_FAMILY, RESPONSE_MESSAGE, Bytes.toBytes(response));
return put;
}*/
}
package cn.quantgroup.report.service.thirdpartymonitor;
import cn.quantgroup.report.cmpt.CommonAlarmCmpt;
import cn.quantgroup.report.constant.TransactionCodeEnum;
import cn.quantgroup.report.domain.master.*;
import cn.quantgroup.report.enums.RequestUrlType;
import cn.quantgroup.report.mapper.master.*;
import cn.quantgroup.report.service.usersdk.IUserCenterService;
import com.google.common.base.Stopwatch;
//import com.lkb.data.hbase.dataservice.DataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.FastDateFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class ThirdpartyApiMonitorService { //extends DataService
private static final FastDateFormat dateFormat = FastDateFormat.getInstance("yyyyMM", TimeZone.getDefault(), Locale.getDefault());
private static final String DATA_PRICE_CACHE = "MONITOR.DATA_PRICE_CACHE";
private static final String DATA_QRY_RECORD = "MONITOR.DATA_QRY_RECORD.";
private static final String DATA_ACCOUNT = "MONITOR.ACCOUNT.";
@Autowired
private UnionPayApiRequestEventMapper unionPayApiRequestEventMapper;
@Autowired
private CommonApiReqestEventMapper commonApiReqestEventMapper;
@Autowired
private ApiRequestLogPOMapper apiRequestLogPOMapper;
@Autowired
private TransactionLogPOMapper transactionLogPOMapper;
@Autowired
private CostRecordPOMapper costRecordPOMapper;
@Autowired
private DataPriceConfigPOMapper dataPriceConfigPOMapper;
@Autowired
private AccountPOMapper accountPOMapper;
@Autowired
private CommonAlarmCmpt commonAlarmCmpt;
@Autowired
private IUserCenterService userCenterService;
@Autowired
private RedisTemplate redisTemplate;
private static Map<String, DataPriceConfigPO> dataPriceMap = null;
@Value("${isDebug}")
private Boolean isDebug;
/**
*
* @param id 用户标示
* @param urlType 数据源类型
* @param isBilling 是否收费(0,收费 1 ,不收费)
* @param responseMessage 返回的信息(成功,权限不足,参数错误。。。等)
* @param millis 该次请求耗时
* @param businessCode 返回码,与返回信息对应
* 修改主要是isBilling 之后将增加是否计费字段,废弃之前httpcode都为200的字段
*/
public void create(String id, RequestUrlType urlType, String isBilling, String responseMessage, int millis, String businessCode, String...args) {
Stopwatch stopwatch = Stopwatch.createStarted();
switch (urlType) {
case CreditCardRecord:
unionPayApiRequestEventMapper.insert(UnionPayApiRequestEvent.builder()
.bankCardNo(id)
.mills(millis)
.requestUrlType(urlType.name())
.businessCode(businessCode)
.timeCreated(new Date())
.build());
break;
//量化派数据产品输出黑名等级
case LhpBlackListLevel:
commonApiReqestEventMapper.insert(CommonWithBillingApiRequestEvent.builder().userId(id)
.isBilling(isBilling)
.mills(millis)
.requestUrlType(urlType.name())
.responseCode(businessCode)
.responseMessage(responseMessage)
.timeCreated(new Date()).build());
break;
default:
log.error("暂时未监控{}", urlType.name());
break;
}
log.info("保存调用记录完成, id: {} , urlType: {} , 耗时: {} ", id, urlType, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
public void saveLog(RequestUrlType urlType, String code, String msg, String flag, int millis) {
try {
apiRequestLogPOMapper.insert(ApiRequestLogPO.builder()
.urlType(urlType.name())
.resCode(code)
.resMsg(msg)
.hitFlag(flag)
.timeElapse(millis)
.createTime(new Date())
.suffix(dateFormat.format(new Date())).build());
}catch (Exception e){
log.error("保存接口请求记录失败", e);
}
}
public void saveTransactionLog(RequestUrlType urlType, String transactionId, String uuid, TransactionCodeEnum code) {
try {
transactionLogPOMapper.insert(TransactionLogPO.builder()
.transactionId(transactionId)
.uuid(uuid)
.urlType(urlType.name())
.code(code.getCode())
.timeCreated(new Date()).build());
}catch (Exception e){
log.error("保存接口请求记录TransactionLog失败", e);
}
}
public void saveTransactionLogByPhone(RequestUrlType urlType, String transactionId, String phone, TransactionCodeEnum code) {
try {
String uuid = userCenterService.getUuidByPhoneNumber(phone);
log.info("TransactionLog 查询 phone: {}, uuid: {}", phone, uuid);
transactionLogPOMapper.insert(TransactionLogPO.builder()
.transactionId(transactionId)
.uuid(uuid)
.urlType(urlType.name())
.code(code.getCode())
.timeCreated(new Date()).build());
}catch (Exception e){
log.error("保存接口请求记录TransactionLog失败", e);
}
}
public void saveTransactionLogByIdentifyNumber(RequestUrlType urlType, String transactionId, String identifyNumber, TransactionCodeEnum code) {
try {
String uuid = userCenterService.getUuidByIdentityNumber(identifyNumber);
log.info("TransactionLog 查询 identifyNumber: {}, uuid: {}", identifyNumber, uuid);
transactionLogPOMapper.insert(TransactionLogPO.builder()
.transactionId(transactionId)
.uuid(uuid)
.urlType(urlType.name())
.code(code.getCode())
.timeCreated(new Date()).build());
}catch (Exception e){
log.error("保存接口请求记录TransactionLog失败", e);
}
}
public void recordCostInDb(RequestUrlType urlType, String sourceName, Integer invokeTimes, BigDecimal cost, BigDecimal balance) {
costRecordPOMapper.insert(CostRecordPO.builder()
.urlType(urlType.name())
.sourceName(sourceName)
.invokeTimes(invokeTimes)
.cost(cost)
.balance(balance)
.createTime(new Date())
.suffix(dateFormat.format(new Date())).build());
}
public DataPriceConfigPO qryDataPrice(RequestUrlType urlType) {
try {
dataPriceMap = redisTemplate.opsForHash().entries(DATA_PRICE_CACHE);
if (dataPriceMap == null || dataPriceMap.size() == 0) {
synchronized (ThirdpartyApiMonitorService.class) {
if (dataPriceMap == null || dataPriceMap.size() == 0) {
List<DataPriceConfigPO> dataPriceConfigPOS = dataPriceConfigPOMapper.queryByParams(DataPriceConfigPO.builder().status("1").build());
dataPriceMap = new ConcurrentHashMap<>();
for (DataPriceConfigPO dataPriceConfigPO : dataPriceConfigPOS) {
dataPriceMap.put(dataPriceConfigPO.getUrlType(), dataPriceConfigPO);
}
redisTemplate.opsForHash().putAll(DATA_PRICE_CACHE, dataPriceMap);
}
}
}
}catch (Exception e){
log.error("获取配置数据失败", e);
return null;
}
return dataPriceMap.get(urlType.name());
}
public AccountPO qryAccount(String sourceName) {
List<AccountPO> accountPOS = accountPOMapper.selectByExample(AccountPO.builder().sourceName(sourceName).status("1").build());
return accountPOS.get(0);
}
private void updateAccount(AccountPO accountPO) {
accountPOMapper.updateByParams(accountPO);
}
public void recordCost(RequestUrlType urlType, String sourceName){
Long times = redisTemplate.opsForValue().increment(DATA_QRY_RECORD + urlType.name(), 1l);
DataPriceConfigPO dataPriceConfigPO = qryDataPrice(urlType);
if(times >= dataPriceConfigPO.getFrequency()){
String lockKey = DATA_ACCOUNT + sourceName;
boolean result = lock(lockKey, 60);
if(!result) return;
try{
AccountPO accountPO = qryAccount(sourceName);
BigDecimal blance = accountPO.getBlance();
BigDecimal cost = dataPriceConfigPO.getPrice().multiply(BigDecimal.valueOf(times));
blance = blance.subtract(cost);
accountPO.setBlance(blance);
if(blance.compareTo(accountPO.getThershold()) < 0){
commonAlarmCmpt.alarm("Warn", "三方数据源告警", "数据源【"+ sourceName +"】 余额已不足"+accountPO.getThershold()+", 目前账户余额为"+blance);
}
updateAccount(accountPO);
recordCostInDb(urlType, sourceName, times.intValue(), cost, blance);
redisTemplate.delete(DATA_QRY_RECORD + urlType.name());
}catch (Exception e){
log.error("扣费异常, requestUrlType: {} ", urlType, e);
}finally {
unlock(lockKey);
}
}
}
public void saveInHBase(RequestUrlType urlType, String id, String requestJson, String responseJson) {
}
/*public void saveInHBase(RequestUrlType urlType, String id, String requestJson, String responseJson) {
Stopwatch stopwatch = Stopwatch.createStarted();
if (BooleanUtils.isTrue(isDebug)) {
log.info("测试环境下不写入数据,urlType={},id={},requestJson={},responseJson={}", urlType, MaskedUtils.buildMaskedCommonString(id), requestJson, responseJson);
return;
}
Table table = null;
try {
table = connection.getTable(ThirdPartyBean.TABLE_NAME);
ThirdPartyBean thirdPartyDataRow = new ThirdPartyBean(id, urlType.name(), requestJson, responseJson);
Put put = thirdPartyDataRow.generatePut();
List<Get> rows = Lists.newArrayList(new Get(thirdPartyDataRow.findRowKey()));
List<String> contents = Lists.newArrayList(JSON.toJSONString(thirdPartyDataRow));
KafkaService.getInstance.process(table.existsAll(rows), ThirdPartyDataRow.TABLE_NAME.toString(), contents);
table.put(put);
} catch (Exception ex) {
log.error("Put the data error! urlType:{},id:{},requestJson:{},responseJson:{}", urlType, id, requestJson, responseJson, ex);
} finally {
IOUtils.closeQuietly(table);
}
log.info("数据源保存hbase完毕, id: {} , urlType: {} , 耗时: {} ", id, urlType, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}*/
/* public String loadInHBase(RequestUrlType urlType, String id) {
return loadInHBaseAndCheckTimeOut(urlType, id, 60);
}
public <T> T loadObjectInHBase(RequestUrlType requestUrlType, String id, TypeReference<T> clazz) {
String responseInHBase = loadInHBase(requestUrlType, id);
if (StringUtils.isNotBlank(responseInHBase)) {
T result = JSON.parseObject(responseInHBase, clazz);
if (result != null) {
log.info("直接从hbase拿到数据,responseInHBase:{}", responseInHBase);
}
return result;
}
return null;
}*/
/* public <T> T loadObjectInHBase(RequestUrlType requestUrlType, String id, Class<T> clazz) {
String responseInHBase = loadInHBase(requestUrlType, id);
if (StringUtils.isNotBlank(responseInHBase)) {
T result = JSON.parseObject(responseInHBase, clazz);
return result;
}
return null;
}*/
/*public JSONObject loadObjectInHbaseTimeOut(RequestUrlType urlType, String id, Integer days){
String data = loadInHBaseAndCheckTimeOut(urlType, id, days);
if(StringUtils.isNotBlank(data)){
return JSON.parseObject(data, JSONObject.class);
}
return null;
}*/
public String loadInHBaseAndCheckTimeOut(RequestUrlType urlType, String id, Integer days) {
return null;
}
/*public String loadInHBaseAndCheckTimeOut(RequestUrlType urlType, String id, Integer days) {
if (!HBaseConfig.readHBaseFirst.get().booleanValue()) {
log.info("不读取hbase哦噢噢噢噢");
return null;
}
QGPreconditions.checkArgument(StringUtils.isNotEmpty(id), QGExceptionType.COMMON_STRING_PARAM_IS_NULL);
QGPreconditions.checkArgument(urlType != null, QGExceptionType.COMMON_STRING_PARAM_IS_NULL);
Table table = null;
try {
table = connection.getTable(ThirdPartyDataRow.TABLE_NAME);
byte[] prefix = RowKeyTool.getMD5Prefix(id, 4);
if (prefix == null) {
log.error("The uuid is is error! urlType:{},id:{}", urlType, id);
return null;
}
Get get = new Get(Bytes.add(prefix, RowKeyTool.createRowKeyField(id), Bytes.toBytes("|" + urlType.name())));
Result result = table.get(get);
if (result == null || result.isEmpty()) {
return null;
}
byte[] responseMessage = result.getValue(ThirdPartyDataRow.COLUMN_FAMILY, ThirdPartyDataRow.RESPONSE_MESSAGE);
byte[] requestMessage = result.getValue(ThirdPartyDataRow.COLUMN_FAMILY, ThirdPartyDataRow.REQUEST_MESSAGE);
if (days != null && days.intValue() > 0) {
byte[] requestTime = result.getValue(ThirdPartyDataRow.COLUMN_FAMILY, ThirdPartyDataRow.REQUEST_TIME);
if (requestTime == null || requestTime.length == 0) {
return null;
}
long timeCreated = ClockUtils.hBaseParseTimestampFromDateTimeString(Bytes.toString(requestTime));
if (ClockUtils.getDaysBetween(timeCreated, ClockUtils.now()) > days) {
return null;
}
}
if (urlType.equals(HaoAnIdentityCheck)){
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestMessage",Bytes.toString(requestMessage));
jsonObject.put("responseMessage",Bytes.toString(responseMessage));
return jsonObject.toJSONString();
}
log.info("从habse拿到数据 urlType:{},id:{}", urlType, id);
return Bytes.toString(responseMessage);
} catch (Exception ex) {
log.error("Get the data error! urlType:{},id:{}", urlType, id, ex);
return null;
} finally {
IOUtils.closeQuietly(table);
}
}
*/
/**
* lock
*
*/
public boolean lock(String lockKey, long timeOutSecond) {
long nano = System.nanoTime();
final Random r = new Random();
try {
while ((System.nanoTime() - nano) < 8000000000L) {
RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
boolean exits = connection.setNX(lockKey.getBytes(), new byte[0]);
connection.close();
//获取锁
if (exits) {
redisTemplate.expire(lockKey, timeOutSecond, TimeUnit.SECONDS);
return true;
}
try {
Thread.sleep(3, r.nextInt(500));
} catch (InterruptedException e) {
log.error("{}", e.getMessage(), e);
}
}
}catch (Exception e){
unlock(lockKey);
}
return false;
}
/**
* unlock
*
* @param lockKey
*/
public void unlock(String lockKey) {
//防止死锁
try {
RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
connection.del(lockKey.getBytes());
connection.close();
}catch (Exception e){
log.error("{}", e.getMessage(), e);
}
}
}
package cn.quantgroup.report.service.usersdk;
import cn.quantgroup.report.domain.sdk.SdkUser;
import cn.quantgroup.report.domain.xyqbuser.User;
import cn.quantgroup.report.domain.xyqbuser.UserDetail;
public interface IUserCenterService {
/**
* 根据手机号查用户
* @param phoneNo
* @return
*/
public SdkUser getSdkUserByPhoneNo(String phoneNo);
/**
* 根据uuid查用户
* @param uuid
* @return
*/
public SdkUser getSdkUserByUuid(String uuid);
public User getSdkUserByUserId(String userId);
public UserDetail getSdkUserDetailByUserId(Long userId);
public Long getUserIdByIdentityNumberAndName(String identityNumber, String name);
public Long getUserIdByIdentityNumber(String identityNumber);
public String getUuidByIdentityNumber(String identityNumber);
public String getUuidByPhoneNumber(String phoneNumber);
public SdkUser getUserFullInfoByUuid(String uuid);
}
package cn.quantgroup.report.service.usersdk.impl;
import cn.quantgroup.motan.bean.UserInfo;
import cn.quantgroup.motan.retbean.XUser;
import cn.quantgroup.motan.retbean.XUserDetail;
import cn.quantgroup.motan.retbean.XUserFullInfo;
import cn.quantgroup.motan.vo.UserSysResult;
import cn.quantgroup.report.cmpt.CommonAlarmCmpt;
import cn.quantgroup.report.domain.sdk.SdkUser;
import cn.quantgroup.report.domain.xyqbuser.User;
import cn.quantgroup.report.error.QGExceptionType;
import cn.quantgroup.report.error.QGPreconditions;
import cn.quantgroup.report.service.usersdk.IUserCenterService;
import cn.quantgroup.report.domain.xyqbuser.UserDetail;
import cn.quantgroup.report.service.http.IHttpService;
import cn.quantgroup.user.IUserSdkService;
import cn.quantgroup.user.UserSdkServiceFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
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;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class UserCenterServiceImpl implements IUserCenterService {
private static final Logger LOGGER = LoggerFactory.getLogger(UserCenterServiceImpl.class);
@Autowired
@Qualifier("httpClient")
private CloseableHttpClient httpClient;
@Value("${user.sdk.url}")
private String userSysUrl;
private IUserSdkService userSdkService;
@Autowired
private CommonAlarmCmpt iMonitorAlarmService;
@Value("${b.user.url}")
private String bUserUrl;
@Autowired
private IHttpService iHttpService;
@PostConstruct
private void init() {
userSdkService = UserSdkServiceFactory.generateSDKService(userSysUrl, httpClient);
}
@Override
public SdkUser getSdkUserByPhoneNo(String phoneNo) {
try{
UserSysResult<UserInfo> findUserInfoByPhone = userSdkService.findUserInfoByPhone(phoneNo);
SdkUser sdkUser = new SdkUser();
if(findUserInfoByPhone.isSuccess()&&findUserInfoByPhone.getData()!=null){
UserInfo data = findUserInfoByPhone.getData();
BeanUtils.copyProperties(data, sdkUser);
return sdkUser;
}
}catch(Exception e){
LOGGER.error("查询用户用心异常,phoneNo: {} , {}",phoneNo,e);
iMonitorAlarmService.alarm("WARN","用户中心查询异常告警","接口 : findUserInfoByPhone(phoneNo) , 异常信息:"+e.getMessage());
}
return null;
}
@Override
public SdkUser getSdkUserByUuid(String uuid) {
try{
UserSysResult<UserInfo> findUserInfoByPhone = userSdkService.findUserInfoByUuid(uuid);
SdkUser sdkUser = new SdkUser();
LOGGER.info("用户中心查询uuid: {} , SDKUser结果:{}", uuid, findUserInfoByPhone);
if(findUserInfoByPhone.isSuccess()&&findUserInfoByPhone.getData()!=null){
UserInfo data = findUserInfoByPhone.getData();
BeanUtils.copyProperties(data, sdkUser);
return sdkUser;
}
}catch(Exception e){
LOGGER.error("查询用户用心异常,uuid: {} , {}",uuid,e);
iMonitorAlarmService.alarm("WARN","用户中心查询异常告警","接口 : findUserInfoByUuid(uuid) , 异常信息:"+e.getMessage());
}
return null;
}
@Override
public User getSdkUserByUserId(String userId) {
try{
UserSysResult<XUser> userByUserId = userSdkService.findUserByUserId(Long.parseLong(userId));
User user = new User();
if(userByUserId.isSuccess()&&userByUserId.getData()!=null){
XUser data = userByUserId.getData();
BeanUtils.copyProperties(data, user);
return user;
}
}catch(Exception e){
LOGGER.error("查询用户用心异常,uuid: {} , {}",userId,e);
iMonitorAlarmService.alarm("WARN","用户中心查询异常告警","接口 : findUserByUserId(userId) , 异常信息:"+e.getMessage());
}
return null;
}
@Override
public UserDetail getSdkUserDetailByUserId(Long userId) {
try{
UserSysResult<XUserDetail> userDetailUserSysResult = userSdkService.findUserDetailByUserId(userId);
UserDetail userDetail = new UserDetail();
if(userDetailUserSysResult.isSuccess() && userDetailUserSysResult.getData()!=null){
XUserDetail xUserDetail = userDetailUserSysResult.getData();
BeanUtils.copyProperties(xUserDetail, userDetail);
return userDetail;
}
}catch(Exception e){
LOGGER.error("查询用户中心用户详情异常, userId: {} , {}", userId, e);
iMonitorAlarmService.alarm("WARN","用户中心查询异常告警","接口 : getSdkUserDetailByUserId(userId) , 异常信息:"+e.getMessage());
}
return null;
}
@Override
public Long getUserIdByIdentityNumberAndName(String identityNumber, String name) {
UserSysResult<List<XUserDetail>> userDetailBySpecification = userSdkService.queryUserDetailBySpecification(null, null, identityNumber);
LOGGER.info("getUserIdByIdentityNumberAndName, identityNumber: {} , name:{}, 结果:{}", identityNumber, name, JSON.toJSONString(userDetailBySpecification));
List<UserDetail> userDetails = new ArrayList<>();
if(userDetailBySpecification.isSuccess()&&userDetailBySpecification.getData()!=null){
List<XUserDetail> xUserDetails = userDetailBySpecification.getData();
xUserDetails.forEach(xUserDetail2 -> {
UserDetail userDetail = new UserDetail();
BeanUtils.copyProperties(xUserDetail2, userDetail);
userDetails.add(userDetail);
});
QGPreconditions.checkArgument(CollectionUtils.isNotEmpty(userDetails), QGExceptionType.XYQB_USER_NOT_EXSIT);
Optional<UserDetail> optional = userDetails.parallelStream().filter(detail -> StringUtils.equals(detail.getName(), name)).findFirst();
boolean isPresent = optional.isPresent();
QGPreconditions.checkArgument(isPresent, QGExceptionType.XYQB_USER_NOT_MATCH);
long userId = optional.get().getUserId();
return userId;
}
return null;
}
public Long getUserIdByIdentityNumber(String identityNumber) {
UserSysResult<List<XUserDetail>> userDetailBySpecification = userSdkService.queryUserDetailBySpecification(null, null, identityNumber);
LOGGER.info("getUserIdByIdentityNumber, identityNumber:{}, 结果:{}", identityNumber, JSON.toJSONString(userDetailBySpecification));
List<UserDetail> userDetails = new ArrayList<>();
if(userDetailBySpecification.isSuccess()&&userDetailBySpecification.getData()!=null){
List<XUserDetail> xUserDetails = userDetailBySpecification.getData();
xUserDetails.forEach(xUserDetail2 -> {
UserDetail userDetail = new UserDetail();
BeanUtils.copyProperties(xUserDetail2, userDetail);
userDetails.add(userDetail);
});
QGPreconditions.checkArgument(CollectionUtils.isNotEmpty(userDetails), QGExceptionType.XYQB_USER_NOT_EXSIT);
Optional<UserDetail> optional = userDetails.parallelStream().filter(detail -> (detail.getUserId() != null)).findFirst();
boolean isPresent = optional.isPresent();
QGPreconditions.checkArgument(isPresent, QGExceptionType.XYQB_USER_NOT_MATCH);
long userId = optional.get().getUserId();
return userId;
}
return null;
}
@Override
public String getUuidByIdentityNumber(String identityNumber) {
try {
UserSysResult<List<XUserDetail>> userDetailBySpecification = userSdkService.queryUserDetailBySpecification(null, null, identityNumber);
LOGGER.info("getUuidByIdentityNumber, identityNumber: {} , 结果:{}", identityNumber, JSON.toJSONString(userDetailBySpecification));
List<UserDetail> userDetails = new ArrayList<>();
if (userDetailBySpecification.isSuccess() && userDetailBySpecification.getData() != null) {
List<XUserDetail> xUserDetails = userDetailBySpecification.getData();
xUserDetails.forEach(xUserDetail2 -> {
UserDetail userDetail = new UserDetail();
BeanUtils.copyProperties(xUserDetail2, userDetail);
userDetails.add(userDetail);
});
QGPreconditions.checkArgument(CollectionUtils.isNotEmpty(userDetails), QGExceptionType.XYQB_USER_NOT_EXSIT);
Optional<UserDetail> optional = userDetails.parallelStream().filter(detail -> (detail.getUserId() != null)).findFirst();
boolean isPresent = optional.isPresent();
QGPreconditions.checkArgument(isPresent, QGExceptionType.XYQB_USER_NOT_MATCH);
long userId = optional.get().getUserId();
User user = getSdkUserByUserId(String.valueOf(userId));
if (user == null) {
LOGGER.info("查询用户用心,identityNumber: {} , user {}",identityNumber, user);
return null;
}
return user.getUuid();
}
}catch (Exception e){
LOGGER.error("查询用户用心异常,identityNumber: {} , {}",identityNumber,e);
}
return null;
}
@Override
public String getUuidByPhoneNumber(String phoneNumber) {
if(StringUtils.isEmpty(phoneNumber)){
return null;
}
String uuid = null;
try {
SdkUser user = getSdkUserByPhoneNo(phoneNumber);
if (user != null) {
uuid = user.getUuid();
}
}catch (Exception e){
LOGGER.error("查询用户用心异常,phoneNumber: {} , {}",phoneNumber,e);
}
return uuid;
}
@Override
public SdkUser getUserFullInfoByUuid(String uuid) {
try{
if(StringUtils.isNotBlank(uuid)){
if(uuid.startsWith("600_")){
return getBUserInfo(uuid);
}else{
UserSysResult<XUserFullInfo> findUserInfoByPhone = userSdkService.findUserFullInfoByUuid(uuid);
SdkUser sdkUser = new SdkUser();
LOGGER.info("三方数据源查询用户中心用户全量信息结果, uuid: {} , result:{}", uuid, findUserInfoByPhone, JSON.toJSONString(findUserInfoByPhone));
if(findUserInfoByPhone.isSuccess()&&findUserInfoByPhone.getData()!=null){
XUserFullInfo data = findUserInfoByPhone.getData();
BeanUtils.copyProperties(data, sdkUser);
return sdkUser;
}
}
}else{
LOGGER.error("三方数据源查询用户中心用户全量信息结果用户Id不正确, uuid: {} ", uuid);
}
}catch(Exception e){
LOGGER.error("三方数据源查询用户中心用户全量信息结果用户异常,uuid:{}, {}",uuid,e);
}
return null;
}
public SdkUser getBUserInfo(String uuid){
try{
//bUserUrl = "http://192.168.29.45:9059/ex/user/query";//本地联调
String bUserInfo = iHttpService.get(bUserUrl, ImmutableMap.of("uuid", uuid));
LOGGER.info("外部渠道(B端)查询用户信息结果, uuid: {} ,result:{}", uuid, bUserInfo);
if(StringUtils.isNotBlank(bUserInfo)){
JSONObject jsonObject = JSON.parseObject(bUserInfo);
Integer code = jsonObject.getInteger("code");
if(0==code){
SdkUser sdkUser = new SdkUser();
JSONObject info = jsonObject.getJSONObject("body");
sdkUser.setPhoneNo(info.getString("phoneNo"));
sdkUser.setIdNo(info.getString("idNo"));
sdkUser.setName(info.getString("name"));
sdkUser.setUuid(uuid);
//2019.10.10 B端用户查询增加md5加密
sdkUser.setIdNoMd5(info.getString("idNoMd5"));
sdkUser.setPhoneNoMd5(info.getString("phoneNoMd5"));
return sdkUser;
}
}
}catch(Exception e){
LOGGER.error("外部渠道(B端)查询用户信息异常, uuid: {} ", uuid, e);
}
return null;
}
}
package cn.quantgroup.report.service.xyqbuser;
import cn.quantgroup.report.error.QGExceptionType;
import cn.quantgroup.report.mapper.xyqbuser.UserMapper;
import cn.quantgroup.report.domain.xyqbuser.User;
import cn.quantgroup.report.domain.xyqbuser.UserDetail;
import cn.quantgroup.report.error.QGPreconditions;
import cn.quantgroup.report.mapper.xyqbuser.UserDetailMapper;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
public class XyqbUserService {
@Autowired
private UserDetailMapper userDetailMapper;
@Autowired
private UserMapper userMapper;
public Long findUserIdByIdentityNumberAndName(String identityNumber, String name) {
List<UserDetail> userDetailList = userDetailMapper.selectByIdentityNumber(identityNumber);
log.info("91征信匹配查询用户详细信息, identityNumber:{}, name:{}, 结果:{}", identityNumber, name, JSON.toJSONString(userDetailList));
QGPreconditions.checkArgument(CollectionUtils.isNotEmpty(userDetailList), QGExceptionType.XYQB_USER_NOT_EXSIT);
Optional<UserDetail> optional = userDetailList.parallelStream().filter(detail -> StringUtils.equals(detail.getName(), name)).findFirst();
QGPreconditions.checkArgument(optional.isPresent(), QGExceptionType.XYQB_USER_NOT_MATCH);
return optional.get().getUserId();
}
public User getUserByUUid(String uuid) {
return userMapper.selectByUuid(uuid);
}
public User getUserById(Long id) {
return userMapper.selectByPrimaryKey(id);
}
public UserDetail getUserDetailByUserID(Long userId) {
return userDetailMapper.selectByUserId(userId);
}
}
package cn.quantgroup.report.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Hashtable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 校验身份证信息
*
* @author renfeng
* @date: 2016年9月27日 下午5:38:07
* @version v1.0
*/
public class CheckIdCard {
public static void main(String[] args) {
String IDStr = "422204710412473";
// String IDStr = "440301197812121292";
String result = trans15bitTo18bit(IDStr);
System.out.print("您的18位身份证号是:" + result);
System.out.println(CheckIdCard.IDCardValidate(IDStr));
}
/**
* 功能:身份证的有效验证
*
* @param IDStr
* 身份证号
* @return 有效:返回"" 无效:返回String信息
* @throws ParseException
*/
@SuppressWarnings("rawtypes")
public static String IDCardValidate(String IDStr) {
try{
String errorInfo = "";// 记录错误信息
String[] ValCodeArr = { "1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2" };
String[] Wi = { "7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2" };
String Ai = "";
//号码的长度 15位或18位
if (IDStr.length() != 15 && IDStr.length() != 18) {
errorInfo = "身份证号码长度应该为15位或18位。";
return errorInfo;
}
//数字 除最后以为都为数字
if (IDStr.length() == 18) {
Ai = IDStr.substring(0, 17);
} else if (IDStr.length() == 15) {
Ai = IDStr.substring(0, 6) + "19" + IDStr.substring(6, 15);
}
if (isNumeric(Ai) == false) {
errorInfo = "身份证15位号码都应为数字 ; 18位号码除最后一位外,都应为数字。";
return errorInfo;
}
//出生年月是否有效
String strYear = Ai.substring(6, 10);// 年份
String strMonth = Ai.substring(10, 12);// 月份
String strDay = Ai.substring(12, 14);// 月份
if (isDataFormat(strYear + "-" + strMonth + "-" + strDay) == false) {
errorInfo = "身份证生日无效。";
return errorInfo;
}
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) > 150
|| (gc.getTime().getTime() - s.parse(strYear + "-" + strMonth + "-" + strDay).getTime()) < 0) {
errorInfo = "身份证生日不在有效范围。";
return errorInfo;
}
if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) {
errorInfo = "身份证月份无效";
return errorInfo;
}
if (Integer.parseInt(strDay) > 31 || Integer.parseInt(strDay) == 0) {
errorInfo = "身份证日期无效";
return errorInfo;
}
//地区码时候有效
Hashtable h = GetAreaCode();
if (h.get(Ai.substring(0, 2)) == null) {
errorInfo = "身份证地区编码错误。";
return errorInfo;
}
//判断最后一位的值
int TotalmulAiWi = 0;
for (int i = 0; i < 17; i++) {
TotalmulAiWi = TotalmulAiWi + Integer.parseInt(String.valueOf(Ai.charAt(i))) * Integer.parseInt(Wi[i]);
}
int modValue = TotalmulAiWi % 11;
String strVerifyCode = ValCodeArr[modValue];
Ai = Ai + strVerifyCode;
if (IDStr.length() == 18) {
if (Ai.equalsIgnoreCase(IDStr) == false) {
errorInfo = "身份证无效,不是合法的身份证号码";
return errorInfo;
}
}
}catch(Exception e){
e.printStackTrace();
return "";
}
return "";
}
/**
* 功能:设置地区编码
*
* @return Hashtable 对象
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Hashtable GetAreaCode() {
Hashtable hashtable = new Hashtable();
hashtable.put("11", "北京");
hashtable.put("12", "天津");
hashtable.put("13", "河北");
hashtable.put("14", "山西");
hashtable.put("15", "内蒙古");
hashtable.put("21", "辽宁");
hashtable.put("22", "吉林");
hashtable.put("23", "黑龙江");
hashtable.put("31", "上海");
hashtable.put("32", "江苏");
hashtable.put("33", "浙江");
hashtable.put("34", "安徽");
hashtable.put("35", "福建");
hashtable.put("36", "江西");
hashtable.put("37", "山东");
hashtable.put("41", "河南");
hashtable.put("42", "湖北");
hashtable.put("43", "湖南");
hashtable.put("44", "广东");
hashtable.put("45", "广西");
hashtable.put("46", "海南");
hashtable.put("50", "重庆");
hashtable.put("51", "四川");
hashtable.put("52", "贵州");
hashtable.put("53", "云南");
hashtable.put("54", "西藏");
hashtable.put("61", "陕西");
hashtable.put("62", "甘肃");
hashtable.put("63", "青海");
hashtable.put("64", "宁夏");
hashtable.put("65", "新疆");
hashtable.put("71", "台湾");
hashtable.put("81", "香港");
hashtable.put("82", "澳门");
hashtable.put("91", "国外");
return hashtable;
}
/**
* 验证日期字符串是否是YYYY-MM-DD格式
*
* @param str
* @return
*/
public static boolean isDataFormat(String str) {
boolean flag = false;
// regxStr="[1-9][0-9]{3}-[0-1][0-2]-((0[1-9])|([12][0-9])|(3[01]))";
String regxStr = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$";
Pattern pattern1 = Pattern.compile(regxStr);
Matcher isNo = pattern1.matcher(str);
if (isNo.matches()) {
flag = true;
}
return flag;
}
public static String trans15bitTo18bit(String IDStr){
String[] input = IDStr.split("");
String[] result = new String[18];
for(int i=0;i<input.length;i++){
if(i<=5){
result[i] = input[i];
}else{
result[i+2] = input[i];
}
}
//年份最后两位小于17,年份为20XX,否则为19XX
if(Integer.valueOf(input[6])<=1&&Integer.valueOf(input[7])<=7){
result[6]="2";
result[7]="0";
}else{
result[6]="1";
result[7]="9";
}
//计算最后一位
String[] xs = {"7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"};
//前十七位乘以系数[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],
int sum = 0;
for(int i=0;i<17;i++){
sum+= Integer.valueOf(result[i]) * Integer.valueOf(xs[i]);
}
//对11求余,的余数 0 - 10
int rod = sum % 11;
//所得余数映射到对应数字即可
if(rod==0){ result[17] = "1";
}else if(rod==1){ result[17] = "0";
}else if(rod==2){ result[17] = "X";
}else if(rod==3){ result[17] = "9";
}else if(rod==4){ result[17] = "8";
}else if(rod==5){ result[17] = "7";
}else if(rod==6){ result[17] = "6";
}else if(rod==7){ result[17] = "5";
}else if(rod==8){ result[17] = "4";
}else if(rod==9){ result[17] = "3";
}else if(rod==10){ result[17] = "2";}
StringBuilder builder = new StringBuilder();
for(String c : result){
builder.append(c);
}
return builder.toString();
}
/**
* 功能:判断字符串是否为数字
*
* @param str
* @return
*/
private static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
}
package cn.quantgroup.report.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CheckUtils {
private static final Pattern phone_pattern = Pattern.compile("^((\\d{11}))$");
private static final Pattern name_pattern = Pattern.compile("^([a-zA-Z0-9\\u4e00-\\u9fa5\\·]{1,20})$");
public static boolean checkIfPhoneOk(String phone){
if(phone == null) return false;
Matcher matcher = phone_pattern.matcher(phone);
return matcher.matches();
}
public static boolean checkIfNameOk(String name){
if(name == null) return false;
Matcher matcher = name_pattern.matcher(name);
return matcher.matches();
}
}
package cn.quantgroup.report.utils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Days;
import org.joda.time.Months;
import org.joda.time.format.DateTimeFormat;
public class ClockUtils {
public static final String TIME_ZONE = "Asia/Shanghai";
public static final String DATE_FORMAT = "yyyyMMdd";
public static final Long MILLS_PER_DAY = 24 * 60 * 60 * 1000l;
public static final long MILLS_PER_MINUTE = 60 * 1000l;
public static final String DATE_FORMAT_FOR_ORDER_PROGRESS_UPDATE_YEAR = "yyyy-MM-dd";
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String ISO_8601_DATE_TIME_FORMAT = "yyyy-MM-ddTHH:mm:ss";
public static final String HBASE_DATE_TIME_FORMAT = "yyyyMMddHHmmsss";
public static long nowDateInMillis() {
return nowDate()
.withHourOfDay(0)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.getMillis();
}
public static long nowDateInMillsWithHour(int hour) {
return nowDate()
.withHourOfDay(hour)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.getMillis();
}
public static String dateTimeStringFromTimestamp(Long timestamp) {
return dateTimeStringFromTimestamp(timestamp, DATE_TIME_FORMAT);
}
public static String hBaseDateTimeStringFromTimestamp(Long timestamp) {
return dateTimeStringFromTimestamp(timestamp, HBASE_DATE_TIME_FORMAT);
}
public static String iso8601dateTimeStringFromTimestamp(Long timestamp) {
return dateTimeStringFromTimestamp(timestamp, ISO_8601_DATE_TIME_FORMAT);
}
public static long hBaseParseTimestampFromDateTimeString(String dateTimeString) {
return DateTime.parse(dateTimeString, DateTimeFormat.forPattern(HBASE_DATE_TIME_FORMAT)).getMillis();
}
public static long parseTimestampFromDateTimeString(String dateTimeString) {
return DateTime.parse(dateTimeString, DateTimeFormat.forPattern(DATE_TIME_FORMAT)).getMillis();
}
public static String dateTimeStringFromTimestamp(Long timestamp, String format) {
if (null == timestamp) {
return null;
}
return date(timestamp).toString(DateTimeFormat.forPattern(format));
}
public static DateTime date(Long timestamp) {
return new DateTime(timestamp, getTimeZone());
}
public static DateTime nowDate() {
return new DateTime(getTimeZone());
}
public static DateTimeZone getTimeZone() {
return DateTimeZone.forID(TIME_ZONE);
}
public static long daysAgoInMillis(int daysAgo) {
return nowDateInMillis() - MILLS_PER_DAY * daysAgo;
}
public static long monthsAgoInMillis(int monthsAgo) {
return nowDate()
.withHourOfDay(0)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.minusMonths(monthsAgo)
.getMillis();
}
public static long minutesAgoInMillis(int minutes) {
return now() - MILLS_PER_MINUTE * minutes;
}
public static long now() {
return nowDate().getMillis();
}
public static int getDaysBetween(Long startMillis, Long endMills) {
return Days.daysBetween(date(startMillis), date(endMills)).getDays() + 1;
}
public static int getMonthsBetween(Long startMillis, Long endMills) {
return Months.monthsBetween(date(startMillis), date(endMills)).getMonths() + 1;
}
}
package cn.quantgroup.report.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.google.common.collect.Maps;
import java.util.Map;
public class ConverterCacheUtils {
private static final Map<Object, JSONObject> objectCache = Maps.newConcurrentMap();
private static final SerializeConfig jsonConfig = new SerializeConfig();
public static JSONObject convertedFromObject(Object object) {
if (object == null) {
return null;
}
JSONObject jsonObject = objectCache.get(object);
if (jsonObject != null) {
return jsonObject;
}
String jsonString = JSON.toJSONString(object, jsonConfig);//过滤null字段
jsonObject = (JSONObject) JSON.parse(jsonString);
if (jsonObject == null) {
return null;
}
objectCache.put(object, jsonObject);
return jsonObject;
}
}
package cn.quantgroup.report.utils;
/**
* Created by Alan on 2018/6/12.
*/
public class DataFuzzyUtils {
private static void swap(char[] chars, int i, int j){
char tmp = chars[i];
chars[i] = chars[j];
chars[j] = tmp;
}
public static String shufflePhoneNum(String text){
try {
char[] chars = text.toCharArray();
swap(chars, 0, 1);
swap(chars, 2, 4);
swap(chars, 3, 8);
swap(chars, 7, 10);
swap(chars, 5, 9);
return new String(chars);
}catch (Exception e){
return text;
}
}
}
package cn.quantgroup.report.utils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Author fengjunkai
* @Date 2019-03-27 14:28
*/
public class DateUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(DateUtils.class);
private static final String[] monthStrArray = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
/**
* yyyy-MM-dd
* @return
*/
public static String getYesterdayDateStr() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
DateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = new Date(cal.getTimeInMillis());
return sf.format(startDate);
}
/**
* 获取下一年的年月字符串组合 eg:201701 201702 ...
*
* @return
* @version 1.0
*/
public static String[] getNextYearMonthStr() {
String[] ret = new String[12];
Calendar c = Calendar.getInstance();
int nextYear = c.get(Calendar.YEAR) + 1;
for (int i = 0; i < monthStrArray.length; i++) {
ret[i] = nextYear + monthStrArray[i];
}
return ret;
}
/**
* 获取当年的年月字符串组合 eg:201601 201602 ...
*
* @return
* @version 1.0
*/
public static String getCurrentYearMonthStr() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
return format.format(new Date());
}
/**
* 时间戳转化为时间格式
* @param unixTime
* @return
*/
public static String convertToDateString(long unixTime) {
DateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = new Date(unixTime);
return sf.format(startDate);
}
/**
* 获取当前时间对应昨天的日期
*
* @return
*/
public static Date getYesterdayDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
return cal.getTime();
}
/**
* 获取昨天0点的日期
*
* @return
*/
public static Date getYesterdayZeroDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取从昨天起7天前的日期
*
* @return
*/
public static Date getYesterday7DaysAgoZeroDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -6);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取今天0点的日期
*
* @return
*/
public static Date getTodayZeroDateII() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取今天23点的日期
*
* @return
*/
public static Date getToday23Date() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取今天1点的日期
*
* @return
*/
public static Date getTodayOneHourDate() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取给定日期的1点
*
* @param date
* @return
*/
public static Date getOneHourByDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 给定日期7天前的1点
*
* @param date
* @return
*/
public static Date get7DayAgoOneHourByDate(Date date) {
Calendar cal = Calendar.getInstance();
if (date != null) {
cal.setTime(date);
}
cal.add(Calendar.DATE, -7);
cal.set(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取昨天的前七天的零点
* @return
*/
public static Date get7DayAgo0HourByYesterday() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -8);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取30天前的零点
* @return
*/
public static Date get30DayAgo0HourByYesterday() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -31);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取给定日期的明天的0点日期
*
* @param date
* @return
*/
public static Date getTommowZeroHourByDate(Date date) {
Calendar cal = Calendar.getInstance();
if (date != null) {
cal.setTime(date);
}
cal.add(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取给定日期的0点
*
* @param date
* @return
*/
public static Date getZeroHourByDate(Date date) {
Calendar cal = Calendar.getInstance();
if (date != null) {
cal.setTime(date);
}
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取日期的小时数
*
* @param date
* @return
*/
public static int getHourFromDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.HOUR_OF_DAY);
}
/**
* 获取给定日期的23点
*
* @param date
* @return
*/
public static Date get23HourByDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 整点
*
* @return
*/
public static Date getCurrentHour() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
int hour = cal.get(Calendar.HOUR_OF_DAY);
if (hour == 0) {
cal.add(Calendar.DATE, 1);
}
return cal.getTime();
}
/**
* 当前小时的整点
*
* @return
*/
public static Date getNowHour() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取下一个整点的日期
*
* @return
*/
public static Date getNextHourDate() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.HOUR_OF_DAY, 1);
return cal.getTime();
}
/**
* 获取前天0点日期
*
* @return
*/
public static Date getDayBeforeYesterdayZeroDate() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -2);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取当前时间到明天0:10的毫秒值差
*
* @return
*/
public static long getNowToTomorrowZeroMillis() {
// 当前时间毫秒数
long current = System.currentTimeMillis();
// 今天零点零分零秒的毫秒数
long today = current / (1000 * 3600 * 24) * (1000 * 3600 * 24)
- TimeZone.getDefault().getRawOffset();
// 明天0:10的毫秒数
long tomorrow = today + 24 * 60 * 60 * 1000 + 10 * 60 * 1000;
return tomorrow - current;
}
/**
* 获取当前时间到下个整点的毫秒值差
*
* @return
*/
public static long getNowToNextZeroTimeMillis() {
// 当前时间毫秒数
long current = System.currentTimeMillis();
// 下个整点的毫秒数
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long nextHour = cal.getTime().getTime();
return nextHour - current;
}
/**
* 当前时间到明天零点的毫秒差值
*
* @return
*/
public static long getNowToTodayZeroDateMillis() {
// 当前时间毫秒数
long current = System.currentTimeMillis();
// 明天零点毫秒数
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long millis = cal.getTimeInMillis();
return millis - current;
}
/**
* 当天凌晨的日期
*
* @return
*/
public static Date getTodayZeroDate() {
// 当前时间毫秒数
long current = System.currentTimeMillis();
// 今天零点零分零秒的毫秒数
long today = (current + 3600 * 1000 * 8)/ (1000 * 3600 * 24) * (1000 * 3600 * 24)
- TimeZone.getDefault().getRawOffset();
return new Date(today);
}
/**
* 格式化日期到整小时
*
* @param date
* @return
*/
public static Date formatDateToHour(Date date) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
Date result = new Date();
try {
result = format.parse(format.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
/**
* 获取昨天的当前时间的整点往前推n个小时的各个整点
*
* @param n
* @return
*/
public static List<Date> getYesterdayPreNHourTimeList(int n) {
List<Date> result = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
result.add(cal.getTime());
for (int i = 0; i < n - 1; i++) {
cal.add(Calendar.HOUR_OF_DAY, -1);
result.add(cal.getTime());
}
return result;
}
/**
* 获取今天的当前时间整点往前推n个小时的各个整点
*
* @param n
* @return
*/
public static List<Date> getTodayPreNHourTimeList(int n) {
List<Date> result = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
result.add(cal.getTime());
for (int i = 0; i < n - 1; i++) {
cal.add(Calendar.HOUR_OF_DAY, -1);
result.add(cal.getTime());
}
return result;
}
/**
* 获取24小时字符串list
*
* @return
*/
public static List<String> get24HoursStringList() {
List<String> result = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
DateFormat format = new SimpleDateFormat("HH:00");
//0点
result.add(format.format(cal.getTime()));
for (int i = 1; i < 24; i++) {
cal.add(Calendar.HOUR_OF_DAY, 1);
result.add(format.format(cal.getTime()));
}
return result;
}
/**
* 对当前日期进行判断<br>
* 出现一种情况:整点执行的定时任务在前一小时xx:59:59执行
*/
public static Date judgeCurrentDate() {
Calendar cal = Calendar.getInstance();
int minute = cal.get(Calendar.MINUTE);
//当前的分时间是50分钟之后
if (minute >= 50) {
//把小时数+1
cal.add(Calendar.HOUR_OF_DAY, 1);
}
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 给定时间往前推24小时
*
* @param date
* @return
*/
public static Date getYesterdayDateByDate(Date date) {
long current = date.getTime();
long yesterday = current - 24 * 60 * 60 * 1000;
return new Date(yesterday);
}
/**
* 根据当前时间获取过去7天的同一时间段日期
*
* @return
*/
public static List<Date> getPast7DayListByNow() {
List<Date> result = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
int minute = cal.get(Calendar.MINUTE);
if (minute > 30) {
cal.add(Calendar.HOUR_OF_DAY, 1);
}
for (int i = 0; i < 7; i++) {
cal.add(Calendar.DATE, -1);
result.add(cal.getTime());
}
return result;
}
/**
* 过去N天的零点日期(包括今天)
*
* @param n
* @return
*/
public static List<Date> getPastNDaysZeroTimeDateList(int n) {
List<Date> result = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//今天
result.add(cal.getTime());
for (int i = 1; i < n; i++) {
cal.add(Calendar.DATE, -1);
result.add(cal.getTime());
}
return result;
}
/**
* 过去N天的零点日期(不包括今天和昨天)
*
*/
public static List<Date> getPastNDaysZeroTimeDateListII(int start, int count) {
List<Date> result = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
for (int i = 1; i < count; i++) {
cal.add(Calendar.DATE, -1);
if (i <= start) {
continue;
}
result.add(cal.getTime());
}
return result;
}
/**
* 给定时间往后推24小时
*
* @param date
* @return
*/
public static Date getNext24HourDateByDate(Date date) {
long current = date.getTime();
long tomorrow = current + 24 * 60 * 60 * 1000;
return new Date(tomorrow);
}
/**
* 获取日期前24个小时的list
*
* @param n
* @param date
* @return
*/
public static List<Date> getPreNHourListByDate(int n, Date date) {
List<Date> result = new ArrayList<>(n);
result.add(date);
long timeMillis = date.getTime();
for (int i = 1; i < n; i++) {
timeMillis = timeMillis - 60 * 60 * 1000;
result.add(new Date(timeMillis));
}
return result;
}
/**
* 判断当前时间是否在某段小时区间内
*
* @param sHour
* @param eHour
* @return
*/
public static boolean judgeNowBetweenPeriodOfHour(int sHour, int eHour) {
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
if (hour >= sHour && hour <= eHour) {
return true;
}
return false;
}
public static boolean isTodayDate(Date date) {
try {
Date today = getTodayZeroDateII();
if (date.getTime() >= today.getTime()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean isTodayDate(String dateStr) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = format.parse(dateStr);
return isTodayDate(date);
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
/**
* 获取N天前的零点日期
*
* @param n
* @return
*/
public static Date getHistoryZeroDateByN(int n) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.DATE, -n);
return cal.getTime();
}
/**
* 计算日期相差天数
* @param date1
* @param date2
* @return
*/
public static int differentDays(Date date1,Date date2) {
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
int day1= cal1.get(Calendar.DAY_OF_YEAR);
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR);
if(year1 != year2) {
int timeDistance = 0 ;
for(int i = year1 ; i < year2 ; i ++) {
if(i%4==0 && i%100!=0 || i%400==0) {
timeDistance += 366;
} else {
timeDistance += 365;
}
}
return timeDistance + (day2-day1) ;
} else {
System.out.println("判断day2 - day1 : " + (day2-day1));
return day2-day1;
}
}
/**
* 获取N个小时前的整点日期
*
* @param n
* @return
*/
public static Date getHistoryHourDateByN(int n) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, -n);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取给定日期的昨天的日期并格式化
*
* @param date
* @return
*/
public static String getLastDayStringDateByDate(Date date) {
DateFormat format = new SimpleDateFormat("MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, -1);
return format.format(cal.getTime());
}
/**
* 获取昨天零点的前一秒
* @return
*/
public static Date getYesterdayBeforeOneSec() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, -1);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取指定时间的下一个整点(非零点时刻)
* @param date
* @return Date
*/
public static Date getNextOneHourSpecifyTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int hour = c.get(Calendar.HOUR);
if(hour != 0) {
c.set(Calendar.HOUR, hour + 1);
}
return c.getTime();
}
public static String convertToTimeSlot(long unixTime) {
long days = unixTime / (1000 * 60 * 60 * 24);
long hours = (unixTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
long minutes = (unixTime % (1000 * 60 * 60)) / (1000 * 60);
long seconds = (unixTime % (1000 * 60)) / 1000;
if (unixTime >= 1000 * 60 * 60 * 24) {
return days + "天" + hours + "时" + minutes + "分" + seconds + "秒";
} else if (unixTime >= 1000 * 60 * 60) {
return hours + "时" + minutes + "分" + seconds + "秒";
} else if (unixTime >= 1000 * 60) {
return minutes + "分" + seconds + "秒";
} else if (unixTime >= 1000) {
return seconds + "秒";
}
return null;
}
/**
* 获取给定日期的前N天
*/
public static Date getPastNDayZeroHourByDate(Date date, int n) {
Calendar instance = Calendar.getInstance();
instance.setTime(date);
instance.set(Calendar.DATE,instance.get(Calendar.DATE) - n);
return instance.getTime();
}
/**
* 计算两个日期相差的天数
* @param date1
* @param date2
* @return
*/
public static int differentDaysByMillisecond(Date date1,Date date2) {
int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
return days;
}
/**
* 获取当天N点的毫秒值
* @param hour
* @return
*/
public static long getTodayNHourMillisecond(int hour) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 0);
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime().getTime();
}
/**
* 获取当前时间小时数(24小时制)
* @return
*/
public static int getCurrentTimeHour() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR_OF_DAY);
}
/**
* 获取指定时间小时数(24小时制)
* @return
*/
public static int getDesignTimeHour(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.HOUR_OF_DAY);
}
public static Date parseDate(String dateStr) {
Date parseDate = null;
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
parseDate = dateFormat.parse(dateStr);
return parseDate;
}catch (Exception e){
LOGGER.error("日志解析失败", e);
}
return parseDate;
}
public static String formatDate(Date date, String format) {
try {
DateFormat dateFormat = new SimpleDateFormat(format);
String dateStr = dateFormat.format(date);
return dateStr;
}catch (Exception e){
LOGGER.error("日志解析失败", e);
return "";
}
}
public static String parse(Date date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(date);
}
public static Date parseDate(String format, String dateStr) {
Date parseDate = null;
try {
DateFormat dateFormat = null;
if(StringUtils.isNotEmpty(format)){
dateFormat = new SimpleDateFormat(format);
}else{
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
parseDate = dateFormat.parse(dateStr);
return parseDate;
}catch (Exception e){
LOGGER.error("日志解析失败, format: {} , dateStr: {} ", format, dateStr, e);
}
return parseDate;
}
public static void main(String[] args) {
/* DateFormat df = new SimpleDateFormat("MM-dd");
// int currentTimeHour = getCurrentTimeHour();
// System.out.println(currentTimeHour);
Date startTime = DateUtils.getHistoryZeroDateByN(7);
Date today = DateUtils.parseDate("2018-08-28");
int num = DateUtils.differentDays(today, new Date());
System.out.println(formatDate(new Date(), "yyyy-MM-dd"));
System.out.println(DateUtils.getHistoryZeroDateByN(1));
System.out.println(today);
System.out.println(df.format(startTime));*/
Date date1 = DateUtils.parseDate("yyyy-MM-dd'T'HH:mm:ss", "2020-03-12T16:34:38");
Date date2 = DateUtils.parseDate("yyyy-MM-dd'T'HH:mm:ss", "2020-03-12T16:34:36");
//int dff = DateUtils.differentDaysByMillisecond(date1, date2);
int dff = (int)(date2.getTime() - date1.getTime());
System.out.println("dff="+dff+",H="+dff*3/60);
}
}
package cn.quantgroup.report.utils;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
/**
* Created by renfeng on 2019/4/22.
*/
public enum HikDataSourceTidbRisk {
HIK_DATA_SOURCE_TIDB_RISK;
public DataSource dataSourceJdbc;
HikDataSourceTidbRisk(){
if(dataSourceJdbc==null){
System.out.println("======tidb.risk_datasource创建数据库连接dataSource1======");
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://fengkong-tidb.quantgroups.com:4010/risk_datasource?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true");
config.setUsername("risk_datasource_w");
config.setPassword("50GjQLd6hUOSeTMB");
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setMaximumPoolSize(50);
config.setMinimumIdle(20);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
dataSourceJdbc = new HikariDataSource(config);
System.out.println("tidb.risk_datasource创建数据库连接完毕");
}
}
}
package cn.quantgroup.report.utils;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.UUID;
public class IdUtils {
// 起始的时间戳
private final static long START_STMP = 1539141250000L;
// 每一部分最大值
private final static long MAX_SEQUENCE = -1L ^ (-1L << 12);
private static long sequence = 0L; // 序列号
private static long lastStmp = -1L;// 上一次时间戳
//产生下一个ID
public static synchronized String nextId(String seqName) {
long seqId = (seqName + getLocalMac()).hashCode() & 0x7FFFFFFF;
long currStmp = getNewstmp();
if (currStmp < lastStmp) {
throw new RuntimeException("Clock moved backwards. Refusing to generate id");
}
if (currStmp == lastStmp) {
//if条件里表示当前调用和上一次调用落在了相同毫秒内,只能通过第三部分,序列号自增来判断为唯一,所以+1.
sequence = (sequence + 1) & MAX_SEQUENCE;
//同一毫秒的序列数已经达到最大,只能等待下一个毫秒
if (sequence == 0L) {
currStmp = getNextMill();
}
} else {
//不同毫秒内,序列号置为0
//执行到这个分支的前提是currTimestamp > lastTimestamp,说明本次调用跟上次调用对比,已经不再同一个毫秒内了,这个时候序号可以重新回置0了。
sequence = 0L;
}
lastStmp = currStmp;
//就是用相对毫秒数、机器ID和自增序号拼接
return "" + (currStmp - START_STMP) + seqId + sequence;
}
private static long getNextMill() {
long mill = getNewstmp();
while (mill <= lastStmp) {
mill = getNewstmp();
}
return mill;
}
private static long getNewstmp() {
return System.currentTimeMillis();
}
//获取网卡,获取地址
private static String getLocalMac() {
try {
InetAddress ia = InetAddress.getLocalHost();
byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < mac.length; i++) {
if (i != 0) {
sb.append("-");
}
//字节转换为整数
int temp = mac[i] & 0xff;
String str = Integer.toHexString(temp);
if (str.length() == 1) {
sb.append("0" + str);
} else {
sb.append(str);
}
}
return sb.toString().toUpperCase();
}catch (Exception e){
return UUID.randomUUID().toString();
}
}
public static String getUuid(){
String uuid = UUID.randomUUID().toString();
uuid = uuid.replace("-", "");
return uuid;
}
public static void main(String[] args) {
System.out.println(getLocalMac());
long seqId = ("order" + getLocalMac()).hashCode();
System.out.println(seqId);
int i = 0;
while(i++<10) {
System.out.println(IdUtils.nextId("order"));
}
}
}
package cn.quantgroup.report.utils;
import cn.quantgroup.report.domain.tidbrisk.CallRecord3;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
import java.sql.*;
import java.util.List;
import static cn.quantgroup.report.utils.HikDataSourceTidbRisk.HIK_DATA_SOURCE_TIDB_RISK;
/**
* @Author fengjunkai
*/
@Slf4j
public class JdbcUtils {
/*
public static void prepareBatchUpdateExecuteTransactionid(String sql, List<CallRecord1> callRecord1s){
Connection conn = null;
PreparedStatement ps = null;
try {
conn = HIK_DATA_SOURCE.dataSourceJdbc.getConnection();
ps = conn.prepareStatement(sql);
conn.setAutoCommit(false);
// String sql = "INSERT INTO `call_record` (`request_url`, `transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?,?,?,?,?,?,?)";
for (int i = 0; i < callRecord1s.size(); i++) {
CallRecord1 callRecord1 = callRecord1s.get(i);
ps.setString(1, callRecord1.getTransactionId());
ps.setString(2, callRecord1.getUuid());
ps.setString(3, callRecord1.getUrlType());
ps.setString(4, callRecord1.getCode());
ps.setTimestamp(5, callRecord1.getCreated_at());
ps.setTimestamp(6, callRecord1.getUpdated_at());
ps.addBatch();
}
ps.executeBatch();
conn.commit();
}catch(Exception e){
System.out.println("======执行sqlException异常======"+sql+"\r\n");
System.out.println("");
e.printStackTrace();
}finally {
close(conn, ps,null);
}
}
*/
private static void close(Connection conn, Statement st, ResultSet rs){
try {
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void batchUpdateExecuteCallRecord(DataSource dataSourceJdbc, String sql, List<CallRecord3> callRecord3List){
Connection conn = null;
PreparedStatement ps = null;
try {
//conn = dataSourceJdbc.getConnection(); //这样的慢,rewriteBatchedStatements=true不生效
conn = HIK_DATA_SOURCE_TIDB_RISK.dataSourceJdbc.getConnection();
ps = conn.prepareStatement(sql);
conn.setAutoCommit(false);
//"INSERT INTO `call_record` (`request_url`, `channel_type`, `channel_id`, `transaction_id`, `uuid`, `url_type`, `code`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"
for (int i = 0; i < callRecord3List.size(); i++) {
CallRecord3 callRecord3 = callRecord3List.get(i);
ps.setString(1, callRecord3.getRequestUrl());
ps.setString(2, callRecord3.getChannelType());
ps.setString(3, callRecord3.getChannelId());
ps.setString(4, callRecord3.getTransactionId());
ps.setString(5, callRecord3.getUuid());
ps.setString(6, callRecord3.getUrlType());
ps.setInt(7, callRecord3.getCode());
ps.setTimestamp(8, callRecord3.getCreatedAt());
ps.setTimestamp(9, callRecord3.getUpdatedAt());
ps.addBatch();
}
ps.executeBatch();
conn.commit();
}catch(Exception e){
log.error("======执行batchUpdateExecuteCallRecord异常======"+sql+"\r\n",e);
log.error("方法batchUpdateExecuteCallRecord异常, DATA: {} \n", JSON.toJSON(callRecord3List));
e.printStackTrace();
}finally {
close(conn, ps,null);
}
}
public static void batchInsertExecuteCallRecord(String sql, List<CallRecord3> callRecord3List){
Connection conn = null;
PreparedStatement ps = null;
try {
conn = HIK_DATA_SOURCE_TIDB_RISK.dataSourceJdbc.getConnection();
ps = conn.prepareStatement(sql);
conn.setAutoCommit(false);
for (int i = 0; i < callRecord3List.size(); i++) {
CallRecord3 callRecord3 = callRecord3List.get(i);
//delete from call_record where id=? AND transaction_id =?
ps.setLong(1, callRecord3.getId());
ps.setString(2, callRecord3.getTransactionId());
ps.addBatch();
}
ps.executeBatch();
conn.commit();
}catch(Exception e){
log.error("======执行batchInsertExecuteCallRecord异常======"+sql+"\r\n",e);
log.error("方法batchInsertExecuteCallRecord异常, DATA: {} \n", JSON.toJSON(callRecord3List));
e.printStackTrace();
}finally {
close(conn, ps,null);
}
}
}
package cn.quantgroup.report.utils;
import org.apache.commons.lang3.StringUtils;
public class MaskedUtils {
public static String buildMaskedAccountNumber(String accountNumber) {
return StringUtils.substring(accountNumber, accountNumber.length() - 4);
}
public static String buildMaskedAccountNumber4BitExposed(String accountNumber) {
final String overlay = StringUtils.repeat("*", accountNumber.length() - 4);
return StringUtils.overlay(accountNumber, overlay, 0, accountNumber.length() - 4);
}
public static String buildMaskedCorporateAccountNumber(String accountNumber) {
return StringUtils.substring(accountNumber, accountNumber.length() - 4);
}
public static String buildMaskedIdentityNumber(String identityNumber) {
if (identityNumber != null) {
final String overlay = StringUtils.repeat("*", identityNumber.length() - 4);
return StringUtils.overlay(identityNumber, overlay, 3, identityNumber.length() - 1);
}
return null;
}
public static String buildMaskedMobileNumber(String mobileNumber) {
final String overlay = StringUtils.repeat("*", 4);
return StringUtils.overlay(mobileNumber, overlay, 3, 7);
}
public static String buildMaskedName(String name) {
if (StringUtils.isBlank(name)) {
return name;
}
final String overlay = StringUtils.repeat("*", name.length() - 1);
return StringUtils.overlay(name, overlay, 0, name.length() - 1);
}
public static String buildMaskedNameFirstBitExposed(String name) {
if (name == null || name.length() <= 1) {
return name;
}
final String overlay = StringUtils.repeat("*", name.length() - 1);
return StringUtils.overlay(name, overlay, 1, name.length());
}
public static String buildMaskedMobileNumber7Bit(String mobileNumber) {
final String overlay = StringUtils.repeat("*", 7);
return StringUtils.overlay(mobileNumber, overlay, 0, 7);
}
public static String buildMaskedIdentityNumber7BitExposed(String identityNumber) {
if (identityNumber != null) {
final String overlay = StringUtils.repeat("*", identityNumber.length() - 7);
return StringUtils.overlay(identityNumber, overlay, 3, identityNumber.length() - 4);
}
return null;
}
public static String buildMaskedCommonString(String string) {
if (StringUtils.isBlank(string)) {
return string;
}
if (string.length() > 15) {
final String overlay = StringUtils.repeat("*", string.length() - 7);
return StringUtils.overlay(string, overlay, 3, string.length() - 4);
}
if (string.length() > 10) {
final String overlay = StringUtils.repeat("*", string.length() - 8);
return StringUtils.overlay(string, overlay, 5, string.length() - 3);
}
if (string.length() > 5) {
final String overlay = StringUtils.repeat("*", string.length() - 5);
return StringUtils.overlay(string, overlay, 3, string.length() - 2);
}
final String overlay = StringUtils.repeat("*", string.length() - 1);
return StringUtils.overlay(string, overlay, 1, string.length());
}
public static String buildMantissaMobileNumber(String mobileNumber) {
return StringUtils.substring(mobileNumber, mobileNumber.length() - 4);
}
public static String buildMaskedIdentityNumberMantissa(String identityNumber) {
if (StringUtils.isNotBlank(identityNumber)) {
final String overlay = StringUtils.repeat("*", identityNumber.length() - 14);
return StringUtils.overlay(identityNumber, overlay, 14, identityNumber.length());
}
return null;
}
public static String maskedMobileNumber7BitExposed(String mobileNumber) {
if (StringUtils.isNotBlank(mobileNumber) && mobileNumber.length() >= 7) {
final String overlay = StringUtils.repeat("*", mobileNumber.length() - 7);
return StringUtils.overlay(mobileNumber, overlay, 7, mobileNumber.length());
}
return mobileNumber;
}
public static String maskedBankAccountNumber6BitExposed(String bankAccountNumber) {
if (StringUtils.isNotBlank(bankAccountNumber) && bankAccountNumber.length() >= 6) {
final String overlay = StringUtils.repeat("*", bankAccountNumber.length() - 6);
return StringUtils.overlay(bankAccountNumber, overlay, 6, bankAccountNumber.length());
}
return bankAccountNumber;
}
}
package cn.quantgroup.report.utils;
import cn.quantgroup.report.service.manualTool.ManualToolService;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* -----------------------------------------------------------------------------<br>
* 描述: <br>
* 作者: Haoyanhui <br>
* 时间:2019.09.09 22:34 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Slf4j
public class ReadOrWriteTxt {
/**传入txt路径读取txt文件
* @param txtPath
* @return 返回读取到的内容
*/
public static String readTxt(String txtPath) {
File file = new File(txtPath);
if(file.isFile() && file.exists()){
try {
FileInputStream fileInputStream = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer sb = new StringBuffer();
String text = null;
while((text = bufferedReader.readLine()) != null){
sb.append(text);
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
/**使用FileOutputStream来写入txt文件
* @param txtPath txt文件路径
* @param content 需要写入的文本
*/
public static void writeTxt(String txtPath,String content){
FileOutputStream fileOutputStream = null;
File file = new File(txtPath);
try {
if(file.exists()){
//判断文件是否存在,如果不存在就新建一个txt
file.createNewFile();
}
fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(content.getBytes());
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeTxt(String txtPath,List<String> contentList){
FileOutputStream fileOutputStream = null;
File file = new File(txtPath);
try {
if(file.exists()){
//判断文件是否存在,如果不存在就新建一个txt
file.createNewFile();
}
fileOutputStream = new FileOutputStream(file);
for(String content:contentList){
fileOutputStream.write(content.getBytes());
}
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static List<String> readTxtList(String txtPath) {
File file = new File(txtPath);
if(file.isFile() && file.exists()){
List<String> lineList = new ArrayList<String>();
try {
FileInputStream fileInputStream = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "GBK");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer sb = new StringBuffer();
String text = null;
while((text = bufferedReader.readLine()) != null){
lineList.add(text);
}
return lineList;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public static List<String> readResourceFilList(String fileName) {
InputStream isr = ManualToolService.class.getResourceAsStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(isr));
List<String> lineList = new ArrayList<String>();
try {
boolean inKey = false;
/*for (String line = br.readLine(); line != null; line = br.readLine()) {
line = line.trim();
if (!inKey) {
if (line.contains("---BEGIN---")) {
inKey = true;
}
continue;
} else {
if (line.contains("---END---")) {
inKey = false;
break;
}
lineList.add(line);
}
}*/
for (String line = br.readLine(); line != null; line = br.readLine()) {
line = line.trim();
lineList.add(line);
}
br.close();
isr.close();
} catch (IOException e) {
e.printStackTrace();
log.error("读取:" + fileName + "异常", e);
}
return lineList;
}
public static void main(String[] args) {
/* //String filePath = "D:\\JavaTeam\\shmf.txt";
String filePath = "/opt/web_app/shmf.txt";
String queryType = "aa";
String writeFilePath = "";
if(filePath.lastIndexOf("/")!=-1){//linux
writeFilePath = filePath.substring(0,filePath.lastIndexOf("/"))+"/"+queryType+".txt";
}else{//windows
writeFilePath = filePath.substring(0,filePath.lastIndexOf("\\"))+"\\"+queryType+".txt";
}
System.out.println(filePath);
System.out.println(writeFilePath);*/
/*String path="/manualTool/user_back_400.txt";
List<String> listStr = ReadOrWriteTxt.readResourceFilList(path);
for(String srt:listStr){
System.out.println(listStr);
}*/
}
}
package cn.quantgroup.report.utils;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.CertificateException;
public class SSLUtils {
public static SSLSocketFactory getSSLContext(String password, InputStream keyStoreInputStream) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, IOException, KeyManagementException {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(keyStoreInputStream, password.toCharArray());
keyManagerFactory.init(keyStore, password.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), (SecureRandom) null);
return ctx.getSocketFactory();
}
}
package cn.quantgroup.report.utils;
import org.apache.commons.lang.StringUtils;
public class StringUtil {
private static final char UNDERLINE = '_';
public static String shortPrintLog(String log, int length){
if(StringUtils.isBlank(log)){
return log;
}
return log.substring(0, Math.min(log.length(), length));
}
public static String shortPrintLog(String log){
return shortPrintLog(log, 500);
}
/**
* 描述: 下划线 转 驼峰 <br/>
* 参数: [param] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.18 <br/>
*/
public static String underlineToCamel(String param){
if (param==null||"".equals(param.trim())){
return "";
}
int len=param.length();
StringBuilder sb=new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = Character.toLowerCase(param.charAt(i));
if (c == UNDERLINE){
if (++i<len){
sb.append(Character.toUpperCase(param.charAt(i)));
}
}else{
sb.append(c);
}
}
return sb.toString();
}
/**
* 描述: 下划线转 首字母大写的缩写 <br/>
* 参数: [param] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.18 <br/>
*/
public static String underlineToFirstChar(String param){
if (param==null||"".equals(param.trim())){
return "";
}
if(param.indexOf(String.valueOf(UNDERLINE))==-1){
return param;
}
StringBuffer buff = new StringBuffer();
String[] tmps = param.split(String.valueOf(UNDERLINE));
for(int i=0;i<tmps.length;i++){
if(tmps[i].length()>0){
buff.append(tmps[i].substring(0,1).toUpperCase());
}
};
return buff.toString();
}
/**
* 描述: 下划线转 首字母大写的缩写(木槿科技返回字段) <br/>
* 参数: [param] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.18 <br/>
*/
public static final String muJinunderlineToFirstChar(String param){
if("idRiskList".equals(param)){
return "IRL";
}else if("phoneRiskList".equals(param)){
return "PRL";
}else{
return underlineToFirstChar(param);
}
}
}
package cn.quantgroup.report.utils;
import lombok.extern.slf4j.Slf4j;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@Slf4j
public class TrustServerManager implements X509TrustManager {
X509TrustManager sunJSSEX509TrustManager;
public TrustServerManager(String type, InputStream inputStream, String password) throws Exception {
KeyStore ks = KeyStore.getInstance(type);
ks.load(inputStream, password.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509", "SunJSSE");
tmf.init(ks);
TrustManager tms[] = tmf.getTrustManagers();
/*
* Iterate over the returned trustmanagers, look for an instance of
* X509TrustManager. If found, use that as our "default" trust manager.
*/
for (int i = 0; i < tms.length; i++) {
if (tms[i] instanceof X509TrustManager) {
sunJSSEX509TrustManager = (X509TrustManager) tms[i];
return;
}
}
throw new RuntimeException("TrustServerManager Couldn't initialize");
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
try {
sunJSSEX509TrustManager.checkClientTrusted(chain, authType);
} catch (CertificateException ex) {
log.error("checkClientTrusted fail", ex);
}
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
try {
sunJSSEX509TrustManager.checkServerTrusted(chain, authType);
} catch (CertificateException ex) {
log.error("checkServerTrusted fail,authType:{}", authType, ex);
}
}
/*
* Merely pass this through.
*/
public X509Certificate[] getAcceptedIssuers() {
return sunJSSEX509TrustManager.getAcceptedIssuers();
}
}
package cn.quantgroup.report.utils.commonutil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.util.Arrays;
/**
* <p> The describe </p>
*
* @author Li Xingping
*/
@Slf4j
public class AESUtils {
/**
* The constant that denotes the algorithm being used.
*/
private static final String algorithm = "AES";
/**
* The private constructor to prevent instantiation of this object.
*/
private AESUtils() {
}
/**
* The method that will generate a random {@link SecretKey}.
*
* @return The key generated.
*/
public static SecretKey generateKey() {
try {
KeyGenerator keyGenerator = KeyGenerator.getInstance(algorithm);
keyGenerator.init(128);
return keyGenerator.generateKey();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* Creates a new {@link SecretKey} based on a password.
*
* @param password The password that will be the {@link SecretKey}.
* @return The key.
*/
public static SecretKey createKey(String password) {
try {
byte[] key = password.getBytes("UTF-8");
MessageDigest sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16); // use only first 128 bit
return new SecretKeySpec(key, algorithm);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* Creates a new {@link SecretKey} based on a password with a specified salt.
*
* @param salt The random salt.
* @param password The password that will be the {@link SecretKey}.
* @return The key.
*/
public static SecretKey createKey(byte[] salt, String password) {
try {
byte[] key = (Arrays.toString(salt) + password).getBytes("UTF-8");
MessageDigest sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16); // use only first 128 bit
return new SecretKeySpec(key, algorithm);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* The method that writes the {@link SecretKey} to a file.
*
* @param key The key to write.
* @param file The file to create.
* @throws IOException If the file could not be created.
*/
public static void writeKey(SecretKey key, File file) throws IOException {
try (FileOutputStream fis = new FileOutputStream(file)) {
fis.write(key.getEncoded());
}
}
/**
* Gets a {@link SecretKey} from a {@link File}.
*
* @param file The file that is encoded as a key.
* @return The key.
* @throws IOException The exception thrown if the file could not be read as a {@link SecretKey}.
*/
public static SecretKey getSecretKey(File file) throws IOException {
return new SecretKeySpec(Files.readAllBytes(file.toPath()), algorithm);
}
/**
* The method that will encrypt data.
*
* @param secretKey The key used to encrypt the data.
* @param data The data to encrypt.
* @return The encrypted data.
*/
public static byte[] encrypt(SecretKey secretKey, byte[] data) {
try {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return cipher.doFinal(data);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* The method that will decrypt a piece of encrypted data.
*
* @param password The password used to decrypt the data.
* @param encrypted The encrypted data.
* @return The decrypted data.
*/
public static byte[] decrypt(String password, byte[] encrypted) {
try {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, AESUtils.createKey(password));
return cipher.doFinal(encrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* The method that will decrypt a piece of encrypted data.
*
* @param secretKey The key used to decrypt encrypted data.
* @param encrypted The encrypted data.
* @return The decrypted data.
*/
public static byte[] decrypt(SecretKey secretKey, byte[] encrypted) {
try {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return cipher.doFinal(encrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void main(String[] args) {
//加密appKey
String appKey = "mICFRDO8mbYGhTAbluXkmhGaZf6V7yrJfbSjKeLIrqfPQFXHsqEwB4bSqguy1Ejp";
//加密内容体
String data = "{\"number\":\"130321199001228727\"}";
//加密后数据
byte[] bytes = encrypt(createKey(appKey), data.getBytes());
//转为base64。此数据即为接口请求的参数体
String encryptData = new String(new Base64().encode(bytes));
System.out.println(encryptData);
}
}
package cn.quantgroup.report.utils.commonutil;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
//import sun.misc.BASE64Decoder;
//import sun.misc.BASE64Encoder;
public class AesCrypto {
// 加密算法
public static String ALGO = "AES";
public static String ALGO_MODE = "AES/CBC/NoPadding";
// public static String KEY = "*&^(KLJOOIJ==dk8";
public static String IV = "0000000000000000";
/**
* 用来进行加密的操作
*
* @param Data
* @return
* @throws Exception
*/
public static String encrypt(String Data, String key) {
try {
Cipher cipher = Cipher.getInstance(ALGO_MODE);
int blockSize = cipher.getBlockSize();
byte[] dataBytes = Data.getBytes();
int plaintextLength = dataBytes.length;
if (plaintextLength % blockSize != 0) {
plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
}
byte[] plaintext = new byte[plaintextLength];
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes("utf-8"), ALGO);
IvParameterSpec ivspec = new IvParameterSpec(IV.getBytes("utf-8"));
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
byte[] encrypted = cipher.doFinal(plaintext);
String EncStr = new BASE64Encoder().encode(encrypted);
return EncStr;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 用来进行解密的操作
*
* @param encryptedData
* @return
* @throws Exception
*/
public static String decrypt(String encryptedData, String key) {
try {
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(encryptedData);
Cipher cipher = Cipher.getInstance(ALGO_MODE);
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes("utf-8"), ALGO);
IvParameterSpec ivspec = new IvParameterSpec(IV.getBytes("utf-8"));
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original);
return originalString;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
/*
2 * Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
package cn.quantgroup.report.utils.commonutil;
import sun.misc.CEFormatException;
import sun.misc.CEStreamExhausted;
import java.io.OutputStream;
import java.io.PushbackInputStream;
/**
* 32 * This class implements a BASE64 Character decoder as specified in RFC1521.
* 33 *
* 34 * This RFC is part of the MIME specification which is published by the
* 35 * Internet Engineering Task Force (IETF). Unlike some other encoding
* 36 * schemes there is nothing in this encoding that tells the decoder
* 37 * where a buffer starts or stops, so to use it you will need to isolate
* 38 * your encoded data into a single chunk and then feed them this decoder.
* 39 * The simplest way to do that is to read all of the encoded data into a
* 40 * string and then use:
* 41 * <pre>
* 42 * byte mydata[];
* 43 * BASE64Decoder base64 = new BASE64Decoder();
* 44 *
* 45 * mydata = base64.decodeBuffer(bufferString);
* 46 * </pre>
* 47 * This will decode the String in <i>bufferString</i> and give you an array
* 48 * of bytes in the array <i>myData</i>.
* 49 *
* 50 * On errors, this class throws a CEFormatException with the following detail
* 51 * strings:
* 52 * <pre>
* 53 * "BASE64Decoder: Not enough bytes for an atom."
* 54 * </pre>
* 55 *
* 56 * @author Chuck McManis
* 57 * @see CharacterEncoder
* 58 * @see BASE64Decoder
* 59
*/
public class BASE64Decoder extends CharacterDecoder {
/**
* This class has 4 bytes per atom
*/
protected int bytesPerAtom() {
return (4);
}
/**
* Any multiple of 4 will do, 72 might be common
*/
protected int bytesPerLine() {
return (72);
}
/**
* 74 * This character array provides the character to value map
* 75 * based on RFC1521.
* 76
*/
private final static char pem_array[] = {
// 0 1 2 3 4 5 6 7
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 1
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 2
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 3
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 4
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 5
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 6
'4', '5', '6', '7', '8', '9', '+', '/' // 7
};
private final static byte pem_convert_array[] = new byte[256];
static {
for (int i = 0; i < 255; i++) {
pem_convert_array[i] = -1;
}
for (int i = 0; i < pem_array.length; i++) {
pem_convert_array[pem_array[i]] = (byte) i;
}
}
byte decode_buffer[] = new byte[4];
/**
* 103 * Decode one BASE64 atom into 1, 2, or 3 bytes of data.
* 104
*/
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem)
throws java.io.IOException {
int i;
byte a = -1, b = -1, c = -1, d = -1;
if (rem < 2) {
throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
}
do {
i = inStream.read();
if (i == -1) {
throw new CEStreamExhausted();
}
} while (i == '\n' || i == '\r');
decode_buffer[0] = (byte) i;
i = readFully(inStream, decode_buffer, 1, rem - 1);
if (i == -1) {
throw new CEStreamExhausted();
}
if (rem > 3 && decode_buffer[3] == '=') {
rem = 3;
}
if (rem > 2 && decode_buffer[2] == '=') {
rem = 2;
}
switch (rem) {
case 4:
d = pem_convert_array[decode_buffer[3] & 0xff];
// NOBREAK
case 3:
c = pem_convert_array[decode_buffer[2] & 0xff];
// NOBREAK
case 2:
b = pem_convert_array[decode_buffer[1] & 0xff];
a = pem_convert_array[decode_buffer[0] & 0xff];
break;
}
switch (rem) {
case 2:
outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)));
break;
case 3:
outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)));
outStream.write((byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)));
break;
case 4:
outStream.write((byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)));
outStream.write((byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)));
outStream.write((byte) (((c << 6) & 0xc0) | (d & 0x3f)));
break;
}
return;
}
}
\ No newline at end of file
/*
2 * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
package cn.quantgroup.report.utils.commonutil;
import java.io.IOException;
import java.io.OutputStream;
/**
* This class implements a BASE64 Character encoder as specified in RFC1521.
* This RFC is part of the MIME specification as published by the Internet
* Engineering Task Force (IETF). Unlike some other encoding schemes there is
* nothing in this encoding that indicates where a buffer starts or ends.
*
* This means that the encoded text will simply start with the first line of
* encoded text and end with the last line of encoded text.
*
* @author Chuck McManis
* @see CharacterEncoder
* @see BASE64Decoder
*/
public class BASE64Encoder extends CharacterEncoder
{
/** this class encodes three bytes per atom. */
protected int bytesPerAtom()
{
return (3);
}
/**
* this class encodes 57 bytes per line. This results in a maximum of 57/3 *
* 4 or 76 characters per output line. Not counting the line termination.
*/
protected int bytesPerLine()
{
return (57);
}
/** This array maps the characters to their 6 bit values */
private final static char pem_array[] =
{
// 0 1 2 3 4 5 6 7
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 1
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 2
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 3
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 4
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 5
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 6
'4', '5', '6', '7', '8', '9', '+', '/' // 7
};
/**
* encodeAtom - Take three bytes of input and encode it as 4 printable
* characters. Note that if the length in len is less than three is encodes
* either one or two '=' signs to indicate padding characters.
*/
protected void encodeAtom(OutputStream outStream, byte data[], int offset,
int len) throws IOException
{
byte a, b, c;
if (len == 1)
{
a = data[offset];
b = 0;
c = 0;
outStream.write(pem_array[(a >>> 2) & 0x3F]);
outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
outStream.write('=');
outStream.write('=');
} else if (len == 2)
{
a = data[offset];
b = data[offset + 1];
c = 0;
outStream.write(pem_array[(a >>> 2) & 0x3F]);
outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
outStream.write('=');
} else
{
a = data[offset];
b = data[offset + 1];
c = data[offset + 2];
outStream.write(pem_array[(a >>> 2) & 0x3F]);
outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
outStream.write(pem_array[c & 0x3F]);
}
}
}
\ No newline at end of file
package cn.quantgroup.report.utils.commonutil;
import java.io.*;
/**
* Base64 编码和解码。
*
* @author 宋立君
* @date 2014年07月03日
*/
public class Base64 {
public Base64() {
}
/**
* 功能:编码字符串
*
* @author 宋立君
* @date 2014年07月03日
* @param data
* 源字符串
* @return String
*/
public static String encode(String data) {
return new String(encode(data.getBytes()));
}
/**
* 功能:解码字符串
*
* @author 宋立君
* @date 2014年07月03日
* @param data
* 源字符串
* @return String
*/
public static String decode(String data) {
return new String(decode(data.toCharArray()));
}
/**
* 功能:编码byte[]
*
* @author 宋立君
* @date 2014年07月03日
* @param data
* 源
* @return char[]
*/
public static char[] encode(byte[] data) {
char[] out = new char[((data.length + 2) / 3) * 4];
for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
boolean quad = false;
boolean trip = false;
int val = (0xFF & (int) data[i]);
val <<= 8;
if ((i + 1) < data.length) {
val |= (0xFF & (int) data[i + 1]);
trip = true;
}
val <<= 8;
if ((i + 2) < data.length) {
val |= (0xFF & (int) data[i + 2]);
quad = true;
}
out[index + 3] = alphabet[(quad ? (val & 0x3F) : 64)];
val >>= 6;
out[index + 2] = alphabet[(trip ? (val & 0x3F) : 64)];
val >>= 6;
out[index + 1] = alphabet[val & 0x3F];
val >>= 6;
out[index + 0] = alphabet[val & 0x3F];
}
return out;
}
/**
* 功能:解码
*
* @author 宋立君
* @date 2014年07月03日
* @param data
* 编码后的字符数组
* @return byte[]
*/
public static byte[] decode(char[] data) {
int tempLen = data.length;
for (int ix = 0; ix < data.length; ix++) {
if ((data[ix] > 255) || codes[data[ix]] < 0) {
--tempLen; // ignore non-valid chars and padding
}
}
// calculate required length:
// -- 3 bytes for every 4 valid base64 chars
// -- plus 2 bytes if there are 3 extra base64 chars,
// or plus 1 byte if there are 2 extra.
int len = (tempLen / 4) * 3;
if ((tempLen % 4) == 3) {
len += 2;
}
if ((tempLen % 4) == 2) {
len += 1;
}
byte[] out = new byte[len];
int shift = 0; // # of excess bits stored in accum
int accum = 0; // excess bits
int index = 0;
// we now go through the entire array (NOT using the 'tempLen' value)
for (int ix = 0; ix < data.length; ix++) {
int value = (data[ix] > 255) ? -1 : codes[data[ix]];
if (value >= 0) { // skip over non-code
accum <<= 6; // bits shift up by 6 each time thru
shift += 6; // loop, with new bits being put in
accum |= value; // at the bottom.
if (shift >= 8) { // whenever there are 8 or more shifted in,
shift -= 8; // write them out (from the top, leaving any
out[index++] = // excess at the bottom for next iteration.
(byte) ((accum >> shift) & 0xff);
}
}
}
// if there is STILL something wrong we just have to throw up now!
if (index != out.length) {
throw new Error("Miscalculated data length (wrote " + index
+ " instead of " + out.length + ")");
}
return out;
}
/**
* 功能:编码文件
*
* @author 宋立君
* @date 2014年07月03日
* @param file
* 源文件
*/
public static void encode(File file) throws IOException {
if (!file.exists()) {
System.exit(0);
}
else {
byte[] decoded = readBytes(file);
char[] encoded = encode(decoded);
writeChars(file, encoded);
}
file = null;
}
/**
* 功能:解码文件。
*
* @author 宋立君
* @date 2014年07月03日
* @param file
* 源文件
* @throws IOException
*/
public static void decode(File file) throws IOException {
if (!file.exists()) {
System.exit(0);
} else {
char[] encoded = readChars(file);
byte[] decoded = decode(encoded);
writeBytes(file, decoded);
}
file = null;
}
//
// code characters for values 0..63
//
private static char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
.toCharArray();
//
// lookup table for converting base64 characters to value in range 0..63
//
private static byte[] codes = new byte[256];
static {
for (int i = 0; i < 256; i++) {
codes[i] = -1;
// LoggerUtil.debug(i + "&" + codes[i] + " ");
}
for (int i = 'A'; i <= 'Z'; i++) {
codes[i] = (byte) (i - 'A');
// LoggerUtil.debug(i + "&" + codes[i] + " ");
}
for (int i = 'a'; i <= 'z'; i++) {
codes[i] = (byte) (26 + i - 'a');
// LoggerUtil.debug(i + "&" + codes[i] + " ");
}
for (int i = '0'; i <= '9'; i++) {
codes[i] = (byte) (52 + i - '0');
// LoggerUtil.debug(i + "&" + codes[i] + " ");
}
codes['+'] = 62;
codes['/'] = 63;
}
private static byte[] readBytes(File file) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b = null;
InputStream fis = null;
InputStream is = null;
try {
fis = new FileInputStream(file);
is = new BufferedInputStream(fis);
int count = 0;
byte[] buf = new byte[16384];
while ((count = is.read(buf)) != -1) {
if (count > 0) {
baos.write(buf, 0, count);
}
}
b = baos.toByteArray();
} finally {
try {
if (fis != null)
fis.close();
if (is != null)
is.close();
if (baos != null)
baos.close();
} catch (Exception e) {
System.out.println(e);
}
}
return b;
}
private static char[] readChars(File file) throws IOException {
CharArrayWriter caw = new CharArrayWriter();
Reader fr = null;
Reader in = null;
try {
fr = new FileReader(file);
in = new BufferedReader(fr);
int count = 0;
char[] buf = new char[16384];
while ((count = in.read(buf)) != -1) {
if (count > 0) {
caw.write(buf, 0, count);
}
}
} finally {
try {
if (caw != null)
caw.close();
if (in != null)
in.close();
if (fr != null)
fr.close();
} catch (Exception e) {
System.out.println(e);
}
}
return caw.toCharArray();
}
private static void writeBytes(File file, byte[] data) throws IOException {
OutputStream fos = null;
OutputStream os = null;
try {
fos = new FileOutputStream(file);
os = new BufferedOutputStream(fos);
os.write(data);
} finally {
try {
if (os != null)
os.close();
if (fos != null)
fos.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
private static void writeChars(File file, char[] data) throws IOException {
Writer fos = null;
Writer os = null;
try {
fos = new FileWriter(file);
os = new BufferedWriter(fos);
os.write(data);
} finally {
try {
if (os != null)
os.close();
if (fos != null)
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
// /////////////////////////////////////////////////
// end of test code.
// /////////////////////////////////////////////////
}
\ No newline at end of file
/*
2 * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
package cn.quantgroup.report.utils.commonutil;
import sun.misc.CEStreamExhausted;
import java.io.*;
import java.nio.ByteBuffer;
/**
* 37 * This class defines the decoding half of character encoders. 38 * A
* character decoder is an algorithim for transforming 8 bit 39 * binary data
* that has been encoded into text by a character 40 * encoder, back into
* original binary form. 41 * 42 * The character encoders, in general, have been
* structured 43 * around a central theme that binary data can be encoded into
* 44 * text that has the form: 45 * 46 *
* <p>
* <pre>
* 47 * [Buffer Prefix]
* 48 * [Line Prefix][encoded data atoms][Line Suffix]
* 49 * [Buffer Suffix]
* 50 *
* </pre>
* <p>
* 51 * 52 * Of course in the simplest encoding schemes, the buffer has no 53 *
* distinct prefix of suffix, however all have some fixed relationship 54 *
* between the text in an 'atom' and the binary data itself. 55 * 56 * In the
* CharacterEncoder and CharacterDecoder classes, one complete 57 * chunk of
* data is referred to as a <i>buffer</i>. Encoded buffers 58 * are all text,
* and decoded buffers (sometimes just referred to as 59 * buffers) are binary
* octets. 60 * 61 * To create a custom decoder, you must, at a minimum, overide
* three 62 * abstract methods in this class. 63 *
* <DL>
* 64 *
* <DD>bytesPerAtom which tells the decoder how many bytes to 65 * expect from
* decodeAtom 66 *
* <DD>decodeAtom which decodes the bytes sent to it as text. 67 *
* <DD>bytesPerLine which tells the encoder the maximum number of 68 * bytes per
* line. 69 *
* </DL>
* 70 * 71 * In general, the character decoders return error in the form of a 72
* * CEFormatException. The syntax of the detail string is 73 *
* <p>
* <pre>
* 74 * DecoderClassName: Error message.
* 75 *
* </pre>
* <p>
* 76 * 77 * Several useful decoders have already been written and are 78 *
* referenced in the See Also list below. 79 * 80 * @author Chuck McManis 81 * @see
* CEFormatException 82 * @see CharacterEncoder 83 * @see UCDecoder 84 * @see
* UUDecoder 85 * @see BASE64Decoder 86
*/
public abstract class CharacterDecoder {
/**
* Return the number of bytes per atom of decoding
*/
abstract protected int bytesPerAtom();
/**
* Return the maximum number of bytes that can be encoded per line
*/
abstract protected int bytesPerLine();
/**
* decode the beginning of the buffer, by default this is a NOP.
*/
protected void decodeBufferPrefix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
}
/**
* decode the buffer suffix, again by default it is a NOP.
*/
protected void decodeBufferSuffix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
}
/**
* 103 * This method should return, if it knows, the number of bytes 104 *
* that will be decoded. Many formats such as uuencoding findLoanInfoList 105 * this
* information. By default we return the maximum bytes that 106 * could have
* been encoded on the line. 107
*/
protected int decodeLinePrefix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
return (bytesPerLine());
}
/**
* 113 * This method post processes the line, if there are error detection
* 114 * or correction codes in a line, they are generally processed by 115
* * this method. The simplest version of this method looks for the 116 *
* (newline) character. 117
*/
protected void decodeLineSuffix(PushbackInputStream aStream,
OutputStream bStream) throws IOException {
}
/**
* 121 * This method does an actual decode. It takes the decoded bytes and
* 122 * writes them to the OutputStream. The integer <i>l</i> tells the 123
* * method how many bytes are required. This is always <= bytesPerAtom().
* 124
*/
protected void decodeAtom(PushbackInputStream aStream,
OutputStream bStream, int l) throws IOException {
throw new CEStreamExhausted();
}
/**
* 130 * This method works around the bizarre semantics of
* BufferedInputStream's 131 * read method. 132
*/
protected int readFully(InputStream in, byte buffer[], int offset, int len)
throws java.io.IOException {
for (int i = 0; i < len; i++) {
int q = in.read();
if (q == -1)
return ((i == 0) ? -1 : i);
buffer[i + offset] = (byte) q;
}
return len;
}
/**
* 145 * Decode the text from the InputStream and write the decoded 146 *
* octets to the OutputStream. This method runs until the stream 147 * is
* exhausted. 148 * @exception CEFormatException An error has occured while
* decoding 149 * @exception CEStreamExhausted The input stream is
* unexpectedly out of data 150
*/
public void decodeBuffer(InputStream aStream, OutputStream bStream)
throws IOException {
int i;
@SuppressWarnings("unused")
int totalBytes = 0;
PushbackInputStream ps = new PushbackInputStream(aStream);
decodeBufferPrefix(ps, bStream);
while (true) {
int length;
try {
length = decodeLinePrefix(ps, bStream);
for (i = 0; (i + bytesPerAtom()) < length; i += bytesPerAtom()) {
decodeAtom(ps, bStream, bytesPerAtom());
totalBytes += bytesPerAtom();
}
if ((i + bytesPerAtom()) == length) {
decodeAtom(ps, bStream, bytesPerAtom());
totalBytes += bytesPerAtom();
} else {
decodeAtom(ps, bStream, length - i);
totalBytes += (length - i);
}
decodeLineSuffix(ps, bStream);
} catch (CEStreamExhausted e) {
break;
}
}
decodeBufferSuffix(ps, bStream);
}
/**
* 182 * Alternate decode interface that takes a String containing the
* encoded 183 * buffer and returns a byte array containing the data. 184 * @exception
* CEFormatException An error has occured while decoding 185
*/
@SuppressWarnings("deprecation")
public byte decodeBuffer(String inputString)[]throws IOException {
byte inputBuffer[] = new byte[inputString.length()];
ByteArrayInputStream inStream;
ByteArrayOutputStream outStream;
inputString.getBytes(0, inputString.length(), inputBuffer, 0);
inStream = new ByteArrayInputStream(inputBuffer);
outStream = new ByteArrayOutputStream();
decodeBuffer(inStream, outStream);
return (outStream.toByteArray());
}
/**
* 199 * Decode the contents of the inputstream into a buffer. 200
*/
public byte decodeBuffer(InputStream in)[]throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
decodeBuffer(in, outStream);
return (outStream.toByteArray());
}
/**
* 208 * Decode the contents of the String into a ByteBuffer. 209
*/
public ByteBuffer decodeBufferToByteBuffer(String inputString)
throws IOException {
return ByteBuffer.wrap(decodeBuffer(inputString));
}
/**
* 216 * Decode the contents of the inputStream into a ByteBuffer. 217
*/
public ByteBuffer decodeBufferToByteBuffer(InputStream in)
throws IOException {
return ByteBuffer.wrap(decodeBuffer(in));
}
}
\ No newline at end of file
package cn.quantgroup.report.utils.commonutil;
/*
2 * Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
import java.io.*;
import java.nio.ByteBuffer;
/**
* 38 * This class defines the encoding half of character encoders. 39 * A
* character encoder is an algorithim for transforming 8 bit binary 40 * data
* into text (generally 7 bit ASCII or 8 bit ISO-Latin-1 text) 41 * for
* transmition over text channels such as e-mail and network news. 42 * 43 * The
* character encoders have been structured around a central theme 44 * that, in
* general, the encoded text has the form: 45 * 46 *
*
* <pre>
* 47 * [Buffer Prefix]
* 48 * [Line Prefix][encoded data atoms][Line Suffix]
* 49 * [Buffer Suffix]
* 50 *
* </pre>
*
* 51 * 52 * In the CharacterEncoder and CharacterDecoder classes, one complete
* 53 * chunk of data is referred to as a <i>buffer</i>. Encoded buffers 54 *
* are all text, and decoded buffers (sometimes just referred to as 55 *
* buffers) are binary octets. 56 * 57 * To create a custom encoder, you must,
* at a minimum, overide three 58 * abstract methods in this class. 59 *
* <DL>
* 60 *
* <DD>bytesPerAtom which tells the encoder how many bytes to 61 * send to
* encodeAtom 62 *
* <DD>encodeAtom which encodes the bytes sent to it as text. 63 *
* <DD>bytesPerLine which tells the encoder the maximum number of 64 * bytes per
* line. 65 *
* </DL>
* 66 * 67 * Several useful encoders have already been written and are 68 *
* referenced in the See Also list below. 69 * 70 * @author Chuck McManis 71 * @see
* CharacterDecoder; 72 * @see UCEncoder 73 * @see UUEncoder 74 * @see
* BASE64Encoder 75
*/
public abstract class CharacterEncoder
{
/** Stream that understands "printing" */
protected PrintStream pStream;
/** Return the number of bytes per atom of encoding */
abstract protected int bytesPerAtom();
/** Return the number of bytes that can be encoded per line */
abstract protected int bytesPerLine();
/**
* 88 * Encode the prefix for the entire buffer. By default is simply 89 *
* opens the PrintStream for use by the other functions. 90
*/
protected void encodeBufferPrefix(OutputStream aStream) throws IOException
{
pStream = new PrintStream(aStream);
}
/**
* 96 * Encode the suffix for the entire buffer. 97
*/
protected void encodeBufferSuffix(OutputStream aStream) throws IOException
{
}
/**
* 102 * Encode the prefix that starts every output line. 103
*/
protected void encodeLinePrefix(OutputStream aStream, int aLength)
throws IOException
{
}
/**
* 109 * Encode the suffix that ends every output line. By default 110 *
* this method just prints a <newline> into the output stream. 111
*/
protected void encodeLineSuffix(OutputStream aStream) throws IOException
{
pStream.println();
}
/** Encode one "atom" of information into characters. */
abstract protected void encodeAtom(OutputStream aStream, byte someBytes[],
int anOffset, int aLength) throws IOException;
/**
* 121 * This method works around the bizarre semantics of
* BufferedInputStream's 122 * read method. 123
*/
protected int readFully(InputStream in, byte buffer[])
throws java.io.IOException
{
for (int i = 0; i < buffer.length; i++)
{
int q = in.read();
if (q == -1)
return i;
buffer[i] = (byte) q;
}
return buffer.length;
}
/**
* 136 * Encode bytes from the input stream, and write them as text
* characters 137 * to the output stream. This method will run until it
* exhausts the 138 * input stream, but does not print the line suffix for a
* final 139 * line that is shorter than bytesPerLine(). 140
*/
public void encode(InputStream inStream, OutputStream outStream)
throws IOException
{
int j;
int numBytes;
byte tmpbuffer[] = new byte[bytesPerLine()];
encodeBufferPrefix(outStream);
while (true)
{
numBytes = readFully(inStream, tmpbuffer);
if (numBytes == 0)
{
break;
}
encodeLinePrefix(outStream, numBytes);
for (j = 0; j < numBytes; j += bytesPerAtom())
{
if ((j + bytesPerAtom()) <= numBytes)
{
encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
} else
{
encodeAtom(outStream, tmpbuffer, j, (numBytes) - j);
}
}
if (numBytes < bytesPerLine())
{
break;
} else
{
encodeLineSuffix(outStream);
}
}
encodeBufferSuffix(outStream);
}
/**
* 173 * Encode the buffer in <i>aBuffer</i> and write the encoded 174 *
* result to the OutputStream <i>aStream</i>. 175
*/
public void encode(byte aBuffer[], OutputStream aStream) throws IOException
{
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
encode(inStream, aStream);
}
/**
* 183 * A 'streamless' version of encode that simply takes a buffer of 184
* * bytes and returns a string containing the encoded buffer. 185
*/
public String encode(byte aBuffer[])
{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
String retVal = null;
try
{
encode(inStream, outStream);
// explicit ascii->unicode conversion
retVal = outStream.toString("8859_1");
} catch (Exception IOException)
{
// This should never happen.
throw new Error("CharacterEncoder.encode internal error");
}
return (retVal);
}
/**
* 202 * Return a byte array from the remaining bytes in this ByteBuffer.
* 203 *
* <P>
* 204 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
* 205 *
* <P>
* 206 * To avoid an extra copy, the implementation will attempt to return
* the 207 * byte array backing the ByteBuffer. If this is not possible, a
* 208 * new byte array will be created. 209
*/
private byte[] getBytes(ByteBuffer bb)
{
/*
* This should never return a BufferOverflowException, as we're 213 *
* careful to allocate just the right amount. 214
*/
byte[] buf = null;
/*
* 218 * If it has a usable backing byte buffer, use it. Use only 219 *
* if the array exactly represents the current ByteBuffer. 220
*/
if (bb.hasArray())
{
byte[] tmp = bb.array();
if ((tmp.length == bb.capacity()) && (tmp.length == bb.remaining()))
{
buf = tmp;
bb.position(bb.limit());
}
}
if (buf == null)
{
/*
* 232 * This class doesn't have a concept of encode(buf, len, off),
* 233 * so if we have a partial buffer, we must reallocate 234 *
* space. 235
*/
buf = new byte[bb.remaining()];
/*
* 239 * position() automatically updated 240
*/
bb.get(buf);
}
return buf;
}
/**
* 248 * Encode the <i>aBuffer</i> ByteBuffer and write the encoded 249 *
* result to the OutputStream <i>aStream</i>. 250 *
* <P>
* 251 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
* 252
*/
public void encode(ByteBuffer aBuffer, OutputStream aStream)
throws IOException
{
byte[] buf = getBytes(aBuffer);
encode(buf, aStream);
}
/**
* 260 * A 'streamless' version of encode that simply takes a ByteBuffer 261
* * and returns a string containing the encoded buffer. 262 *
* <P>
* 263 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
* 264
*/
public String encode(ByteBuffer aBuffer)
{
byte[] buf = getBytes(aBuffer);
return encode(buf);
}
/**
* 271 * Encode bytes from the input stream, and write them as text
* characters 272 * to the output stream. This method will run until it
* exhausts the 273 * input stream. It differs from encode in that it will
* add the 274 * line at the end of a final line that is shorter than
* bytesPerLine(). 275
*/
public void encodeBuffer(InputStream inStream, OutputStream outStream)
throws IOException
{
int j;
int numBytes;
byte tmpbuffer[] = new byte[bytesPerLine()];
encodeBufferPrefix(outStream);
while (true)
{
numBytes = readFully(inStream, tmpbuffer);
if (numBytes == 0)
{
break;
}
encodeLinePrefix(outStream, numBytes);
for (j = 0; j < numBytes; j += bytesPerAtom())
{
if ((j + bytesPerAtom()) <= numBytes)
{
encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
} else
{
encodeAtom(outStream, tmpbuffer, j, (numBytes) - j);
}
}
encodeLineSuffix(outStream);
if (numBytes < bytesPerLine())
{
break;
}
}
encodeBufferSuffix(outStream);
}
/**
* 306 * Encode the buffer in <i>aBuffer</i> and write the encoded 307 *
* result to the OutputStream <i>aStream</i>. 308
*/
public void encodeBuffer(byte aBuffer[], OutputStream aStream)
throws IOException
{
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
encodeBuffer(inStream, aStream);
}
/**
* 316 * A 'streamless' version of encode that simply takes a buffer of 317
* * bytes and returns a string containing the encoded buffer. 318
*/
public String encodeBuffer(byte aBuffer[])
{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
try
{
encodeBuffer(inStream, outStream);
} catch (Exception IOException)
{
// This should never happen.
throw new Error("CharacterEncoder.encodeBuffer internal error");
}
return (outStream.toString());
}
/**
* 332 * Encode the <i>aBuffer</i> ByteBuffer and write the encoded 333 *
* result to the OutputStream <i>aStream</i>. 334 *
* <P>
* 335 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
* 336
*/
public void encodeBuffer(ByteBuffer aBuffer, OutputStream aStream)
throws IOException
{
byte[] buf = getBytes(aBuffer);
encodeBuffer(buf, aStream);
}
/**
* 344 * A 'streamless' version of encode that simply takes a ByteBuffer 345
* * and returns a string containing the encoded buffer. 346 *
* <P>
* 347 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
* 348
*/
public String encodeBuffer(ByteBuffer aBuffer)
{
byte[] buf = getBytes(aBuffer);
return encodeBuffer(buf);
}
}
\ No newline at end of file
package cn.quantgroup.report.utils.commonutil;
import org.apache.commons.codec.binary.Base64;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
/**
*
* DES加密算法工具
* @author jveri
*
*/
/**
*
* DES加密算法工具类
* @author jveri
*
*/
public class DESUtil {
//算法名称
public static final String KEY_ALGORITHM = "DES";
//算法名称/加密模式/填充方式
//-->>ECB:电子密码本模式
public static final String CIPHER_ALGORITHM = "DES/ECB/PKCS5Padding";
/**
*
* 生成密钥key对象
* @return 密钥对象
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
* @throws Exception
*/
private static SecretKey keyGenerator(String keyStr) throws Exception {
//byte input[] = HexString2Bytes(keyStr);
DESKeySpec desKey = new DESKeySpec(keyStr.getBytes("UTF-8"));
//创建一个密匙工厂,然后用它把DESKeySpec转换成
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(desKey);
return securekey;
}
private static int parse(char c) {
if (c >= 'a') return (c - 'a' + 10) & 0x0f;
if (c >= 'A') return (c - 'A' + 10) & 0x0f;
return (c - '0') & 0x0f;
}
// 从十六进制字符串到字节数组转换
public static byte[] HexString2Bytes(String hexstr) {
byte[] b = new byte[hexstr.length() / 2];
int j = 0;
for (int i = 0; i < b.length; i++) {
char c0 = hexstr.charAt(j++);
char c1 = hexstr.charAt(j++);
b[i] = (byte) ((parse(c0) << 4) | parse(c1));
}
return b;
}
/**
* 加密数据
* @param data 待加密数据
* @param key 密钥
* @return 加密后的数据
*/
public static String encrypt(String data, String key) throws Exception {
Key deskey = keyGenerator(key);
// 实例化Cipher对象,它用于完成实际的加密操作
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
SecureRandom random = new SecureRandom();
// 初始化Cipher对象,设置为加密模式
cipher.init(Cipher.ENCRYPT_MODE, deskey, random);
byte[] results = cipher.doFinal(data.getBytes("UTF-8"));
// 十六进制结果进行核对
/*for (int i = 0; i < results.length; i++) {
System.out.print(results[i] + " ");
}*/
// 执行加密操作。加密后的结果通常都会用Base64编码进行传输
return Base64.encodeBase64String(results);
}
/**
* 解密数据
* @param data 待解密数据
* @param key 密钥
* @return 解密后的数据
*/
public static String decrypt(String data, String key) throws Exception {
Key deskey = keyGenerator(key);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
//初始化Cipher对象,设置为解密模式
cipher.init(Cipher.DECRYPT_MODE, deskey);
// 执行解密操作
return new String(cipher.doFinal(Base64.decodeBase64(data)));
}
}
package cn.quantgroup.report.utils.commonutil;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
public class MD5Util {
private static ThreadLocal<MessageDigest> messageDigestHolder = new ThreadLocal();
static final char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
public MD5Util() {
}
public static String getMd5(String plainText) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
// 32位加密
return buf.toString();
// 16位的加密
// return buf.toString().substring(8, 24);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
public static String getMD5Format(String data) {
try {
MessageDigest e = (MessageDigest) messageDigestHolder.get();
if (e == null) {
e = MessageDigest.getInstance("MD5");
messageDigestHolder.set(e);
}
e.update(data.getBytes());
byte[] b = e.digest();
String digestHexStr = "";
for (int i = 0; i < 16; ++i) {
digestHexStr = digestHexStr + byteHEX(b[i]);
}
return digestHexStr;
} catch (Exception var5) {
System.out.println(var5);
return null;
}
}
public static String getMD5Format(byte[] data) {
try {
MessageDigest e = (MessageDigest) messageDigestHolder.get();
if (e == null) {
e = MessageDigest.getInstance("MD5");
messageDigestHolder.set(e);
}
e.update(data);
byte[] b = e.digest();
String digestHexStr = "";
for (int i = 0; i < 16; ++i) {
digestHexStr = digestHexStr + byteHEX(b[i]);
}
return digestHexStr;
} catch (Exception var5) {
return null;
}
}
private static String byteHEX(byte ib) {
char[] ob = new char[]{hexDigits[ib >>> 4 & 15], hexDigits[ib & 15]};
String s = new String(ob);
return s;
}
static {
try {
MessageDigest e = MessageDigest.getInstance("MD5");
messageDigestHolder.set(e);
} catch (NoSuchAlgorithmException var1) {
System.out.println(var1);
}
}
/**
* 描述: md5.digest <br/>
* 参数: [msg] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.20 <br/>
*/
public static String getMD5Digest(String msg) {
try {
MessageDigest md5 = (MessageDigest) messageDigestHolder.get();
if (md5 == null) {
md5 = MessageDigest.getInstance("MD5");
messageDigestHolder.set(md5);
}
byte[] byteArray=null;
byteArray=msg.getBytes();
byte[] md5Bytes=md5.digest(byteArray);
StringBuffer hexValue=new StringBuffer();
for(int i=0; i < md5Bytes.length; i++) {
int val=((int)md5Bytes[i]) & 0xff;
if(val < 16)
hexValue.append("0");
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
} catch (Exception var5) {
System.out.println(var5);
return null;
}
}
/**
* 描述: 生成含有16位随机盐的MD5加密串 <br/>
* 参数: [msg] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.26 <br/>
*/
public static String get48Md5(String msg) {
Random r = new Random();
StringBuilder sb = new StringBuilder(16);
sb.append(r.nextInt(99999999)).append(r.nextInt(99999999));
int len = sb.length();
if (len < 16) {
for (int i = 0; i < 16 - len; i++) {
sb.append("0");
}
}
String salt = sb.toString();
msg = getMd5(msg + salt);
char[] cs = new char[48];
for (int i = 0; i < 48; i += 3) {
cs[i] = msg.charAt(i / 3 * 2);
char c = salt.charAt(i / 3);
cs[i + 1] = c;
cs[i + 2] = msg.charAt(i / 3 * 2 + 1);
}
return new String(cs);
}
/**
* 描述: 校验48位str48Md5是否正确 <br/>
* 参数: [msg, str48Md5] <br/>
* 返回值: boolean <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.26 <br/>
*/
public static boolean verify48Md5(String msg, String str48Md5) {
char[] cs1 = new char[32];
char[] cs2 = new char[16];
for (int i = 0; i < 48; i += 3) {
cs1[i / 3 * 2] = str48Md5.charAt(i);
cs1[i / 3 * 2 + 1] = str48Md5.charAt(i + 2);
cs2[i / 3] = str48Md5.charAt(i + 1);
}
String salt = new String(cs2);
return getMd5(msg + salt).equals(new String(cs1));
}
}
package cn.quantgroup.report.utils.commonutil;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* -----------------------------------------------------------------------------<br>
* 描述: hmacSha1加密工具类<br>
* 作者: Haoyanhui <br>
* 时间:2019.09.11 15:12 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public class MyHmacSha1 {
/**
* @描述 hmacSha1加密
* @参数 [data:字符串, key]
* @返回值 byte[]
* @创建人 yanhui.Hao
* @创建时间 2019.09.11
*/
public static byte[] hmacSha1(String data, byte[] key) {//String[] datas, byte[] key
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
Mac mac = null;
try {
mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (InvalidKeyException e) {
throw new RuntimeException(e.getMessage(), e);
}
try {
mac.update(data.getBytes(Charset.forName("utf-8")));
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
return mac.doFinal();
}
/**
* @描述 hmacSha1加密
* @参数 [dataArry:字符串数组, key]
* @返回值 byte[]
* @创建人 yanhui.Hao
* @创建时间 2019.09.11
*/
public static byte[] hmacSha1(String[] dataArry, byte[] key) {
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
Mac mac = null;
try {
mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (InvalidKeyException e) {
throw new RuntimeException(e.getMessage(), e);
}
try {
for (String data : dataArry) {
mac.update(data.getBytes(Charset.forName("utf-8")));
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
return mac.doFinal();
}
public static String byte2hex(final byte[] b) {
String hs = "";
for (int n = 0; n < b.length; n++) {
String stmp = (java.lang.Integer.toHexString(b[n] & 0xFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs;
}
}
package cn.quantgroup.report.utils.commonutil;
import cn.quantgroup.report.error.QGExceptionType;
import cn.quantgroup.report.error.QGPreconditions;
import org.apache.commons.lang3.StringUtils;
/**
* 三要素/uuid 参数空校验
*
* @Author fengjunkai
* @Date 2019-06-13 17:06
*/
public class ParammeterCheckUtils {
public static void checkParams(String transactionId, String uuid, String phone, String idCard, String name){
QGPreconditions.checkArgument(StringUtils.isNotBlank(phone), QGExceptionType.COMMON_STRING_PARAM_IS_ALL_NULL, "phone");
QGPreconditions.checkArgument(StringUtils.isNotBlank(idCard), QGExceptionType.COMMON_STRING_PARAM_IS_ALL_NULL, "idCard");
QGPreconditions.checkArgument(StringUtils.isNotBlank(name), QGExceptionType.COMMON_STRING_PARAM_IS_ALL_NULL, "name");
QGPreconditions.checkArgument(StringUtils.isNotBlank(uuid), QGExceptionType.COMMON_STRING_PARAM_IS_ALL_NULL, "uuid");
}
}
package cn.quantgroup.report.utils.commonutil;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
/**
* -----------------------------------------------------------------------------<br>
* 描述: RSA加密,解密<br>
* 作者:yanhui.Hao <br>
* 时间:2019.09.26 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public class RSAEncrypt {
//private static Map<Integer, String> keyMap = new HashMap<Integer, String>(); //用于封装随机产生的公钥与私钥
/**
* 随机生成密钥对
* @throws NoSuchAlgorithmException
*/
public static Map<Integer, String> genKeyPair() throws NoSuchAlgorithmException {
// KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
// 初始化密钥对生成器,密钥大小为96-1024位
keyPairGen.initialize(1024,new SecureRandom());
// 生成一个密钥对,保存在keyPair中
KeyPair keyPair = keyPairGen.generateKeyPair();
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); // 得到私钥
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); // 得到公钥
String publicKeyString = new String(Base64.encodeBase64(publicKey.getEncoded()));
// 得到私钥字符串
String privateKeyString = new String(Base64.encodeBase64((privateKey.getEncoded())));
// 将公钥和私钥保存到Map
Map<Integer, String> keyMap = new HashMap<Integer, String>();
keyMap.put(0,publicKeyString); //0表示公钥
keyMap.put(1,privateKeyString); //1表示私钥
return keyMap;
}
/**
* RSA公钥加密
*
* @param str
* 加密字符串
* @param publicKey
* 公钥
* @return 密文
* @throws Exception
* 加密过程中的异常信息
*/
public static String encrypt( String str, String publicKey ) throws Exception{
//base64编码的公钥
byte[] decoded = Base64.decodeBase64(publicKey);
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
//RSA加密
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
return outStr;
}
/**
* RSA私钥解密
*
* @param str
* 加密字符串
* @param privateKey
* 私钥
* @return 铭文
* @throws Exception
* 解密过程中的异常信息
*/
public static String decrypt(String str, String privateKey) throws Exception{
//64位解码加密后的字符串
byte[] inputByte = Base64.decodeBase64(str.getBytes("UTF-8"));
//base64编码的私钥
byte[] decoded = Base64.decodeBase64(privateKey);
RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
//RSA解密
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, priKey);
String outStr = new String(cipher.doFinal(inputByte));
return outStr;
}
public static void main(String[] args) throws Exception {
//生成公钥和私钥
Map<Integer, String> keyMap = genKeyPair();
//加密字符串
String message = "123456";
System.out.println("随机生成的公钥为:" + keyMap.get(0));
System.err.println("随机生成的私钥为:" + keyMap.get(1));
String messageEn = encrypt(message,keyMap.get(0));
System.err.println(message + "|加密后的字符串为:\n" + messageEn);
String messageDe = decrypt(messageEn,keyMap.get(1));
System.out.println("还原后的字符串为:" + messageDe);
}
}
package cn.quantgroup.report.utils.commonutil;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Author fengjunkai
* @Date 2019-07-22 17:53
*/
public class RegexPaserUtil {
private String beginRegex;
private String endRegex;
private Matcher matcher;
public final static String TEXTTEGEX = ".*?";
public final static String W = "\\W*?";
public final static String N = "";
public final static String TEXTEGEXANDNRT = "[\\s\\S]*?";
public final static String zel_all_chars = "[\\s\\S]*";
private List<String> filterRegexList = new ArrayList<String>();
// 是否为全正常中英文、符号的情况验证
public static String All_Chinese_Char = "[\\sA-Za-z\\d\\u4E00-\\u9FA5\\pP\\pZ\\pM\\pN\u3040-\u309F\u30A0-\u30FF+\\-*/\\\\$●=><|\\[\\]]";
public Pattern All_Chinese_Char_Pattern = Pattern.compile(All_Chinese_Char);
// 此处的中文判断,包括中文、英文、数字、中英文符号等
public boolean isAllChineseChar(String source) {
if (source == null || source.trim().length() == 0) {
return true;
} else {
char[] charArray = source.toCharArray();
for (char c : charArray) {
if (!(All_Chinese_Char_Pattern.matcher(c + "").find())) {
return false;
}
}
return true;
}
}
public RegexPaserUtil(String beginRegex, String endRegex, String content,
String textRegex) {
this.beginRegex = beginRegex;
this.endRegex = endRegex;
StringBuilder sb = new StringBuilder();
sb.append(beginRegex);
sb.append(textRegex);
sb.append(endRegex);
matcher = Pattern.compile(sb.toString()).matcher(content);
}
// 此处的content变量暂未用
public RegexPaserUtil(String beginRegex, String textRegex, String endRegex,
String content, String flag) {
this.beginRegex = beginRegex;
this.endRegex = endRegex;
StringBuilder sb = new StringBuilder();
sb.append(beginRegex);
sb.append(textRegex);
sb.append(endRegex);
matcher = Pattern.compile(sb.toString()).matcher(content);
}
public RegexPaserUtil(String beginRegex, String endRegex, String textRegex) {
this.beginRegex = beginRegex;
this.endRegex = endRegex;
StringBuilder sb = new StringBuilder();
sb.append(beginRegex);
sb.append(textRegex);
sb.append(endRegex);
matcher = Pattern.compile(sb.toString()).matcher(N);
}
public RegexPaserUtil(String beginRegex, String endRegex) {
this.beginRegex = beginRegex;
this.endRegex = endRegex;
StringBuilder sb = new StringBuilder();
sb.append(beginRegex);
sb.append(TEXTTEGEX);
sb.append(endRegex);
matcher = Pattern.compile(sb.toString()).matcher(N);
}
public String getSimpleText() {
if (matcher.find()) {
String str = matcher.group().trim();
return str;
}
return null;
}
public String getText() {
if (matcher.find()) {
String str = matcher.group().trim().replaceFirst(beginRegex, N)
.replaceAll(endRegex, N);
Iterator<String> it = filterRegexList.iterator();
while (it.hasNext()) {
str = str.replaceAll(it.next(), N);
}
return str;
}
return null;
}
public String getLastText() {
String str = null;
while (matcher.find()) {
str = matcher.group().trim().replaceFirst(beginRegex, N)
.replaceAll(endRegex, N);
}
return str;
}
public String getNext() {
return matcher.group();
}
public String getNextTxt() {
String str = matcher.group().trim().replaceFirst(beginRegex, N)
.replaceAll(endRegex, N);
Iterator<String> it = filterRegexList.iterator();
while (it.hasNext()) {
str = str.replaceAll(it.next(), N);
}
return str;
}
/**
* 是指过滤了相关标签
*
* @return
*/
public String getNextAddFilter() {
String str = matcher.group();
Iterator<String> it = filterRegexList.iterator();
while (it.hasNext()) {
str = str.replaceAll(it.next(), N);
}
return str;
}
/**
* 循环遍历时,得到真正的txt,而不是匹配全部
*
* @return
*/
public String getNextText() {
String str = matcher.group();
str = str.replaceFirst(beginRegex, N).replaceAll(endRegex, N);
return str;
}
public boolean hasNext() {
return matcher.find();
}
public RegexPaserUtil reset(String content) {
this.matcher.reset(content);
return this;
}
public RegexPaserUtil addFilterRegex(String filterRegex) {
filterRegexList.add(filterRegex);
return this;
}
public String getTextList() {
String str = "";
int count = 0;
while (matcher.find()) {
if (count == 0) {
str = matcher.group().trim().replaceFirst(beginRegex, N)
.replaceAll(endRegex, N);
} else {
str += ("#" + matcher.group().trim()
.replaceFirst(beginRegex, N).replaceAll(endRegex, N));
}
count++;
}
return str;
}
/**
* 获得可匹配对象
*
* @param input
* @param regex
* @return
*/
public static Matcher getMatcher(String input, Pattern pattern) {
Matcher defaultMatcher = null;
Pattern defaultPattern = null;
defaultPattern = pattern;
defaultMatcher = defaultPattern.matcher(input);
return defaultMatcher;
}
public static void main(String[] args) {
String source = "��� ���� ";
RegexPaserUtil regexPaserUtil = new RegexPaserUtil(null, null);
System.out.println(regexPaserUtil.isAllChineseChar(source));
}
}
package cn.quantgroup.report.utils.dingtalk;
import cn.quantgroup.report.service.http.IHttpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 量化派2百行钉钉提醒 <br>
* 作者:yanhui.Hao <br>
* 时间:2020.01.06 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Component
@Slf4j
public class DingTalk {
@Autowired
private IHttpService iHttpService;
public static final String talkUri = "https://alertserv-dataservice.quantgroup.cn/common/alert/dingtalk";
//量化派2百行
public static final String webHook = "https://oapi.dingtalk.com/robot/send?access_token=ef3cafb299ec6cb7442b2795d4d0c48e940756f7f267cfa895dbb419adb00128";
@Async
public void talk(String alarmLevel, String msgTitle, String msgContent) {
try{
Map<String, String> param = new HashMap<>();
param.put("webhook", webHook);
param.put("alarmLevel", alarmLevel);//"Warn"
param.put("msgTitle", "量化派2百行:" + msgTitle);
param.put("msgContent", msgContent);
// param.put("toUsers", "15542661376,18612632691");
String resp = iHttpService.post(talkUri, param);
log.info("钉钉报警接口调用结束, resp: {} ", resp);
}catch (Exception e){
log.warn("钉钉报警接口调用异常! ",e);
}
}
@Async
public void talk(String alarmLevel, String msgTitle, Exception e) {
try{
if (e == null) {
return;
}
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
Map<String, String> param = new HashMap<>();
param.put("webhook", webHook);
param.put("alarmLevel", alarmLevel);//"Warn"
param.put("msgTitle", "量化派2百行:" + msgTitle);
param.put("msgContent", sw.toString().length() > 500 ? sw.toString().substring(0, 499) : sw.toString());
// param.put("toUsers", "15542661376,18612632691");
String resp = iHttpService.post(talkUri, param);
log.info("测试钉钉报警接口结果!resp:{}", resp);
log.info("钉钉报警接口调用结束, resp: {} ", resp);
}catch (Exception e2){
log.warn("钉钉报警接口调用异常! ",e2);
}
}
@Async
public void talk_ToUser(String msgTitle, String msgContent) {
try{
Map<String, String> param = new HashMap<>();
param.put("webhook", webHook);
param.put("alarmLevel", "ERROE");//
param.put("msgTitle", "量化派2百行:"+msgTitle);
param.put("msgContent", msgContent);
param.put("toUsers", "18010105506");
String resp = iHttpService.post(talkUri, param);
log.info("钉钉报警接口调用结束, resp: {} ", resp);
}catch (Exception e){
log.warn("钉钉报警接口调用异常! ",e);
}
}
@Async
public void talk(String alarmLevel, String msgTitle, QgException e) {
Map<String, String> param = new HashMap<>();
param.put("webhook", webHook);
param.put("alarmLevel", alarmLevel);//"Warn"
param.put("msgTitle", "量化派2百行:" + msgTitle);
param.put("msgContent", exceptionToString(e));
// param.put("toUsers", "15542661376,18612632691");
String resp = iHttpService.post(talkUri, param);
log.info("测试钉钉报警接口结果!resp:{}", resp);
}
public String exceptionToString(QgException e) {
return new StringBuffer()
.append(e.alarm)
.append(":")
.append(e.message == null ? "" : (e.message.length() > 500 ? e.message.substring(0, 499) : e.message)).toString();
}
}
package cn.quantgroup.report.utils.dingtalk;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* @author :dongjianhua
* @date :Created in 2019/11/4 10:38
* @description:异常类
* @modified By:
* @version: 1.0
*/
public class QgException extends RuntimeException {
//提醒标题
public String alarm;
//堆栈信息 或者报错信息
public String message;
public QgException(String exMsg) {
alarm = exMsg;
}
public QgException(String exMsg, String message) {
super(message,null);
alarm = exMsg;
this.message = message;
}
public QgException(String exMsg, Exception e) {
super(e);
alarm = exMsg;
message = getStackTrace(e);
}
public static String getStackTrace(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
t.printStackTrace(pw);
return sw.toString();
} finally {
pw.close();
}
}
}
package cn.quantgroup.report.utils.http;
import cn.quantgroup.report.error.QGException;
import cn.quantgroup.report.error.QGExceptionType;
import cn.quantgroup.report.response.RiskHttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.*;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.zip.GZIPOutputStream;
/**
* Created by suh on 2017/12/18.
*/
@Slf4j
public class HttpRequestUtil {
private static PoolingHttpClientConnectionManager connMgr;
private static RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(10000).build();
private static CloseableHttpClient httpClient=null;
private final static Object syncLock = new Object();
/** 针对中诚信手机号实名验证 调用频繁 Read timed out问题 */
private static RequestConfig requestConfig2 = RequestConfig.custom().setConnectTimeout(6000).setSocketTimeout(15000).build();
private static CloseableHttpClient httpClient2 = null;
static {
try {
//添加对https的支持,该sslContext没有加载客户端证书
// 如果需要加载客户端证书,请使用如下sslContext,其中KEYSTORE_FILE和KEYSTORE_PASSWORD分别是你的证书路径和证书密码
//KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()
//FileInputStream instream = new FileInputStream(new File(KEYSTORE_FILE));
//keyStore.load(instream, KEYSTORE_PASSWORD.toCharArray());
//SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keyStore,KEYSTORE_PASSWORD.toCharArray())
// .loadTrustMaterial(null, new TrustSelfSignedStrategy())
//.build();
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,SSLConnectionSocketFactory.getDefaultHostnameVerifier());
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslsf)
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.build();
connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connMgr.setMaxTotal(50);
connMgr.setDefaultMaxPerRoute(25);
}catch (Exception e){
log.warn("httpUtils init get exception:",e);
}
}
public static CloseableHttpClient getHttpClient(){
if(httpClient == null){
synchronized (syncLock){
if(httpClient == null){
httpClient =HttpClients.custom().setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
}
}
}
return httpClient;
}
public static CloseableHttpClient getHttpClient2(){
if(httpClient2 == null){
synchronized (syncLock){
if(httpClient2 == null){
httpClient2 =HttpClients.custom().setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig2).build();
}
}
}
return httpClient2;
}
/**
* 发送 GET 请求(HTTP),不带输入数据
*
* @param url
* @return
*/
public static RiskHttpResponse doGet(String url) {
return doGet(url, new HashMap<String, Object>());
}
/**
* 发送 GET 请求(HTTP),K-V形式
*
* @param url
* @param params
* @return
*/
public static RiskHttpResponse doGet(String url, Map<String, Object> params) {
String apiUrl = url;
StringBuffer param = new StringBuffer();
int i = 0;
for (String key : params.keySet()) {
if (i == 0)
param.append("?");
else
param.append("&");
param.append(key).append("=").append(params.get(key));
i++;
}
apiUrl += param;
//CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
//modify 2019.09.18
//httpClient = getHttpClient();
long startUtc = System.currentTimeMillis();
httpClient2 = getHttpClient();
HttpGet httpGet = new HttpGet(apiUrl);
try {
HttpResponse response = httpClient2.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(entity));
EntityUtils.consume(entity);
return new RiskHttpResponse(jsonObject,statusCode);
} catch (Exception e){
long endtUtc = System.currentTimeMillis();
log.error("apiUrl: "+apiUrl+"请求失败, cost: "+(endtUtc-startUtc)+".ms ", e);
// throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_FAIL,e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+apiUrl);
}finally {
httpGet.releaseConnection();
}
}
/**
* 发送 POST 请求(HTTP),不带输入数据
*
* @param apiUrl
* @return
*/
public static RiskHttpResponse doPost(String apiUrl) {
return doPost(apiUrl, new HashMap<String, Object>());
}
/**
* 发送 POST 请求(HTTP),K-V形式
*
* @param apiUrl API接口URL
* @param params 参数map
* @return
*/
public static RiskHttpResponse doPost(String apiUrl, Map<String, Object> params) {
//CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(apiUrl);
try {
List<NameValuePair> pairList = new ArrayList<>(params.size());
for (Map.Entry<String, Object> entry : params.entrySet()) {
NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry
.getValue().toString());
pairList.add(pair);
}
httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
HttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(entity));
EntityUtils.consume(entity);
return new RiskHttpResponse(jsonObject,statusCode);
} catch (IOException e) {
log.error("apiUrl: "+apiUrl+"请求失败", e);
// throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_FAIL,e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+apiUrl);
} finally {
httpPost.releaseConnection();
}
}
/**
* 发送 POST 请求(HTTP),JSON形式
*
* @param apiUrl
* @param json json对象
* @return
*/
public static RiskHttpResponse doPost(String apiUrl, JSONObject json) {
httpClient = getHttpClient();
// CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
HttpPost httpPost = new HttpPost(apiUrl);
try {
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity(json.toString(), "UTF-8");//解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
HttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(entity));
EntityUtils.consume(entity);
return new RiskHttpResponse(jsonObject,statusCode);
} catch (IOException e) {
log.error("apiUrl: "+apiUrl+"请求失败", e);
// throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_FAIL,e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+apiUrl);
} finally {
httpPost.releaseConnection();
}
}
public static RiskHttpResponse doGzipHttp(String url, JSONObject jsonObject) {
httpClient = getHttpClient();
//CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "text/plain");
httpPost.setHeader("Content-Encoding", "gzip");
try {
String message = JSON.toJSONString(jsonObject);
ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
originalContent.write(message.getBytes(Charset.forName("UTF-8")));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
originalContent.writeTo(gzipOut);
gzipOut.finish();
httpPost.setEntity(new ByteArrayEntity(baos.toByteArray()));
HttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
JSONObject object = JSONObject.parseObject(EntityUtils.toString(entity));
EntityUtils.consume(entity);
return new RiskHttpResponse(object, statusCode);
} catch (Exception e) {
log.error("apiUrl: "+url+"请求失败", e);
// throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_FAIL,e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+url);
} finally {
httpPost.releaseConnection();
}
}
public static RiskHttpResponse doGzipPost(String url,JSONObject jsonObject) {
try {
URL parsedUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) parsedUrl.openConnection();
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.addRequestProperty("Content-Type", "text/plain");
connection.addRequestProperty("Content-Encoding","gzip");
connection.setDoOutput(true);
String bodyStr = JSON.toJSONString(jsonObject);
byte[] body = bodyStr.getBytes("UTF-8");
if (body != null) {
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(body);
gzip.finish();
gzip.close();
}
connection.connect();
RiskHttpResponse response = new RiskHttpResponse();
int responseCode = connection.getResponseCode();
response.setCode(responseCode);
if (responseCode != HttpURLConnection.HTTP_OK) {
String responseData = getContent(connection.getErrorStream());
response.setJsonObject(JSONObject.parseObject(responseData));
} else {
String responseData = getContent(connection.getInputStream());
response.setJsonObject(JSONObject.parseObject(responseData));
}
return response;
} catch (Exception e) {
log.error("apiUrl: "+url+"请求失败", e);
// throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_FAIL,e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+url);
}
}
private static String getContent(InputStream in) {
StringBuffer sb = new StringBuffer();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(in, "utf-8"));
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
/**
* 发送 SSL POST 请求(HTTPS),K-V形式
*
* @param apiUrl API接口URL
* @param params 参数map
* @return
*/
public static String doPostSSL(String apiUrl, Map<String, Object> params) {
httpClient = getHttpClient();
// CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()).setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
HttpPost httpPost = new HttpPost(apiUrl);
CloseableHttpResponse response = null;
String httpStr = null;
try {
httpPost.setConfig(requestConfig);
List<NameValuePair> pairList = new ArrayList<NameValuePair>(params.size());
for (Map.Entry<String, Object> entry : params.entrySet()) {
NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry
.getValue().toString());
pairList.add(pair);
}
httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("utf-8")));
response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
return null;
}
HttpEntity entity = response.getEntity();
if (entity == null) {
return null;
}
httpStr = EntityUtils.toString(entity, "utf-8");
} catch (Exception e) {
log.error("apiUrl: "+apiUrl+"请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+apiUrl);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
return httpStr;
}
/**
* 发送 SSL POST 请求(HTTPS),K-V形式
*
* @param apiUrl API接口URL
* @param params 参数map
* @return
*/
public static String doPostSSL(String apiUrl, Map<String, String> headers, Map<String, String> params) {
httpClient = getHttpClient();
// CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()).setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
HttpPost httpPost = new HttpPost(apiUrl);
CloseableHttpResponse response = null;
String httpStr = null;
try {
headers.forEach(httpPost::addHeader);
httpPost.setConfig(requestConfig);
StringBuilder sb = new StringBuilder("{");
params.forEach((a, b) -> {
sb.append("\"" + a + "\"" + ":\"" + b + "\",");
});
String body = sb.substring(0, sb.length() - 1) + "}";
httpPost.setEntity(new StringEntity(body));
response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
// if (statusCode != HttpStatus.SC_OK) {
// return null;
// }
HttpEntity entity = response.getEntity();
// if (entity == null) {
// return null;
// }
httpStr = EntityUtils.toString(entity, "utf-8");
} catch (Exception e) {
log.error("apiUrl: "+apiUrl+"请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+apiUrl);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
return httpStr;
}
/**
* 发送 SSL POST 请求(HTTPS),JSON形式
*
* @param apiUrl API接口URL
* @param json JSON对象
* @return
*/
public static String doPostSSL(String apiUrl, JSONObject json) {
httpClient = getHttpClient();
// CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()).setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build();
HttpPost httpPost = new HttpPost(apiUrl);
CloseableHttpResponse response = null;
String httpStr = null;
try {
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity(json.toString(), "UTF-8");//解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
return null;
}
HttpEntity entity = response.getEntity();
if (entity == null) {
return null;
}
httpStr = EntityUtils.toString(entity, "utf-8");
} catch (Exception e) {
log.error("apiUrl: "+apiUrl+"请求失败", e);
// throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_FAIL,e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:"+apiUrl);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
return httpStr;
}
/**
* 创建SSL安全连接
*
* @return
*/
private static SSLConnectionSocketFactory createSSLConnSocketFactory() {
SSLConnectionSocketFactory sslsf = null;
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
@Override
public void verify(String host, SSLSocket ssl) throws IOException {
}
@Override
public void verify(String host, X509Certificate cert) throws SSLException {
}
@Override
public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
}
});
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
return sslsf;
}
/**
* 描述: FaceID风控服务-多头API post请求调用 <br/>
* 参数: [apiUrl, textMap] <br/>
* 返回值: java.util.Map<java.lang.String,java.lang.String> <br/>
* responseCode:http的返回code; content:返回的结果 <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.11 <br/>
*/
public static Map<String,String> doRiskInfoVerifyPost(String apiUrl, Map<String, String> textMap, String log_urlType) {
Map<String,String> resultMap = new HashMap<String,String>();
HttpURLConnection conn = null;
String BOUNDARY = "-----------12345654321-------------";
try {
// 设置请求参数
URL url = new URL(apiUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
conn.setRequestProperty("Content-Type","multipart/form-data; boundary=" + BOUNDARY);
conn.setRequestProperty("Charset", "UTF-8");
OutputStream out = new DataOutputStream(conn.getOutputStream());
// 对File 和 String 集合进行判空
if (textMap != null) {
StringBuffer strBuf = new StringBuffer();
Iterator iter = textMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String inputName = (String) entry.getKey();
String inputValue = (String) entry.getValue();
if (inputValue == null) {
continue;
}
strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n");
strBuf.append("Content-Disposition: form-data; name=\""+ inputName + "\"\r\n\r\n");
strBuf.append(inputValue);
}
out.write(strBuf.toString().getBytes("UTF-8"));
}
byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
out.write(endData);
out.flush();
out.close();
int responseCode = conn.getResponseCode();
String res = "";
if (responseCode == 200) {
// 读取正确返回信息
StringBuffer strBuf = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
strBuf.append(line).append("\n");
}
res = strBuf.toString();
reader.close();
reader = null;
} else {
// 读取错误返回信息
StringBuffer error = new StringBuffer();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
String line1 = null;
while ((line1 = bufferedReader.readLine()) != null) {
error.append(line1).append("\n");
}
res = error.toString();
bufferedReader.close();
bufferedReader = null;
}
//log.info("responseCode:"+responseCode+",msg="+res);
resultMap.put("responseCode",""+responseCode);
resultMap.put("content",res);
} catch (Exception e) {
log.error("httpRequest urlType="+log_urlType+", apiUrl: "+apiUrl+"发送POST请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, log_urlType+":"+e.toString());
} finally {
// 关闭流
if (conn != null) {
conn.disconnect();
conn = null;
}
}
return resultMap;
}
/**
* 描述: 木槿科技借贷风险名单查询 get请求 <br/>
* 参数: [inUrl] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.17 <br/>
*/
public static String muJinReadByGet(String apiUrl,String log_urlType) {
StringBuffer sbf = new StringBuffer();
String strRead = null;
// 模拟浏览器
String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
HttpURLConnection connection = null;
try {
// 连接URL地址
URL url = new URL(apiUrl);
// 根据拼凑的URL,打开连接,URL.openConnection函数会根据URL的类型,返回不同的URLConnection子类的对象,这里URL是一个http,因此实际返回的是HttpURLConnection
connection = (HttpURLConnection) url.openConnection();
// 设置连接访问方法及超时参数
connection.setRequestMethod("GET");
connection.setReadTimeout(30000);
connection.setConnectTimeout(30000);
connection.setRequestProperty("User-agent", userAgent);
// 进行连接,但是实际上get request要在下一句的connection.getInputStream()函数中才会真正发到 服务器
connection.connect();
// 取得输入流,并使用Reader读取
InputStream is = connection.getInputStream();
// 读取数据编码处理
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
}
reader.close();
}catch (IOException e) {
log.error("httpRequest urlType="+log_urlType+", apiUrl: "+apiUrl+"发送GET请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, log_urlType+":"+e.toString());
} finally {
// 关闭流
if (connection != null) {
// 断开连接
connection.disconnect();
connection=null;
}
}
return sbf.toString();
}
/**
* 描述: SSLContext方式的 融慧量化派定制化模型 get请求 <br/>
* 参数: [inUrl:请求地址; jsonParam:参数; log_urlType:请求的业务模块,方便排查问题] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.20 <br/>
*/
public static String remoteCall(String apiUrl, String jsonParam,String log_urlType) {
if(log_urlType==null){
log_urlType = "";
}
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
try {
// 信任所有
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
SSLConnectionSocketFactory sslCSF = new SSLConnectionSocketFactory(sslContext,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom().setSSLSocketFactory(sslCSF).build();
HttpPost post = new HttpPost(apiUrl);
StringEntity s = new StringEntity(jsonParam, "UTF-8");
s.setContentType("application/json");
s.setContentEncoding("UTF-8");
post.setEntity(s);
response = httpClient.execute(post);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// 获取响应实体
HttpEntity entity = response.getEntity();
if (entity != null) {
return EntityUtils.toString(entity, "UTF-8");
}
}else{
HttpEntity entity = response.getEntity();
String errorMsg = "";
if (entity != null) {
errorMsg = EntityUtils.toString(entity, "UTF-8");
}
log.warn("httpRequest urlType="+log_urlType+", apiUrl: {} , httpStatus: {} , errorMsg: {} ", apiUrl, response.getStatusLine().getStatusCode(),errorMsg);
}
} catch (Exception e) {
log.error("httpRequest urlType="+log_urlType+", apiUrl: "+apiUrl+"发送GET请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, log_urlType+":"+e.toString());
} finally {
try {
if (null != httpClient) {
httpClient.close();
}
if (null != response) {
response.close();
}
} catch (IOException e) {
log.error("httpRequest urlType="+log_urlType+", apiUrl: "+apiUrl+"关闭连接异常", e);
e.printStackTrace();
}
}
return null;
}
/**
* 描述: 发送 POST 请求(HTTP),JSON形式 <br/>
* 备注: 和RiskHttpResponse doPost(String apiUrl, JSONObject json)方法一样,只是新增了urlType,完了方便日志排查
* 参数: [apiUrl, json, log_urlType] <br/>
* 返回值: RiskHttpResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.29 <br/>
*/
public static RiskHttpResponse doPost(String apiUrl, JSONObject json,String log_urlType) {
httpClient = getHttpClient();
// CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
HttpPost httpPost = new HttpPost(apiUrl);
try {
httpPost.setConfig(requestConfig);
StringEntity stringEntity = new StringEntity(json.toString(), "UTF-8");//解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
HttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(entity));
EntityUtils.consume(entity);
return new RiskHttpResponse(jsonObject,statusCode);
} catch (IOException e) {
log.error("httpRequest urlType="+log_urlType+", apiUrl: "+apiUrl+"请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, log_urlType+":"+e.toString());
} finally {
httpPost.releaseConnection();
}
}
public static String mySelfDoGet(String url, Map<String, Object> params) {
String apiUrl = url;
StringBuffer param = new StringBuffer();
int i = 0;
for (String key : params.keySet()) {
if (i == 0)
param.append("?");
else
param.append("&");
param.append(key).append("=").append(params.get(key));
i++;
}
apiUrl += param;
long startUtc = System.currentTimeMillis();
httpClient2 = getHttpClient();
HttpGet httpGet = new HttpGet(apiUrl);
try {
HttpResponse response = httpClient2.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String context = EntityUtils.toString(entity,"utf-8");
EntityUtils.consume(entity);
return context;
} catch (Exception e){
long endtUtc = System.currentTimeMillis();
log.error("apiUrl: "+apiUrl+"百行征信手动报送请求失败, cost: "+(endtUtc-startUtc)+".ms ", e);
}finally {
httpGet.releaseConnection();
}
return null;
}
/**
* 描述: 中互金 POST Content-Type:application/json;Charset=utf-8 <br/>
* 参数: [apiUrl, jsonObject, log_urlType] <br/>
* 返回值: java.lang.String <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.10.14 <br/>
*/
public static String doPostOfZhongHuJin(String apiUrl,JSONObject jsonObject,String log_urlType) {
String response = "";
try {
String bodyStr = JSON.toJSONString(jsonObject);
byte[] body = bodyStr.getBytes("UTF-8");
java.net.URL parsedUrl = new java.net.URL(apiUrl);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) parsedUrl.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(10000);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(body.length));
OutputStream outStream = conn.getOutputStream();
outStream.write(body);
outStream.flush();
outStream.close();
if(conn.getResponseCode() == 200){
BufferedReader in = new BufferedReader(new InputStreamReader((InputStream) conn.getInputStream(), "UTF-8"));
response = in.readLine();
in.close();
}
conn.disconnect();
return response;
} catch (Exception e) {
log.error("httpRequest urlType="+log_urlType+", apiUrl: "+apiUrl+"请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString()+";url="+apiUrl);
}
}
//重新报送的工具使用,可能慢
public static String doPostTool(String apiUrl, Map<String, Object> params) {
String response = "";
try {
String bodyStr = JSON.toJSONString(params);
byte[] body = bodyStr.getBytes("UTF-8");
java.net.URL parsedUrl = new java.net.URL(apiUrl);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) parsedUrl.openConnection();
conn.setConnectTimeout(6000);
conn.setReadTimeout(60000);//60秒
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(body.length));
OutputStream outStream = conn.getOutputStream();
outStream.write(body);
outStream.flush();
outStream.close();
if(conn.getResponseCode() == 200){
BufferedReader in = new BufferedReader(new InputStreamReader((InputStream) conn.getInputStream(), "UTF-8"));
response = in.readLine();
in.close();
}
conn.disconnect();
return response;
} catch (Exception e) {
log.error("doPostTool httpRequest, apiUrl: "+apiUrl+"请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString()+";url="+apiUrl);
}finally {
}
}
}
package cn.quantgroup.report.utils.json;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.*;
/**
* @Author fengjunkai
* @Date 2019-06-10 16:29
*/
public class JSONUtils {
public static void getBeforeFeatures(Object featureObject, Map<String, Object> resultMap) {
JSONObject featureJson = (JSONObject) featureObject;
Iterator<Map.Entry<String, Object>> iterator = featureJson.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> objectEntry = iterator.next();
String key = objectEntry.getKey();
Object value = objectEntry.getValue();
if (value instanceof JSONObject) {
getBeforeFeatures(value, resultMap);
} else if (value instanceof JSONArray) {
resultMap.put(key, value);
} else {
resultMap.put(key, value);
}
}
}
public static void getFeature(Object featureObject, Map<String, Object> resultMap, Map<String, Object> keyMap, String prefix) {
JSONObject featuresJson = (JSONObject) featureObject;
Iterator<Map.Entry<String, Object>> iterator = featuresJson.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> entryMap = iterator.next();
String key = entryMap.getKey();
Object value = entryMap.getValue();
if (value instanceof JSONArray) {
resultMap.put(prefix + key, value);
keyMap.put(prefix + key, key);
} else if (value instanceof JSONObject) {
JSONObject jsonObject1 = featuresJson.getJSONObject(key);
Iterator<Map.Entry<String, Object>> iterator1 = jsonObject1.entrySet().iterator();
while (iterator1.hasNext()) {
Map.Entry<String, Object> entryMap1 = iterator1.next();
String key1 = entryMap1.getKey();
Object value1 = entryMap1.getValue();
if (value1 instanceof JSONArray) {
resultMap.put(prefix + key + "_" + key1, value1);
keyMap.put(prefix + key + "_" + key1, key1);
} else if (value1 instanceof JSONObject) {
JSONObject jsonObject2 = jsonObject1.getJSONObject(key1);
Iterator<Map.Entry<String, Object>> iterator2 = jsonObject2.entrySet().iterator();
while (iterator2.hasNext()) {
Map.Entry<String, Object> entryMap2 = iterator2.next();
String key2 = entryMap2.getKey();
Object value2 = entryMap2.getValue();
if (value2 instanceof JSONArray) {
resultMap.put(prefix + key + "_" + key1 + "_" + key2, value2);
keyMap.put(prefix + key + "_" + key1 + "_" + key2, key2);
} else if (value2 instanceof JSONObject) {
JSONObject jsonObject3 = jsonObject2.getJSONObject(key2);
Iterator<Map.Entry<String, Object>> iterator3 = jsonObject3.entrySet().iterator();
while (iterator3.hasNext()) {
Map.Entry<String, Object> entryMap3 = iterator3.next();
String key3 = entryMap3.getKey();
Object value3 = entryMap3.getValue();
if (value3 instanceof JSONArray) {
resultMap.put(prefix + key + "_" + key1 + "_" + key2 + "_" + key3, value3);
keyMap.put(prefix + key + "_" + key1 + "_" + key2 + "_" + key3, key3);
} else if (value3 instanceof JSONObject) {
System.out.println("===============================未知=======================");
} else {
resultMap.put(prefix + key + "_" + key1 + "_" + key2 + "_" + key3, value3);
keyMap.put(prefix + key + "_" + key1 + "_" + key2 + "_" + key3, key3);
}
}
} else {
resultMap.put(prefix + key + "_" + key1 + "_" + key2, value2);
keyMap.put(prefix + key + "_" + key1 + "_" + key2, key2);
}
}
} else {
resultMap.put(prefix + key + "_" + key1, value1);
keyMap.put(prefix + key + "_" + key1, key1);
}
}
} else {
resultMap.put(prefix + key, value);
keyMap.put(prefix + key, key);
}
}
}
/**
* 描述: 将一个有多层结构的json对象平铺展开,遇到数组不平铺 <br/>
* (为空避免二级以下key重复,所有用parent.Children1.Children2.....) <br/>
* 参数: [parentKey, objJson, resultMap] <br/>
* 返回值: void <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.05 <br/>
*/
public static void analysisJson(String parentKey, Object objJson,Map<String,Object> resultMap){
if(parentKey==null){
parentKey = "";
}
//如果obj为json数组
if(objJson instanceof JSONArray){
JSONArray objArray = (JSONArray)objJson;
resultMap.put(parentKey, objArray);
}
//如果为json对象
else if(objJson instanceof JSONObject){
JSONObject jsonObject = (JSONObject)objJson;
//Iterator it = jsonObject.keys();
Iterator<String> it = jsonObject.keySet().iterator();
while(it.hasNext()){
String key = it.next().toString();
Object object = jsonObject.get(key);
//如果得到的是数组
if(object instanceof JSONArray){
JSONArray objArray = (JSONArray)object;
analysisJson(parentKey+"."+key,objArray,resultMap);
}
//如果key中是一个json对象
else if(object instanceof JSONObject){
analysisJson(parentKey+"."+key,(JSONObject)object,resultMap);
}
//如果key中是其他
else{
resultMap.put(parentKey+"."+key, object);
}
}
}
}
public static void main(String[] args) {
try {
// String featureData = FileUtils.readFileToString(new File("/Users/fengjunkai/Documents/临时文件/百行征信/baihang/temp.txt"), "utf-8");
String featureData = FileUtils.readFileToString(new File("/Users/fengjunkai/Documents/量化派文档/三方数据源/百行征信文档/百行查询返回查得数据/查得.txt"), "utf-8");
JSONObject jsonObject = JSON.parseObject(featureData);
Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> keyMap = new HashMap<>();
getFeature(jsonObject, resultMap, keyMap, "baihang_");
System.out.println(JSON.toJSONString(resultMap));
System.out.println(JSON.toJSONString(keyMap));
// System.out.println(JSONObject.toJSONString(resultMap));
// Map<String,Object> terResultMap = new HashMap<>();
// Iterator<Map.Entry<String, Object>> iterator = resultMap.entrySet().iterator();
// while (iterator.hasNext()){
// Map<String,Object> bodyMap = new HashMap<>();
// Map.Entry<String,Object> entryMap = iterator.next();
// String key = entryMap.getKey();
// Object value = entryMap.getValue();
// bodyMap.put("state", "200");
// bodyMap.put("value", value);
// terResultMap.put(key, bodyMap);
// }
// System.out.println(JSON.parseObject(JSON.toJSONString(terResultMap)));
String sql = "INSERT INTO `merchant_field_mapping`(`field`, `third_field`, `method_name`, `location_method`, `field_name`, `field_source_name`, `field_type`, `parent_keys`, `service_name`, `created_at`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '', '%s', CURRENT_TIMESTAMP());";
List<String> list = FileUtils.readLines(new File("/Users/fengjunkai/Downloads/key_value_mapping.txt"), "utf-8");
Iterator<String> iterator1 = list.iterator();
while (iterator1.hasNext()){
String next = iterator1.next();
String third = next.split("###")[0];
String localKey = next.split("###")[1];
System.out.println(String.format(sql, localKey, third, "queryBaiHangPersionCreditReport", third, "", "百行个人征信报告", "Integer", "baiHangQueryService"));
}
//
// Iterator<Map.Entry<String, Object>> iterator = keyMap.entrySet().iterator();
// while (iterator.hasNext()) {
// Map.Entry<String, Object> next = iterator.next();
// String key = next.getKey();
// Object value = next.getValue();
// System.out.println(String.format(sql, value, key, "moxieRiskV2", key, "", "魔蝎申请准入报告V2.0", "String", "moxieRiskService"));
// }
} catch (Exception e) {
e.printStackTrace();
}
}
}
app.id=renhang-report
namespace=application,tech.service.urls,tech.common,tech.sleuth,tech.deploy,tech.msg.sdk
\ No newline at end of file
-----BEGIN PRIVATE KEY-----
duiFangWeiTiGong
-----END PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKkr3ojBpD3Ry0RKIVPYwfxu1hAnihpnqTShMUc+eou7qNtZaLhNV5rV/yPYEZBgoNGcJkPP3+vhcSdGHy+ItAgRicxykT+5ANIxevyLisPOLF4pSQPdemmwnmfsheV1l0VwB1uc4T4c9QEFeLz/d/SiPDwnYdCisRR5RKz/YrWwIDAQAB
-----END PUBLIC KEY-----
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCWXGJSOw/qQBXaui9Z7NITO4wV3f5Ysh7tbC9op/X33AI6JP8Zlnh7+ZPmuddrYHc683n+qdU3cONCaOTuWmBiXNDQfRqMkR69vpGJel7l9RpFqlR7pyWGkZ1Bac4wUXT+ewPjutT6LyKUaBbIV8Z4jIqO7j/qtvqJt1oHzNzZtwIDAQAB
-----END PUBLIC KEY-----
<?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.quantgroup.report.mapper.baihang.ApplyLoanInfoMapper">
<resultMap id="ApplyLoanInfoBaseResultMap" type="cn.quantgroup.report.domain.baihang.ApplyLoanInfo">
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="queryReason" jdbcType="INTEGER" property="queryReason"/>
<result column="guaranteeType" jdbcType="INTEGER" property="guaranteeType"/>
<result column="loanPurpose" jdbcType="INTEGER" property="loanPurpose"/>
<result column="customType" jdbcType="INTEGER" property="customType"/>
<result column="applyAmount" jdbcType="DECIMAL" property="applyAmount"/>
<result column="loanId" jdbcType="VARCHAR" property="loanId"/>
</resultMap>
<!--<select id="findApplyLoanInfo" resultMap="ApplyLoanInfoBaseResultMap">
select b.name as name, b.id_no as pid, b.phone_no as mobile, '1' as queryReason, '1' as guaranteeType, '1' as loanPurpose, '99' as customType, '-1' as applyAmount, a.order_no as loanId
from xyqb_i_apply_quota_record a left join xyqb_user_i_user_detail b on a.user_id=b.user_id
where a.created_at>=DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y-%m-%d');
</select>-->
<!--<select id="findApplyLoanInfoByThreeElements" parameterType="cn.quantgroup.report.domain.baihang.BaiHangThreeElements" resultMap="ApplyLoanInfoBaseResultMap">
select b.name as name, b.id_no as pid, b.phone_no as mobile, '1' as queryReason, '1' as guaranteeType, '1' as loanPurpose, '99' as customType, '-1' as applyAmount, a.order_no as loanId
from xyqb_i_apply_quota_record a left join xyqb_user_i_user_detail b on a.user_id=b.user_id
where b.name=#{name} and b.id_no=#{idCard} and b.phone_no=#{phone} limit 1;
</select>-->
<!--申请-->
<!--<select id="findStockApplyLoanInfo" resultMap="ApplyLoanInfoBaseResultMap">
select * from
(select
b.name name
,b.id_no pid
,b.phone_no mobile
,'1' queryReason
,'1' guaranteeType
,'1' loanPurpose
,'99' customType
,'-1' applyAmount
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
where a.funding_corp_id=480 and a.transaction_status in (2,5) and a.loan_paid_at > '2019-05-09 19:07:00' and a.loan_paid_at &lt; '2019-05-29') a
</select>-->
<!--百行-助贷申请存量数据 整理 2019.10.23-->
<select id="queryStockApplyLoanInfoZhuDai" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord" resultType="cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai">
select a.loan_application_history_id reqID
from xyqb_i_loan_application_manifest_history a
where a.loan_paid_at >= #{startTime,jdbcType=VARCHAR}
and a.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
</select>
<!--1.1百行助贷-非联合贷 申请实时 2019.10.28-->
<select id="findRealTimeApplyLoanZhuDai" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord" resultType="cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,'1' isFinTechAgencyBusiness
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,if(d.order_no is null,a.loan_application_history_id,d.order_no) applyId
,'1' applyType
,b.name name
,'1' idType
,b.id_no pid
,b.phone_no mobile
,b.email emailAddress
,case when j.education=1 then '10'
when j.education=2 then '20'
when j.education=3 then '30'
when j.education in (4,6) then '40'
when j.education=5 then '50'
when j.education in (7,8) then '60'
else '70' end eduBackground
,'500' degree
,'1' guaranteeType
,'1' loanPurpose
,'99' customType
,'-1' applyAmount
,'8' livingCondition
,case when j.marry_status=1 then '10'
when j.marry_status=2 then '20'
when j.marry_status=4 then '30'
when j.marry_status=3 then '40'
else '90' end marriageStatus
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_loan_base_info j on a.loan_application_history_id=j.loan_id
where a.funding_corp_id in (420,520,580,650,670,810,240,640,700)
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
and case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end >= #{startTime,jdbcType=VARCHAR}
and case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end &lt; #{endTime,jdbcType=VARCHAR};
<!-- p2p 2019.12.13 -->
<!--
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,'1' isFinTechAgencyBusiness
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,if(d.order_no is null,a.loan_application_history_id,d.order_no) applyId
,'1' applyType
,b.name name
,'1' idType
,b.id_no pid
,b.phone_no mobile
,b.email emailAddress
,case when j.education=1 then '10'
when j.education=2 then '20'
when j.education=3 then '30'
when j.education in (4,6) then '40'
when j.education=5 then '50'
when j.education in (7,8) then '60'
else '70' end eduBackground
,'500' degree
,'1' guaranteeType
,'1' loanPurpose
,'99' customType
,'-1' applyAmount
,'8' livingCondition
,case when j.marry_status=1 then '10'
when j.marry_status=2 then '20'
when j.marry_status=4 then '30'
when j.marry_status=3 then '40'
else '90' end marriageStatus
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
left join xyqb_i_quota_credit i on d.order_no=i.order_no
left join xyqb_i_loan_base_info j on a.loan_application_history_id=j.loan_id
where a.funding_corp_id in (540,210)
and a.contract_term >=3
and a.transaction_status in (2,5)
and case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end >= #{startTime,jdbcType=VARCHAR}
and case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end &lt; #{endTime,jdbcType=VARCHAR};
-->
</select>
<!--1.2百行助贷-联合贷 申请实时 2019.10.28-->
<select id="findRealTimeApplyLoanZhuDaiLh" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord" resultType="cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,'1' isFinTechAgencyBusiness
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,if(d.order_no is null,a.loan_application_history_id,d.order_no) applyId
,'1' applyType
,b.name name
,'1' idType
,b.id_no pid
,b.phone_no mobile
,b.email emailAddress
,case when j.education=1 then '10'
when j.education=2 then '20'
when j.education=3 then '30'
when j.education in (4,6) then '40'
when j.education=5 then '50'
when j.education in (7,8) then '60'
else '70' end eduBackground
,'500' degree
,'1' guaranteeType
,'1' loanPurpose
,'99' customType
,'-1' applyAmount
,'8' livingCondition
,case when j.marry_status=1 then '10'
when j.marry_status=2 then '20'
when j.marry_status=4 then '30'
when j.marry_status=3 then '40'
else '90' end marriageStatus
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_loan_base_info j on a.loan_application_history_id=j.loan_id
where a.funding_corp_id in (880,890)
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
and case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end >= #{startTime,jdbcType=VARCHAR}
and case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end &lt; #{endTime,jdbcType=VARCHAR};
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.baihang.LoanInfoMapper">
<!--<resultMap id="LoanInfoResultMap" type="cn.quantgroup.report.domain.baihang.LoanInfoVo">
<result column="reqID" jdbcType="VARCHAR" property="reqID"/>
<result column="opCode" jdbcType="VARCHAR" property="opCode"/>
<result column="uploadTs" jdbcType="VARCHAR" property="uploadTs"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="loanId" jdbcType="VARCHAR" property="loanId"/>
<result column="guaranteeType" jdbcType="VARCHAR" property="guaranteeType"/>
<result column="loanPurpose" jdbcType="VARCHAR" property="loanPurpose"/>
<result column="applyDate" jdbcType="VARCHAR" property="applyDate"/>
<result column="accountOpenDate" jdbcType="VARCHAR" property="accountOpenDate"/>
<result column="issueDate" jdbcType="VARCHAR" property="issueDate"/>
<result column="dueDate" jdbcType="VARCHAR" property="dueDate"/>
<result column="loanAmount" jdbcType="VARCHAR" property="loanAmount"/>
<result column="totalTerm" jdbcType="VARCHAR" property="totalTerm"/>
<result column="targetRepayDateType" jdbcType="VARCHAR" property="targetRepayDateType"/>
<result column="termPeriod" jdbcType="VARCHAR" property="termPeriod"/>
<result column="firstRepaymentDate" jdbcType="VARCHAR" property="firstRepaymentDate"/>
<result column="gracePeriod" jdbcType="VARCHAR" property="gracePeriod"/>
</resultMap>-->
<resultMap id="LoanInfoVoResultMapByBS" type="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai"><!-- LoanInfoVo-->
<result column="reqID" jdbcType="INTEGER" property="reqID"/>
<result column="opCode" jdbcType="VARCHAR" property="opCode"/>
<result column="uploadTs" jdbcType="VARCHAR" property="uploadTs"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="loanId" jdbcType="VARCHAR" property="loanId"/>
<result column="guaranteeType" jdbcType="INTEGER" property="guaranteeType"/>
<result column="loanPurpose" jdbcType="INTEGER" property="loanPurpose"/>
<result column="applyDate" jdbcType="VARCHAR" property="applyDate"/>
<result column="accountOpenDate" jdbcType="VARCHAR" property="accountOpenDate"/>
<result column="issueDate" jdbcType="VARCHAR" property="issueDate"/>
<result column="dueDate" jdbcType="VARCHAR" property="dueDate"/>
<result column="loanAmount" jdbcType="VARCHAR" property="loanAmount"/>
<result column="totalTerm" jdbcType="INTEGER" property="totalTerm"/>
<result column="targetRepayDateType" jdbcType="VARCHAR" property="targetRepayDateType"/>
<result column="termPeriod" jdbcType="VARCHAR" property="termPeriod"/>
<result column="firstRepaymentDate" jdbcType="VARCHAR" property="firstRepaymentDate"/>
<result column="gracePeriod" jdbcType="VARCHAR" property="gracePeriod"/>
</resultMap>
<!--报送实时放款数据(广达百行征信报送)-->
<!-- <select id="findLoanInfo" resultMap="LoanInfoResultMap" >
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at&lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at&lt;h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,if(a.contract_term=1,'1','2') targetRepayDateType
,if(a.contract_term=1,'30','-1') termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'0' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
left join xyqb_i_quota_credit i on d.order_no=i.order_no
/*where a.funding_corp_id in (480,710) and e.term_no=a.contract_term and g.term_no=1*/
where a.funding_corp_id in (480,710,630,790,820) and e.term_no=a.contract_term and g.term_no=1
and a.transaction_status in (2,5)
and a.created_at>=DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y-%m-%d')
and a.created_at&lt;DATE_FORMAT(NOW(), '%Y-%m-%d');
</select>-->
<!--广达重新报送实时放款数据-->
<!--<select id="findLoanInfoByTime" resultMap="LoanInfoResultMap" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord">
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at&lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at&lt;h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,if(a.contract_term=1,'1','2') targetRepayDateType
,if(a.contract_term=1,'30','-1') termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'0' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
left join xyqb_i_quota_credit i on d.order_no=i.order_no
where a.funding_corp_id in (480,710) and e.term_no=a.contract_term and g.term_no=1
and a.transaction_status in (2,5)
and a.created_at>=#{startTime}
and a.created_at&lt;#{endTime};
</select>-->
<!--广达存量放款数据报送-->
<!-- <select id="stockLoanInfo" resultMap="LoanInfoResultMap" >
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at&lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at&lt;h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,if(a.contract_term=1,'1','2') targetRepayDateType
,if(a.contract_term=1,'30','-1') termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'0' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
left join xyqb_i_quota_credit i on d.order_no=i.order_no
where a.funding_corp_id in (480,710) and e.term_no=a.contract_term and g.term_no=1
and a.transaction_status in (2,5);
/* and a.loan_paid_at > '2019-05-09 10:30:07' and a.loan_paid_at &lt; '2019-05-29' order by a.loan_paid_at;*/
</select>-->
<!--根据loan_application_history_id查询最晚还款日-->
<select id="findTargetRepaymentDayList" parameterType="java.lang.String" resultType="java.lang.String">
select date(DATE_SUB(deadline,INTERVAL 1 second)) from xyqb_i_repayment_plan where loan_application_history_id=#{reqID}
</select>
<!--1.根据order_no查询 loan_application_history_id 工具报送 2019.09.25-->
<select id="findHistoryIdByOrderNo" resultType="java.lang.String">
select a.loan_application_history_id as loanApplicationHistoryId
from xyqb_i_loan_application_manifest_history a
left join rc_real_time_data_pool.xyqb_i_loan_account_ext b on a.loan_application_history_id=b.loan_id
left join rc_real_time_data_pool.xyqb_i_apply_quota_record c on b.order_no=c.order_no
where c.order_no IN
<foreach collection="array" item="orderNo" index="index" open="(" close=")" separator=",">
#{orderNo}
</foreach>
</select>
<!--2.根据loan_application_history_id查询工具报送的bean 放款 2019.09.25-->
<select id="findLoanInfoD2ByHistoryId" resultType="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai"> <!--resultMap="LoanInfoVoResultMapByBS"-->
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(a.funding_corp_id in (240,640,700),'深圳市小赢科技有限责任公司','广州惠金小额贷款有限公司') institutionalFundingPartner
,if(a.funding_corp_id in (240,640,700),'91440300MA5DMXHN4R','91440101MA59G7X78Y') institutionalFundingPartnerID
,j.corp_loan_id relationID
,'' institutionalFundingPartnerLoanID
,if(d.order_no is null,a.loan_application_history_id,d.order_no) orderID
,'' preCreditLimit
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at &lt; h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,'2' targetRepayDateType
,'-1' termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
-- ,'0' gracePeriod
-- ,'30' gracePeriod
,if(a.funding_corp_id in (880,890),'30','0') gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_waiting_funding_corp_operate_people j on a.loan_application_history_id=j.loan_application_history_id
where a.funding_corp_id in (420,520,580,650,670,810,240,640,700, 880,890) and
e.term_no=a.contract_term and g.term_no=1
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
AND a.loan_application_history_id=#{loanApplicationHistoryId}
</select>
<!--百行-助贷放款存量数据 整理 2019.10.23-->
<select id="queryStockLoanInfoZhuDai" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord" resultType="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai">
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(a.funding_corp_id in (240,640,700),'深圳市小赢科技有限责任公司','广州惠金小额贷款有限公司') institutionalFundingPartner
,if(a.funding_corp_id in (240,640,700),'91440300MA5DMXHN4R','91440101MA59G7X78Y') institutionalFundingPartnerID
,j.corp_loan_id relationID
,'' institutionalFundingPartnerLoanID
,if(d.order_no is null,a.loan_application_history_id,d.order_no) orderID
,'' preCreditLimit
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at &lt; h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,if(a.contract_term=1,'1','2') targetRepayDateType
,if(a.contract_term=1,'30','-1') termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'0' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_waiting_funding_corp_operate_people j on a.loan_application_history_id=j.loan_application_history_id
where a.funding_corp_id in (420,520,580,650,670,810,240,640,700) and e.term_no=a.contract_term and g.term_no=1
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
and a.loan_paid_at >= #{startTime,jdbcType=VARCHAR}
and a.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR};
</select>
<!--2.1百行助贷-非联合贷 放款实时 2019.10.28-->
<select id="findRealTimeLoanInfoZhuDai" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord" resultType="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai">
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(a.funding_corp_id in (240,640,700),'深圳市小赢科技有限责任公司','广州惠金小额贷款有限公司') institutionalFundingPartner
,if(a.funding_corp_id in (240,640,700),'91440300MA5DMXHN4R','91440101MA59G7X78Y') institutionalFundingPartnerID
,j.corp_loan_id relationID
,'' institutionalFundingPartnerLoanID
,if(d.order_no is null,a.loan_application_history_id,d.order_no) orderID
,'' preCreditLimit
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at &lt; h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,'2' targetRepayDateType
,'-1' termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'0' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_waiting_funding_corp_operate_people j on a.loan_application_history_id=j.loan_application_history_id
where
a.loan_paid_at>= #{startTime,jdbcType=VARCHAR}
and a.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
and a.funding_corp_id in (420,520,580,650,670,810,240,640,700)
and e.term_no=a.contract_term and g.term_no=1
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
;
<!--p2p 2019.12.13-->
<!--select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(a.funding_corp_id=210,'大连金州广源小额贷款有限公司','广州惠金小额贷款有限公司') institutionalFundingPartner
,if(a.funding_corp_id=210,'91210200696039834G','91440101MA59G7X78Y') institutionalFundingPartnerID
,j.corp_loan_id relationID
,'' institutionalFundingPartnerLoanID
,if(d.order_no is null,a.loan_application_history_id,d.order_no) orderID
,'' preCreditLimit
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;= f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at &lt; h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,'2' targetRepayDateType
,'-1' termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'0' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
left join xyqb_i_quota_credit i on d.order_no=i.order_no
left join xyqb_i_waiting_funding_corp_operate_people j on a.loan_application_history_id=j.loan_application_history_id
left join xyqb_i_loan_withdraw_record k on a.loan_application_history_id=k.loan_id
where a.funding_corp_id in (540,210) and g.term_no=1
and e.term_no=a.contract_term and e.repayment_status=3 and e.repaid_at &lt; '2019-10-25'
and if(a.loan_paid_at>='2018-01-01',a.contract_term >3,a.contract_term >=3)
and a.transaction_status in (2,5)
and (k.id is null or k.status=3)
and a.loan_paid_at >= #{startTime,jdbcType=VARCHAR}
and a.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR};
-->
</select>
<!--2.2百行助贷-联合贷 放款实时 2019.10.28-->
<select id="findRealTimeLoanInfoZhuDaiLh" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord" resultType="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai">
select a.loan_application_history_id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,'广州惠金小额贷款有限公司' institutionalFundingPartner
,'91440101MA59G7X78Y' institutionalFundingPartnerID
,j.corp_loan_id relationID
,'' institutionalFundingPartnerLoanID
,if(d.order_no is null,a.loan_application_history_id,d.order_no) orderID
,'' preCreditLimit
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,'1' guaranteeType
,'1' loanPurpose
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,DATE_FORMAT(case when d.created_at is null and f.created_at>=h.created_at then f.created_at
when d.created_at is null and f.created_at &lt;h.created_at then h.created_at
else d.created_at end,'%Y-%m-%dT%H:%i:%S') as accountOpenDate
,DATE_FORMAT(a.loan_paid_at,'%Y-%m-%dT%H:%i:%S') issueDate
,date(date_sub(e.deadline,INTERVAL 1 second)) dueDate
,a.contract_loan_amount loanAmount
,a.contract_term totalTerm
,'2' targetRepayDateType
,'-1' termPeriod
,date(date_sub(g.deadline,INTERVAL 1 second)) firstRepaymentDate
,'30' gracePeriod
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_repayment_plan e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_repayment_plan g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_waiting_funding_corp_operate_people j on a.loan_application_history_id=j.loan_application_history_id
where
a.loan_paid_at>= #{startTime,jdbcType=VARCHAR}
and a.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
and a.funding_corp_id in (880,890)
and e.term_no=a.contract_term and g.term_no=1
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
;
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.baihang.RepaymentLoanInfoMapper">
<!--<resultMap id="RepaymetnLoanInfoResultMap" tyRepaymentLoanInfoInfo">-->
<!--<result column="reqID" jdbcType="VARCHAR" property="reqID"/>-->
<!--<result column="opCode" jdbcType="VARCHAR" property="opCode"/>-->
<!--<result column="uploadTs" jdbcType="VARCHAR" property="uploadTs"/>-->
<!--<result column="loanId" jdbcType="VARCHAR" property="loanId"/>-->
<!--<result column="name" jdbcType="VARCHAR" property="name"/>-->
<!--<result column="pid" jdbcType="VARCHAR" property="pid"/>-->
<!--<result column="mobile" jdbcType="VARCHAR" property="mobile"/>-->
<!--<result column="termNo" jdbcType="VARCHAR" property="termNo"/>-->
<!--<result column="termStatus" jdbcType="VARCHAR" property="termStatus"/>-->
<!--<result column="targetRepaymentDate" jdbcType="VARCHAR" property="targetRepaymentDate"/>-->
<!--<result column="realRepaymentDate" jdbcType="VARCHAR" property="realRepaymentDate"/>-->
<!--<result column="plannedPayment" jdbcType="VARCHAR" property="plannedPayment"/>-->
<!--<result column="targetRepayment" jdbcType="VARCHAR" property="targetRepayment"/>-->
<!--<result column="realRepayment" jdbcType="VARCHAR" property="realRepayment"/>-->
<!--<result column="overdueStatus" jdbcType="VARCHAR" property="overdueStatus"/>-->
<!--<result column="statusConfirmAt" jdbcType="VARCHAR" property="statusConfirmAt"/>-->
<!--<result column="overdueAmount" jdbcType="VARCHAR" property="overdueAmount"/>-->
<!--<result column="remainingAmount" jdbcType="VARCHAR" property="remainingAmount"/>-->
<!--<result column="loanStatus" jdbcType="VARCHAR" property="loanStatus"/>-->
<!--</resultMap>-->
<!--实时逾期还款(广达百行征信报送)-->
<!--<select id="findRepayMentLoanInfoOverdue"
parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,a.term_no termNo
,date(DATE_sub(a.deadline,INTERVAL 1 second)) targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,f.dkye remainingAmount
,case when f.yqze>0 then '2'
when f.dkye=0 then '3'
when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus
,'overdue' termStatus
from (select a.*
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
where a.repayment_status not in (3,4) and
if(b.contract_term>a.term_no,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)>=0)
and floor(DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF(#{endTime,jdbcType=VARCHAR,jdbcType=VARCHAR},a.deadline)/30
&#45;&#45; and (b.funding_corp_id=480 or (b.funding_corp_id=710 and b.loan_paid_at>='2019-05-29')) and b.transaction_status in (2,5) ) a
and (b.funding_corp_id=480 or (b.funding_corp_id=710 and b.loan_paid_at>='2019-05-29') or
(b.funding_corp_id in (630,790,820) and b.loan_paid_at>='2019-10-16')
) and b.transaction_status in (2,5) ) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},g.principal+g.interest+g.service_fee,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR}),g.principal,0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
&#45;&#45; where b.funding_corp_id in (480,710)
where b.funding_corp_id in (480,710,630,790,820)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id;
</select>
-->
<!--实时还款(广达百行征信报送)-->
<!--<select id="findRepayMentLoanInfo" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) termNo
,date(DATE_sub(if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.deadline,h.max_deadline),INTERVAL 1 second)) targetRepaymentDate
,DATE_FORMAT(a.repaid_at,'%Y-%m-%dT%H:%i:%S') realRepaymentDate
,j.required_repayment plannedPayment
,f.yqze+sum(a.required_repayment) targetRepayment
,sum(a.required_repayment) realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,min(i.dkye) remainingAmount
,case when f.yqze>0 then '2'
when i.dkye=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)&lt;f.max_term_no then '2'
when i.dkye=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)= f.max_term_no then '3'
when f.yqze=0 and i.dkye>0 then '1'
end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus
from (
select a.*,if(c.term_no is null,a.term_no,c.term_no) next_term
,if(c.deadline is null,a.deadline,c.deadline) next_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no=c.term_no-1
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
and (b.funding_corp_id=480 or (b.funding_corp_id=710 and b.loan_paid_at>='2019-05-29') or
(b.funding_corp_id in (630,790,820) and b.loan_paid_at>='2019-10-16') )) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (
select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.required_repayment,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR}),g.principal,0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
,max(a.term_no) max_term_no
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
where b.funding_corp_id in (480,710,630,790,820)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.repaid_at,a.deadline,a.term_no
,max(c.term_no) max_term
,max(c.deadline) max_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
where DATEDIFF(a.repaid_at,c.deadline)>=-1
and b.funding_corp_id in (480,710,630,790,820)
group by a.loan_application_history_id,a.term_no) h
on a.loan_application_history_id=h.loan_application_history_id and a.term_no=h.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(d.term_no>a.term_no,d.principal,0)) dkye
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record d on a.loan_application_history_id=d.loan_application_history_id
where b.funding_corp_id in (480,710,630,790,820)
group by a.loan_application_history_id,a.term_no) i
on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join xyqb_i_repayment_plan j on a.loan_application_history_id=j.loan_application_history_id
and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)=j.term_no
group by if(d.order_no is null,a.loan_application_history_id,d.order_no),
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)
</select>
-->
<!-- <select id="findName" parameterType="cn.quantgroup.report.domain.baihang.BaiHangName"
resultType="cn.quantgroup.report.domain.baihang.BaiHangNameResult">
select d.NAME name
,d.id_no pid
,d.phone_no mobile
from xyqb_i_loan_application_history a
left join xyqb_i_loan_account_ext b on a.id=b.loan_id
left join xyqb_i_apply_quota_record c on b.order_no=c.order_no
left join xyqb_user_i_user_detail d on a.user_id=d.user_id
where c.order_no=#{loanId}
union
select d.NAME name
,d.id_no pid
,d.phone_no mobile
from xyqb_i_loan_application_history a
left join xyqb_i_loan_account_ext b on a.id=b.loan_id
left join xyqb_i_apply_quota_record c on b.order_no=c.order_no
left join xyqb_user_i_user_detail d on a.user_id=d.user_id
where a.id=#{loanId};
</select>-->
<!--百行-助贷“逾期还款”存量数据 整理 2019.10.23-->
<select id="queryStockRepayMentInfoOverdueZhuDai" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,a.term_no termNo
,date(DATE_sub(a.deadline,INTERVAL 1 second)) targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,f.dkye remainingAmount
,case when f.yqze>0 then '2'
when f.dkye=0 then '3'
when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus
,'overdue' termStatus
from (select a.*
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and
if(b.contract_term>a.term_no,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)>=0)
and floor(DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30
and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
and b.transaction_status in (2,5)
and b.contract_term not in (2,3)) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},if(b.loan_paid_at>='2018-01-01',g.principal+g.interest+g.service_fee,h.principle+h.interest+h.service_fee_per_term),0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
</select>
<!--百行-助贷“还款”存量数据 整理 2019.10.23-->
<select id="queryStockRepayMentInfoZhuDai" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) termNo
,date(DATE_sub(if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.deadline,h.max_deadline),INTERVAL 1 second)) targetRepaymentDate
,DATE_FORMAT(a.repaid_at,'%Y-%m-%dT%H:%i:%S') realRepaymentDate
,j.required_repayment plannedPayment
,f.yqze+sum(a.required_repayment) targetRepayment
,sum(a.required_repayment) realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,min(i.dkye) remainingAmount
,case when f.yqze>0 then '2'
when i.dkye=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) &lt; f.max_term_no then '2'
when i.dkye=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)= f.max_term_no then '3'
when f.yqze=0 and i.dkye>0 then '1'
end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus
from (
select a.*,if(c.term_no is null,a.term_no,c.term_no) next_term
,if(c.deadline is null,a.deadline,c.deadline) next_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no=c.term_no-1
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
and b.contract_term not in (2,3)
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (
select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.required_repayment,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
,max(a.term_no) max_term_no
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.repaid_at,a.deadline,a.term_no
,max(c.term_no) max_term
,max(c.deadline) max_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
where DATEDIFF(a.repaid_at,c.deadline)>=-1
and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
group by a.loan_application_history_id,a.term_no) h
on a.loan_application_history_id=h.loan_application_history_id and a.term_no=h.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(d.term_no>a.term_no,d.principal,0)) dkye
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_record d on a.loan_application_history_id=d.loan_application_history_id
where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)
group by a.loan_application_history_id,a.term_no) i
on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join xyqb_i_repayment_plan j on a.loan_application_history_id=j.loan_application_history_id
and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)=j.term_no
group by if(d.order_no is null,a.loan_application_history_id,d.order_no),
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)
</select>
<!--3.1百行助贷-非联合贷 实时还款 2019.10.28-->
<select id="findRealTimeRepayMentInfo" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
<!-- 助贷 -->
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) termNo
,date(DATE_sub(if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.deadline,h.max_deadline),INTERVAL 1 second)) targetRepaymentDate
,DATE_FORMAT(a.repaid_at,'%Y-%m-%dT%H:%i:%S') realRepaymentDate
,j.required_repayment plannedPayment
,f.yqze+sum(a.required_repayment) targetRepayment
,sum(a.required_repayment) realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF( #{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT( #{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye)) remainingAmount
,case when f.yqze>0 then '2'
when min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye))=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) &lt; f.max_term_no then '2'
when min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye))=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)= f.max_term_no then '3'
when f.yqze=0 and min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye))>0 then '1'
end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus
from (
select
a.id,a.user_id,a.loan_application_history_id,a.term_no,a.deadline,a.required_repayment,a.repayment_status,a.repaid_at,a.created_at,
if(c.term_no is null,a.term_no,c.term_no) next_term
,if(c.deadline is null,a.deadline,c.deadline) next_deadline
,b.loan_paid_at
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan_bak c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no=c.term_no-1
where a.repaid_at>= #{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
/*and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
and b.contract_term not in (2,3)
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (
select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.required_repayment,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
,max(a.term_no) max_term_no
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
/*where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
group by a.loan_application_history_id
) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.repaid_at,a.deadline,a.term_no
,max(c.term_no) max_term
,max(c.deadline) max_deadline
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan_bak c on a.loan_application_history_id=c.loan_application_history_id
where DATEDIFF(a.repaid_at,c.deadline)>=-1
/*and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
group by a.loan_application_history_id,a.term_no
) h
on a.loan_application_history_id=h.loan_application_history_id and a.term_no=h.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(d.term_no>a.term_no,d.principal,0)) dkye
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_record d on a.loan_application_history_id=d.loan_application_history_id
/*where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
group by a.loan_application_history_id,a.term_no
) i
on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(e.term_no>a.term_no,h.principle,0)) dkye
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan_bak e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_plan_amount_detail h on e.id=h.plan_id
/*where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
group by a.loan_application_history_id,a.term_no
) i2
on a.loan_application_history_id=i2.loan_application_history_id and a.term_no=i2.term_no
left join xyqb_i_repayment_plan_bak j on a.loan_application_history_id=j.loan_application_history_id
and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)=j.term_no
group by if(d.order_no is null,a.loan_application_history_id,d.order_no),
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term);
<!--p2p 2019.12.13-->
<!--
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) termNo
,date(DATE_sub(if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.deadline,h.max_deadline),INTERVAL 1 second)) targetRepaymentDate
,DATE_FORMAT(a.repaid_at,'%Y-%m-%dT%H:%i:%S') realRepaymentDate
,j.required_repayment plannedPayment
,f.yqze+sum(a.required_repayment) targetRepayment
,sum(a.required_repayment) realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye)) remainingAmount
,case when f.yqze>0 then '2'
when min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye))=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) &lt; f.max_term_no then '2'
when min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye))=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)= f.max_term_no then '3'
when f.yqze=0 and min(if(a.loan_paid_at>='2018-01-01',i.dkye,i2.dkye))>0 then '1'
end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus
from (
select /* a.*, */
a.id,a.user_id,a.loan_application_history_id,a.term_no,a.deadline,a.required_repayment,a.repayment_status,a.repaid_at,a.created_at,
if(c.term_no is null,a.term_no,c.term_no) next_term
,if(c.deadline is null,a.deadline,c.deadline) next_deadline
,b.loan_paid_at
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan_p2p_bak c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no=c.term_no-1
left join xyqb_i_loan_withdraw_record k on a.loan_application_history_id=k.loan_id
left join xyqb_i_repayment_plan_p2p_bak g on b.loan_application_history_id=g.loan_application_history_id
and g.term_no=b.contract_term
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
and b.funding_corp_id in (210,540)
and if(b.loan_paid_at>='2018-01-01',b.contract_term >3,b.contract_term >=3)
and (k.id is null or k.status=3)
and g.repayment_status=3 and g.repaid_at &lt; '2019-10-25'
and b.loan_paid_at>='2016-11-01'
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (
select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.required_repayment,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
,max(a.term_no) max_term_no
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (210,540)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.repaid_at,a.deadline,a.term_no
,max(c.term_no) max_term
,max(c.deadline) max_deadline
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan_p2p_bak c on a.loan_application_history_id=c.loan_application_history_id
where DATEDIFF(a.repaid_at,c.deadline)>=-1
and b.funding_corp_id in (210,540)
group by a.loan_application_history_id,a.term_no) h
on a.loan_application_history_id=h.loan_application_history_id and a.term_no=h.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(d.term_no>a.term_no,d.principal,0)) dkye
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_record d on a.loan_application_history_id=d.loan_application_history_id
where b.funding_corp_id in (210,540)
group by a.loan_application_history_id,a.term_no) i
on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(e.term_no>a.term_no,h.principle,0)) dkye
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan_p2p_bak e on a.loan_application_history_id=e.loan_application_history_id
left join xyqb_i_plan_amount_detail h on e.id=h.plan_id
where b.funding_corp_id in (210,540)
group by a.loan_application_history_id,a.term_no) i2
on a.loan_application_history_id=i2.loan_application_history_id and a.term_no=i2.term_no
left join xyqb_i_repayment_plan_p2p_bak j on a.loan_application_history_id=j.loan_application_history_id
and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)=j.term_no
group by if(d.order_no is null,a.loan_application_history_id,d.order_no),
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term);
-->
</select>
<!--3.2百行助贷-联合贷 实时还款 2019.10.28-->
<select id="findRealTimeRepayMentInfoLh" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) termNo
,date(DATE_sub(if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.deadline,h.max_deadline),INTERVAL 1 second)) targetRepaymentDate
,DATE_FORMAT(a.repaid_at,'%Y-%m-%dT%H:%i:%S') realRepaymentDate
,j.required_repayment plannedPayment
,f.yqze+sum(a.required_repayment) targetRepayment
,sum(a.required_repayment) realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF( #{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT( #{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,min(i.dkye) remainingAmount
,case when f.yqze>0 then '2'
when min(i.dkye)=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) &lt; f.max_term_no then '2'
when min(i.dkye)=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)= f.max_term_no then '3'
when f.yqze=0 and min(i.dkye)>0 then '1'
end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus
from (
select a.*,if(c.term_no is null,a.term_no,c.term_no) next_term
,if(c.deadline is null,a.deadline,c.deadline) next_deadline
,b.loan_paid_at
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no=c.term_no-1
where a.repaid_at>= #{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
and b.funding_corp_id in (880,890)
and b.contract_term not in (2,3)
and b.loan_paid_at>='2019-10-25'
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (
select a.loan_application_history_id
,sum(if(((a.repayment_status !=3 and DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=30) or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR} and DATEDIFF(a.repaid_at,a.deadline)>=30)) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.required_repayment,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR}),g.principal,0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
,max(a.term_no) max_term_no
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
where b.funding_corp_id in (880,890)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.repaid_at,a.deadline,a.term_no
,max(c.term_no) max_term
,max(c.deadline) max_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
where DATEDIFF(a.repaid_at,c.deadline)>=-1
and b.funding_corp_id in (880,890)
group by a.loan_application_history_id,a.term_no) h
on a.loan_application_history_id=h.loan_application_history_id and a.term_no=h.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(d.term_no>a.term_no,d.principal,0)) dkye
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_repayment_record d on a.loan_application_history_id=d.loan_application_history_id
where b.funding_corp_id in (880,890)
group by a.loan_application_history_id,a.term_no) i
on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join xyqb_i_repayment_plan j on a.loan_application_history_id=j.loan_application_history_id
and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)=j.term_no
group by if(d.order_no is null,a.loan_application_history_id,d.order_no),
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term);
</select>
<!--4.1百行助贷-非联合贷 实时逾期还款 2019.10.28-->
<select id="findRealTimeRepayMentOverdue" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
<!-- 助贷 -->
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,a.term_no termNo
,date(DATE_sub(a.deadline,INTERVAL 1 second)) targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF( #{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT( #{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,f.dkye remainingAmount
,case when f.yqze>0 then '2'
when f.dkye=0 then '3'
when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus
,'overdue' termStatus
from (
select
a.id,a.user_id,a.loan_application_history_id,a.term_no,a.deadline,a.required_repayment,a.repayment_status,a.repaid_at,a.repayment_received_at
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b /**xyqb_i_loan_application_manifest_history*/
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and
if(b.contract_term>a.term_no,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=0)
and floor(DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30
/**and b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
and b.transaction_status in (2,5)
and b.contract_term not in (2,3)
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (
select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},if(b.loan_paid_at>='2018-01-01',g.principal+g.interest+g.service_fee,h.principle+h.interest+h.service_fee_per_term),0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
from xyqb_i_repayment_plan_bak a
left join xyqb_i_loan_a_m_history_bak b on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
/** where b.funding_corp_id in (420,520,580,650,670,810,240,640,700)*/
group by a.loan_application_history_id
) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id;
<!-- p2p 2019.12.13 -->
<!--
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,a.term_no termNo
,date(DATE_sub(a.deadline,INTERVAL 1 second)) targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,f.dkye remainingAmount
,case when f.yqze>0 then '2'
when f.dkye=0 then '3'
when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus
,'overdue' termStatus
from (select /* a.* */
a.id,a.user_id,a.loan_application_history_id,a.term_no,a.deadline,a.required_repayment,a.repayment_status,a.repaid_at,a.repayment_received_at
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb_i_loan_withdraw_record k on a.loan_application_history_id=k.loan_id
left join xyqb_i_repayment_plan_p2p_bak g on b.loan_application_history_id=g.loan_application_history_id
and b.contract_term=g.term_no
where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and
if(b.contract_term>a.term_no,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)>=0)
and floor(DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30
and b.funding_corp_id in (210,540)
and b.transaction_status in (2,5)
and if(b.loan_paid_at>='2018-01-01',b.contract_term >3,b.contract_term >=3)
and (k.id is null or k.status=3)
and g.repayment_status=3 and g.repaid_at &lt; '2019-10-25'
and b.loan_paid_at>='2016-11-01'
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},if(b.loan_paid_at>='2018-01-01',g.principal+g.interest+g.service_fee,h.principle+h.interest+h.service_fee_per_term),0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=#{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
from xyqb_i_repayment_plan_p2p_bak a
left join xyqb_i_loan_a_m_history_p2p_bak b /**xyqb_i_loan_application_manifest_history b*/
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (210,540)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id;
-->
</select>
<!--4.2百行助贷-联合贷 实时逾期还款 2019.10.28-->
<select id="findRealTimeRepayMentOverdueLh" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,a.term_no termNo
,date(DATE_sub(a.deadline,INTERVAL 1 second)) targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF( #{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT( #{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,f.dkye remainingAmount
,case when f.yqze>0 then '2'
when f.dkye=0 then '3'
when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus
,'overdue' termStatus
from (select a.*
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
where ((a.repayment_status !=3 and DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=30) or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR} and DATEDIFF(a.repaid_at,a.deadline)>=30)) and
if(b.contract_term>a.term_no,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)=30,DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=30)
and floor(DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)/30
and b.funding_corp_id in (880,890)
and b.transaction_status in (2,5)
and b.contract_term not in (2,3)
and b.loan_paid_at>='2019-10-25'
) a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join (select a.loan_application_history_id
,sum(if(((a.repayment_status !=3 and DATEDIFF( #{endTime,jdbcType=VARCHAR},a.deadline)>=30) or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR} and DATEDIFF(a.repaid_at,a.deadline)>=30)) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.required_repayment,0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
from xyqb_i_repayment_plan a
left join xyqb_i_loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id
left join xyqb_i_plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (880,890)
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb_i_repayment_record g on a.id=g.repayment_plan_id;
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.AccountPOMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.AccountPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<result column="id" jdbcType="INTEGER" property="id" />
<result column="source_name" jdbcType="VARCHAR" property="sourceName" />
<result column="blance" jdbcType="DECIMAL" property="blance" />
<result column="thershold" jdbcType="DECIMAL" property="thershold" />
<result column="status" jdbcType="VARCHAR" property="status" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, source_name, blance, thershold, `status`
</sql>
<select id="selectByExample" parameterType="cn.quantgroup.report.domain.master.AccountPO" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List"/>
from account
<trim prefix="where" prefixOverrides="and">
<if test="id != null">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="sourceName != null">
and source_name = #{sourceName,jdbcType=VARCHAR}
</if>
</trim>
</select>
<update id="updateByParams" parameterType="cn.quantgroup.report.domain.master.DataPriceConfigPO">
update account
<set>
<if test="blance != null">
blance = #{blance,jdbcType=DECIMAL}
</if>
</set>
<trim prefix="where" prefixOverrides="and">
<if test="id != null">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="sourceName != null">
and source_name = #{sourceName,jdbcType=VARCHAR}
</if>
</trim>
</update>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.AccountPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into account (id, source_name, blance, thershold,
`status`)
values (#{id,jdbcType=INTEGER}, #{sourceName,jdbcType=VARCHAR}, #{blance,jdbcType=DECIMAL}, #{thershold,jdbcType=DECIMAL},
#{status,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.AccountPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into account
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="sourceName != null">
source_name,
</if>
<if test="blance != null">
blance,
</if>
<if test="thershold != null">
thershold,
</if>
<if test="status != null">
`status`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="sourceName != null">
#{sourceName,jdbcType=VARCHAR},
</if>
<if test="blance != null">
#{blance,jdbcType=DECIMAL},
</if>
<if test="thershold != null">
#{thershold,jdbcType=DECIMAL},
</if>
<if test="status != null">
#{status,jdbcType=VARCHAR},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.ApiRequestLogPOMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.ApiRequestLogPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<result column="id" jdbcType="BIGINT" property="id" />
<result column="url_type" jdbcType="VARCHAR" property="urlType" />
<result column="res_code" jdbcType="VARCHAR" property="resCode" />
<result column="res_msg" jdbcType="VARCHAR" property="resMsg" />
<result column="hit_flag" jdbcType="VARCHAR" property="hitFlag" />
<result column="time_elapse" jdbcType="INTEGER" property="timeElapse" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.ApiRequestLogPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into api_request_log_${suffix} (id, url_type, res_code,
res_msg, hit_flag, time_elapse, create_time
)
values (#{id,jdbcType=BIGINT}, #{urlType,jdbcType=VARCHAR}, #{resCode,jdbcType=VARCHAR},
#{resMsg,jdbcType=VARCHAR}, #{hitFlag,jdbcType=VARCHAR}, #{timeElapse,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.ApiRequestLogPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into api_request_log_${suffix}
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="urlType != null">
url_type,
</if>
<if test="resCode != null">
res_code,
</if>
<if test="resMsg != null">
res_msg,
</if>
<if test="hitFlag != null">
hit_flag,
</if>
<if test="timeElapse != null">
time_elapse,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="urlType != null">
#{urlType,jdbcType=VARCHAR},
</if>
<if test="resCode != null">
#{resCode,jdbcType=VARCHAR},
</if>
<if test="resMsg != null">
#{resMsg,jdbcType=VARCHAR},
</if>
<if test="hitFlag != null">
#{hitFlag,jdbcType=VARCHAR},
</if>
<if test="timeElapse != null">
#{timeElapse,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.ApplyLoanInfoDbMapper">
<resultMap id="ApplyLoanInfoBaseResultMap" type="cn.quantgroup.report.domain.baihang.ApplyLoanInfo">
<result column="recordId" jdbcType="VARCHAR" property="record_id"/>
<result column="reqID" jdbcType="VARCHAR" property="req_id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="queryReason" jdbcType="INTEGER" property="queryReason"/>
<result column="guaranteeType" jdbcType="INTEGER" property="guaranteeType"/>
<result column="loanPurpose" jdbcType="INTEGER" property="loanPurpose"/>
<result column="customType" jdbcType="INTEGER" property="customType"/>
<result column="applyAmount" jdbcType="DECIMAL" property="applyAmount"/>
<result column="loanId" jdbcType="VARCHAR" property="loanId"/>
</resultMap>
<select id="saveApplyLoanInfoRecordLog" parameterType="cn.quantgroup.report.domain.baihang.ApplyLoanInfo">
insert into apply_loan_info (record_id, req_id, name, pid,mobile,query_reason,guarantee_type,loan_purpose,custom_type,apply_amount)
VALUES (#{record_Id},#{reqID},#{name},#{pid},#{mobile},#{queryReason},#{guaranteeType},#{loanPurpose},#{customType},#{applyAmount})
</select>
<!--1.根据loan_application_history_id查询工具报送的bean 申请A1 2019.10.20-->
<select id="findApplyInfoA1ByHistoryId" resultType="cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%Y-%m-%dT%H:%i:%S') uploadTs
,'1' isFinTechAgencyBusiness
,DATE_FORMAT(case when i.created_at is null and h.created_at &lt;=f.created_at then h.created_at
when i.created_at is null and h.created_at>f.created_at then f.created_at
else i.created_at end,'%Y-%m-%dT%H:%i:%S') as applyDate
,if(d.order_no is null,a.loan_application_history_id,d.order_no) applyId
,'1' applyType
,b.name name
,'1' idType
,b.id_no pid
,b.phone_no mobile
,b.email emailAddress
,case when j.education=1 then '10'
when j.education=2 then '20'
when j.education=3 then '30'
when j.education in (4,6) then '40'
when j.education=5 then '50'
when j.education in (7,8) then '60'
else '70' end eduBackground
,'500' degree
,'1' guaranteeType
,'1' loanPurpose
,'99' customType
,'-1' applyAmount
,'8' livingCondition
,case when j.marry_status=1 then '10'
when j.marry_status=2 then '20'
when j.marry_status=4 then '30'
when j.marry_status=3 then '40'
else '90' end marriageStatus
from xyqb_i_loan_application_manifest_history a
left join xyqb_user_i_user_detail b on a.user_id=b.user_id
left join xyqb_i_loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb_i_apply_quota_record d on c.order_no=d.order_no
left join xyqb_i_loan_submit_info f on a.loan_application_history_id=f.loan_id
left join xyqb_i_loan_application_history h on a.loan_application_history_id=h.id
/* 2020.01.06表迁移 left join xyqb_i_quota_credit i on d.order_no=i.order_no */
left join business_flow_i_apply_list i on d.order_no=i.apply_no
left join xyqb_i_loan_base_info j on a.loan_application_history_id=j.loan_id
where a.funding_corp_id in (420,520,580,650,670,810,240,640,700, 880,890)
and a.contract_term not in (2,3)
and a.transaction_status in (2,5)
AND a.loan_application_history_id=#{loanApplicationHistoryId}
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.CommonApiReqestEventMapper">
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.CommonWithBillingApiRequestEvent">
insert into common_request_event(user_id,time_created,mills,response_code,response_message,request_url_type,is_billing) values(#{userId},#{timeCreated},#{mills},#{responseCode},#{responseMessage},#{requestUrlType},#{isBilling})
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.CostRecordPOMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.CostRecordPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<result column="id" jdbcType="INTEGER" property="id" />
<result column="source_name" jdbcType="VARCHAR" property="sourceName" />
<result column="url_type" jdbcType="VARCHAR" property="urlType" />
<result column="invoke_times" jdbcType="INTEGER" property="invokeTimes" />
<result column="cost" jdbcType="DECIMAL" property="cost" />
<result column="balance" jdbcType="DECIMAL" property="balance" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.CostRecordPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into cost_record (id, source_name, url_type,
invoke_times, cost, balance,
create_time)
values (#{id,jdbcType=INTEGER}, #{sourceName,jdbcType=VARCHAR}, #{urlType,jdbcType=VARCHAR},
#{invokeTimes,jdbcType=INTEGER}, #{cost,jdbcType=DECIMAL}, #{balance,jdbcType=DECIMAL},
#{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.CostRecordPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into cost_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="sourceName != null">
source_name,
</if>
<if test="urlType != null">
url_type,
</if>
<if test="invokeTimes != null">
invoke_times,
</if>
<if test="cost != null">
cost,
</if>
<if test="balance != null">
balance,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="sourceName != null">
#{sourceName,jdbcType=VARCHAR},
</if>
<if test="urlType != null">
#{urlType,jdbcType=VARCHAR},
</if>
<if test="invokeTimes != null">
#{invokeTimes,jdbcType=INTEGER},
</if>
<if test="cost != null">
#{cost,jdbcType=DECIMAL},
</if>
<if test="balance != null">
#{balance,jdbcType=DECIMAL},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.DataPriceConfigPOMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.DataPriceConfigPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<result column="id" jdbcType="INTEGER" property="id" />
<result column="source_name" jdbcType="VARCHAR" property="sourceName" />
<result column="data_type" jdbcType="VARCHAR" property="dataType" />
<result column="url_type" jdbcType="VARCHAR" property="urlType" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="frequency" jdbcType="INTEGER" property="frequency" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
id, source_name, data_type, url_type, price, frequency
</sql>
<select id="queryByParams" resultMap="BaseResultMap" parameterType="cn.quantgroup.report.domain.master.DataPriceConfigPO">
select
<include refid="Base_Column_List"/>
from data_price_config
<trim prefix="where" prefixOverrides="and">
<if test="id != null">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="sourceName != null">
and source_name = #{sourceName,jdbcType=VARCHAR}
</if>
<if test="dataType != null">
and data_type = #{dataType,jdbcType=VARCHAR}
</if>
<if test="urlType != null">
and url_type = #{urlType,jdbcType=VARCHAR}
</if>
<if test="status != null">
and status = #{status,jdbcType=VARCHAR}
</if>
</trim>
</select>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.DataPriceConfigPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into data_price_config (id, source_name, data_type,
url_type, price, frequency, `status`,
create_time)
values (#{id,jdbcType=INTEGER}, #{sourceName,jdbcType=VARCHAR}, #{dataType,jdbcType=VARCHAR},
#{urlType,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},#{frequency,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.DataPriceConfigPO">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into data_price_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="sourceName != null">
source_name,
</if>
<if test="dataType != null">
data_type,
</if>
<if test="urlType != null">
url_type,
</if>
<if test="price != null">
price,
</if>
<if test="frequency != null">
frequency,
</if>
<if test="status != null">
`status`,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="sourceName != null">
#{sourceName,jdbcType=VARCHAR},
</if>
<if test="dataType != null">
#{dataType,jdbcType=VARCHAR},
</if>
<if test="urlType != null">
#{urlType,jdbcType=VARCHAR},
</if>
<if test="price != null">
#{price,jdbcType=DECIMAL},
</if>
<if test="frequency != null">
#{frequency,jdbcType=INTEGER},
</if>
<if test="status != null">
#{status,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.DataSourceCacheConfigMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.DataSourceCacheConfig">
<result column="product_type" jdbcType="VARCHAR" property="productType" />
<result column="product_name" jdbcType="VARCHAR" property="productName" />
<result column="product_cache_time" jdbcType="INTEGER" property="productCacheTime" />
<result column="product_cache_time" jdbcType="INTEGER" property="productCacheTime" />
<result column="product_test_cache_time" jdbcType="INTEGER" property="productTestCacheTime" />
<result column="data_source_name" jdbcType="VARCHAR" property="dataSourceName" />
</resultMap>
<select id="findAllCacheConfig" parameterType="cn.quantgroup.report.domain.master.DataSourceCacheConfig" resultMap="BaseResultMap">
select * from data_source_cache_config where enable = true;
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.DsSpecialUserHandleMapper">
<resultMap id="selectResultMap" type="cn.quantgroup.report.domain.master.DsSpecialUserHandle">
<result column="method_name" jdbcType="VARCHAR" property="methodName" />
<result column="service_name" jdbcType="VARCHAR" property="serviceName" />
<result column="uuid" jdbcType="VARCHAR" property="uuid" />
</resultMap>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.DsSpecialUserHandle">
insert into ds_special_user_handle(method_name,service_name,uuid)
values(#{methodName,jdbcType=VARCHAR},#{serviceName,jdbcType=VARCHAR},#{uuid,jdbcType=VARCHAR})
</insert>
<select id="selectAllByEnable" parameterType="cn.quantgroup.report.domain.master.DsSpecialUserHandle" resultMap="selectResultMap">
select c.method_name, c.service_name, c.uuid from ds_special_user_handle c where c.enable=true;
</select>
<update id="updateNotEnableByParams" parameterType="cn.quantgroup.report.domain.master.DsSpecialUserHandle">
update ds_special_user_handle c
set c.enable=false
where c.enable=true
<if test="methodName != null">
AND c.method_name = #{methodName,jdbcType=VARCHAR}
</if>
<if test="serviceName != null">
AND c.service_name = #{serviceName,jdbcType=VARCHAR}
</if>
<if test="uuid != null">
AND c.uuid = #{uuid,jdbcType=VARCHAR}
</if>
</update>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.ElevenBeiApiReqestEventMapper">
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.ElevenBeiApiRequestEvent">
insert into eleven_bei_api_request_event(identity_number,time_created,mills,response_code,response_message,request_url_type,is_billing) values(#{identity},#{timeCreated},#{mills},#{responseCode},#{responseMessage},#{requestUrlType},#{isBilling})
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.IntelliCreditLoanIssueMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="loan_type" jdbcType="VARCHAR" property="loanType"/>
<result column="account_open_date" jdbcType="BIGINT" property="accountOpenDate"/>
<result column="apply_date" jdbcType="BIGINT" property="applyDate"/>
<result column="issue_date" jdbcType="BIGINT" property="issueDate"/>
<result column="loan_amount" jdbcType="DECIMAL" property="loanAmount"/>
<result column="loan_id" jdbcType="BIGINT" property="loanId"/>
<result column="total_term" jdbcType="INTEGER" property="totalTerm"/>
<result column="first_repayment_date" jdbcType="BIGINT" property="firstRepaymentDate"/>
<result column="term_period" jdbcType="INTEGER" property="termPeriod"/>
<result column="plan_count" jdbcType="INTEGER" property="planCount"/>
<result column="status" jdbcType="TINYINT" property="status"/>
<result column="time_created" jdbcType="TIMESTAMP" property="timeCreated"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs"
type="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
<result column="device" jdbcType="LONGVARCHAR" property="device"/>
</resultMap>
<sql id="Base_Column_List">
id, name, pid, mobile, loan_type, account_open_date, apply_date, issue_date, loan_amount,
loan_id, total_term, first_repayment_date, term_period, plan_count, status, time_created
</sql>
<sql id="Blob_Column_List">
device
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from intelli_credit_loan_issue
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectUndoneByBeginId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from intelli_credit_loan_issue
where id > #{id,jdbcType=BIGINT} and `status` > 1
</select>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into intelli_credit_loan_issue (name, pid, mobile,
loan_type, account_open_date, apply_date,
issue_date, loan_amount, loan_id,
total_term, first_repayment_date, term_period,
plan_count, status, time_created,
device)
values (#{name,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR},
#{loanType,jdbcType=VARCHAR}, #{accountOpenDate,jdbcType=BIGINT}, #{applyDate,jdbcType=BIGINT},
#{issueDate,jdbcType=BIGINT}, #{loanAmount,jdbcType=DECIMAL}, #{loanId,jdbcType=BIGINT},
#{totalTerm,jdbcType=INTEGER}, #{firstRepaymentDate,jdbcType=INTEGER}, #{termPeriod,jdbcType=INTEGER},
#{planCount,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}, #{timeCreated,jdbcType=TIMESTAMP},
#{device,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into intelli_credit_loan_issue
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
name,
</if>
<if test="pid != null">
pid,
</if>
<if test="mobile != null">
mobile,
</if>
<if test="loanType != null">
loan_type,
</if>
<if test="accountOpenDate != null">
account_open_date,
</if>
<if test="applyDate != null">
apply_date,
</if>
<if test="issueDate != null">
issue_date,
</if>
<if test="loanAmount != null">
loan_amount,
</if>
<if test="loanId != null">
loan_id,
</if>
<if test="totalTerm != null">
total_term,
</if>
<if test="firstRepaymentDate != null">
first_repayment_date,
</if>
<if test="termPeriod != null">
term_period,
</if>
<if test="planCount != null">
plan_count,
</if>
<if test="status != null">
status,
</if>
<if test="timeCreated != null">
time_created,
</if>
<if test="device != null">
device,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="pid != null">
#{pid,jdbcType=VARCHAR},
</if>
<if test="mobile != null">
#{mobile,jdbcType=VARCHAR},
</if>
<if test="loanType != null">
#{loanType,jdbcType=VARCHAR},
</if>
<if test="accountOpenDate != null">
#{accountOpenDate,jdbcType=BIGINT},
</if>
<if test="applyDate != null">
#{applyDate,jdbcType=BIGINT},
</if>
<if test="issueDate != null">
#{issueDate,jdbcType=BIGINT},
</if>
<if test="loanAmount != null">
#{loanAmount,jdbcType=DECIMAL},
</if>
<if test="loanId != null">
#{loanId,jdbcType=BIGINT},
</if>
<if test="totalTerm != null">
#{totalTerm,jdbcType=INTEGER},
</if>
<if test="firstRepaymentDate != null">
#{firstRepaymentDate,jdbcType=INTEGER},
</if>
<if test="termPeriod != null">
#{termPeriod,jdbcType=INTEGER},
</if>
<if test="planCount != null">
#{planCount,jdbcType=INTEGER},
</if>
<if test="status != null">
#{status,jdbcType=TINYINT},
</if>
<if test="timeCreated != null">
#{timeCreated,jdbcType=TIMESTAMP},
</if>
<if test="device != null">
#{device,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective"
parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
update intelli_credit_loan_issue
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="pid != null">
pid = #{pid,jdbcType=VARCHAR},
</if>
<if test="mobile != null">
mobile = #{mobile,jdbcType=VARCHAR},
</if>
<if test="loanType != null">
loan_type = #{loanType,jdbcType=VARCHAR},
</if>
<if test="accountOpenDate != null">
account_open_date = #{accountOpenDate,jdbcType=BIGINT},
</if>
<if test="applyDate != null">
apply_date = #{applyDate,jdbcType=BIGINT},
</if>
<if test="issueDate != null">
issue_date = #{issueDate,jdbcType=BIGINT},
</if>
<if test="loanAmount != null">
loan_amount = #{loanAmount,jdbcType=DECIMAL},
</if>
<if test="loanId != null">
loan_id = #{loanId,jdbcType=BIGINT},
</if>
<if test="totalTerm != null">
total_term = #{totalTerm,jdbcType=INTEGER},
</if>
<if test="firstRepaymentDate != null">
first_repayment_date = #{firstRepaymentDate,jdbcType=INTEGER},
</if>
<if test="termPeriod != null">
term_period = #{termPeriod,jdbcType=INTEGER},
</if>
<if test="planCount != null">
plan_count = #{planCount,jdbcType=INTEGER},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</if>
<if test="timeCreated != null">
time_created = #{timeCreated,jdbcType=TIMESTAMP},
</if>
<if test="device != null">
device = #{device,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs"
parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
UPDATE intelli_credit_loan_issue
SET name = #{name,jdbcType=VARCHAR},
pid = #{pid,jdbcType=VARCHAR},
mobile = #{mobile,jdbcType=VARCHAR},
loan_type = #{loanType,jdbcType=VARCHAR},
account_open_date = #{accountOpenDate,jdbcType=BIGINT},
apply_date = #{applyDate,jdbcType=BIGINT},
issue_date = #{issueDate,jdbcType=BIGINT},
loan_amount = #{loanAmount,jdbcType=DECIMAL},
loan_id = #{loanId,jdbcType=BIGINT},
total_term = #{totalTerm,jdbcType=INTEGER},
first_repayment_date = #{firstRepaymentDate,jdbcType=INTEGER},
term_period = #{termPeriod,jdbcType=INTEGER},
plan_count = #{planCount,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT},
time_created = #{timeCreated,jdbcType=TIMESTAMP},
device = #{device,jdbcType=LONGVARCHAR}
WHERE id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanIssue">
UPDATE intelli_credit_loan_issue
SET name = #{name,jdbcType=VARCHAR},
pid = #{pid,jdbcType=VARCHAR},
mobile = #{mobile,jdbcType=VARCHAR},
loan_type = #{loanType,jdbcType=VARCHAR},
account_open_date = #{accountOpenDate,jdbcType=BIGINT},
apply_date = #{applyDate,jdbcType=BIGINT},
issue_date = #{issueDate,jdbcType=BIGINT},
loan_amount = #{loanAmount,jdbcType=DECIMAL},
loan_id = #{loanId,jdbcType=BIGINT},
total_term = #{totalTerm,jdbcType=INTEGER},
first_repayment_date = #{firstRepaymentDate,jdbcType=INTEGER},
term_period = #{termPeriod,jdbcType=INTEGER},
plan_count = #{planCount,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT},
time_created = #{timeCreated,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.IntelliCreditLoanTraceMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.IntelliCreditLoanTrace">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="loan_id" jdbcType="BIGINT" property="loanId"/>
<result column="repayment_plan_id" jdbcType="BIGINT" property="repaymentPlanId"/>
<result column="term_no" jdbcType="INTEGER" property="termNo"/>
<result column="term_status" jdbcType="VARCHAR" property="termStatus"/>
<result column="target_repayment_date" jdbcType="BIGINT" property="targetRepaymentDate"/>
<result column="real_repayment_date" jdbcType="BIGINT" property="realRepaymentDate"/>
<result column="target_repayment" jdbcType="DECIMAL" property="targetRepayment"/>
<result column="real_repayment" jdbcType="DECIMAL" property="realRepayment"/>
<result column="status_confirm_at" jdbcType="BIGINT" property="statusConfirmAt"/>
<result column="overdue_status" jdbcType="VARCHAR" property="overdueStatus"/>
<result column="status" jdbcType="TINYINT" property="status"/>
</resultMap>
<sql id="Base_Column_List">
id, loan_id, repayment_plan_id, term_no, term_status, target_repayment_date, real_repayment_date,
target_repayment, real_repayment, status_confirm_at, overdue_status, status
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from intelli_credit_loan_trace
where id = #{id,jdbcType=BIGINT}
</select>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanTrace">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into intelli_credit_loan_trace (loan_id, repayment_plan_id, term_no,
term_status, target_repayment_date, real_repayment_date,
target_repayment, real_repayment, status_confirm_at,
overdue_status, status)
values (#{loanId,jdbcType=BIGINT}, #{repaymentPlanId,jdbcType=BIGINT}, #{termNo,jdbcType=INTEGER},
#{termStatus,jdbcType=VARCHAR}, #{targetRepaymentDate,jdbcType=BIGINT}, #{realRepaymentDate,jdbcType=BIGINT},
#{targetRepayment,jdbcType=DECIMAL}, #{realRepayment,jdbcType=DECIMAL}, #{statusConfirmAt,jdbcType=BIGINT},
#{overdueStatus,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanTrace">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into intelli_credit_loan_trace
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="loanId != null">
loan_id,
</if>
<if test="repaymentPlanId != null">
repayment_plan_id,
</if>
<if test="termNo != null">
term_no,
</if>
<if test="termStatus != null">
term_status,
</if>
<if test="targetRepaymentDate != null">
target_repayment_date,
</if>
<if test="realRepaymentDate != null">
real_repayment_date,
</if>
<if test="targetRepayment != null">
target_repayment,
</if>
<if test="realRepayment != null">
real_repayment,
</if>
<if test="statusConfirmAt != null">
status_confirm_at,
</if>
<if test="overdueStatus != null">
overdue_status,
</if>
<if test="status != null">
status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="loanId != null">
#{loanId,jdbcType=BIGINT},
</if>
<if test="repaymentPlanId != null">
#{repaymentPlanId,jdbcType=BIGINT},
</if>
<if test="termNo != null">
#{termNo,jdbcType=INTEGER},
</if>
<if test="termStatus != null">
#{termStatus,jdbcType=VARCHAR},
</if>
<if test="targetRepaymentDate != null">
#{targetRepaymentDate,jdbcType=BIGINT},
</if>
<if test="realRepaymentDate != null">
#{realRepaymentDate,jdbcType=BIGINT},
</if>
<if test="targetRepayment != null">
#{targetRepayment,jdbcType=DECIMAL},
</if>
<if test="realRepayment != null">
#{realRepayment,jdbcType=DECIMAL},
</if>
<if test="statusConfirmAt != null">
#{statusConfirmAt,jdbcType=BIGINT},
</if>
<if test="overdueStatus != null">
#{overdueStatus,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=TINYINT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective"
parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanTrace">
update intelli_credit_loan_trace
<set>
<if test="loanId != null">
loan_id = #{loanId,jdbcType=BIGINT},
</if>
<if test="repaymentPlanId != null">
repayment_plan_id = #{repaymentPlanId,jdbcType=BIGINT},
</if>
<if test="termNo != null">
term_no = #{termNo,jdbcType=INTEGER},
</if>
<if test="termStatus != null">
term_status = #{termStatus,jdbcType=VARCHAR},
</if>
<if test="targetRepaymentDate != null">
target_repayment_date = #{targetRepaymentDate,jdbcType=BIGINT},
</if>
<if test="realRepaymentDate != null">
real_repayment_date = #{realRepaymentDate,jdbcType=BIGINT},
</if>
<if test="targetRepayment != null">
target_repayment = #{targetRepayment,jdbcType=DECIMAL},
</if>
<if test="realRepayment != null">
real_repayment = #{realRepayment,jdbcType=DECIMAL},
</if>
<if test="statusConfirmAt != null">
status_confirm_at = #{statusConfirmAt,jdbcType=BIGINT},
</if>
<if test="overdueStatus != null">
overdue_status = #{overdueStatus,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="cn.quantgroup.report.domain.master.IntelliCreditLoanTrace">
UPDATE intelli_credit_loan_trace
SET loan_id = #{loanId,jdbcType=BIGINT},
repayment_plan_id = #{repaymentPlanId,jdbcType=BIGINT},
term_no = #{termNo,jdbcType=INTEGER},
term_status = #{termStatus,jdbcType=VARCHAR},
target_repayment_date = #{targetRepaymentDate,jdbcType=BIGINT},
real_repayment_date = #{realRepaymentDate,jdbcType=BIGINT},
target_repayment = #{targetRepayment,jdbcType=DECIMAL},
real_repayment = #{realRepayment,jdbcType=DECIMAL},
status_confirm_at = #{statusConfirmAt,jdbcType=BIGINT},
overdue_status = #{overdueStatus,jdbcType=VARCHAR},
status = #{status,jdbcType=TINYINT}
WHERE id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.IntelliCreditRequestEventMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.IntelliCreditRequestEvent">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="uuid" jdbcType="VARCHAR" property="uuid" />
<result column="time_created" jdbcType="TIMESTAMP" property="timeCreated" />
<result column="http_code" jdbcType="INTEGER" property="httpCode" />
<result column="response_message" jdbcType="VARCHAR" property="responseMessage" />
<result column="mills" jdbcType="INTEGER" property="mills" />
</resultMap>
<sql id="Base_Column_List">
id, loan_id, time_created, http_code, response_message, mills
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from intelli_credit_request_event
where id = #{id,jdbcType=BIGINT}
</select>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.IntelliCreditRequestEvent">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into intelli_credit_request_event (uuid, time_created, http_code,
response_message, mills)
values (#{uuid,jdbcType=VARCHAR}, #{timeCreated,jdbcType=TIMESTAMP}, #{httpCode,jdbcType=INTEGER},
#{responseMessage,jdbcType=VARCHAR}, #{mills,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="cn.quantgroup.report.domain.master.IntelliCreditRequestEvent">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into intelli_credit_request_event
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="loanId != null">
loan_id,
</if>
<if test="timeCreated != null">
time_created,
</if>
<if test="httpCode != null">
http_code,
</if>
<if test="responseMessage != null">
response_message,
</if>
<if test="mills != null">
mills,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="loanId != null">
#{loanId,jdbcType=BIGINT},
</if>
<if test="timeCreated != null">
#{timeCreated,jdbcType=TIMESTAMP},
</if>
<if test="httpCode != null">
#{httpCode,jdbcType=INTEGER},
</if>
<if test="responseMessage != null">
#{responseMessage,jdbcType=VARCHAR},
</if>
<if test="mills != null">
#{mills,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="cn.quantgroup.report.domain.master.IntelliCreditRequestEvent">
update intelli_credit_request_event
<set>
<if test="loanId != null">
loan_id = #{loanId,jdbcType=BIGINT},
</if>
<if test="timeCreated != null">
time_created = #{timeCreated,jdbcType=TIMESTAMP},
</if>
<if test="httpCode != null">
http_code = #{httpCode,jdbcType=INTEGER},
</if>
<if test="responseMessage != null">
response_message = #{responseMessage,jdbcType=VARCHAR},
</if>
<if test="mills != null">
mills = #{mills,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="cn.quantgroup.report.domain.master.IntelliCreditRequestEvent">
update intelli_credit_request_event
set loan_id = #{loanId,jdbcType=BIGINT},
time_created = #{timeCreated,jdbcType=TIMESTAMP},
http_code = #{httpCode,jdbcType=INTEGER},
response_message = #{responseMessage,jdbcType=VARCHAR},
mills = #{mills,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.LoanInfoDbMapper">
<resultMap id="LoanInfoResultMap" type="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai">
<result column="recordId" jdbcType="VARCHAR" property="record_id"/>
<result column="reqID" jdbcType="VARCHAR" property="req_id"/>
<result column="opCode" jdbcType="VARCHAR" property="op_Code"/>
<result column="uploadTs" jdbcType="VARCHAR" property="upload_ts"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="loanId" jdbcType="VARCHAR" property="loan_id"/>
<result column="guaranteeType" jdbcType="INTEGER" property="guarantee_type"/>
<result column="loanPurpose" jdbcType="INTEGER" property="loan_purpose"/>
<result column="applyDate" jdbcType="VARCHAR" property="apply_date"/>
<result column="accountOpenDate" jdbcType="VARCHAR" property="account_open_date"/>
<result column="issueDate" jdbcType="VARCHAR" property="issue_date"/>
<result column="dueDate" jdbcType="VARCHAR" property="due_date"/>
<result column="loanAmount" jdbcType="DECIMAL" property="loan_amount"/>
<result column="totalTerm" jdbcType="INTEGER" property="total_term"/>
<result column="targetRepayDateType" jdbcType="INTEGER" property="target_repay_date_type"/>
<result column="termPeriod" jdbcType="INTEGER" property="term_period"/>
<result column="firstRepaymentDate" jdbcType="VARCHAR" property="first_repayment_date"/>
<result column="gracePeriod" jdbcType="INTEGER" property="grace_period"/>
</resultMap>
<select id="saveLoanInfoRecordLog" parameterType="cn.quantgroup.report.domain.baihang.LoanInfoZhuDai">
<!--insert into loan_info_zhudai (record_id, req_id, name, pid,mobile,op_Code,upload_ts,loan_id,guarantee_type,loan_purpose,apply_date,account_open_date,
issue_date,due_date,loan_amount,total_term,target_repay_date_type,term_period,first_repayment_date,grace_period)
VALUES (#{recordId},#{reqID},#{name},#{pid},#{mobile},#{opCode},#{uploadTs},#{loanId},#{guaranteeType},#{loanPurpose},#{applyDate}
,#{accountOpenDate},#{issueDate},#{dueDate},#{loanAmount},#{totalTerm},#{targetRepayDateType},#{termPeriod},#{firstRepaymentDate},#{gracePeriod})*/-->
insert into loan_info_zhudai (record_id, req_id, name, pid,mobile,op_Code,upload_ts,loan_id,guarantee_type,loan_purpose,apply_date,account_open_date,
issue_date,due_date,loan_amount,total_term,target_repay_date_type,term_period,first_repayment_date,grace_period,
institutional_funding_partner,institutional_funding_partner_id,institutional_funding_partner_loan_id,relation_id,order_id,pre_credit_limit)
VALUES (#{recordId},#{reqID},#{name},#{pid},#{mobile},#{opCode},#{uploadTs},#{loanId},#{guaranteeType},#{loanPurpose},#{applyDate},
#{accountOpenDate},#{issueDate},#{dueDate},#{loanAmount},#{totalTerm},#{targetRepayDateType},#{termPeriod},#{firstRepaymentDate},#{gracePeriod},
#{institutionalFundingPartner},#{institutionalFundingPartnerID},#{institutionalFundingPartnerLoanID},#{relationID},#{orderID},#{preCreditLimit})
</select>
<update id="updateCurrentRecordEnableFalce" parameterType="cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord">
update loan_info_zhudai set enable = #{enable, jdbcType=VARCHAR} where record_id = #{recordId, jdbcType=VARCHAR};
</update>
<!--<select id="findAll" resultMap="LoanInfoResultMap">
select * from loan_info_zhudai where enable = false;
</select>-->
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.RepaymentLoanInfoDbMapper">
<resultMap id="RepaymetnLoanInfoResultMap" type="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
<result column="reqID" jdbcType="VARCHAR" property="req_id"/>
<result column="recordId" jdbcType="VARCHAR" property="record_id"/>
<result column="opCode" jdbcType="VARCHAR" property="op_code"/>
<result column="uploadTs" jdbcType="VARCHAR" property="upload_ts"/>
<result column="loanId" jdbcType="VARCHAR" property="loan_id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="termNo" jdbcType="INTEGER" property="term_no"/>
<result column="termStatus" jdbcType="VARCHAR" property="term_status"/>
<result column="targetRepaymentDate" jdbcType="VARCHAR" property="target_repayment_date"/>
<result column="realRepaymentDate" jdbcType="VARCHAR" property="real_repayment_date"/>
<result column="plannedPayment" jdbcType="DECIMAL" property="planned_payment"/>
<result column="targetRepayment" jdbcType="DECIMAL" property="target_repayment"/>
<result column="realRepayment" jdbcType="DECIMAL" property="real_repayment"/>
<result column="overdueStatus" jdbcType="VARCHAR" property="overdue_status"/>
<result column="statusConfirmAt" jdbcType="VARCHAR" property="status_confirm_at"/>
<result column="overdueAmount" jdbcType="DECIMAL" property="overdue_amount"/>
<result column="remainingAmount" jdbcType="DECIMAL" property="remaining_amount"/>
<result column="loanStatus" jdbcType="INTEGER" property="loan_status"/>
</resultMap>
<resultMap id="RepaymentLoanInfoVoResultMapByBS" type="cn.quantgroup.report.domain.baihang.RepaymentLoanInfoLog">
<result column="reqID" jdbcType="VARCHAR" property="req_id"/>
<result column="opCode" jdbcType="VARCHAR" property="op_code"/>
<result column="uploadTs" jdbcType="VARCHAR" property="upload_ts"/>
<result column="loanId" jdbcType="VARCHAR" property="loan_id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="termNo" jdbcType="INTEGER" property="term_no"/>
<result column="termStatus" jdbcType="VARCHAR" property="term_status"/>
<result column="targetRepaymentDate" jdbcType="VARCHAR" property="target_repayment_date"/>
<result column="realRepaymentDate" jdbcType="VARCHAR" property="real_repayment_date"/>
<result column="plannedPayment" jdbcType="DECIMAL" property="planned_payment"/>
<result column="targetRepayment" jdbcType="DECIMAL" property="target_repayment"/>
<result column="realRepayment" jdbcType="DECIMAL" property="real_repayment"/>
<result column="overdueStatus" jdbcType="VARCHAR" property="overdue_status"/>
<result column="statusConfirmAt" jdbcType="VARCHAR" property="status_confirm_at"/>
<result column="overdueAmount" jdbcType="DECIMAL" property="overdue_amount"/>
<result column="remainingAmount" jdbcType="DECIMAL" property="remaining_amount"/>
<result column="loanStatus" jdbcType="INTEGER" property="loan_status"/>
<result column="recordId" jdbcType="VARCHAR" property="record_id"/>
<result column="id" jdbcType="DECIMAL" property="id"/>
<result column="enable" jdbcType="INTEGER" property="enable"/>
<result column="createdAt" jdbcType="VARCHAR" property="created_at"/>
<result column="updatedAt" jdbcType="VARCHAR" property="updated_at"/>
</resultMap>
<select id="saveRepaymentLoanInfoLog" parameterType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai" resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
insert into
repayment_loan_info_zhudai
(record_id,req_id ,name,pid ,mobile ,op_code ,upload_ts ,loan_id ,term_no ,term_status ,target_repayment_date ,real_repayment_date,planned_payment ,target_repayment,real_repayment ,overdue_amount,remaining_amount,overdue_status,loan_status,status_confirm_at)
values (#{recordId, jdbcType=VARCHAR},#{reqID, jdbcType=VARCHAR},#{name, jdbcType=VARCHAR},#{pid, jdbcType=VARCHAR},#{mobile, jdbcType=VARCHAR},#{opCode, jdbcType=VARCHAR},
#{uploadTs, jdbcType=VARCHAR},#{loanId, jdbcType=VARCHAR},#{termNo, jdbcType=INTEGER},#{termStatus, jdbcType=INTEGER},#{targetRepaymentDate, jdbcType=VARCHAR},#{realRepaymentDate, jdbcType=VARCHAR},
#{plannedPayment, jdbcType=DECIMAL},#{targetRepayment, jdbcType=DECIMAL},#{realRepayment, jdbcType=DECIMAL},#{overdueAmount, jdbcType=DECIMAL},#{remainingAmount, jdbcType=DECIMAL},
#{overdueStatus, jdbcType=INTEGER},#{loanStatus, jdbcType=INTEGER},#{statusConfirmAt, jdbcType=VARCHAR})
</select>
<update id="updateCurrentRecordEnableFalse" parameterType="cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord">
update repayment_loan_info_zhudai set enable = #{enable, jdbcType=VARCHAR}, updated_at = CURRENT_TIMESTAMP() where record_id = #{recordId, jdbcType=VARCHAR};
</update>
<!-- <select id="findAll" resultMap="RepaymetnLoanInfoResultMap">
select * from repayment_loan_info_zhudai where enable = false;
</select>-->
<select id="findLastOne" parameterType="cn.quantgroup.report.domain.baihang.BaiHangRepayment" resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select id, record_id, req_id, loan_id, term_no, status_confirm_at, term_status
from repayment_loan_info_zhudai where loan_id = #{loanId} and term_no = #{termNo}
<!--2020.01.07 17:55 值针对当天,还款报了,逾期又有一条的情况 DATE_FORMAT(now(),'%Y-%m-%d') -->
<!-- 2020.02.06 16:14和广达保持一致 and created_at >= #{sendDate} -->
limit 1;
</select>
<!--根据日志中的reqID查询loan_id及还款信息 2019.09.25-->
<select id="findByD3RecordId" resultMap="RepaymentLoanInfoVoResultMapByBS">
SELECT * from repayment_loan_info_zhudai
WHERE op_code='A' and record_id IN
<foreach collection="array" item="recordId" index="index" open="(" close=")" separator=",">
#{recordId}
</foreach>
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.RepaymentLoanWhiteListMapper">
<resultMap id="repaymentLoanWhiteListMap" type="cn.quantgroup.report.domain.master.RepaymentLoanWhiteList">
<!--<result column="id" jdbcType="DECIMAL" property="id"/>-->
<result column="pid" jdbcType="VARCHAR" property="pid"/>
<result column="mobile" jdbcType="VARCHAR" property="mobile"/>
<result column="loanId" jdbcType="VARCHAR" property="loan_id"/>
<result column="type" jdbcType="INTEGER" property="type"/>
<!--<result column="enable" jdbcType="INTEGER" property="enable"/>
<result column="createdAt" jdbcType="VARCHAR" property="created_at"/>-->
</resultMap>
<!--<update id="updateCurrentRecordEnableFalce" parameterType="cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord">
update loan_info_zhudai set enable = #{enable, jdbcType=VARCHAR} where record_id = #{recordId, jdbcType=VARCHAR};
</update>-->
<!--<select id="findByD3RecordId" resultMap="RepaymentLoanInfoVoResultMapByBS">
SELECT * from repayment_loan_info_zhudai
WHERE op_code='A' and record_id IN
<foreach collection="array" item="recordId" index="index" open="(" close=")" separator=",">
#{recordId}
</foreach>
</select>-->
<select id="findRepaymentLoanWhiteListOne" resultMap="repaymentLoanWhiteListMap">
select pid, mobile, loan_id, type from repayment_loan_white_list
where loan_id=#{loanId} AND type=#{type} AND enable=1
limit 1;
</select>
<!--<select id="findLastOne" parameterType="cn.quantgroup.report.domain.baihang.BaiHangRepayment" resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select id, record_id, req_id, loan_id, term_no, status_confirm_at, term_status
from repayment_loan_info_zhudai where loan_id = #{loanId} and term_no = #{termNo}
&lt;!&ndash;2020.01.07 17:55 值针对当天,还款报了,逾期又有一条的情况 DATE_FORMAT(now(),'%Y-%m-%d') &ndash;&gt;
and created_at >= #{sendDate}
limit 1;
</select>-->
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.TransactionLogPOMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.master.TransactionLogPO">
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId" />
<result column="uuid" jdbcType="VARCHAR" property="uuid" />
<result column="url_type" jdbcType="VARCHAR" property="urlType" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="time_created" jdbcType="TIMESTAMP" property="timeCreated" />
</resultMap>
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.TransactionLogPO">
insert into transaction_log (transaction_id, uuid, url_type, code, time_created)
values (#{transactionId,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{urlType,jdbcType=VARCHAR}, #{code,jdbcType=INTEGER},
#{timeCreated,jdbcType=TIMESTAMP}
)
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.master.UnionPayApiRequestEventMapper">
<insert id="insert" parameterType="cn.quantgroup.report.domain.master.UnionPayApiRequestEvent">
insert into union_pay_api_request_event(bankCardNo,time_created,mills,businessCode,request_url_type) values(#{bankCardNo},#{timeCreated},#{mills},#{businessCode},#{requestUrlType})
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.tidbrisk.CallRecordMapper">
<!--
<resultMap id="BaseResultMap" type="cn.quantgroup.risk.datasource.domain.master.TransactionLogPO">
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId" />
<result column="uuid" jdbcType="VARCHAR" property="uuid" />
<result column="url_type" jdbcType="VARCHAR" property="urlType" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="time_created" jdbcType="TIMESTAMP" property="timeCreated" />
</resultMap>
<insert id="insert" parameterType="cn.quantgroup.risk.datasource.domain.master.TransactionLogPO">
insert into transaction_log (transaction_id, uuid, url_type, code, time_created)
values (#{transactionId,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{urlType,jdbcType=VARCHAR}, #{code,jdbcType=INTEGER},
#{timeCreated,jdbcType=TIMESTAMP}
)
</insert>
-->
<insert id="insertCallRecord" parameterType="cn.quantgroup.report.domain.tidbrisk.CallRecord2">
INSERT INTO call_record (channel_type,channel_id,transaction_id,uuid,url_type,`code` ,request_url,created_at, updated_at)
VALUES
( #{channelType,jdbcType=VARCHAR},
#{channelId,jdbcType=VARCHAR},
#{transactionId,jdbcType=VARCHAR},
#{uuid,jdbcType=VARCHAR},
#{urlType,jdbcType=VARCHAR},
#{code,jdbcType=INTEGER},
#{requestUrl,jdbcType=VARCHAR},
now(),
now()
)
</insert>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.xyqbuser.UserDetailMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.xyqbuser.UserDetail">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="user_id" jdbcType="BIGINT" property="userId"/>
<result column="phone_no" jdbcType="VARCHAR" property="phoneNo"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="id_no" jdbcType="VARCHAR" property="idNo"/>
<result column="id_type" jdbcType="TINYINT" property="idType"/>
<result column="is_authenticated" jdbcType="BIT" property="isAuthenticated"/>
<result column="gender" jdbcType="TINYINT" property="gender"/>
<result column="email" jdbcType="VARCHAR" property="email"/>
<result column="qq" jdbcType="VARCHAR" property="qq"/>
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
</resultMap>
<sql id="Base_Column_List">
id, user_id, phone_no, name, id_no, id_type, is_authenticated, gender, email, qq,
created_at, updated_at
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user_detail
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectByUserId" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user_detail
where user_id = #{userId,jdbcType=BIGINT}
</select>
<select id="selectByIdentityNumber" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user_detail
where id_no = #{identityNumber,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
<?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.quantgroup.report.mapper.xyqbuser.UserMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.report.domain.xyqbuser.User">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="phone_no" jdbcType="VARCHAR" property="phoneNo"/>
<result column="uuid" jdbcType="VARCHAR" property="uuid"/>
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
</resultMap>
<sql id="Base_Column_List">
id, phone_no, uuid,created_at
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectByUuid" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user
where uuid = #{uuid,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
CREATE TABLE `common_api_request_event` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`uuid` VARCHAR(64) NOT NULL,
`time_created` DATETIME,
`response_code` VARCHAR(50),
`response_message` VARCHAR(512),
`business_code` VARCHAR(128),
`mills` INT(11),
`request_url_type` VARCHAR(50),
PRIMARY KEY (`id`),
KEY `index__request_url_type_and_uuid` (`request_url_type`, `uuid`)
);
\ No newline at end of file
CREATE TABLE `intelli_credit_request_event` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`loan_id` BIGINT NOT NULL,
`time_created` DATETIME,
`http_code` INT(11),
`response_message` VARCHAR(512),
`mills` INT(11),
PRIMARY KEY (`id`),
KEY `index__loan_id_and_http_code` (`loan_id`, `http_code`)
);
CREATE TABLE `intelli_credit_loan_issue` (
`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(512),
`pid` VARCHAR(512),
`mobile` VARCHAR(512),
`loan_type` VARCHAR(512),
`account_open_date` BIGINT NOT NULL DEFAULT 0,
`apply_date` BIGINT NOT NULL DEFAULT 0,
`issue_date` BIGINT NOT NULL DEFAULT 0,
`loan_amount` DECIMAL(10, 2) NOT NULL DEFAULT 0,
`loan_id` BIGINT NOT NULL,
`total_term` INT(11),
`first_repayment_date` BIGINT,
`term_period` INT(11),
`plan_count` INT(11),
`status` TINYINT NOT NULL DEFAULT 0,
`device` TEXT,
`time_created` DATETIME,
UNIQUE KEY `unique_index__loan_id` (`loan_id`)
);
CREATE TABLE `intelli_credit_loan_trace` (
`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`loan_id` BIGINT NOT NULL,
`repayment_plan_id` BIGINT NOT NULL,
`term_no` INT(11),
`term_status` VARCHAR(1),
`target_repayment_date` BIGINT NOT NULL DEFAULT 0,
`real_repayment_date` BIGINT NOT NULL DEFAULT 0,
`target_repayment` DECIMAL(10, 2) NOT NULL DEFAULT 0,
`real_repayment` DECIMAL(10, 2) NOT NULL DEFAULT 0,
`status_confirm_at` BIGINT NOT NULL DEFAULT 0,
`overdue_status` VARCHAR(1),
`status` TINYINT NOT NULL DEFAULT 0,
UNIQUE KEY `unique_index__loan_id_and_term_no` (`loan_id`, `term_no`),
KEY `index__status_and_repayment_plan_id` (`status`, `repayment_plan_id`)
);
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<properties resource="application.properties"/>
<classPathEntry location="${mbg.jdbc.driver-location}"/>
<context id="mysql" defaultModelType="conditional" targetRuntime="MyBatis3">
<property name="mergeable" value="true"></property>
<property name="javaFileEncoding" value="UTF-8"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"/>
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="${mbg.jdbc.driver-class-name}"
connectionURL="${mbg.jdbc.url}"
userId="${mbg.jdbc.username}"
password="${mbg.jdbc.password}">
</jdbcConnection>
<javaModelGenerator targetProject="${mbg.target-project.java}"
targetPackage="${mbg.target-package.domain}">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetProject="${mbg.target-project.resources}"
targetPackage="${mbg.target-package.mapper}">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetProject="${mbg.target-project.java}"
targetPackage="${mbg.target-package.mapper}">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table tableName="t_user_auth_info" enableInsert="false" enableDeleteByPrimaryKey="false"
enableUpdateByPrimaryKey="false" enableUpdateByExample="false" enableCountByExample="false"
enableSelectByExample="false"
enableDeleteByExample="false">
<generatedKey column="id" identity="true" sqlStatement="MySql"/>
</table>
<!--<table tableName="user_info" enableInsert="false" enableDeleteByPrimaryKey="false"-->
<!--enableUpdateByPrimaryKey="false" enableUpdateByExample="false" enableCountByExample="false"-->
<!--enableSelectByExample="false"-->
<!--enableDeleteByExample="false">-->
<!--<generatedKey column="id" identity="true" sqlStatement="MySql"/>-->
<!--</table>-->
</context>
</generatorConfiguration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<springProperty name="spring.application.name" source="spring.application.name"/>
<property name="LOG_LEVEL_PATTERN"
value="%clr(%5p) %clr([${spring.application.name:-},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]){yellow}"/>
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%10.10t]){faint} [%40.40file:%4.4line] %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!-- 这里面定义了 CONSOLE_LOG_PATTERN, FILE_LOG_PATTERN 等日志格式, 还定义了一些日志级别 -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${FILE_LOG_PATTERN}</pattern>
</layout>
</appender>
<!--logstash-->
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>172.30.220.6:9646</destination>
<!-- encoder is required -->
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<logger name="com.atomikos" level="warn"/>
<logger name="org.springframework" level="warn"/>
<logger name="org.mybatis" level="warn"/>
<logger name="org.apache" level="warn"/>
<logger name="ch.qos.logback" level="warn"/>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="stash"/>
</root>
</configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<springProperty name="spring.application.name" source="spring.application.name"/>
<property name="LOG_LEVEL_PATTERN"
value="%5p [${spring.application.name:-},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]"/>
<!--<property name="FILE_LOG_PATTERN"
value="${FILE_LOG_PATTERN:-%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} -&#45;&#45; [%thread] [%file:%line] %logger - %msg%n}"/>-->
<property name="FILE_LOG_PATTERN"
value="${FILE_LOG_PATTERN:-%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} --- [%logger{50}:%line] - %msg%n}"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/home/quant_group/renhang-report/logs/renhang-report.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
/home/quant_group/renhang-report/logs/renhang-report.log.%d{yyyy-MM-dd}
</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- logstash -->
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>172.30.220.6:9652</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<logger name="com.atomikos" level="warn"/>
<logger name="org.springframework" level="warn"/>
<logger name="org.mybatis" level="warn"/>
<logger name="org.apache" level="warn"/>
<logger name="ch.qos.logback" level="warn"/>
<root level="info">
<appender-ref ref="FILE"/>
<appender-ref ref="stash"/>
</root>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<springProperty name="spring.application.name" source="spring.application.name"/>
<property name="LOG_LEVEL_PATTERN"
value="%5p [${spring.application.name:-},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]"/>
<property name="FILE_LOG_PATTERN"
value="${FILE_LOG_PATTERN:-%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} --- [%thread] [%file:%line] %logger - %msg%n}"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/home/quant_group/logs/renhang-report.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
/home/quant_group/logs/renhang-report.log.%d{yyyy-MM-dd}
</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="com.atomikos" level="warn"/>
<logger name="org.springframework" level="warn"/>
<logger name="org.mybatis" level="warn"/>
<logger name="org.apache" level="warn"/>
<logger name="ch.qos.logback" level="warn"/>
<root level="info">
<appender-ref ref="FILE"/>
</root>
</configuration>
\ No newline at end of file
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMl14FDREBF9aP7dAmmRxT9t7r5oYkODVMKT59LMc4g3ww51pP9FxVBGN6HGrGIuav6ePMBKygfyvN/Pa54sJetj9dpQMpifdIjlW5WjAwn1Uug6T1r7R61f9NZqT5NaGH8f24ZnrePKurdN5dfYE8qM+XFik8ZJdY3a2V1w7XqjAgMBAAECgYByRpoaXaymryO6xjUTGyvvIfW2LlHnB/0xbmKm0XCLiU3sytDwOGyHb30pGCA6hSgODEZbsVDOl2OJ9QePrm1HCiAocXimkghPsOnCQ7ZIDKQG7DSAoJya0FVAzkygEBCX/deZqXGMvLSjFnsskZEJkr3Gj+WWMIFNE8RsHwmjwQJBAOrdaPgYsy4BJ+EyiaqKTQ3ibuOYKyrV6PbpKQlVLgO4aFFUNh8uvf3Gh51CCIZ/7tSvBAxxTJ5z5+zkMrbUmSECQQDblu1iM+mgF76GQQ7oZurtEmVMQJWX+0xnAb1DBsLgdngmMA2ff1GOAM91mDL5CR45DmBEt9NnQxXKeAksaYdDAkBeM3wctlt3wkLqkkihPGN3hDCR3MDDp5SPJCmvcpjIKTi+Fha3HxpZJT3Tl16wA7QZXjEzhGYEz9xgKY8lwdPBAkEApWj4YgwGxUB9lTX2m9vCxVghFCJmTTjQIZuuzImQTHMRKHr0GBxY+6XioItIgk17BbGtlLYAOf3PsVdgWaMYbwJAGOU8tGn2xuIZq/YQ/8jKQyzMyyFUtoGDBjEZ+h0d7joDnEMcwSzwpIB5TkYo7i5Z9Vnl2E/fApanI7RCyclVBw==
-----END PRIVATE KEY-----
\ No newline at end of file
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJdeBQ0RARfWj+3QJpkcU/be6+aGJDg1TCk+fSzHOIN8MOdaT/RcVQRjehxqxiLmr+njzASsoH8rzfz2ueLCXrY/XaUDKYn3SI5VuVowMJ9VLoOk9a+0etX/TWak+TWhh/H9uGZ63jyrq3TeXX2BPKjPlxYpPGSXWN2tldcO16owIDAQAB
-----END PUBLIC KEY-----
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="Integer" type="java.lang.Integer"/>
<typeAlias alias="Long" type="java.lang.Long"/>
<typeAlias alias="HashMap" type="java.util.HashMap"/>
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
</typeAliases>
</configuration>
\ No newline at end of file
package cn.quantgroup.report;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class RenhangReportApplicationTests {
@Test
void contextLoads() {
}
}
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