From 4d730af0447c686133130d0116a0fa3dd82c2dca Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Tue, 10 Nov 2026 01:41:03 +0000
Subject: [PATCH] Merge branch 'wcd-2411-update' into wcd
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java | 213 +++++++++++++++++------------------------------------
1 files changed, 69 insertions(+), 144 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
index 55353d4..58f0637 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
@@ -146,8 +146,8 @@
//获取当前登入人信息
User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
Role role = user.getRoles().iterator().next();
- //除超管、总经理只能修改自己信息
- if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
+ // 除超管、总经理只能修改自己信息
+ if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){
throw new BadRequestException("只能修改自己的记录");
}
@@ -323,8 +323,8 @@
Role role = user.getRoles().iterator().next();
//根据id查询记录
Optional<Attendance> attendance = attendanceRepository.findById(id);
- //除超管、总经理只能删除自己信息
- if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
+ // 除超管、总经理只能删除自己信息
+ if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
if (!Long.valueOf(attendance.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
throw new BadRequestException("只能删除自己的记录");
}
@@ -342,8 +342,8 @@
//获取当前登入人信息
User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
Role role = user.getRoles().iterator().next();
- //除超管、总经理只能补自己的卡
- if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
+ // 除超管、总经理只能补自己的卡
+ if (!Constant.SUPER_LEVEL_LIST.contains(Long.valueOf(role.getLevel()))) {
if (!Long.valueOf(userId).equals(SecurityUtils.getCurrentUserId())){
throw new BadRequestException("只能补自己的卡");
}
@@ -447,11 +447,11 @@
public void download(List<AttendanceDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (AttendanceDto attendance : all) {
- String startLocationResults = attendance.getStartLocationResults() != null ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getStartLocationResults()).getLabel() : "";
- String startClockResults = attendance.getStartClockResults() != null ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getStartClockResults()).getLabel() : "";
- String endLocationResults = attendance.getEndLocationResults() != null ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getEndLocationResults()).getLabel() : "";
- String endClockResults = attendance.getEndClockResults() != null ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getEndClockResults()).getLabel() : "";
- String dateType = attendance.getDateType() != null ? dictDetailRepository.findByDictNameAndValue("date_type", attendance.getDateType()).getLabel() : "";
+ String startLocationResults = StringUtils.isNotBlank(attendance.getStartLocationResults()) ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getStartLocationResults()).getLabel() : "";
+ String startClockResults = StringUtils.isNotBlank(attendance.getStartClockResults()) ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getStartClockResults()).getLabel() : "";
+ String endLocationResults = StringUtils.isNotBlank(attendance.getEndLocationResults()) ? dictDetailRepository.findByDictNameAndValue("location_results", attendance.getEndLocationResults()).getLabel() : "";
+ String endClockResults = StringUtils.isNotBlank(attendance.getEndClockResults()) ? dictDetailRepository.findByDictNameAndValue("attendance_state", attendance.getEndClockResults()).getLabel() : "";
+ String dateType = StringUtils.isNotBlank(attendance.getDateType()) ? dictDetailRepository.findByDictNameAndValue("date_type", attendance.getDateType()).getLabel() : "";
Map<String,Object> map = new LinkedHashMap<>();
map.put("员工", attendance.getUserName());
map.put("考勤日期", attendance.getAttendanceDate());
@@ -510,6 +510,7 @@
// 休息时间管理
List<Calculate> breakParts = new ArrayList<>();
breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime));
+ breakParts.add(new Calculate(rosteringWorkEndTime, rosteringWorkEndTime.plusMinutes(30)));
// 出差信息
List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, startOfDate, endOfDate);
@@ -533,42 +534,23 @@
new Calculate(attendanceOvertime.getOvertimeStartTime().toLocalDateTime(), attendanceOvertime.getOvertimeEndTime().toLocalDateTime())
).collect(Collectors.toList())
);
- attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), (result, current) -> {
- // 删除重复时间,合并相连的时间段
- if (result.empty()) {
- result.push(current);
- return result;
- }
- Calculate last = result.peek();
- if (last.getEnd().isBefore(current.getStart())) {
- result.push(current);
- } else if (last.getEnd().isBefore(current.getEnd())) {
- last.setEnd(current.getEnd());
- }
- return result;
- }, (o1, o2) -> null).forEach(calculate -> {
- // 去除休息时间:午休等
- for (Calculate breakPart : breakParts) {
- if ((calculate.getStart().isBefore(breakPart.getStart()) && calculate.getEnd().isAfter(breakPart.getStart()))
- || (calculate.getStart().isBefore(breakPart.getEnd()) && calculate.getEnd().isAfter(breakPart.getEnd()))) {
- Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart());
- Calculate calculate2 = new Calculate(breakPart.getEnd(), calculate.getEnd());
- if (calculate1.getStart().isBefore(calculate1.getEnd())) {
- resultParts.add(calculate1);
- }
- if (calculate2.getStart().isBefore(calculate2.getEnd())) {
- resultParts.add(calculate2);
- }
- } else {
- resultParts.add(calculate);
- }
- }
- });
-
// 请假信息
List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(userId, startOfDate, endOfDate);
-// // 加班信息
-// List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, startOfDate, endOfDate);
+ attendanceParts.addAll(
+ attendanceLeaveList.stream()
+ .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_LACTATION_LEAVE.equals(attendanceLeave.getLeaveType())
+ ).map(attendanceLeave ->
+ new Calculate(attendanceLeave.getLeaveStartTime().toLocalDateTime(), attendanceLeave.getLeaveEndTime().toLocalDateTime())
+ ).collect(Collectors.toList())
+ );
+ attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), Calculate::mergeTimeRanges, (o1, o2) -> null).forEach(calculate -> {
+ // 去除休息时间:午休等
+ resultParts.addAll(Calculate.calculateRemainingCalculate(calculate, breakParts.toArray(new Calculate[0])));
+ });
// 出勤时间累计
BigDecimal result = resultParts.stream()
@@ -577,18 +559,12 @@
(total, current) -> total.add(BigDecimal.valueOf(current)),
(o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP
);
- BigDecimal annualLeaveHours = attendanceLeaveList.stream()
- .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
- || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType())
- || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
-// || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())
- ).map(attendanceLeave -> BigDecimal.valueOf(attendanceLeave.getLeaveDuration())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
// TODO: 此方法只用于计算指定日期工时,不可用于钱款统计的工时计算
- return result.add(annualLeaveHours).doubleValue();
+ return result.doubleValue();
}
@Override
- public Double queryAttendanceHolidaysOverTimeHours(AttendanceQueryCriteria criteria) {
+ public Double queryAttendanceLegalOverTimeHours(AttendanceQueryCriteria criteria) {
// 结算结算三个月前的(法定节假日)
LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusMonths(3L);
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
@@ -607,6 +583,10 @@
.filter(sysConfigHoliday -> Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(sysConfigHoliday.getDateType()))
.mapToDouble(sysConfigHoliday -> {
for (AttendanceOvertime attendanceOvertime : attendanceOvertimeList) {
+ if (attendanceOvertime.getApprovalUserId().equals(0L) && StringUtils.isBlank(attendanceOvertime.getWecomSpNo())) {
+ // 特殊转换的调休不结算为工资:如上年度剩余年假转换的调休
+ continue;
+ }
if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(attendanceOvertime.getOvertimeStartTime().toLocalDateTime().truncatedTo(ChronoUnit.DAYS))) {
return attendanceOvertime.getRemainingDuration();
}
@@ -616,7 +596,7 @@
}
@Override
- public Double queryAttendanceWeekendOverTimeHours(AttendanceQueryCriteria criteria) {
+ public Double queryAttendanceUnLegalOverTimeHours(AttendanceQueryCriteria criteria) {
// 结算结算三个月前的
LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusMonths(3L);
LocalDate endDate = startDate.plusMonths(1).minusDays(1);
@@ -631,13 +611,13 @@
Map<LocalDate, String> sysConfigHolidayMap = sysConfigHolidayMonthList.stream().collect(Collectors.toMap(sch -> sch.getHolidayDate().toLocalDateTime().toLocalDate(), SysConfigHoliday::getDateType));
return attendanceOvertimeList.stream().mapToDouble(ao -> {
+ if (ao.getApprovalUserId().equals(0L) && StringUtils.isBlank(ao.getWecomSpNo())) {
+ // 特殊转换的调休不结算为工资:如上年度剩余年假转换的调休
+ return 0.0D;
+ }
LocalDate localDate = ao.getOvertimeStartTime().toLocalDateTime().toLocalDate();
- DayOfWeek dayOfWeek = ao.getOvertimeStartTime().toLocalDateTime().toLocalDate().getDayOfWeek();
- if ((sysConfigHolidayMap.containsKey(localDate) &&
- sysConfigHolidayMap.get(localDate).equals(Constant.DATE_TYPE_WEEKEND) &&
- !sysConfigHolidayMap.get(localDate).equals(Constant.DATE_TYPE_WEEKDAY) &&
- !sysConfigHolidayMap.get(localDate).equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) ||
- (dayOfWeek.equals(DayOfWeek.SATURDAY) || dayOfWeek.equals(DayOfWeek.SUNDAY))
+ if ((sysConfigHolidayMap.containsKey(localDate) && !sysConfigHolidayMap.get(localDate).equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) ||
+ (!sysConfigHolidayMap.containsKey(localDate))
) {
return ao.getRemainingDuration();
}
@@ -659,17 +639,19 @@
Long distance = ChronoUnit.DAYS.between(startDate, endDate);
return Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).filter(localDate -> {
- if (StringUtils.isBlank(type)) {
+ SysConfigHoliday currentSysConfigHoliday = sysConfigHolidayMonthList.stream().filter(sch -> sch.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay())).findFirst().orElse(null);
+ if (StringUtils.isBlank(type) || type.equals(Constant.DATE_TYPE_WEEKDAY)) {
// 默认(工作日)
- for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayMonthList) {
- if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay())) {
- return Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHoliday.getDateType());
- }
+ if (currentSysConfigHoliday != null) {
+ return Constant.DATE_TYPE_WEEKDAY.equals(currentSysConfigHoliday.getDateType());
}
return localDate.getDayOfWeek() != DayOfWeek.SATURDAY && localDate.getDayOfWeek() != DayOfWeek.SUNDAY;
+ } else if (type.equals(Constant.DATE_TYPE_WEEKEND)) {
+ // 双休日(特殊标记:因不一定会被记录在假期设定里)
+ return (currentSysConfigHoliday == null || type.equals(currentSysConfigHoliday.getDateType())) && (localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY);
} else {
// 其他类型
- return sysConfigHolidayMonthList.stream().anyMatch(sch -> sch.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay()) && type.equals(sch.getDateType()));
+ return currentSysConfigHoliday != null && type.equals(currentSysConfigHoliday.getDateType());
}
}).map(localDate -> {
LocalDateTime startOfDate = localDate.atTime(0, 0, 0);
@@ -694,7 +676,16 @@
// 正常时间管理
List<Calculate> breakParts = new ArrayList<>();
- breakParts.add(new Calculate(rosteringWorkStartTime, rosteringWorkEndTime.plusMinutes(30)));
+ if (StringUtils.isBlank(type) || type.equals(Constant.DATE_TYPE_WEEKDAY)) {
+ // 工作日:去除工作时间及休息时间
+ breakParts.add(new Calculate(rosteringWorkStartTime, rosteringWorkEndTime.plusMinutes(30)));
+ } else {
+ // 其他:仅去除休息时间
+ LocalDateTime lunchStartTime = attendanceDate.getRosteringLunchStartTime() == null ? null : attendanceDate.getRosteringLunchStartTime().toLocalDateTime();
+ LocalDateTime lunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime();
+ breakParts.add(new Calculate(lunchStartTime, lunchEndTime));
+ breakParts.add(new Calculate(rosteringWorkEndTime, rosteringWorkEndTime.plusMinutes(30)));
+ }
// 查询调休(因工作日加班过0点加班时间可转调休的规定,部分调休与加班时间重复,需要扣除这部分时间,具体可咨询Lief)
List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(criteria.getUserId(), DateUtil.parseAttStartTime(startOfDate), DateUtil.parseAttEndTime(endOfDate));
breakParts.addAll(attendanceOvertimeList.stream().map(ao -> new Calculate(ao.getOvertimeStartTime().toLocalDateTime(), ao.getOvertimeEndTime().toLocalDateTime())).collect(Collectors.toList()));
@@ -714,36 +705,9 @@
List<Calculate> resultParts = new ArrayList<>();
- attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), (result, current) -> {
- // 删除重复时间,合并相连的时间段
- if (result.empty()) {
- result.push(current);
- return result;
- }
- Calculate last = result.peek();
- if (last.getEnd().isBefore(current.getStart())) {
- result.push(current);
- } else if (last.getEnd().isBefore(current.getEnd())) {
- last.setEnd(current.getEnd());
- }
- return result;
- }, (o1, o2) -> null).forEach(calculate -> {
+ attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), Calculate::mergeTimeRanges, (o1, o2) -> null).forEach(calculate -> {
// 去除休息时间:午休等
- for (Calculate breakPart : breakParts) {
- if ((!calculate.getStart().isAfter(breakPart.getStart()) && !calculate.getEnd().isBefore(breakPart.getStart()))
- || (!calculate.getStart().isAfter(breakPart.getEnd()) && !calculate.getEnd().isBefore(breakPart.getEnd()))) {
- Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart());
- Calculate calculate2 = new Calculate(breakPart.getEnd(), calculate.getEnd());
- if (calculate1.getStart().isBefore(calculate1.getEnd())) {
- resultParts.add(calculate1);
- }
- if (calculate2.getStart().isBefore(calculate2.getEnd())) {
- resultParts.add(calculate2);
- }
- } else if (calculate.getEnd().isBefore(breakPart.getStart()) || calculate.getStart().isAfter(breakPart.getEnd())) {
- resultParts.add(calculate);
- }
- }
+ resultParts.addAll(Calculate.calculateRemainingCalculate(calculate, breakParts.toArray(new Calculate[0])));
});
// 出勤时间累计
@@ -753,7 +717,7 @@
// 加班时长不足0.5小时的部分不计入加班统计。
long halfHour = result / 30;
return BigDecimal.valueOf(halfHour).multiply(BigDecimal.valueOf(0.5));
- }).reduce(BigDecimal::add).get().doubleValue();
+ }).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).doubleValue();
}
@Override
@@ -825,20 +789,7 @@
).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList())
);
// 合并请假时间
- List<Calculate> finalBreakParts = breakParts.stream().sorted().reduce(new Stack<>(), (result, current) -> {
- // 删除重复时间,合并相连的时间段
- if (result.empty()) {
- result.push(current);
- return result;
- }
- Calculate last = result.peek();
- if (last.getEnd().isBefore(current.getStart())) {
- result.push(current);
- } else if (last.getEnd().isBefore(current.getEnd())) {
- last.setEnd(current.getEnd());
- }
- return result;
- }, (o1, o2) -> null);
+ List<Calculate> finalBreakParts = breakParts.stream().sorted().reduce(new Stack<>(), Calculate::mergeTimeRanges, (o1, o2) -> null);
// 出差信息
List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(criteria.getUserId(), startOfDate, endOfDate);
@@ -874,36 +825,9 @@
List<Calculate> resultParts = new ArrayList<>();
- attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), (result, current) -> {
- // 删除重复时间,合并相连的时间段
- if (result.empty()) {
- result.push(current);
- return result;
- }
- Calculate last = result.peek();
- if (last.getEnd().isBefore(current.getStart())) {
- result.push(current);
- } else if (last.getEnd().isBefore(current.getEnd())) {
- last.setEnd(current.getEnd());
- }
- return result;
- }, (o1, o2) -> null).forEach(calculate -> {
+ attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), Calculate::mergeTimeRanges, (o1, o2) -> null).forEach(calculate -> {
// 去除休息时间:午休等
- for (Calculate breakPart : finalBreakParts) {
- if ((calculate.getStart().isBefore(breakPart.getStart()) && calculate.getEnd().isAfter(breakPart.getStart()))
- || (calculate.getStart().isBefore(breakPart.getEnd()) && calculate.getEnd().isAfter(breakPart.getEnd()))) {
- Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart());
- Calculate calculate2 = new Calculate(breakPart.getEnd(), calculate.getEnd());
- if (calculate1.getStart().isBefore(calculate1.getEnd())) {
- resultParts.add(calculate1);
- }
- if (calculate2.getStart().isBefore(calculate2.getEnd())) {
- resultParts.add(calculate2);
- }
- } else {
- resultParts.add(calculate);
- }
- }
+ resultParts.addAll(Calculate.calculateRemainingCalculate(calculate, finalBreakParts.toArray(new Calculate[0])));
});
// 出勤时间累计
@@ -916,10 +840,11 @@
// 年假不扣工时
BigDecimal annualLeaveHours = attendanceLeaveList.stream()
.filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
- || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType())
- || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
- || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType()))
- .map(attendanceLeave -> {
+ || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())
+ || Constant.LEAVE_TYPE_LACTATION_LEAVE.equals(attendanceLeave.getLeaveType())
+ ).map(attendanceLeave -> {
if (Constant.LEAVE_TIME_TYPE_HOUR.equals(attendanceLeave.getLeaveDurationUnit())) {
return BigDecimal.valueOf(attendanceLeave.getLeaveDuration());
} else {
--
Gitblit v1.9.3