Commit b194b275 authored by liwenbin's avatar liwenbin

fix

parent fce613a7
......@@ -190,195 +190,4 @@ public class AssetServiceImpl implements IAssetService{
}
return sb.toString();
}
/**
* 如果使用资方模块,需要去命中资方
* @param assetForm
*/
public String hitFundIfUseFundModule(AssetForm assetForm, Map<String, Object> data, ExecuteType executeType) {
// 如果auditResult为true, amount或term有一个为空, 那就不管是否是测试,都不能使用资方模块了
// 同时兼容量子魔方白名单,白名单的没有期数直接返回
if ("true".equals(assetForm.getAuditResult()) && (StringUtils.isEmpty(assetForm.getAmount()) || StringUtils.isEmpty(assetForm.getTerm()))) {
return null;
}
FundModuleChannelFundConfigNew config = fundModuleChannelFundConfigNewService.findByBizChannel(assetForm.getBizChannel());
// 未找到资方渠道配置直接通知
if (config == null) {
return null;
}
QGPreconditions.checkArgument(config != null, QGExceptionType.NOT_FOUNT_CHANNEL_FUNDS_INFO, assetForm.getBizChannel());
JSONArray fundArray = new JSONArray();
// 资方去重, 可能存在多条件同一个资方
Set<String> fundSet = new HashSet<>();
List<ChannelFundConfigNew> fundConfigList = JSONArray.parseArray(config.getFunds(), ChannelFundConfigNew.class);
A : for (ChannelFundConfigNew channelFundConfig : fundConfigList) {
IRuleVO ruleVO = ruleService.getIRuleVo(channelFundConfig.getLimits());
if (ruleVO == null) { throw new QGException(QGExceptionType.CRATE_RULE_VO_ERROR); }
// 如果参数为空,直接不满足
Set<String> params = ruleVO.getParamNames();
for (String key : params) {
if (!data.containsKey(key)) {
continue A;
}
}
if (!ruleVO.valid(data)) {
continue A;
}
// 是否配了审核条件
boolean hasAuditResultLimit = params.contains("audit_result");
if (!hasAuditResultLimit) {
// 如果没配,自动过一层auditResult@true的条件
if (!ruleService.valid("audit_result==true", data)) {
continue A;
}
}
String key = channelFundConfig.getFundId() + "_" + channelFundConfig.getFundProductId() + "_" + channelFundConfig.getPriority();
if (!fundSet.contains(key)) {
// 创建并增加资方配置
JSONObject fundInfoJSON = new JSONObject();
fundInfoJSON.put("fundId", channelFundConfig.getFundId());
fundInfoJSON.put("fundProductId", channelFundConfig.getFundProductId());
fundInfoJSON.put("priority", channelFundConfig.getPriority());
fundInfoJSON.put("feeType", channelFundConfig.getFeeType());
fundInfoJSON.put("rateType", channelFundConfig.getRateType());
fundInfoJSON.put("rate", channelFundConfig.getRate());
fundArray.add(fundInfoJSON);
log.info("资方模块用户命中资方条件, uuid : {}, assetNo : {}, bizNo : {}, bizChannel : {}, fundId : {}, fundProductId : {}",
assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizNo(), assetForm.getBizChannel(), channelFundConfig.getFundId(), channelFundConfig.getFundProductId());
fundSet.add(key);
}
}
// 如果审核拒绝,也没命中任何资方, 直接返回
if ("false".equals(assetForm.getAuditResult()) && fundArray.size() == 0) {
return null;
}
QGPreconditions.checkArgument(fundArray.size() != 0, QGExceptionType.NO_FUND_INFO_BEEN_HIT, assetForm.getBizChannel(), assetForm.getAmount(), assetForm.getTerm());
// 看命中优先级是否符合要求
boolean[] bucket = new boolean[fundArray.size() + 1];
for (int i = 0, len = fundArray.size(); i < len; i++) {
int priority = fundArray.getJSONObject(i).getIntValue("priority");
if (!(priority > 0 && priority <= len)) {
throw new QGException(QGExceptionType.FUND_PRIORITY_IS_ERROR, assetForm.getBizChannel(), assetForm.getAmount(), assetForm.getTerm());
}
if (bucket[priority]) {
// 多个相同的优先级
throw new QGException(QGExceptionType.FUND_PRIORITY_IS_ERROR, assetForm.getBizChannel(), assetForm.getAmount(), assetForm.getTerm());
}
bucket[priority] = true;
}
String hitFinanceProduct = createFinancePro(assetForm, fundArray);
log.info("资方模块组成金融产品集完成, uuid : {}, assetNo : {}, bizNo : {}, bizChannel : {}, financeProduct : {}, executeType : {}", assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizNo(), assetForm.getBizChannel(), hitFinanceProduct, executeType.name());
return hitFinanceProduct;
}
/**
* 资方模块命中后结果处理
* @param assetForm
* @param hitFinanceProduct
* @return
*/
private AssetForm checkFundResult(AssetForm assetForm, String hitFinanceProduct) {
if (hitFinanceProduct == null) {
if ("false".equals(assetForm.getAuditResult())) {
// 把传过来的额度和期数处理为null
assetForm.setAmount(null);
assetForm.setTerm(null);
}
return assetForm;
}
// 金融产品集替换
String oldFinanceProduct = assetForm.getFinanceProducts();
assetForm.setFinanceProducts(hitFinanceProduct);
// 审核结果替换
String oldAuditResult = assetForm.getAuditResult();
if ("false".equals(oldAuditResult)) {
assetForm.setAuditResult("true");
}
// 保存日志
financeProductHitLogService.saveLog(assetForm, oldFinanceProduct, hitFinanceProduct, oldAuditResult, assetForm.getAuditResult(), ExecuteType.ONLINE);
log.info("资方命中后,审核最终结果, assetForm : {}", JSON.toJSONString(assetForm));
return assetForm;
}
/**
* 组建金融产品集
* @param assetForm
* @param fundArray
* @return
*/
private String createFinancePro(AssetForm assetForm, JSONArray fundArray) {
// 首先判断是否有额度期数
QGPreconditions.checkArgument(StringUtils.isNotEmpty(assetForm.getAmount()) && StringUtils.isNotEmpty(assetForm.getTerm()), QGExceptionType.HIT_FUND_BUT_AMOUNT_OR_TERM_IS_EMPTY);
JSONArray financeProductArray = new JSONArray();
JSONObject amountJSON = new JSONObject();
financeProductArray.add(amountJSON);
amountJSON.put("min", assetForm.getAmount());
amountJSON.put("max", assetForm.getAmount());
JSONArray termArray = new JSONArray();
amountJSON.put("terms", termArray);
JSONObject termJSON = new JSONObject();
termArray.add(termJSON);
try {
// 不能是string,否则资方那边会报错
termJSON.put("term", Integer.parseInt(assetForm.getTerm()));
} catch (Exception e) {
termJSON.put("term", Double.parseDouble(assetForm.getTerm()));
}
termJSON.put("fundInfo", fundArray);
return JSON.toJSONString(financeProductArray);
}
/**
* 资方配置空跑
* @param assetForm
* @param data
*/
private void doTestExecute(AssetForm assetForm, Map<String, Object> data) {
executorPool.execute(() -> {
try {
assetForm.setBizChannel("88888_" + assetForm.getBizChannel());
String hitFundPro = hitFundIfUseFundModule(assetForm, data, ExecuteType.TEST);
if (hitFundPro != null) {
// 如果命中了记录一下,并且如果审核状态为false改为true
String oldFundPro = assetForm.getFinanceProducts();
String oldAuditResult = assetForm.getAuditResult();
assetForm.setFinanceProducts(hitFundPro);
assetForm.setAuditResult("true");
financeProductHitLogService.saveLog(assetForm, oldFundPro, hitFundPro, oldAuditResult, assetForm.getAuditResult(), ExecuteType.TEST);
} else {
// 如果没命中,且审核结果未false
if ("false".equals(assetForm.getAuditResult())) {
// 把传过来的额度和期数处理为null
assetForm.setAmount(null);
assetForm.setTerm(null);
}
}
log.info("空跑审核最终结果, assetForm : {}", JSON.toJSONString(assetForm));
} catch (QGException qe) {
log.error("资方配置执行空跑出现错误 : {}, uuid : {}, bizChannel : {}, bizType : {}, bizNo : {}, assetNo : {} ",
qe.qgExceptionType.code + "->" + qe.detail, assetForm.getUuid(),
assetForm.getBizChannel(), assetForm.getBizType(),
assetForm.getBizNo(), assetForm.getAssetNo());
alarmService.dingtalkAlarm("Warn", "资方配置执行空跑出现错误", "bizChannel : " + assetForm.getBizChannel()
+ " , bizType : " + assetForm.getBizType() + " , bizNo : " + assetForm.getBizNo()
+ " , assetNo : " + assetForm.getAssetNo() + " , uuid : " + assetForm.getUuid()
+ " , 错误信息 : " + qe.qgExceptionType.code + "->" + qe.detail);
} catch (Exception ex) {
log.error("资方配置执行空跑出现异常, uuid : {}, bizChannel : {}, bizType : {}, bizNo : {}, assetNo : {} ", assetForm.getUuid(),
assetForm.getBizChannel(), assetForm.getBizType(),
assetForm.getBizNo(), assetForm.getAssetNo(), ex);
alarmService.dingtalkAlarm("Warn", "资方配置执行空跑出现异常", "bizChannel : " + assetForm.getBizChannel()
+ " , bizType : " + assetForm.getBizType() + " , bizNo : " + assetForm.getBizNo()
+ " , assetNo : " + assetForm.getAssetNo() + " , uuid : " + assetForm.getUuid()
+ " , 错误信息 : 未知错误.");
}
});
}
}
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