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

助贷资金路由模块

parent 0b913ddc
......@@ -30,4 +30,9 @@ public class RedisKeyConstants {
* 你我贷token
*/
public static final String NI_WO_DAI_TOKEN_KEY = "DATA_EXPORT_PLATFORM:NIWODAI:TOKEN:YHABEA";
/**
* 完成路由的资方缓存KEY
*/
public static final String FINISH_ROUTE_AID_FUND_KEY="FINISH.ROUTE.AID.FUND.KEY.IJN9_";
}
......@@ -148,7 +148,7 @@ public class AssetDistributeServiceImpl implements IAssetDistributeService{
return StatusConstants.FAIL;
case DistributeConstants.RuleType.AID_FUND_ROUTE: {
GlobalResponse response = aidFundRouteService.aidFundRoute(assetForm, asset.getUserLoanType(), data);
int status = response.getCode() == 0 ? StatusConstants.SUCCESS : StatusConstants.FAIL;
int status = response.getCode() == 0 ? StatusConstants.WAIT : StatusConstants.FAIL;
//助贷资金路由 分配失败没有 mq消息 成功有
if(status==0){
// 助贷资金路由目前不从mq里接受终态
......@@ -156,8 +156,7 @@ public class AssetDistributeServiceImpl implements IAssetDistributeService{
assetDistributeRecordService.updateAssetDistribute(assetDistributeRecord);
}
return status;
}
case DistributeConstants.RuleType.DIVERSION:
}case DistributeConstants.RuleType.DIVERSION:
notifyService.notifyFundServer(assetForm, data);
return StatusConstants.WAIT;
default:
......
......@@ -10,6 +10,7 @@ import com.quantgroup.asset.distribution.service.httpclient.IHttpService;
import com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundConfig;
import com.quantgroup.asset.distribution.service.jpa.entity.AidLoanFundRouteRecord;
import com.quantgroup.asset.distribution.service.redis.IRedisService;
import com.quantgroup.asset.distribution.service.rule.IRuleService;
import com.quantgroup.asset.distribution.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
......@@ -27,6 +28,7 @@ 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;
import static com.quantgroup.asset.distribution.constant.RedisKeyConstants.FINISH_ROUTE_AID_FUND_KEY;
/**
* Created by renfeng on 2019/7/19.
......@@ -49,6 +51,9 @@ public class AidFundRouteServiceImpl implements IAidFundRouteService {
@Autowired
private IHttpService iHttpService;
@Autowired
private IRuleService ruleService;
/**
* 助贷资金路由
*
......@@ -86,39 +91,43 @@ public class AidFundRouteServiceImpl implements IAidFundRouteService {
log.info("助贷资金优先级筛选开始, uuid : {} , bizNo : {} ,助贷资金池 : {} ",assetForm.getUuid(),assetForm.getBizNo(),JSON.toJSONString(aidLoanFundConfigList));
//按优先级排序
TreeSet<AidLoanFundConfig> aidLoanFundConfigSet = new TreeSet<>(Comparator.comparing(AidLoanFundConfig::getFundPriority));
TreeSet<AidLoanFundConfig> aidLoanFundConfigSet = new TreeSet<AidLoanFundConfig>(Comparator.comparing(AidLoanFundConfig::getFundPriority));
aidLoanFundConfigSet.addAll(aidLoanFundConfigList);
AidLoanFundConfig first = aidLoanFundConfigSet.first();
log.info("助贷资金筛选完成, uuid : {} , bizNo : {} ,助贷资金 : {} ",assetForm.getUuid(),assetForm.getBizNo(),JSON.toJSONString(first));
for(AidLoanFundConfig aidLoanFundConfig : aidLoanFundConfigSet){
//此助贷资方如果已经被这笔订单路由过 就跳过
if(String.valueOf(aidLoanFundConfig.getFundId())
.equals(redisServiceAssetForm.getString(FINISH_ROUTE_AID_FUND_KEY + assetForm.getBizNo())))
continue;
if(ruleService.valid(aidLoanFundConfig.getFundRuleEl(), data)){
//助贷资金准入接口调用
boolean accessResult = false;//todo 调用真实的准入接口
//保存主贷资金路由记录
AidLoanFundRouteRecord aidLoanFundRouteRecord = new AidLoanFundRouteRecord();
aidLoanFundRouteRecord.setAidFundRouteStatus(1);//1-未完成 2-成功 3-失败
aidLoanFundRouteRecord.setAidFundRouteStatus(accessResult?1:2);//1-准入成功 2-准入失败 3-进件成功 4-进件失败
aidLoanFundRouteRecord.setAssetNo(assetForm.getAssetNo());
aidLoanFundRouteRecord.setUuid(assetForm.getUuid());
aidLoanFundRouteRecord.setBizChannel(assetForm.getBizChannel());
aidLoanFundRouteRecord.setBizNo(assetForm.getBizNo());
aidLoanFundRouteRecord.setFinanceProductType(Integer.parseInt(assetForm.getBizType()));
aidLoanFundRouteRecord.setUserLoanType(userLoanType);
aidLoanFundRouteRecord.setFundNo(first.getFundNo());
aidLoanFundRouteRecord.setFundId(first.getFundId());
aidLoanFundRouteRecord.setFundNo(aidLoanFundConfig.getFundNo());
aidLoanFundRouteRecord.setFundId(aidLoanFundConfig.getFundId());
aidLoanFundRouteRecord.setEnable(true);
iAidFundRouteRecordService.saveAidLoanFundRouteRecord(aidLoanFundRouteRecord);
//通知资方
Map<String,String> response = iHttpService.postHasResponse(assetForm.getCallbackUrl(), assetForm.transToNotifyMap(data));
log.info("主贷资金路由-准入完成, bizChannel : {} , uuid : {} , bizNo : {} , fundId : {} , 准入结果: {} ",assetForm.getBizChannel(),assetForm.getUuid(),assetForm.getBizNo(),aidLoanFundRouteRecord.getFundId(),accessResult);
log.info("助贷资金路由-通知资金系统结束,response :{}, uuid : {} , bizNo : {} , callbackUrl:{},params:{}", JSON.toJSONString(response),assetForm.getUuid(),assetForm.getBizNo(),assetForm.getCallbackUrl(), JSON.toJSONString(assetForm.transToNotifyMap(data)));
if(response==null || response.size()==0 || !"200".equals(response.get("statusCode")) || "error".equals(response.get("response"))) {
assetForm.setRepeatCount(assetForm.getRepeatCount() + 1);
redisServiceAssetForm.rightPushEx("AID.LOAN.FUND.ROUTE.NOTIFY.83IUE",assetForm,1, TimeUnit.DAYS);
log.info("助贷资金路由-通知资金系统失败,response :{}, uuid : {} , bizNo : {} , callbackUrl:{},params:{}", JSON.toJSONString(response),assetForm.getUuid(),assetForm.getBizNo(),assetForm.getCallbackUrl(), JSON.toJSONString(assetForm));
}
if(accessResult){
//todo 调用助贷资方进件接口 异步
log.info("主贷资金路由-进件完成, bizChannel : {} , uuid : {} , bizNo : {} , fundId : {} ",assetForm.getBizChannel(),assetForm.getUuid(),assetForm.getBizNo(),aidLoanFundRouteRecord.getFundId());
return GlobalResponse.success();
}
}
}
}
return GlobalResponse.error("未匹配到助贷资金");
}
......
......@@ -48,6 +48,9 @@ public class AidLoanFundConfig implements Serializable{
@Column(name="fund_all_amount_limit")
private String fundAllAmountLimit;
@Column(name="fund_rule_el")
private String fundRuleEl;
@Column(name = "enable")
private Boolean enable;
......
package com.quantgroup.asset.distribution.service.jpa.entity;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* Created by renfeng on 2020/3/24.
*/
@Entity
@Table(name="customer_type_rule_config")
@Data
public class CustomerTypeRuleConfig implements Serializable{
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name="customer_type_rule_no")
private String customerTypeRuleNo;
@Column(name="customer_type_rule_desc")
private String customerTypeRuleDesc;
@Column(name="customer_type")
private Integer customerType;
@Column(name="customer_type_rule_el")
private String customerTypeRuleEl;
@Column(name = "enable")
private Boolean enable;
@Column(name="created_by")
private String createdBy;
@Column(name="updated_by")
private String updatedBy;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
@PrePersist
public void prePersist() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
createdAt = timestamp;
updatedAt = timestamp;
}
@PreUpdate
public void preUpdate() {
updatedAt = new Timestamp(System.currentTimeMillis());
}
}
package com.quantgroup.asset.distribution.service.jpa.repository;
import com.quantgroup.asset.distribution.service.jpa.entity.CustomerTypeRuleConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* Created by renfeng on 2019/7/17.
*/
public interface ICustomerTypeRuleConfigRepository extends JpaRepository<CustomerTypeRuleConfig, Long>{
List<CustomerTypeRuleConfig> findByEnableTrue();
}
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