From c7ed489cee1127e3b4f96edf74e24b01c065ac2a Mon Sep 17 00:00:00 2001
From: yao-zengchun <yao-zengchun@smhc.co.jp>
Date: Thu, 08 Jan 2026 09:47:59 +0000
Subject: [PATCH] Merge branch 'wcd' of http://192.168.1.110:5678/r/pms-upgrade into wcd
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java | 140 +++++++++++++++++++++++++++++-----------------
1 files changed, 88 insertions(+), 52 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java
index 4cb5424..38499bc 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java
@@ -20,16 +20,12 @@
import me.zhengjie.modules.approval.domain.ApproveEvent;
import me.zhengjie.modules.approval.repository.ApproveEventRepository;
import me.zhengjie.modules.approval.service.TemplateControlFieldService;
-import me.zhengjie.modules.approval.service.TemplateService;
import me.zhengjie.modules.approval.service.mapstruct.ApproveEventMapper;
import me.zhengjie.modules.attendance.domain.*;
import me.zhengjie.modules.attendance.repository.*;
import me.zhengjie.modules.attendance.service.AttendanceLeaveService;
import me.zhengjie.modules.attendance.service.AttendanceService;
-import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveDto;
-import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveQueryCriteria;
-import me.zhengjie.modules.attendance.service.dto.AttendanceOvertimeQueryCriteria;
-import me.zhengjie.modules.attendance.service.dto.OvertimeConsumedRecordQueryCriteria;
+import me.zhengjie.modules.attendance.service.dto.*;
import me.zhengjie.modules.attendance.service.mapstruct.AttendanceLeaveMapper;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
@@ -76,15 +72,14 @@
private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
private final UserRepository userRepository;
private final SysConfigHolidayRepository sysConfigHolidayRepository;
- private final AttendanceRepository attendanceRepository;
private final AttendanceGoOutRepository attendanceGoOutRepository;
private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
private final AttendanceOvertimeRepository attendanceOvertimeRepository;
private final ApproveEventRepository approveEventRepository;
private final OvertimeConsumedRecordRepository overtimeConsumedRecordRepository;
+ private final AnnualLeaveRecordRepository annualLeaveRecordRepository;
private final ApproveEventMapper approveEventMapper;
private final WeComServiceImpl weComService;
- private final TemplateService templateService;
private final TemplateControlFieldService templateControlFieldService;
@Override
@@ -483,54 +478,92 @@
* 获取用户年假剩余时长
*/
@Override
- public Double getYearTimeLength(Long userId) {
- //获取年假剩余(新)
- Double surplusYearTime = new Double(0.00);
- // 根据用户查询
- List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId);
- if (sysUserLevelOtherList.size() > 0) {
- for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) {
- // 获取今年
- int year = Calendar.getInstance().get(Calendar.YEAR);
- if (!sysUserLevelOther.getYearMonth().isEmpty() && sysUserLevelOther.getYearMonth().substring(0,4).equals(String.valueOf(year))) {
- //年假总时长
- Double yearTime = Double.valueOf(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
-
- String startTime = year + "-01-01 00:00:00";
- String endTime = year + "-12-31 23:59:59";
- Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(), startTime, endTime);
-
- surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime);
- }
- }
- }
- return surplusYearTime;
- }
-
- /**
- * 获取用户年假剩余时长
- */
- @Override
public Double getYearTimeLength(Long userId, String year) {
- //获取年假剩余(新)
- Double surplusYearTime = new Double(0.00);
+ // 默认参数
+ LocalDate targetDate;
+ if (StringUtils.isBlank(year)) {
+ // 未指定年度
+ targetDate = LocalDate.now();
+ year = String.valueOf(targetDate.getYear());
+ } else {
+ // 指定年度
+ targetDate = LocalDate.now().withYear(Integer.parseInt(year)).withDayOfYear(1);
+ }
+
+ // 获取年假剩余(新)
+ BigDecimal surplusYearTime = BigDecimal.ZERO;
+
// 根据用户查询
List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId);
if (sysUserLevelOtherList.size() > 0) {
- for (SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) {
- if (!sysUserLevelOther.getYearMonth().isEmpty() && sysUserLevelOther.getYearMonth().substring(0,4).equals(String.valueOf(year))) {
- //年假总时长
- Double yearTime = Double.valueOf(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
-
- String startTime = year + "-01-01 00:00:00";
- String endTime = year + "-12-31 23:59:59";
- Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(), startTime, endTime);
-
- surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime);
+ SysUserLevelOther sysUserLevelOther = sysUserLevelOtherList.stream().filter(sulo -> {
+ if (sulo.getStartDate() != null && sulo.getEndDate() != null) {
+ return !targetDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate()) && !targetDate.isAfter(sulo.getEndDate().toLocalDateTime().toLocalDate());
+ } else if (sulo.getStartDate() != null) {
+ return !targetDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate());
}
+ return false;
+ }).sorted(Comparator.comparing(SysUserLevelOther::getStartDate).reversed()).findFirst().orElse(null);
+ if (sysUserLevelOther != null) {
+ // 年假总时长
+ BigDecimal yearTime = new BigDecimal(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8);
+ // 当年使用年假时长
+ String startTime = targetDate.withDayOfYear(1).atTime(4, 0, 0, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ String endTime = targetDate.withDayOfYear(1).plusYears(1).atTime(3, 59, 59, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(), startTime, endTime);
+
+ // 获取上年度结余年假时长
+ String lastYear = String.valueOf(Integer.parseInt(year) - 1);
+ BigDecimal lastYearTime = BigDecimal.ZERO;
+ // 查询年度年假记录
+ AnnualLeaveRecordQueryCriteria criteria = new AnnualLeaveRecordQueryCriteria();
+ criteria.setUserId(userId);
+ criteria.setYear(lastYear);
+ AnnualLeaveRecord annualLeaveRecord = annualLeaveRecordRepository.findOne((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)).orElse(null);
+ if (annualLeaveRecord != null) {
+ lastYearTime = new BigDecimal(annualLeaveRecord.getSurplusHour());
+ } else {
+ // 查询本年度且上年度不存在时创建(2026年1月开始运行上年度结算年假制度)
+ if (LocalDate.now().getYear() == Integer.parseInt(year)) {
+ // 去年(剩余年假大于1才可结算至第二年)
+ LocalDate lastYearDate = targetDate.withDayOfYear(1).minusDays(1);
+ SysUserLevelOther lastSysUserLevelOther = sysUserLevelOtherList.stream().filter(sulo -> {
+ if (sulo.getStartDate() != null && sulo.getEndDate() != null) {
+ return !lastYearDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate()) && !lastYearDate.isAfter(sulo.getEndDate().toLocalDateTime().toLocalDate());
+ } else if (sulo.getStartDate() != null) {
+ return !lastYearDate.isBefore(sulo.getStartDate().toLocalDateTime().toLocalDate());
+ }
+ return false;
+ }).sorted(Comparator.comparing(SysUserLevelOther::getStartDate).reversed()).findFirst().orElse(null);
+ if (lastSysUserLevelOther != null) {
+ // 查询上上年度年假记录
+ AnnualLeaveRecordQueryCriteria beforeLastCriteria = new AnnualLeaveRecordQueryCriteria();
+ beforeLastCriteria.setUserId(userId);
+ beforeLastCriteria.setYear(String.valueOf(Integer.parseInt(lastYear) - 1));
+ AnnualLeaveRecord beforeLastAnnualLeaveRecord = annualLeaveRecordRepository.findOne((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, beforeLastCriteria, criteriaBuilder)).orElseGet(AnnualLeaveRecord::new);
+ // 上年度使用年假时长
+ String lastStartTime = targetDate.minusYears(1).withDayOfYear(1).atTime(4, 0, 0, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ String lastEndTime = targetDate.minusYears(1).withDayOfYear(1).plusYears(1).atTime(3, 59, 59, 0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ Double usedLastYearTime = attendanceLeaveRepository.getSurplusYearTime(userId, lastStartTime, lastEndTime);
+ BigDecimal baseLastYearTime = new BigDecimal(lastSysUserLevelOther.getAnnualLeaveDays() == null ? 0 : lastSysUserLevelOther.getAnnualLeaveDays() * 8);
+ BigDecimal surplusTime = baseLastYearTime.add(Optional.ofNullable(beforeLastAnnualLeaveRecord.getSurplusHour()).map(BigDecimal::valueOf).orElse(BigDecimal.ZERO)).subtract(usedLastYearTime == null ? BigDecimal.ZERO : new BigDecimal(usedLastYearTime)).min(baseLastYearTime);
+ lastYearTime = surplusTime.compareTo(BigDecimal.ONE) < 0 ? BigDecimal.ZERO : surplusTime;
+ }
+
+ AnnualLeaveRecord lastRecord = new AnnualLeaveRecord();
+ lastRecord.setUserId(userId);
+ lastRecord.setYear(lastYear);
+ lastRecord.setSurplusHour(lastYearTime.doubleValue());
+
+ annualLeaveRecordRepository.save(lastRecord);
+ }
+ }
+
+ // 计算本年度剩余年假时长
+ surplusYearTime = yearTime.add(lastYearTime).subtract(new BigDecimal(usedYearTime == null ? 0.0 : usedYearTime));
}
}
- return surplusYearTime;
+ return surplusYearTime.doubleValue();
}
/**
@@ -561,11 +594,14 @@
LocalDateTime endLocalDateTime = localDateTime.withDayOfMonth(1).plusMonths(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);
// 因换休3个月后会被结算,只能统计未结算的,仅当前时间3个月内(只参考月份)的可统计。
- LocalDateTime nowLocalDateTime = localDateTime.now().minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
- if (nowLocalDateTime.isBefore(startLocalDateTime) || nowLocalDateTime.isAfter(endLocalDateTime)) {
- return Double.valueOf(0);
+ LocalDateTime currentStartLocalDateTime = localDateTime.now().minusMonths(2L).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
+ LocalDateTime currentEndLocalDateTime = localDateTime.now().withDayOfMonth(1).plusMonths(1).minusDays(1).withHour(23).withMinute(59).withSecond(59).withNano(0);
+ Calculate finalCalculate = new Calculate(currentStartLocalDateTime, currentEndLocalDateTime).getOverlap(new Calculate(startLocalDateTime, endLocalDateTime));
+ if (finalCalculate != null) {
+ startLocalDateTime = finalCalculate.getStart();
+ endLocalDateTime = finalCalculate.getEnd();
} else {
- startLocalDateTime = nowLocalDateTime;
+ return Double.valueOf(0);
}
// 查询可用调休申请
--
Gitblit v1.9.3