Commit 8954fa72 authored by data-爬虫-任锋's avatar data-爬虫-任锋

助贷资金配置加载模块开发完成

parent 8adf88c5
package com.quantgroup.asset.distribution.constant;
import com.google.common.collect.Lists;
import com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig;
import lombok.Data;
import java.util.List;
......@@ -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;
}
}
......@@ -4,4 +4,10 @@ package com.quantgroup.asset.distribution.constant;
* Created by renfeng on 2019/7/22.
*/
public class RedisKeyConstants {
/**
* 助贷资金池所有key的hmset key
*/
public final static String AID_LOAN_POOLKEYS_HMSET_KEY="AID.LOAN.POOLKEYS.HMSET.KEY.8UJ2WS";
}
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();
}
}
......@@ -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.jpa.entity.AidLoanFundConfig;
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 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.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.
......@@ -21,6 +26,8 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
@Autowired
private IAidLoanFundConfigRepository iAidLoanFundConfigRepository;
@Autowired
private IRedisService<String> redisService;
/**
* 查询全部可用助贷资金
......@@ -29,13 +36,20 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
*/
@Override
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();
if (CollectionUtils.isEmpty(aidLoanFundConfigs))
AID_LOAN_FUND_CONFIG_LIST.addAll(aidLoanFundConfigs);
if (CollectionUtils.isEmpty(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();
}
/**
......
/**
*
*/
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);
}
......@@ -18,6 +18,14 @@ public class UUIDUtil {
public static String getAssetNo() {
return ASSET_STR + UUID.randomUUID().toString().replaceAll("-", "");
}
/**
* 获取uuid
* @return
*/
public static String getUuid(){
return UUID.randomUUID().toString().replaceAll("-", "");
}
public static void main(String[] args) {
System.out.println(getAssetNo());
......
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