Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asset-distribution
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data-spider
asset-distribution
Commits
8954fa72
Commit
8954fa72
authored
Jul 22, 2019
by
data-爬虫-任锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
助贷资金配置加载模块开发完成
parent
8adf88c5
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
625 additions
and
8 deletions
+625
-8
FundingConstants.java
...ntgroup/asset/distribution/constant/FundingConstants.java
+18
-2
RedisKeyConstants.java
...tgroup/asset/distribution/constant/RedisKeyConstants.java
+6
-0
RedisFlushController.java
...p/asset/distribution/controller/RedisFlushController.java
+49
-0
AidLoanFundConfigServiceImpl.java
...on/service/funding/impl/AidLoanFundConfigServiceImpl.java
+20
-6
IRedisService.java
...group/asset/distribution/service/redis/IRedisService.java
+178
-0
RedisServiceImpl.java
...set/distribution/service/redis/impl/RedisServiceImpl.java
+346
-0
UUIDUtil.java
...java/com/quantgroup/asset/distribution/util/UUIDUtil.java
+8
-0
No files found.
src/main/java/com/quantgroup/asset/distribution/constant/FundingConstants.java
View file @
8954fa72
package
com
.
quantgroup
.
asset
.
distribution
.
constant
;
package
com
.
quantgroup
.
asset
.
distribution
.
constant
;
import
com.google.common.collect.Lists
;
import
com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig
;
import
com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig
;
import
lombok.Data
;
import
java.util.List
;
import
java.util.List
;
...
@@ -13,5 +13,21 @@ public class FundingConstants {
...
@@ -13,5 +13,21 @@ public class FundingConstants {
/**
/**
* 助贷资金池
* 助贷资金池
*/
*/
public
final
static
List
<
AidLoanFundConfig
>
AID_LOAN_FUND_CONFIG_LIST
=
Lists
.
newArrayList
();
public
final
static
AidLoanFundConfigPool
AID_LOAN_FUND_CONFIG_POOL
=
new
AidLoanFundConfigPool
();
@Data
public
static
class
AidLoanFundConfigPool
{
private
String
poolKey
;
private
List
<
AidLoanFundConfig
>
aidLoanFundConfigList
;
//是否可用 默认下为false
private
boolean
enable
;
}
}
}
src/main/java/com/quantgroup/asset/distribution/constant/RedisKeyConstants.java
View file @
8954fa72
...
@@ -4,4 +4,10 @@ package com.quantgroup.asset.distribution.constant;
...
@@ -4,4 +4,10 @@ package com.quantgroup.asset.distribution.constant;
* Created by renfeng on 2019/7/22.
* Created by renfeng on 2019/7/22.
*/
*/
public
class
RedisKeyConstants
{
public
class
RedisKeyConstants
{
/**
* 助贷资金池所有key的hmset key
*/
public
final
static
String
AID_LOAN_POOLKEYS_HMSET_KEY
=
"AID.LOAN.POOLKEYS.HMSET.KEY.8UJ2WS"
;
}
}
src/main/java/com/quantgroup/asset/distribution/controller/RedisFlushController.java
0 → 100644
View file @
8954fa72
package
com
.
quantgroup
.
asset
.
distribution
.
controller
;
import
com.quantgroup.asset.distribution.constant.RedisKeyConstants
;
import
com.quantgroup.asset.distribution.model.response.GlobalResponse
;
import
com.quantgroup.asset.distribution.service.redis.IRedisService
;
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
;
/**
* Created by renfeng on 2019/7/22.
*/
@Slf4j
@RestController
@RequestMapping
(
"/ex"
)
public
class
RedisFlushController
{
private
static
String
authKey
=
"3ruhhdf9924hrodnfjkasdhf8209"
;
@Autowired
private
IRedisService
<
String
>
redisService
;
/**
* 助贷资金池刷新
* @param key
* @return
*/
@RequestMapping
(
"/aid_loan_fund_pool_flush"
)
public
GlobalResponse
aidLoanFundPoolFlush
(
String
key
){
if
(
authKey
.
equals
(
key
)){}
redisService
.
del
(
RedisKeyConstants
.
AID_LOAN_POOLKEYS_HMSET_KEY
);
return
GlobalResponse
.
success
();
}
}
src/main/java/com/quantgroup/asset/distribution/service/funding/impl/AidLoanFundConfigServiceImpl.java
View file @
8954fa72
...
@@ -3,14 +3,19 @@ package com.quantgroup.asset.distribution.service.funding.impl;
...
@@ -3,14 +3,19 @@ package com.quantgroup.asset.distribution.service.funding.impl;
import
com.quantgroup.asset.distribution.service.funding.IAidLoanFundConfigService
;
import
com.quantgroup.asset.distribution.service.funding.IAidLoanFundConfigService
;
import
com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig
;
import
com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig
;
import
com.quantgroup.asset.distribution.service.jpa.repository.IAidLoanFundConfigRepository
;
import
com.quantgroup.asset.distribution.service.jpa.repository.IAidLoanFundConfigRepository
;
import
com.quantgroup.asset.distribution.service.redis.IRedisService
;
import
com.quantgroup.asset.distribution.util.UUIDUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
quantgroup
.
asset
.
distribution
.
constant
.
FundingConstants
.
AID_LOAN_FUND_CONFIG_LIST
;
import
static
com
.
quantgroup
.
asset
.
distribution
.
constant
.
FundingConstants
.
AID_LOAN_FUND_CONFIG_POOL
;
import
static
com
.
quantgroup
.
asset
.
distribution
.
constant
.
RedisKeyConstants
.
AID_LOAN_POOLKEYS_HMSET_KEY
;
/**
/**
* Created by renfeng on 2019/7/22.
* Created by renfeng on 2019/7/22.
...
@@ -21,6 +26,8 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
...
@@ -21,6 +26,8 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
@Autowired
@Autowired
private
IAidLoanFundConfigRepository
iAidLoanFundConfigRepository
;
private
IAidLoanFundConfigRepository
iAidLoanFundConfigRepository
;
@Autowired
private
IRedisService
<
String
>
redisService
;
/**
/**
* 查询全部可用助贷资金
* 查询全部可用助贷资金
...
@@ -29,13 +36,20 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
...
@@ -29,13 +36,20 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
*/
*/
@Override
@Override
public
List
<
AidLoanFundConfig
>
findAll
()
{
public
List
<
AidLoanFundConfig
>
findAll
()
{
if
(
AID_LOAN_FUND_CONFIG_LIST
.
size
()<
1
)
{
//助贷资金池key,存在说明有效 不存在说明失效,需要更新内存
String
poolKey
=
AID_LOAN_FUND_CONFIG_POOL
.
isEnable
()?
redisService
.
hmget
(
AID_LOAN_POOLKEYS_HMSET_KEY
,
AID_LOAN_FUND_CONFIG_POOL
.
getPoolKey
()):
null
;
if
(
StringUtils
.
isEmpty
(
poolKey
))
{
List
<
AidLoanFundConfig
>
aidLoanFundConfigs
=
iAidLoanFundConfigRepository
.
findByEnableTrue
();
List
<
AidLoanFundConfig
>
aidLoanFundConfigs
=
iAidLoanFundConfigRepository
.
findByEnableTrue
();
if
(
CollectionUtils
.
isEmpty
(
aidLoanFundConfigs
))
if
(
CollectionUtils
.
isEmpty
(
aidLoanFundConfigs
))
{
AID_LOAN_FUND_CONFIG_LIST
.
addAll
(
aidLoanFundConfigs
);
String
key
=
UUIDUtil
.
getUuid
();
AID_LOAN_FUND_CONFIG_POOL
.
setPoolKey
(
key
);
AID_LOAN_FUND_CONFIG_POOL
.
setAidLoanFundConfigList
(
aidLoanFundConfigs
);
AID_LOAN_FUND_CONFIG_POOL
.
setEnable
(
true
);
//每个服务器节点上的助贷资金池poolKey都不一样,放进redis作为刷新标识
redisService
.
hmset
(
AID_LOAN_POOLKEYS_HMSET_KEY
,
key
,
key
,
7
,
TimeUnit
.
DAYS
);
}
}
}
return
AID_LOAN_FUND_CONFIG_
LIST
;
return
AID_LOAN_FUND_CONFIG_
POOL
.
getAidLoanFundConfigList
()
;
}
}
/**
/**
...
...
src/main/java/com/quantgroup/asset/distribution/service/redis/IRedisService.java
0 → 100644
View file @
8954fa72
/**
*
*/
package
com
.
quantgroup
.
asset
.
distribution
.
service
.
redis
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
/**
*
* @author renfeng
* @date: 2017年3月30日 下午7:31:58
* @version v1.0
* @param <T>
*/
public
interface
IRedisService
<
T
>
{
/**
* 保存字符串
* @param key
* @param value
*/
public
void
setString
(
String
key
,
String
value
);
/**
* 保存字符串 含过期时间
* @param key
* @param value
* @param time
* @param timeUnit
*/
public
void
setStringEx
(
String
key
,
String
value
,
long
time
,
TimeUnit
timeUnit
);
/**
* 获取字符串
* @param key
* @return
*/
public
String
getString
(
String
key
);
/**
* 保存实体类
* @param key
* @param entity
*/
public
void
setEntity
(
String
key
,
T
entity
);
public
void
setEntityEx
(
String
key
,
T
entity
,
long
time
,
TimeUnit
timeUnit
);
/**
* 查询实体类
* @param key
* @return
*/
public
T
getEntity
(
String
key
);
/**
* 保存list
* @param key
* @param list
*/
public
void
setList
(
String
key
,
List
<
T
>
list
);
/**
*
* @param key
* @param list
* @param time
* @param timeUnit
*/
public
void
setListEx
(
String
key
,
List
<
T
>
list
,
long
time
,
TimeUnit
timeUnit
);
/**
* 查询list
* @param key
* @return
*/
public
List
<
T
>
getList
(
String
key
);
/**
* 尾部追加
* @param key
* @param value
* @param time
* @param timeUnit
*/
public
void
rightPushEx
(
String
key
,
T
value
,
long
time
,
TimeUnit
timeUnit
);
/**
* 头部移除
* @param key
*/
public
T
leftPop
(
String
key
);
/**
* 删除元素
* @param key
* @param value
* @param count
*/
public
void
listRemove
(
String
key
,
T
value
,
int
count
);
/**
* 保存map含过期时间
* @param key
* @param map
* @param time
* @param timeUnit
*/
public
void
setMapEx
(
String
key
,
Map
<
String
,
T
>
map
,
long
time
,
TimeUnit
timeUnit
);
/**
* 获取map
* @param key
* @return
*/
public
Map
<
Object
,
Object
>
getMapEx
(
String
key
);
/**
* hmset
* @param key
* @param hashKey
* @param value
*/
public
void
hmset
(
String
key
,
String
hashKey
,
T
value
,
long
time
,
TimeUnit
timeUnit
);
/**
* hmget
* @param key
* @param hashKey
* @return
*/
public
T
hmget
(
String
key
,
String
hashKey
);
/**
* 获取map长度
* @param key
* @return
*/
public
Long
hmgetSize
(
String
key
);
/**
* 原子性操作
* @param key
* @param time
* @param timeUnit
* @return
*/
public
boolean
setIfAbsent
(
String
key
,
String
value
,
long
time
,
TimeUnit
timeUnit
);
/**
* 原子性自增
* @param key
* @param value
* @return
*/
public
long
setIncr
(
String
key
,
long
value
,
long
time
,
TimeUnit
timeUnit
);
/**
* 删除
* @param key
*/
public
void
del
(
String
key
);
/**
* list size
* @param key
* @return
*/
public
long
listSize
(
String
key
);
/**
*
* @param key
* @param expireTime
* @param retryTimes 重试获取锁次数
* @param sleepMillis 休眠时间
* @return
*/
public
boolean
lock
(
String
key
,
Long
expireTime
,
Integer
retryTimes
,
Long
sleepMillis
);
/**
* 默认尝试1次
* @param key
* @param expireTime
* @return
*/
public
boolean
lock
(
String
key
,
Long
expireTime
);
/**
* 释放锁
* @param key
* @return
*/
public
boolean
releaseLock
(
String
key
);
}
src/main/java/com/quantgroup/asset/distribution/service/redis/impl/RedisServiceImpl.java
0 → 100644
View file @
8954fa72
This diff is collapsed.
Click to expand it.
src/main/java/com/quantgroup/asset/distribution/util/UUIDUtil.java
View file @
8954fa72
...
@@ -19,6 +19,14 @@ public class UUIDUtil {
...
@@ -19,6 +19,14 @@ public class UUIDUtil {
return
ASSET_STR
+
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
return
ASSET_STR
+
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
}
}
/**
* 获取uuid
* @return
*/
public
static
String
getUuid
(){
return
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
getAssetNo
());
System
.
out
.
println
(
getAssetNo
());
}
}
...
...
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