Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
baihang-report
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data-spider
baihang-report
Commits
404f3b01
Commit
404f3b01
authored
Nov 11, 2019
by
郝彦辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
逾期和还款查询sql优化,增加xyqb_i_repayment_plan_bak和xyqb_i_loan_a_m_history_bak临时表
parent
97e512b4
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
424 additions
and
3 deletions
+424
-3
XyqbHistoryDataSourceConfig.java
...onfig/datasource/history/XyqbHistoryDataSourceConfig.java
+87
-0
XyqbHistoryDataSourcePreperties.java
...g/datasource/history/XyqbHistoryDataSourcePreperties.java
+29
-0
LoanApplicationManifestHistoryTask.java
...tgroup/report/job/LoanApplicationManifestHistoryTask.java
+146
-0
Constant.java
.../quantgroup/report/service/baihang/constant/Constant.java
+3
-2
RepaymentLoanInfoMapper.xml
...ntgroup/report/mapper/baihang/RepaymentLoanInfoMapper.xml
+159
-1
No files found.
src/main/java/cn/quantgroup/report/config/datasource/history/XyqbHistoryDataSourceConfig.java
0 → 100644
View file @
404f3b01
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.baihang"
;
@Value
(
"${baihang.mapper-locations}"
)
private
String
mapperLocations
;
@Value
(
"${baihang.type-aliases-package}"
)
private
String
typeAliasesPackage
;
@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
);
}
}
src/main/java/cn/quantgroup/report/config/datasource/history/XyqbHistoryDataSourcePreperties.java
0 → 100644
View file @
404f3b01
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
;
//@Value("${data.source.baihang.username}")
private
String
username
=
"xyqb_history_w"
;
//@Value("${data.source.baihang.password}")
private
String
password
=
"KDb18asPu6iEz5lg"
;
}
src/main/java/cn/quantgroup/report/job/LoanApplicationManifestHistoryTask.java
0 → 100644
View file @
404f3b01
package
cn
.
quantgroup
.
report
.
job
;
import
cn.quantgroup.report.service.baihang.constant.Constant
;
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
LoanApplicationManifestHistoryTask
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
LoanApplicationManifestHistoryTask
.
class
);
@Autowired
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
@Autowired
private
JdbcTemplate
xyqbHistoryJdbcTemplate
;
private
static
AtomicBoolean
SYN_Stop
=
new
AtomicBoolean
(
false
);
private
static
String
SQL_COMMONE_TEMPLATE
=
"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##'; "
;
private
static
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##'; "
;
@Async
/*@Scheduled(cron = "0 06 16 * * ?")*/
public
void
startHistoryDateCopy
(){
if
(
increment
()){
redisTemplate
.
expire
(
Constant
.
XYQB_HISTORY_DAI_REPORT_LOCK_KEY
,
10
,
TimeUnit
.
SECONDS
);
//将xyqb_i_loan_application_manifest_history表的数据,同步到xyqb_i_loan_a_m_history_bak
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
());
//table_xyqb_i_loan_a_m_history_bak();
table_xyqb_i_repayment_plan_bak
();
log
.
info
(
"量化派-同步表xyqb_i_loan_application_manifest_history数据结束, endTime: {}, 耗时: {} "
,
LocalDateTime
.
now
(),
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
}
}
public
Boolean
increment
(){
Long
increment
=
redisTemplate
.
opsForValue
().
increment
(
Constant
.
XYQB_HISTORY_DAI_REPORT_LOCK_KEY
,
1
);
return
increment
<=
1
;
}
public
void
table_xyqb_i_loan_a_m_history_bak
(){
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
=
SQL_COMMONE_TEMPLATE
.
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
),
upCount
);
}
catch
(
Exception
e
){
log
.
error
(
"同步xyqb_i_loan_application_manifest_history数据异常, startTime: {} , endTime: {} , counter: {} "
,
starTime
,
endTime
,
counter
,
e
);
}
}
}
public
void
table_xyqb_i_repayment_plan_bak
(){
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
=
SQL_COMMONE_TEMPLATE_PLAN
.
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
),
upCount
);
}
catch
(
Exception
e
){
log
.
error
(
"同步xyqb_i_repayment_plan数据异常, startTime: {} , endTime: {} , counter: {} "
,
starTime
,
endTime
,
counter
,
e
);
}
}
}
}
src/main/java/cn/quantgroup/report/service/baihang/constant/Constant.java
View file @
404f3b01
...
...
@@ -2,9 +2,10 @@ package cn.quantgroup.report.service.baihang.constant;
public
class
Constant
{
public
static
final
String
QG_LOAN_INFO_REPORT_LOCK_KEY
=
"QG_LOAN_INFO_REPORT_LOCK_KEY_UHBVGY"
;
/** 量化派助贷模式-(贷款申请/放款/还款(逾期)三类实时数据)-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"
;
}
src/main/resources/cn/quantgroup/report/mapper/baihang/RepaymentLoanInfoMapper.xml
View file @
404f3b01
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment