package com.kingdee.eas.custom.perfweb.util; /** * 类名称: ReportTurnoverUtil * 功能描述: 流失率报表SQL及计算工具 * 创建日期: 2026-06-23 * 作 者: 青梧 * 版 本: 1.1 */ public final class ReportTurnoverUtil { private ReportTurnoverUtil() { } /** * 追加主动/被动离职过滤条件 * CFSfbdlz字段:0=主动离职,1=被动离职 */ public static void appendPassiveResignFilter(StringBuilder sql, boolean isPassive) { if (isPassive) { sql.append("AND (entry.CFSfbdlz = 1 OR entry.CFSfbdlz = '1') "); } else { sql.append("AND (entry.CFSfbdlz IS NULL OR entry.CFSfbdlz = 0 OR entry.CFSfbdlz = '0') "); } } /** * 计算平均流失率(百分比) * 流失人数 / ((期初人数 + 期末人数) / 2) */ public static double calculateAvgTurnoverRate(int resignCount, int beginCount, int endCount) { double avgCount = (beginCount + endCount) / 2.0; if (avgCount == 0) { return 0.0; } return (resignCount / avgCount) * 100; } /** * 计算比率 */ public static double calculateRatio(int numerator, int denominator) { if (denominator == 0) { return 0.0; } return (double) numerator / denominator; } /** * 计算入职率(百分比) */ public static double calculateEntryRate(int newEntryCount, int beginCount, int endCount) { return calculateAvgTurnoverRate(newEntryCount, beginCount, endCount); } /** * 链式推算期末在岗:期初 + 入职 - 离职。 */ public static int calculateDerivedEndOnDuty(int beginCount, int newEntryCount, int totalResignCount) { return beginCount + newEntryCount - totalResignCount; } /** * 合计行YTD比率(百分比): (累计人数/当前月数) / ((1月期初+当前月期末)/2)。 */ public static double calculateSummaryYtdRate(int cumulativeCount, int currentMonth, int janBeginCount, int currentMonthEndCount) { if (currentMonth <= 0) { return 0.0; } double monthlyAvgNumerator = cumulativeCount / (double) currentMonth; double denominator = (janBeginCount + currentMonthEndCount) / 2.0; if (denominator == 0) { return 0.0; } return (monthlyAvgNumerator / denominator) * 100; } /** * 格式化为百分比字符串(两位小数) */ public static String formatPercent(double rate) { return String.format("%.2f", rate) + "%"; } /** * 比率转百分比字符串(两位小数) */ public static String formatRatioPercent(double ratio) { return formatPercent(ratio * 100); } }