238 lines
8.7 KiB
JavaScript
238 lines
8.7 KiB
JavaScript
|
|
/**
|
|||
|
|
* 数据解析工具函数
|
|||
|
|
* 用于解析借贷申请验证A的返回数据
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取字段值,处理空值
|
|||
|
|
*/
|
|||
|
|
export function getValue(value) {
|
|||
|
|
if (
|
|||
|
|
value === undefined ||
|
|||
|
|
value === null ||
|
|||
|
|
value === "" ||
|
|||
|
|
value === "空"
|
|||
|
|
) {
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
// 如果是字符串数字,转换为数字
|
|||
|
|
if (typeof value === "string" && /^\d+(\.\d+)?$/.test(value)) {
|
|||
|
|
return parseFloat(value);
|
|||
|
|
}
|
|||
|
|
return value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 从原始数据中提取 variableValue
|
|||
|
|
*/
|
|||
|
|
export function extractVariableValue(data) {
|
|||
|
|
try {
|
|||
|
|
return (
|
|||
|
|
data?.risk_screen_v2?.variables?.find(
|
|||
|
|
(v) => v.variableName === "bairong_applyloan_extend"
|
|||
|
|
)?.variableValue || {}
|
|||
|
|
);
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error("提取数据失败:", error);
|
|||
|
|
return {};
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 时间段映射
|
|||
|
|
*/
|
|||
|
|
export const PERIOD_MAP = {
|
|||
|
|
d7: { label: "7天", prefix: "als_d7" },
|
|||
|
|
d15: { label: "15天", prefix: "als_d15" },
|
|||
|
|
m1: { label: "1个月", prefix: "als_m1" },
|
|||
|
|
m3: { label: "3个月", prefix: "als_m3" },
|
|||
|
|
m6: { label: "6个月", prefix: "als_m6" },
|
|||
|
|
m12: { label: "12个月", prefix: "als_m12" },
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取申请次数(按时间段)
|
|||
|
|
*/
|
|||
|
|
export function getApplicationCounts(variableValue, period) {
|
|||
|
|
const { prefix } = PERIOD_MAP[period];
|
|||
|
|
|
|||
|
|
// 计算总申请次数(所有类型的申请次数之和)
|
|||
|
|
const types = [
|
|||
|
|
"id_pdl_allnum", // 线上小额现金贷
|
|||
|
|
"id_caon_allnum", // 线上现金分期
|
|||
|
|
"id_rel_allnum", // 信用卡(类信用卡)
|
|||
|
|
"id_caoff_allnum", // 线下现金分期
|
|||
|
|
"id_cooff_allnum", // 线下消费分期
|
|||
|
|
"id_af_allnum", // 汽车金融
|
|||
|
|
"id_coon_allnum", // 线上消费分期
|
|||
|
|
"id_oth_allnum", // 其他
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
let total = 0;
|
|||
|
|
types.forEach((type) => {
|
|||
|
|
const value = getValue(variableValue[`${prefix}_${type}`]);
|
|||
|
|
total += value;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 银行机构申请次数
|
|||
|
|
const bankTotal = getValue(variableValue[`${prefix}_id_bank_allnum`]) || 0;
|
|||
|
|
|
|||
|
|
// 非银机构申请次数
|
|||
|
|
const nbankTotal =
|
|||
|
|
getValue(variableValue[`${prefix}_id_nbank_allnum`]) || 0;
|
|||
|
|
|
|||
|
|
// 如果计算出的total为0,则使用银行+非银的总和
|
|||
|
|
const finalTotal = total > 0 ? total : bankTotal + nbankTotal;
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
total: finalTotal,
|
|||
|
|
bank: bankTotal,
|
|||
|
|
nbank: nbankTotal,
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取特殊时段(周末/夜间)申请次数(按时间段,银行+非银)
|
|||
|
|
*/
|
|||
|
|
export function getSpecialPeriodCounts(variableValue, period) {
|
|||
|
|
const { prefix } = PERIOD_MAP[period];
|
|||
|
|
|
|||
|
|
const weekendBank =
|
|||
|
|
getValue(variableValue[`${prefix}_id_bank_week_allnum`]) || 0;
|
|||
|
|
const weekendNbank =
|
|||
|
|
getValue(variableValue[`${prefix}_id_nbank_week_allnum`]) || 0;
|
|||
|
|
const nightBank =
|
|||
|
|
getValue(variableValue[`${prefix}_id_bank_night_allnum`]) || 0;
|
|||
|
|
const nightNbank =
|
|||
|
|
getValue(variableValue[`${prefix}_id_nbank_night_allnum`]) || 0;
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
weekend: weekendBank + weekendNbank,
|
|||
|
|
night: nightBank + nightNbank,
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取银行机构申请次数详情
|
|||
|
|
*/
|
|||
|
|
export function getBankApplicationDetails(variableValue, period) {
|
|||
|
|
const { prefix } = PERIOD_MAP[period];
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
pdl: getValue(variableValue[`${prefix}_id_pdl_allnum`]), // 线上小额现金贷
|
|||
|
|
caon: getValue(variableValue[`${prefix}_id_caon_allnum`]), // 线上现金分期
|
|||
|
|
rel: getValue(variableValue[`${prefix}_id_rel_allnum`]), // 信用卡(类信用卡)
|
|||
|
|
caoff: getValue(variableValue[`${prefix}_id_caoff_allnum`]), // 线下现金分期
|
|||
|
|
cooff: getValue(variableValue[`${prefix}_id_cooff_allnum`]), // 线下消费分期
|
|||
|
|
af: getValue(variableValue[`${prefix}_id_af_allnum`]), // 汽车金融
|
|||
|
|
coon: getValue(variableValue[`${prefix}_id_coon_allnum`]), // 线上消费分期
|
|||
|
|
oth: getValue(variableValue[`${prefix}_id_oth_allnum`]), // 其他
|
|||
|
|
bank: getValue(variableValue[`${prefix}_id_bank_allnum`]), // 银行机构申请
|
|||
|
|
tra: getValue(variableValue[`${prefix}_id_bank_tra_allnum`]), // 传统银行申请
|
|||
|
|
ret: getValue(variableValue[`${prefix}_id_bank_ret_allnum`]), // 网络零售银行申请
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取非银机构申请次数详情
|
|||
|
|
*/
|
|||
|
|
export function getNBankApplicationDetails(variableValue, period) {
|
|||
|
|
const { prefix } = PERIOD_MAP[period];
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
nbank: getValue(variableValue[`${prefix}_id_nbank_allnum`]), // 非银机构
|
|||
|
|
p2p: getValue(variableValue[`${prefix}_id_nbank_p2p_allnum`]), // 改制机构
|
|||
|
|
mc: getValue(variableValue[`${prefix}_id_nbank_mc_allnum`]), // 小贷机构
|
|||
|
|
ca: getValue(variableValue[`${prefix}_id_nbank_ca_allnum`]), // 现金类分期机构
|
|||
|
|
cf: getValue(variableValue[`${prefix}_id_nbank_cf_allnum`]), // 消费类分期机构
|
|||
|
|
com: getValue(variableValue[`${prefix}_id_nbank_com_allnum`]), // 代偿类分期机构
|
|||
|
|
oth: getValue(variableValue[`${prefix}_id_nbank_oth_allnum`]), // 其他申请
|
|||
|
|
nsloan: getValue(variableValue[`${prefix}_id_nbank_nsloan_allnum`]), // 持牌网络小贷机构
|
|||
|
|
autofin: getValue(variableValue[`${prefix}_id_nbank_autofin_allnum`]), // 持牌汽车金融机构
|
|||
|
|
sloan: getValue(variableValue[`${prefix}_id_nbank_sloan_allnum`]), // 持牌小贷机构
|
|||
|
|
cons: getValue(variableValue[`${prefix}_id_nbank_cons_allnum`]), // 持牌消费金融机构
|
|||
|
|
finlea: getValue(variableValue[`${prefix}_id_nbank_finlea_allnum`]), // 持牌融资租赁机构
|
|||
|
|
else: getValue(variableValue[`${prefix}_id_nbank_else_allnum`]), // 其他申请
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取银行机构申请机构数详情
|
|||
|
|
*/
|
|||
|
|
export function getBankOrgDetails(variableValue, period) {
|
|||
|
|
const { prefix } = PERIOD_MAP[period];
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
pdl: getValue(variableValue[`${prefix}_id_pdl_orgnum`]),
|
|||
|
|
caon: getValue(variableValue[`${prefix}_id_caon_orgnum`]),
|
|||
|
|
rel: getValue(variableValue[`${prefix}_id_rel_orgnum`]),
|
|||
|
|
caoff: getValue(variableValue[`${prefix}_id_caoff_orgnum`]),
|
|||
|
|
cooff: getValue(variableValue[`${prefix}_id_cooff_orgnum`]),
|
|||
|
|
af: getValue(variableValue[`${prefix}_id_af_orgnum`]),
|
|||
|
|
coon: getValue(variableValue[`${prefix}_id_coon_orgnum`]),
|
|||
|
|
oth: getValue(variableValue[`${prefix}_id_oth_orgnum`]),
|
|||
|
|
bank: getValue(variableValue[`${prefix}_id_bank_orgnum`]),
|
|||
|
|
tra: getValue(variableValue[`${prefix}_id_bank_tra_orgnum`]),
|
|||
|
|
ret: getValue(variableValue[`${prefix}_id_bank_ret_orgnum`]),
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取非银机构申请机构数详情
|
|||
|
|
*/
|
|||
|
|
export function getNBankOrgDetails(variableValue, period) {
|
|||
|
|
const { prefix } = PERIOD_MAP[period];
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
nbank: getValue(variableValue[`${prefix}_id_nbank_orgnum`]),
|
|||
|
|
p2p: getValue(variableValue[`${prefix}_id_nbank_p2p_orgnum`]),
|
|||
|
|
mc: getValue(variableValue[`${prefix}_id_nbank_mc_orgnum`]),
|
|||
|
|
ca: getValue(variableValue[`${prefix}_id_nbank_ca_orgnum`]),
|
|||
|
|
cf: getValue(variableValue[`${prefix}_id_nbank_cf_orgnum`]),
|
|||
|
|
com: getValue(variableValue[`${prefix}_id_nbank_com_orgnum`]),
|
|||
|
|
oth: getValue(variableValue[`${prefix}_id_nbank_oth_orgnum`]),
|
|||
|
|
nsloan: getValue(variableValue[`${prefix}_id_nbank_nsloan_orgnum`]),
|
|||
|
|
autofin: getValue(variableValue[`${prefix}_id_nbank_autofin_orgnum`]),
|
|||
|
|
sloan: getValue(variableValue[`${prefix}_id_nbank_sloan_orgnum`]),
|
|||
|
|
cons: getValue(variableValue[`${prefix}_id_nbank_cons_orgnum`]),
|
|||
|
|
finlea: getValue(variableValue[`${prefix}_id_nbank_finlea_orgnum`]),
|
|||
|
|
else: getValue(variableValue[`${prefix}_id_nbank_else_orgnum`]),
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 字段名称映射
|
|||
|
|
*/
|
|||
|
|
export const FIELD_LABELS = {
|
|||
|
|
// 银行机构申请类型
|
|||
|
|
bank: {
|
|||
|
|
pdl: "申请线上小额现金贷",
|
|||
|
|
caon: "申请线上现金分期",
|
|||
|
|
rel: "申请信用卡(类信用卡)",
|
|||
|
|
caoff: "申请线下现金分期",
|
|||
|
|
cooff: "申请线下消费分期",
|
|||
|
|
af: "申请汽车金融",
|
|||
|
|
coon: "申请线上消费分期",
|
|||
|
|
oth: "申请其他",
|
|||
|
|
bank: "银行机构申请",
|
|||
|
|
tra: "银行机构-传统银行申请",
|
|||
|
|
ret: "银行机构-网络零售银行申请",
|
|||
|
|
},
|
|||
|
|
// 非银机构申请类型
|
|||
|
|
nbank: {
|
|||
|
|
nbank: "非银机构",
|
|||
|
|
p2p: "改制机构",
|
|||
|
|
mc: "小贷机构",
|
|||
|
|
ca: "现金类分期机构",
|
|||
|
|
cf: "消费类分期机构",
|
|||
|
|
com: "代偿类分期机构",
|
|||
|
|
oth: "其他申请",
|
|||
|
|
nsloan: "持牌网络小贷机构",
|
|||
|
|
autofin: "汽车金融",
|
|||
|
|
sloan: "持牌小贷机构",
|
|||
|
|
cons: "持牌消费金融机构",
|
|||
|
|
finlea: "持牌融资租赁机构",
|
|||
|
|
else: "其他申请",
|
|||
|
|
},
|
|||
|
|
};
|