This commit is contained in:
2025-12-18 15:39:43 +08:00
parent d576d8e734
commit 0190e21287
48 changed files with 41428 additions and 379 deletions

View File

@@ -0,0 +1,317 @@
/**
* 贷款风险报告(CJRZQ5E9F)数据拆分工具
* 将完整的贷款风险报告数据拆分成多个独立的模块用于在不同的tab中显示
*/
/**
* 将CJRZQ5E9F数据拆分为多个独立的tab模块
* @param {Array} reportData - 原始报告数据数组
* @returns {Array} 拆分后的模块数组
*/
export function splitCJRZQ5E9FForTabs(reportData) {
// 查找CJRZQ5E9F数据
const cjrzq5e9fData = reportData.find(
(item) => item.data?.apiID === "JRZQ5E9F"
);
if (!cjrzq5e9fData || !cjrzq5e9fData.data?.data) {
return reportData; // 如果没有找到CJRZQ5E9F数据返回原数据
}
const originalData = cjrzq5e9fData.data.data;
const baseTimestamp = cjrzq5e9fData.data.timestamp;
// 创建拆分后的模块数组
const splitModules = [];
// 1. 风险概览
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_RiskOverview",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 2. 信用评分
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_CreditScores",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 3. 贷款行为分析
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_LoanBehaviorAnalysis",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 4. 机构分析
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_InstitutionAnalysis",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 5. 时间趋势分析
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_TimeTrendAnalysis",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 6. 风险指标详情
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_RiskIndicators",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 7. 专业建议
if (originalData && Object.keys(originalData).length > 0) {
splitModules.push({
data: {
apiID: "CJRZQ5E9F_RiskAdvice",
data: originalData,
success: true,
timestamp: baseTimestamp,
},
});
}
// 移除原始的JRZQ5E9F数据添加拆分后的模块
const otherData = reportData.filter(
(item) => item.data?.apiID !== "JRZQ5E9F"
);
return [...otherData, ...splitModules];
}
/**
* 解析区间化数值
* @param {string|number} value - 原始值
* @returns {number} 解析后的数值
*/
export function parseIntervalValue(value) {
if (!value || value === "" || value === "-1") return 0;
const num = parseInt(value);
if (isNaN(num)) return 0;
// 根据区间映射返回大致范围的中值
switch (num) {
case 1:
return 1;
case 2:
return 3;
case 3:
return 7;
case 4:
return 15;
case 5:
return 25;
default:
return num;
}
}
/**
* 格式化指标值显示
* @param {number} value - 数值
* @returns {string} 格式化后的显示文本
*/
export function formatMetricValue(value) {
if (value === 0) return "0";
if (value < 5) return `${value}`;
return `${value}+`;
}
/**
* 格式化天数显示
* @param {number} value - 天数
* @returns {string} 格式化后的显示文本
*/
export function formatDays(value) {
if (value === 0) return "无记录";
if (value < 30) return `${value}`;
if (value < 365) return `${Math.floor(value / 30)}个月`;
return `${Math.floor(value / 365)}`;
}
/**
* 格式化金额显示
* @param {number} value - 金额
* @returns {string} 格式化后的显示文本
*/
export function formatAmount(value) {
if (value === 0) return "0元";
if (value < 1000) return `${value}`;
if (value < 10000) return `${(value / 1000).toFixed(1)}千元`;
return `${(value / 10000).toFixed(1)}万元`;
}
/**
* 计算风险等级
* @param {number} creditScore - 信用风险评分
* @param {number} overdueIndex - 逾期指数
* @param {boolean} currentOverdue - 当前是否逾期
* @returns {object} 包含等级、颜色和描述的对象
*/
export function calculateRiskLevel(creditScore, overdueIndex, currentOverdue) {
if (creditScore > 0.7 || overdueIndex > 0.7 || currentOverdue) {
return {
level: "高风险",
color: "text-red-600",
bgColor: "bg-red-100",
iconColor: "bg-red-500",
description: "存在较高信用风险,建议谨慎放贷",
};
} else if (creditScore > 0.4 || overdueIndex > 0.4) {
return {
level: "中风险",
color: "text-yellow-600",
bgColor: "bg-yellow-100",
iconColor: "bg-yellow-500",
description: "信用风险适中,需要进一步评估",
};
} else {
return {
level: "低风险",
color: "text-green-600",
bgColor: "bg-green-100",
iconColor: "bg-green-500",
description: "信用风险较低,具备良好还款能力",
};
}
}
/**
* 计算信用评分显示
* @param {number} creditRiskScore - 信用风险评分
* @param {number} amountComplianceIndex - 履约金额综合指数
* @param {number} countComplianceIndex - 履约笔数综合指数
* @returns {object} 包含评分、进度和颜色的对象
*/
export function calculateCreditScore(
creditRiskScore,
amountComplianceIndex,
countComplianceIndex
) {
const avgRisk =
(creditRiskScore + amountComplianceIndex + countComplianceIndex) / 3;
// 风险越高,信用分越低
const score = Math.round((1 - avgRisk) * 850 + 150);
const progress = (score / 1000) * 283;
let color = "#ef4444";
if (score >= 750) color = "#10b981";
else if (score >= 650) color = "#f59e0b";
return {
score,
progress,
color,
};
}
/**
* 获取信用等级描述
* @param {number} score - 信用评分
* @returns {string} 等级描述
*/
export function getCreditScoreLevel(score) {
if (score >= 800) return "优秀";
if (score >= 700) return "良好";
if (score >= 600) return "一般";
if (score >= 500) return "较差";
return "很差";
}
/**
* 获取信用等级样式类
* @param {number} score - 信用评分
* @returns {string} 样式类名
*/
export function getCreditScoreBadgeClass(score) {
if (score >= 800) return "bg-green-100 text-green-800";
if (score >= 700) return "bg-blue-100 text-blue-800";
if (score >= 600) return "bg-yellow-100 text-yellow-800";
if (score >= 500) return "bg-orange-100 text-orange-800";
return "bg-red-100 text-red-800";
}
/**
* 获取评分样式类
* @param {number} score - 评分
* @returns {string} 样式类名
*/
export function getScoreClass(score) {
if (score === null) return "text-gray-400";
if (score >= 750) return "text-green-600";
if (score >= 650) return "text-yellow-600";
return "text-red-600";
}
/**
* 获取圆形进度样式
* @param {number} ratio - 比例值 (0-1)
* @returns {object} 样式对象
*/
export function getCircleStyle(ratio) {
let color = "#ef4444";
if (ratio >= 0.8) color = "#10b981";
else if (ratio >= 0.6) color = "#f59e0b";
// 确保至少显示10度让用户知道是图表
const minDegree = 10;
const actualDegree = Math.max(ratio * 360, minDegree);
return {
background: `conic-gradient(${color} ${actualDegree}deg, #e5e7eb 0deg)`,
};
}
/**
* 检查是否有风险数据
* @param {Object} data - 数据对象
* @returns {boolean} 是否有风险
*/
export function hasRiskData(data) {
if (!data) return false;
// 检查对象中是否有非0值
return Object.values(data).some((value) => {
if (typeof value === "number") return value > 0;
if (typeof value === "string")
return value !== "0" && value !== "-" && value !== "";
return false;
});
}