liyong
21 小时以前 217f8ee47bb19f8e154d4012dbe232f0d7af3a3d
src/main/java/com/ruoyi/staff/service/impl/AnalyticsServiceImpl.java
@@ -94,19 +94,22 @@
            Integer leaveCount = staffLeaveMapper.countLeaveByMonth(monthStart, monthEnd);
            vo.setLeaveCount(leaveCount != null ? leaveCount : 0);
            // 计算流失率:流失率 = 月度离职员工数 / 月初员工数 * 100%
            // 计算当期平均在职人数 = (月初员工数 + 月末员工数) / 2
            Double averageStaffCount = (vo.getBeginMonthStaffCount() + vo.getEndMonthStaffCount()) / 2.0;
            // 计算流失率:流失率 = 月度离职员工数 / 当期平均在职人数 * 100%
            Double turnoverRate = 0.0;
            if (vo.getBeginMonthStaffCount() > 0) {
                turnoverRate = (double) vo.getLeaveCount() / vo.getBeginMonthStaffCount() * 100;
            if (averageStaffCount > 0) {
                turnoverRate = (double) vo.getLeaveCount() / averageStaffCount * 100;
                // 保留两位小数
                turnoverRate = Math.round(turnoverRate * 100.0) / 100.0;
            }
            vo.setTurnoverRate(turnoverRate);
            // 计算流动率:流动率 = (月度入职员工数 + 月度离职员工数) / 月初员工数 * 100%
            // 计算流动率:流动率 = (月度入职员工数 + 月度离职员工数) / 当期平均在职人数 * 100%
            Double flowRate = 0.0;
            if (vo.getBeginMonthStaffCount() > 0) {
                flowRate = (double) (vo.getNewHireCount() + vo.getLeaveCount()) / vo.getBeginMonthStaffCount() * 100;
            if (averageStaffCount > 0) {
                flowRate = (double) (vo.getNewHireCount() + vo.getLeaveCount()) / averageStaffCount * 100;
                // 保留两位小数
                flowRate = Math.round(flowRate * 100.0) / 100.0;
            }
@@ -133,26 +136,36 @@
        // 获取月初员工数(即上月末员工数)
        Integer beginMonthStaffCount = staffOnJobMapper.countOnJobStaffByDate(monthStartDate.minusDays(1));
        beginMonthStaffCount = beginMonthStaffCount != null ? beginMonthStaffCount : 0;
        // 获取月末员工数
        Integer endMonthStaffCount = staffOnJobMapper.countOnJobStaffByDate(monthEndDate);
        endMonthStaffCount = endMonthStaffCount != null ? endMonthStaffCount : 0;
        // 获取本月新入职员工数
        Integer newHireCount = staffOnJobMapper.countNewHireByMonth(monthStartDate, monthEndDate);
        newHireCount = newHireCount != null ? newHireCount : 0;
        // 获取本月离职员工数
        Integer leaveCount = staffLeaveMapper.countLeaveByMonth(monthStartDate, monthEndDate);
        leaveCount = leaveCount != null ? leaveCount : 0;
        // 计算总流动率 = (入职人数 + 离职人数) / 月初员工数 * 100%
        // 计算当期平均在职人数 = (月初员工数 + 月末员工数) / 2
        Double averageStaffCount = (beginMonthStaffCount + endMonthStaffCount) / 2.0;
        // 计算总流动率 = (入职人数 + 离职人数) / 当期平均在职人数 * 100%
        Double totalFlowRate = 0.0;
        if (beginMonthStaffCount > 0) {
            totalFlowRate = (double) (newHireCount + leaveCount) / beginMonthStaffCount * 100;
        if (averageStaffCount > 0) {
            totalFlowRate = (double) (newHireCount + leaveCount) / averageStaffCount * 100;
            // 保留两位小数
            totalFlowRate = Math.round(totalFlowRate * 100.0) / 100.0;
        }
        result.setTotalFlowRate(totalFlowRate);
        // 计算总流失率 = 离职人数 / 月初员工数 * 100%
        // 计算总流失率 = 离职人数 / 当期平均在职人数 * 100%
        Double totalTurnoverRate = 0.0;
        if (beginMonthStaffCount > 0) {
            totalTurnoverRate = (double) leaveCount / beginMonthStaffCount * 100;
        if (averageStaffCount > 0) {
            totalTurnoverRate = (double) leaveCount / averageStaffCount * 100;
            // 保留两位小数
            totalTurnoverRate = Math.round(totalTurnoverRate * 100.0) / 100.0;
        }