ReportTurnoverUtil.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.kingdee.eas.custom.perfweb.util;
  2. /**
  3. * 类名称: ReportTurnoverUtil
  4. * 功能描述: 流失率报表SQL及计算工具
  5. * 创建日期: 2026-06-23
  6. * 作 者: 青梧
  7. * 版 本: 1.1
  8. */
  9. public final class ReportTurnoverUtil {
  10. private ReportTurnoverUtil() {
  11. }
  12. /**
  13. * 追加主动/被动离职过滤条件
  14. * CFSfbdlz字段:0=主动离职,1=被动离职
  15. */
  16. public static void appendPassiveResignFilter(StringBuilder sql, boolean isPassive) {
  17. if (isPassive) {
  18. sql.append("AND (entry.CFSfbdlz = 1 OR entry.CFSfbdlz = '1') ");
  19. } else {
  20. sql.append("AND (entry.CFSfbdlz IS NULL OR entry.CFSfbdlz = 0 OR entry.CFSfbdlz = '0') ");
  21. }
  22. }
  23. /**
  24. * 计算平均流失率(百分比)
  25. * 流失人数 / ((期初人数 + 期末人数) / 2)
  26. */
  27. public static double calculateAvgTurnoverRate(int resignCount, int beginCount, int endCount) {
  28. double avgCount = (beginCount + endCount) / 2.0;
  29. if (avgCount == 0) {
  30. return 0.0;
  31. }
  32. return (resignCount / avgCount) * 100;
  33. }
  34. /**
  35. * 计算比率
  36. */
  37. public static double calculateRatio(int numerator, int denominator) {
  38. if (denominator == 0) {
  39. return 0.0;
  40. }
  41. return (double) numerator / denominator;
  42. }
  43. /**
  44. * 计算入职率(百分比)
  45. */
  46. public static double calculateEntryRate(int newEntryCount, int beginCount, int endCount) {
  47. return calculateAvgTurnoverRate(newEntryCount, beginCount, endCount);
  48. }
  49. /**
  50. * 链式推算期末在岗:期初 + 入职 - 离职。
  51. */
  52. public static int calculateDerivedEndOnDuty(int beginCount, int newEntryCount, int totalResignCount) {
  53. return beginCount + newEntryCount - totalResignCount;
  54. }
  55. /**
  56. * 合计行YTD比率(百分比): (累计人数/当前月数) / ((1月期初+当前月期末)/2)。
  57. */
  58. public static double calculateSummaryYtdRate(int cumulativeCount, int currentMonth, int janBeginCount,
  59. int currentMonthEndCount) {
  60. if (currentMonth <= 0) {
  61. return 0.0;
  62. }
  63. double monthlyAvgNumerator = cumulativeCount / (double) currentMonth;
  64. double denominator = (janBeginCount + currentMonthEndCount) / 2.0;
  65. if (denominator == 0) {
  66. return 0.0;
  67. }
  68. return (monthlyAvgNumerator / denominator) * 100;
  69. }
  70. /**
  71. * 格式化为百分比字符串(两位小数)
  72. */
  73. public static String formatPercent(double rate) {
  74. return String.format("%.2f", rate) + "%";
  75. }
  76. /**
  77. * 比率转百分比字符串(两位小数)
  78. */
  79. public static String formatRatioPercent(double ratio) {
  80. return formatPercent(ratio * 100);
  81. }
  82. }