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

助贷资金路由模块开发

parent 8954fa72
......@@ -9,5 +9,16 @@ public class RedisKeyConstants {
/**
* 助贷资金池所有key的hmset key
*/
public final static String AID_LOAN_POOLKEYS_HMSET_KEY="AID.LOAN.POOLKEYS.HMSET.KEY.8UJ2WS";
public final static String AID_LOAN_POOLKEYS_HMSET_KEY="AID.LOAN.POOLKEYS.HMSET.KEY.8UJ2WS_";
/**
* 助贷资金次数限制缓存key
*/
public final static String AID_LOAN_COUNT_LIMIT_KEY="AID.LOAN.COUNT.LIMIT.KEY.23RFRY45_";
/**
* 助贷资金总金额限制缓存key
*/
public final static String AID_LOAN_ALL_AMOUNT_LIMIT_KEY="AID.LOAN.ALL.AMOUNT.LIMIT.KEY.9QDBFD_";
}
......@@ -32,8 +32,8 @@ public class RedisFlushController {
*/
@RequestMapping("/aid_loan_fund_pool_flush")
public GlobalResponse aidLoanFundPoolFlush(String key){
if(authKey.equals(key)){}
redisService.del(RedisKeyConstants.AID_LOAN_POOLKEYS_HMSET_KEY);
if(authKey.equals(key))
redisService.del(RedisKeyConstants.AID_LOAN_POOLKEYS_HMSET_KEY);
return GlobalResponse.success();
}
......
......@@ -3,9 +3,24 @@ package com.quantgroup.asset.distribution.service.funding.impl;
import com.quantgroup.asset.distribution.model.form.AssetForm;
import com.quantgroup.asset.distribution.model.response.GlobalResponse;
import com.quantgroup.asset.distribution.service.funding.IAidFundRouteService;
import com.quantgroup.asset.distribution.service.funding.IAidLoanFundConfigService;
import com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig;
import com.quantgroup.asset.distribution.service.redis.IRedisService;
import com.quantgroup.asset.distribution.util.DateUtil;
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.math.BigDecimal;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.quantgroup.asset.distribution.constant.RedisKeyConstants.AID_LOAN_ALL_AMOUNT_LIMIT_KEY;
import static com.quantgroup.asset.distribution.constant.RedisKeyConstants.AID_LOAN_COUNT_LIMIT_KEY;
/**
* Created by renfeng on 2019/7/19.
*/
......@@ -13,6 +28,13 @@ import org.springframework.stereotype.Service;
@Slf4j
public class AidFundRouteServiceImpl implements IAidFundRouteService {
@Autowired
private IAidLoanFundConfigService iAidLoanFundConfigService;
@Autowired
private IRedisService<String> redisService;
/**
* 助贷资金路由
*
......@@ -22,13 +44,31 @@ public class AidFundRouteServiceImpl implements IAidFundRouteService {
@Override
public GlobalResponse aidFundRoute(AssetForm assetForm) {
//
//第一步 查询所有助贷资金
List<AidLoanFundConfig> aidLoanFundConfigList = iAidLoanFundConfigService.findAll();
return GlobalResponse.success();
//第二步 开关筛选
if(CollectionUtils.isNotEmpty(aidLoanFundConfigList))
aidLoanFundConfigList = aidLoanFundConfigList.parallelStream().filter(aidLoanFundConfig->aidLoanFundConfig.getFundSwitchState()==1).collect(Collectors.toList());
//第三步 限制次数筛选
if(CollectionUtils.isNotEmpty(aidLoanFundConfigList)){
// AID_LOAN_COUNT_LIMIT_KEY + DateUtil.getDay() //TODO 放redis
aidLoanFundConfigList = aidLoanFundConfigList.parallelStream()
.filter(aidLoanFundConfig->aidLoanFundConfig.getFundCountLimit() >=redisService.setIncr(AID_LOAN_COUNT_LIMIT_KEY + DateUtil.getDay(), 0, 3, TimeUnit.DAYS))
.collect(Collectors.toList());
}
//第四步 限制总额度筛选
if(CollectionUtils.isNotEmpty(aidLoanFundConfigList)){
// 获取已放款总金额 AID_LOAN_ALL_AMOUNT_LIMIT_KEY + DateUtil.getDay() //TODO 放redis
String allAmount = redisService.getString(AID_LOAN_ALL_AMOUNT_LIMIT_KEY + DateUtil.getDay());
aidLoanFundConfigList = aidLoanFundConfigList.parallelStream()
.filter(aidLoanFundConfig->new BigDecimal(aidLoanFundConfig.getFundAllAmountLimit()).compareTo(new BigDecimal(StringUtils.isEmpty(allAmount)?"0":allAmount))>0)
.collect(Collectors.toList());
}
//第五步 开始路由
if(CollectionUtils.isNotEmpty(aidLoanFundConfigList)){
//TODO 未接到助贷资金 暂时不能进行开发
}
return GlobalResponse.error("未匹配到助贷资金");
}
}
package com.quantgroup.asset.distribution.service.funding.impl;
import com.google.common.collect.Lists;
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;
......@@ -11,11 +12,13 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
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;
import static java.util.Collections.addAll;
/**
* Created by renfeng on 2019/7/22.
......@@ -49,9 +52,12 @@ public class AidLoanFundConfigServiceImpl implements IAidLoanFundConfigService {
redisService.hmset(AID_LOAN_POOLKEYS_HMSET_KEY,key,key,7, TimeUnit.DAYS);
}
}
return AID_LOAN_FUND_CONFIG_POOL.getAidLoanFundConfigList();
//一定要拷贝
return new ArrayList<>(AID_LOAN_FUND_CONFIG_POOL.getAidLoanFundConfigList()!=null?AID_LOAN_FUND_CONFIG_POOL.getAidLoanFundConfigList():new ArrayList<>());
}
/**
* 根据id查询助贷资金
*
......
package com.quantgroup.asset.distribution.util;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by renfeng on 2019/7/22.
*/
public class DateUtil {
/**
* 获取当前日期(天)
* @return
*/
public static String getDay(){
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(new Date());
}
}
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