From 5db13c2ad6678cf4614b81c95df035c6f47d313d Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 16 十月 2026 21:57:36 +0800
Subject: [PATCH] feat(hrm): 考勤规则放开部门唯一限制,支持同一部门多班次
---
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/attendance/HrmAttendanceRecordServiceImpl.java | 91 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/attendance/HrmAttendanceRecordServiceImpl.java b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/attendance/HrmAttendanceRecordServiceImpl.java
index f7ff44c..2fa76d3 100644
--- a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/attendance/HrmAttendanceRecordServiceImpl.java
+++ b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/attendance/HrmAttendanceRecordServiceImpl.java
@@ -67,6 +67,91 @@
}
@Override
+ public void createImportedRecord(HrmAttendanceRecordDO record) {
+ // 鎸夎�冨嫟瑙勫垯閲嶇畻鎵撳崱绫诲瀷涓庢椂闀匡紝涓嶄俊浠� Excel 濉啓鐨勫��
+ fillClockTypes(record);
+ fillCalculatedHours(record);
+ attendanceRecordMapper.insert(record);
+ }
+
+ @Override
+ public void updateImportedRecord(HrmAttendanceRecordDO record) {
+ fillClockTypes(record);
+ fillCalculatedHours(record);
+ attendanceRecordMapper.updateById(record);
+ }
+
+ /**
+ * 鎸夎�冨嫟瑙勫垯閲嶇畻涓婁笅鐝墦鍗$被鍨嬶紙姝e父/杩熷埌/鏃╅��锛夛紝涓庢墦鍗¢�昏緫淇濇寔涓�鑷�
+ */
+ private void fillClockTypes(HrmAttendanceRecordDO record) {
+ if (record.getDeptId() == null) {
+ return;
+ }
+ // 涓婄彮鎵撳崱绫诲瀷锛氭櫄浜� 涓婄彮鏃堕棿+杩熷埌鍏佽 璁颁负杩熷埌锛堟寜涓婄彮鎵撳崱鏃堕棿鍖归厤鐝锛�
+ if (record.getClockInTime() != null) {
+ HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(
+ record.getDeptId(), record.getClockInTime());
+ if (rule != null && rule.getWorkStartTime() != null) {
+ int lateAllowMinutes = rule.getLateAllowMinutes() != null ? rule.getLateAllowMinutes() : 0;
+ LocalTime lateThreshold = rule.getWorkStartTime().plusMinutes(lateAllowMinutes);
+ LocalTime clockInOnly = record.getClockInTime().toLocalTime();
+ record.setClockInType(clockInOnly.isAfter(lateThreshold)
+ ? HrmAttendanceClockTypeEnum.LATE.getType()
+ : HrmAttendanceClockTypeEnum.NORMAL.getType());
+ }
+ }
+ // 涓嬬彮鎵撳崱绫诲瀷锛氭棭浜� 涓嬬彮鏃堕棿-鏃╅��鍏佽 璁颁负鏃╅��锛堟寜涓嬬彮鎵撳崱鏃堕棿鍖归厤鐝锛�
+ if (record.getClockOutTime() != null) {
+ HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(
+ record.getDeptId(), record.getClockOutTime());
+ if (rule != null && rule.getWorkEndTime() != null) {
+ int earlyAllowMinutes = rule.getEarlyAllowMinutes() != null ? rule.getEarlyAllowMinutes() : 0;
+ LocalTime earlyThreshold = rule.getWorkEndTime().minusMinutes(earlyAllowMinutes);
+ LocalTime clockOutOnly = record.getClockOutTime().toLocalTime();
+ record.setClockOutType(clockOutOnly.isBefore(earlyThreshold)
+ ? HrmAttendanceClockTypeEnum.EARLY.getType()
+ : HrmAttendanceClockTypeEnum.NORMAL.getType());
+ }
+ }
+ }
+
+ /**
+ * 鏍规嵁涓婁笅鐝墦鍗℃椂闂村拰鑰冨嫟瑙勫垯锛岃绠楀伐浣滄椂闀夸笌鍔犵彮鏃堕暱
+ */
+ private void fillCalculatedHours(HrmAttendanceRecordDO record) {
+ // 宸ヤ綔鏃堕暱 = 涓嬬彮鎵撳崱鏃堕棿 - 涓婄彮鎵撳崱鏃堕棿锛堜笌鎵撳崱閫昏緫涓�鑷达級
+ if (record.getClockInTime() != null && record.getClockOutTime() != null) {
+ Duration duration = Duration.between(record.getClockInTime(), record.getClockOutTime());
+ BigDecimal workHours = BigDecimal.valueOf(duration.toMinutes())
+ .divide(BigDecimal.valueOf(60), 2, RoundingMode.HALF_UP);
+ record.setWorkHours(workHours);
+ }
+ // 鍔犵彮鏃堕暱锛氭寜鑰冨嫟瑙勫垯鐨勬爣鍑嗕笅鐝椂闂磋绠楄秴棰濋儴鍒嗭紙鎸変笅鐝墦鍗℃椂闂村尮閰嶇彮娆★級
+ if (record.getClockOutTime() != null && record.getDeptId() != null) {
+ HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(
+ record.getDeptId(), record.getClockOutTime());
+ if (rule != null && rule.getWorkEndTime() != null) {
+ LocalTime workEnd = rule.getWorkEndTime();
+ LocalDate outDate = record.getClockOutTime().toLocalDate();
+ LocalDateTime workEndDateTime = LocalDateTime.of(outDate, workEnd);
+ if (record.getClockOutTime().isAfter(workEndDateTime)) {
+ Duration overtimeDuration = Duration.between(workEndDateTime, record.getClockOutTime());
+ BigDecimal overtimeThreshold = rule.getOvertimeThreshold() != null
+ ? rule.getOvertimeThreshold() : BigDecimal.ZERO;
+ BigDecimal overtimeHours = BigDecimal.valueOf(overtimeDuration.toMinutes())
+ .divide(BigDecimal.valueOf(60), 2, RoundingMode.HALF_UP);
+ record.setOvertimeHours(overtimeHours.compareTo(overtimeThreshold) > 0 ? overtimeHours : BigDecimal.ZERO);
+ } else {
+ record.setOvertimeHours(BigDecimal.ZERO);
+ }
+ } else {
+ record.setOvertimeHours(BigDecimal.ZERO);
+ }
+ }
+ }
+
+ @Override
@Transactional(rollbackFor = Exception.class)
public HrmAttendanceRecordDO clockIn(Long userId, LocalDateTime clockTime, String location) {
LocalDate clockDate = clockTime.toLocalDate();
@@ -79,7 +164,8 @@
if (employee == null) {
throw exception(EMPLOYEE_NOT_EXISTS);
}
- HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(employee.getDeptId());
+ // 鎸夋湰娆℃墦鍗℃椂闂村尮閰嶇彮娆★紙鍚屼竴涓儴闂ㄥ彲鑳介厤缃簡澶氭潯瑙勫垯锛�
+ HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(employee.getDeptId(), clockTime);
if (rule == null) {
throw exception(ATTENDANCE_CLOCK_FAIL_NO_RULE);
}
@@ -132,7 +218,8 @@
if (employee == null) {
throw exception(EMPLOYEE_NOT_EXISTS);
}
- HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(employee.getDeptId());
+ // 鎸夋湰娆℃墦鍗℃椂闂村尮閰嶇彮娆★紙鍚屼竴涓儴闂ㄥ彲鑳介厤缃簡澶氭潯瑙勫垯锛�
+ HrmAttendanceRuleDO rule = attendanceRuleService.getAttendanceRuleByDeptId(employee.getDeptId(), clockTime);
if (rule == null) {
throw exception(ATTENDANCE_CLOCK_FAIL_NO_RULE);
}
--
Gitblit v1.9.3