From 217f8ee47bb19f8e154d4012dbe232f0d7af3a3d Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期五, 30 一月 2026 09:44:27 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New
---
src/main/java/com/ruoyi/staff/service/impl/AnalyticsServiceImpl.java | 71 +++++++++++++++++++++++++----------
1 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/ruoyi/staff/service/impl/AnalyticsServiceImpl.java b/src/main/java/com/ruoyi/staff/service/impl/AnalyticsServiceImpl.java
index 13a440c..ff74b0f 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/AnalyticsServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/AnalyticsServiceImpl.java
@@ -16,7 +16,9 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
@AllArgsConstructor
@Service
@@ -29,16 +31,32 @@
@Override
public List<StaffLeaveDto> staffLeaveReasonAnalytics() {
- List<StaffLeaveDto> result = staffLeaveMapper.staffLeaveReasonAnalytics();
- result.forEach(dto -> {
+ List<StaffLeaveDto> dbResult = staffLeaveMapper.staffLeaveReasonAnalytics();
+
+ // 鍒涘缓涓�涓狹ap鐢ㄤ簬瀛樺偍鎵�鏈夋灇涓惧師鍥犵殑鏁伴噺锛岄粯璁ゅ�间负0
+ Map<String, Integer> reasonCountMap = new HashMap<>();
+ for (StaffLeaveReason reasonEnum : StaffLeaveReason.values()) {
+ reasonCountMap.put(reasonEnum.getCode(), 0);
+ }
+
+ // 灏嗘暟鎹簱鏌ヨ缁撴灉鍚堝苟鍒癕ap涓�
+ for (StaffLeaveDto dto : dbResult) {
String reasonCode = dto.getReason();
- StaffLeaveReason reasonEnum = StaffLeaveReason.getByCode(reasonCode);
- if (reasonEnum != null) {
- dto.setReasonText(reasonEnum.getInfo());
- } else {
- dto.setReasonText("鏈煡鍘熷洜");
+ if (reasonCountMap.containsKey(reasonCode)) {
+ reasonCountMap.put(reasonCode, dto.getCount());
}
- });
+ }
+
+ // 灏哅ap杞崲涓篖ist<StaffLeaveDto>
+ List<StaffLeaveDto> result = new ArrayList<>();
+ for (StaffLeaveReason reasonEnum : StaffLeaveReason.values()) {
+ StaffLeaveDto dto = new StaffLeaveDto();
+ dto.setReason(reasonEnum.getCode());
+ dto.setCount(reasonCountMap.get(reasonEnum.getCode()));
+ dto.setReasonText(reasonEnum.getInfo());
+ result.add(dto);
+ }
+
return result;
}
@@ -76,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;
}
@@ -115,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;
}
--
Gitblit v1.9.3