From 97d2daf71d472fedfd984696836d3ca67e76f42e Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Thu, 16 Jul 2026 09:55:58 +0000
Subject: [PATCH] 工资详情页添加出差和调休相关跳转功能(计算月份修正)
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java | 501 +++++++++++++++++-------------------------------------
1 files changed, 161 insertions(+), 340 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
index 3ec0e87..d213319 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -23,6 +23,7 @@
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.attendance.domain.AttendanceBusinessTravel;
import me.zhengjie.modules.attendance.domain.AttendanceGoOut;
+import me.zhengjie.modules.attendance.domain.Calculate;
import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository;
import me.zhengjie.modules.attendance.repository.AttendanceCardreplacementRepository;
import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository;
@@ -76,10 +77,11 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;
@@ -102,9 +104,7 @@
private final UserCacheManager userCacheManager;
private final OnlineUserService onlineUserService;
private final UserLoginMapper userLoginMapper;
- private final SysLevelRepository sysLevelRepository;
private final SysUserLevelWageRepository sysUserLevelWageRepository;
- private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository;
private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
private final AttendanceRepository attendanceRepository;
private final AttendanceLeaveServiceImpl attendanceLeaveService;
@@ -113,7 +113,6 @@
private final SysConfigHolidayRepository sysConfigHolidayRepository;
private final AttendanceGoOutRepository attendanceGoOutRepository;
private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
- private final SysCompanyRepository sysCompanyRepository;
private final DeptRepository deptRepository;
private final MeritLevelRepository meritLevelRepository;
private final CmnLevelRepository cmnLevelRepository;
@@ -186,9 +185,9 @@
// 判断用户级别工资是否为空
if (sysUserLevelWage != null) {
// 根据ID查询用户级别
- SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
+ CmnLevel cmnLevel = cmnLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(CmnLevel::new);
// 用户
- userDto.get(i).setLevelName(sysLevel.getName());
+ userDto.get(i).setLevelName(cmnLevel.getName());
} else {
// 用户
userDto.get(i).setLevelName(null);
@@ -227,9 +226,9 @@
// 判断用户级别工资是否为空
if (sysUserLevelWage != null) {
// 根据ID查询用户级别
- SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
+ CmnLevel cmnLevel = cmnLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(CmnLevel::new);
// 用户
- userDto.get(i).setLevelName(sysLevel.getName());
+ userDto.get(i).setLevelName(cmnLevel.getName());
} else {
// 用户
userDto.get(i).setLevelName(null);
@@ -474,9 +473,9 @@
// 判断用户级别工资是否为空
if (sysUserLevelWage != null) {
// 根据ID查询用户级别
- SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
+ CmnLevel cmnLevel = cmnLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(CmnLevel::new);
// 用户
- usersDto.get(i).setLevelName(sysLevel.getName());
+ usersDto.get(i).setLevelName(cmnLevel.getName());
} else {
// 用户
usersDto.get(i).setLevelName(null);
@@ -508,9 +507,9 @@
// 判断用户级别工资是否为空
if (sysUserLevelWage != null) {
// 根据ID查询用户级别
- SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
+ CmnLevel cmnLevel = cmnLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(CmnLevel::new);
// 用户
- usersDto.get(i).setLevelName(sysLevel.getName());
+ usersDto.get(i).setLevelName(cmnLevel.getName());
} else {
// 用户
usersDto.get(i).setLevelName(null);
@@ -543,8 +542,6 @@
redisUtils.del(CacheKey.TOTAL_USER);
redisUtils.del("user::AllUser");
userRepository.save(resources);
- // 判断用户级别变更
-// checkUserLevel(resources.getId(), null, resources.getLevelId());
// 判断用户级别变更(新)
checkUserLevelNew(resources);
}
@@ -593,6 +590,7 @@
user.setRoles(resources.getRoles());
user.setDept(resources.getDept());
user.setJobs(resources.getJobs());
+ user.setJobSecond(resources.getJobSecond());
user.setCompanys(resources.getCompanys());
user.setPhone(resources.getPhone());
user.setNickName(resources.getNickName());
@@ -608,10 +606,11 @@
Long tempNewLevelId = user.getLevelId();
redisUtils.del("user::AllUser");
userRepository.save(user);
- // 判断用户级别变更
- checkUserLevel(user.getId(), tempOldLevelId, tempNewLevelId);
-// // 判断用户级别变更(新)
-// checkUserLevelNew(resources, tempOldLevelId, tempNewLevelId);
+ // 判断用户级别变更(新)
+ if (tempOldLevelId != null && tempNewLevelId != null && tempOldLevelId != tempNewLevelId) {
+ checkUserLevelNew(user);
+ }
+
// 清除缓存
delCaches(user.getId(), user.getUsername());
}
@@ -805,11 +804,11 @@
String sdfFirstDate = DateUtil.getFirstDayOfMonthFull(sdfDate);
// 目标年月末字符串
String sdfLastDate = DateUtil.getLastDayOfMonthFull(sdfDate);
- // 出勤天数
+ // 出勤天数, 如果包含双休和节假日,则减去对应天数
List<Attendance> attendanceRecordList = attendanceRepository.findAllByUserAndDate(userId, sdfFirstDate, sdfLastDate);
int numDay = 0;
for (Attendance attendance : attendanceRecordList) {
- if (!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_REST)) {
+ if (!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) && !attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) {
numDay++;
}
}
@@ -829,6 +828,8 @@
// 法定节假日
List<String> holiday = new ArrayList<>();
+ // 调休的工作日
+ List<String> workingHoliday = new ArrayList<>();
// 天数
int shouldWordDays = 0;
List<SysConfigHoliday> holidayConfigurationList = sysConfigHolidayRepository.findAll();
@@ -837,6 +838,8 @@
|| holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)
|| holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) {
holiday.add(sdf.format(holidayConfiguration.getHolidayDate()));
+ } else if (holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)) {
+ workingHoliday.add(sdf.format(holidayConfiguration.getHolidayDate()));
}
}
// 获取当月所有日期
@@ -852,7 +855,7 @@
Calendar calendar = Calendar.getInstance();
calendar.setTime(isWeekEnd);
if (isWeekEnd.compareTo(sdf.parse(todayDay)) <= 0) {
- if (!holiday.contains(date) && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
+ if ((!holiday.contains(date) && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) || workingHoliday.contains(date)) {
shouldWordDays += 1;
}
}
@@ -861,101 +864,144 @@
// 月初到今天应工作时长
returnData.put("Time", num);
- DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
User user = userRepository.getById(userId);
- // 考勤上午时间
- Double attCheckOnDuration = 0.0;
- // 考勤下午时间
- Double attCheckOffDuration = 0.0;
+ List<Calculate> resultParts = new ArrayList<>();
+ List<Calculate> calculateList = new ArrayList<>();
+ List<Calculate> breakParts = new ArrayList<>();
for (Attendance attendance : attendanceRecordList) {
// 上班打卡时间不为空并且打卡状态不为出差外出的考勤记录
- if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
- LocalDateTime attCheckOnTime = attendance.getActualWorkStartTime().toLocalDateTime();
- LocalDateTime scheduleStartTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchStartTime().toString() + ":00", formatter2);
- if (attCheckOnTime.compareTo(scheduleStartTime) <= 0) {
- // 获得两个时间之间的相差值
- Duration duration = Duration.between(attCheckOnTime, scheduleStartTime);
- Long minutes = duration.toMinutes();
- Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP)));
- attCheckOnDuration = attCheckOnDuration + hour;
- }
+ if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) &&
+ !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) &&
+ !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS) &&
+ attendance.getActualWorkStartTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0
+ ) {
+ calculateList.add(new Calculate(attendance.getActualWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime()));
}
// 下班打卡时间不为空并且打卡状态不为出差外出的考勤记录
- if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
- LocalDateTime attCheckOffTime = attendance.getActualWorkEndTime().toLocalDateTime();
- LocalDateTime scheduleEndTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchEndTime().toString() + ":00", formatter2);
- if (attCheckOffTime.compareTo(scheduleEndTime) > 0) {
- // 获得两个时间之间的相差值
- Duration duration = Duration.between(scheduleEndTime, attCheckOffTime);
- Long minutes = duration.toMinutes();
- Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP)));
- attCheckOffDuration = attCheckOffDuration + hour;
- }
+ if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) &&
+ !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) &&
+ !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS) &&
+ attendance.getActualWorkEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) > 0
+ ) {
+ calculateList.add(new Calculate(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getActualWorkEndTime().toLocalDateTime()));
}
+ // 休息时间管理(午休和下班后30分钟)
+ breakParts.add(new Calculate(attendance.getRosteringLunchStartTime().toLocalDateTime(), attendance.getRosteringLunchEndTime().toLocalDateTime()));
+ breakParts.add(new Calculate(attendance.getRosteringWorkEndTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime().plusMinutes(30L)));
}
+ calculateList.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 -> {
+ List<Calculate> currentParts = new ArrayList<>();
+ currentParts.add(calculate);
+ // 去除休息时间:午休、下班后30分钟
+ for (Calculate breakPart : breakParts) {
+ List<Calculate> tempParts = new ArrayList<>();
+ for (Calculate current : currentParts) {
+ if ((current.getStart().isBefore(breakPart.getStart()) && current.getEnd().isAfter(breakPart.getStart()))
+ || (current.getStart().isBefore(breakPart.getEnd()) && current.getEnd().isAfter(breakPart.getEnd()))) {
+ Calculate calculate1 = new Calculate(current.getStart(), breakPart.getStart());
+ Calculate calculate2 = new Calculate(breakPart.getEnd(), current.getEnd());
+ if (calculate1.getStart().isBefore(calculate1.getEnd())) {
+ tempParts.add(calculate1);
+ }
+ if (calculate2.getStart().isBefore(calculate2.getEnd())) {
+ tempParts.add(calculate2);
+ }
+ } else {
+ tempParts.add(current);
+ }
+ }
+ currentParts = tempParts;
+ }
+ // 将处理完所有休息区间后的结果添加到最终结果
+ resultParts.addAll(currentParts);
+ });
+
+ BigDecimal resultTime = resultParts.stream()
+ .map(calculate -> ChronoUnit.SECONDS.between(calculate.getStart(), calculate.getEnd()))
+ .reduce(new BigDecimal(0),
+ (total, current) -> total.add(BigDecimal.valueOf(current)),
+ BigDecimal::add)
+ .divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP
+ );
+
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
String startTime = sdfFirstDate.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime());
String endTime = todayDay.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime());
// 外出时长
Double goOutTimes = 0.0;
// 查询外出表
- List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, Timestamp.valueOf(startTime).toLocalDateTime(), Timestamp.valueOf(endTime).toLocalDateTime());
+ List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, DateUtil.parseAttStartTime(Timestamp.valueOf(startTime).toLocalDateTime()), DateUtil.parseAttEndTime(Timestamp.valueOf(endTime).toLocalDateTime()));
for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) {
goOutTimes = goOutTimes + attendanceGoOut.getOutDuration();
}
// 出差时长
Double bussTimes = 0.0;
// 查询出差表
- List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, Timestamp.valueOf(sdfFirstDate).toLocalDateTime(), Timestamp.valueOf(todayDay.substring(0, 10) + " " + "00:00:00").toLocalDateTime());
+ List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, Timestamp.valueOf(sdfFirstDate).toLocalDateTime(), Timestamp.valueOf(sdfLastDate.substring(0, 10) + " 23:59:59").toLocalDateTime());
for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) {
bussTimes = bussTimes + attendanceBusinessTravel.getTravelDuration();
}
- returnData.put("Times", attCheckOnDuration + attCheckOffDuration + goOutTimes + (bussTimes * 8));
+
+ // 实际工作时长
+ returnData.put("Times", (resultTime.max(BigDecimal.ZERO).doubleValue()) + goOutTimes + (bussTimes * 8));
// 查询某月已完成工时
DecimalFormat decimalFormat = new DecimalFormat("0.##");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(
- Query.query(
- new Criteria("userId").is(userId)
- .and("fillDate")
- .gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime))
- .lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime)))
- .with(Sort.by(Sort.Order.desc("fillDate")))
- , TaskDaliyMongo.class);
+ Query.query(
+ new Criteria("userId").is(userId)
+ .and("fillDate")
+ .gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime))
+ .lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime)))
+ .with(Sort.by(Sort.Order.desc("fillDate")))
+ , TaskDaliyMongo.class);
List<TaskDaliyMongoDto> resultList = daliyMongoList.stream().collect(
- Collectors.groupingBy(
- (TaskDaliyMongo taskDaliyMongo) -> taskDaliyMongo.getTaskUserMongo().getId(),
- Collectors.reducing(
- null,
- (TaskDaliyMongo prev, TaskDaliyMongo cur) -> {
- if (prev == null) {
- if ("1".equals(cur.getTaskUserMongo().getPerformanceType())) {
- cur.setConsumedHours(BigDecimal.valueOf(cur.getTaskUserMongo().getPerformanceHours())
- .multiply(BigDecimal.valueOf(cur.getTaskProgress()))
- .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
- }
- return cur;
- }
- if ("0".equals(cur.getTaskUserMongo().getPerformanceType())) {
- prev.setConsumedHours(prev.getConsumedHours() + cur.getConsumedHours());
- }
- return prev;
- }
+ Collectors.groupingBy(
+ (TaskDaliyMongo taskDaliyMongo) -> taskDaliyMongo.getTaskUserMongo().getId(),
+ Collectors.reducing(
+ null,
+ (TaskDaliyMongo prev, TaskDaliyMongo cur) -> {
+ if (prev == null) {
+ if ("1".equals(cur.getTaskUserMongo().getPerformanceType())) {
+ cur.setConsumedHours(BigDecimal.valueOf(cur.getTaskUserMongo().getPerformanceHours())
+ .multiply(BigDecimal.valueOf(cur.getTaskProgress()))
+ .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
+ }
+ return cur;
+ }
+ if ("0".equals(cur.getTaskUserMongo().getPerformanceType())) {
+ prev.setConsumedHours(prev.getConsumedHours() + cur.getConsumedHours());
+ }
+ return prev;
+ }
+ )
)
- )
).values().stream().map(taskDaliyMongo -> {
if ("1".equals(taskDaliyMongo.getTaskUserMongo().getPerformanceType())) {
// 查询日报表是否存在小于当前月填写的当前任务的日报
List<TaskDaliyMongo> taskDaliyMongoSm = null;
try {
taskDaliyMongoSm = mongoTemplate.find(
- Query.query(new Criteria("userId").is(userId)
- .and("taskUserMongo").is(taskDaliyMongo.getTaskUserMongo())
- .and("fillDate").lt(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)))
- .with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class);
+ Query.query(new Criteria("userId").is(userId)
+ .and("taskUserMongo").is(taskDaliyMongo.getTaskUserMongo())
+ .and("fillDate").lt(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)))
+ .with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class);
} catch (ParseException e) {
throw new RuntimeException(e);
}
@@ -997,28 +1043,47 @@
AttendanceQueryCriteria attendanceQueryCriteria = new AttendanceQueryCriteria();
attendanceQueryCriteria.setUserId(userId);
attendanceQueryCriteria.setTargetYearMonth(sdfDate.substring(0, 7) + "-01");
- Double attendanceOverTimeHours = attendanceService.queryAttendanceOverTimeHours(attendanceQueryCriteria);
+ attendanceQueryCriteria.setDateType(Constant.DATE_TYPE_WEEKDAY);
+ Double attendanceOverTimeHours = attendanceService.queryAttendanceOverTimeHours(attendanceQueryCriteria, null);
returnData.put("attendanceOverTimeHours", attendanceOverTimeHours);
+ Double attendanceHolidayOverTimeHours = attendanceService.queryAttendanceOverTimeHours(attendanceQueryCriteria, Constant.DATE_TYPE_HOLIDAYS);
+ Double attendanceLegalHolidayOverTimeHours = attendanceService.queryAttendanceOverTimeHours(attendanceQueryCriteria, Constant.DATE_TYPE_LEGAL_HOLIDAYS);
+ Double attendanceWeekendHolidayOverTimeHours = attendanceService.queryAttendanceOverTimeHours(attendanceQueryCriteria, Constant.DATE_TYPE_WEEKEND);
+ returnData.put("attendanceHolidayOverTimeHours", attendanceHolidayOverTimeHours + attendanceLegalHolidayOverTimeHours + attendanceWeekendHolidayOverTimeHours);
// 请假时长
AttendanceLeaveQueryCriteria attendanceLeaveQueryCriteria = new AttendanceLeaveQueryCriteria();
attendanceLeaveQueryCriteria.setUserId(userId);
attendanceLeaveQueryCriteria.setLeaveStartTimeLike(sdfDate.substring(0, 7) + "%");
+ attendanceLeaveQueryCriteria.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED);
List<AttendanceLeaveDto> attendanceLeaveDtos = attendanceLeaveService.queryAll(attendanceLeaveQueryCriteria);
- double leaveTimeHours = attendanceLeaveDtos.stream().mapToDouble(AttendanceLeaveDto::getLeaveDuration).sum();
+ double leaveTimeHours = attendanceLeaveDtos.stream().mapToDouble(a -> {
+ if (a.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR)) {
+ return a.getLeaveDuration();
+ } else if (a.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) {
+ return a.getLeaveDuration() * 8;
+ }
+ return 0.0;
+ }).sum();
returnData.put("leaveTimeHours", BigDecimal.valueOf(leaveTimeHours).setScale(2, RoundingMode.HALF_UP).doubleValue());
+ LocalDateTime targetDateTime = yearMonth.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().withDayOfMonth(1).atStartOfDay();
+
// 换休剩余时长
- Double overTime = attendanceLeaveService.getOverTimeLength(userId);
+ Double overTime = attendanceLeaveService.getOverTimeLength(userId, targetDateTime);
returnData.put("overTime", overTime);
- // 待结算换休时长
- Double overTimeClose = attendanceLeaveService.getOverTimeCloseLength(userId);
+ // 待结算(下月即将结算)换休时长
+ Double overTimeClose = attendanceLeaveService.getOverTimeCloseLength(userId, targetDateTime);
returnData.put("overTimeClose", overTimeClose);
+ // 本月结算换休时长
+ Double overTimeCurrentClose = attendanceLeaveService.getOverTimeCurrentCloseLength(userId, targetDateTime);
+ returnData.put("overTimeCurrentClose", overTimeCurrentClose);
+
// 出差天数
- returnData.put("businessDays", attendanceBusinessTravelList.stream().filter(attendanceBusinessTravel -> attendanceBusinessTravel.getCategory().equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_TRAVEL)).count());
- returnData.put("localDays", attendanceBusinessTravelList.stream().filter(attendanceBusinessTravel -> attendanceBusinessTravel.getCategory().equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_SAME_PLACE)).count());
+ returnData.put("businessDays", attendanceBusinessTravelList.stream().filter(attendanceBusinessTravel -> attendanceBusinessTravel.getCategory().equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_TRAVEL) && attendanceBusinessTravel.getApprovalStatus().equals(Constant.BUSSINESS_APPROVE_STATUS_AGREE)).collect(Collectors.toList()).stream().map(AttendanceBusinessTravel::getTravelDuration).reduce(0.0, Double::sum));
+ returnData.put("localDays", attendanceBusinessTravelList.stream().filter(attendanceBusinessTravel -> attendanceBusinessTravel.getCategory().equals(Constant.ATTENDANCE_BUSINESS_TRAVEL_CATEGORY_SAME_PLACE) && attendanceBusinessTravel.getApprovalStatus().equals(Constant.BUSSINESS_APPROVE_STATUS_AGREE)).collect(Collectors.toList()).stream().map(AttendanceBusinessTravel::getTravelDuration).reduce(0.0, Double::sum));
return returnData;
}
@@ -1102,7 +1167,7 @@
List<Map<String, Object>> list = new ArrayList<>();
// for (UserSmallDto userDTO : queryAll) {
// List<String> roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList());
-// String levelName = userDTO.getLevelId() != null ? sysLevelRepository.findById(userDTO.getLevelId()).orElseGet(SysLevel::new).getName() : "";
+// String levelName = userDTO.getLevelId() != null ? cmnLevelRepository.findById(userDTO.getLevelId()).orElseGet(SysLevel::new).getName() : "";
// SysCompany sysCompany = sysCompanyRepository.findById(userDTO.getCompany().getId()).orElseGet(SysCompany::new);
// Map<String, Object> map = new LinkedHashMap<>();
// map.put("用户名", userDTO.getUsername());
@@ -1140,108 +1205,6 @@
*/
private void flushCache(String username) {
userCacheManager.cleanUserCache(username);
- }
-
- /**
- * 判断用户级别变更
- *
- * @param userId
- * @param oldLevelId
- * @param newLevelId
- */
- private void checkUserLevel(Long userId, Long oldLevelId, Long newLevelId) {
- // 查询级别表
- SysLevel sysLevel = sysLevelRepository.findById(newLevelId).orElseGet(SysLevel::new);
- // 判断新旧用户级别ID是否相等
- if (oldLevelId == null) {
- // 创建用户级别工资(旧)
- createSysUserLevelWage(userId, newLevelId);
- // 创建用户级别保险(旧)
- createSysUserLevelInsurance(userId, newLevelId);
-
- } else if (oldLevelId != newLevelId) {
- // 旧用户级别工资
- SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId);
- // 判断旧用户级别工资是否为空
- if (oldSysUserLevelWage != null && oldSysUserLevelWage.getId() != null) {
- // 旧日期字符串
- String oldDateString = oldSysUserLevelWage.getStartDate().toString().substring(0, 10);
- // 获取当前日期
- Date nowDate = new Date();
- // 创建Calendar实例
- Calendar nowCalendar = Calendar.getInstance();
- // 设置当前时间
- nowCalendar.setTime(nowDate);
- // 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10);
- // 判断新、旧日期字符串
- if (oldDateString.equals(nowDateString)) {
- throw new BadRequestException("每天只能调整一次级别,请明日再试!");
- }
- // 设置前一天时间
- nowCalendar.add(Calendar.DATE, -1);
- // 旧用户级别工资
- oldSysUserLevelWage.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
- // 保存
- sysUserLevelWageRepository.save(oldSysUserLevelWage);
- }
- // 创建用户级别工资(旧)
- createSysUserLevelWage(userId, newLevelId);
- // 旧用户级别保险
- SysUserLevelInsurance oldSysUserLevelInsurance = sysUserLevelInsuranceRepository.findLastByUserId(userId);
- // 判断旧用户级别保险是否为空
- if (oldSysUserLevelInsurance != null && oldSysUserLevelInsurance.getId() != null) {
- // 旧日期字符串
- String oldDateString = oldSysUserLevelInsurance.getStartDate().toString().substring(0, 10);
- // 获取当前日期
- Date nowDate = new Date();
- // 创建Calendar实例
- Calendar nowCalendar = Calendar.getInstance();
- // 设置当前时间
- nowCalendar.setTime(nowDate);
- // 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10);
- // 判断新、旧日期字符串
- if (oldDateString.equals(nowDateString)) {
- throw new BadRequestException("每天只能调整一次级别,请明日再试!");
- }
- // 设置前一天时间
- nowCalendar.add(Calendar.DATE, -1);
- // 旧用户级别保险
- oldSysUserLevelInsurance.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
- // 保存
- sysUserLevelInsuranceRepository.save(oldSysUserLevelInsurance);
- }
- // 创建用户级别保险(旧)
- createSysUserLevelInsurance(userId, newLevelId);
- // 旧用户级别其他
- SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId);
- // 判断旧用户级别其他是否为空
- if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) {
- // 旧日期字符串
- String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0, 10);
- // 获取当前日期
- Date nowDate = new Date();
- // 创建Calendar实例
- Calendar nowCalendar = Calendar.getInstance();
- // 设置当前时间
- nowCalendar.setTime(nowDate);
- // 新日期字符串
- String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0, 10);
- // 判断新、旧日期字符串
- if (oldDateString.equals(nowDateString)) {
- throw new BadRequestException("每天只能调整一次级别,请明日再试!");
- }
- // 设置前一天时间
- nowCalendar.add(Calendar.DATE, -1);
- // 旧用户级别保险
- oldSysUserLevelOther.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
- // 保存
- sysUserLevelOtherRepository.save(oldSysUserLevelOther);
- }
- } else {
-
- }
}
/**
@@ -1352,86 +1315,17 @@
* @param cmnLevel
*/
private void createSysUserLevelOther(User resources, CmnLevel cmnLevel) {
- SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM");
- // 获取试用期结束的月初时间
- Timestamp result = getConfirmationTime(resources);
- // 获取实习期结束的年份
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(result);
- int formalYear = calendar.get(Calendar.YEAR);
- // 获取当前年份
- int currentYear = Calendar.getInstance().get(Calendar.YEAR);
+ LocalDate nowLocalDate = LocalDate.now();
-// for (int i = 0; i < 2; i++) {
-// // 第一条记录
-// SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
-// sysUserLevelOther.setUserId(resources.getId());
-// sysUserLevelOther.setLevelId(cmnLevel.getId());
-// sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0));
-//
-// if (i == 1) {
-// // 计算剩余年假
-// Double annualLeave = getAnnualLeave(calendar);
-// sysUserLevelOther.setAnnualLeaveDays(annualLeave);
-// } else {
-// calendar.add(Calendar.YEAR, 1);
-// // 设置月份为一月
-// calendar.set(Calendar.MONTH, Calendar.JANUARY);
-// // 设置月份为一日
-// calendar.set(Calendar.DAY_OF_MONTH, 1);
-//
-// sysUserLevelOther.setAnnualLeaveDays(5.0);
-// }
-// // 年月
-// sysUserLevelOther.setYearMonth(sdf.format(calendar.getTime()));
-//
-//
-// sysUserLevelOtherRepository.save(sysUserLevelOther);
-// }
+ SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
+ sysUserLevelOther.setUserId(resources.getId());
+ sysUserLevelOther.setLevelId(cmnLevel.getId());
+ sysUserLevelOther.setYearMonth(nowLocalDate.format(DateTimeFormatter.ofPattern("yyyy-MM")));
+ sysUserLevelOther.setStartDate(Timestamp.valueOf(nowLocalDate.atStartOfDay()));
+ sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0));
+ sysUserLevelOther.setAnnualLeaveDays(5.0);
- // 添加两条数据
- for (int i = 0; i < 2; i++) {
- if (i == 0) {
- // 第一条记录
- SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
- sysUserLevelOther.setUserId(resources.getId());
- sysUserLevelOther.setLevelId(cmnLevel.getId());
- sysUserLevelOther.setPersonalPerformanceProportion(Double.valueOf(0));
- sysUserLevelOther.setStartDate(Timestamp.valueOf(LocalDate.now().atStartOfDay()));
- // 计算剩余年假
- Double annualLeave = getAnnualLeave(calendar);
- sysUserLevelOther.setAnnualLeaveDays(annualLeave);
- // 判断为今年设置为当前日期
- if (formalYear == currentYear) {
- sysUserLevelOther.setYearMonth(sdf.format(new Date()));
- } else {
- // 设置为明年转正日期
- sysUserLevelOther.setYearMonth(sdf.format(calendar.getTime()));
- }
- sysUserLevelOtherRepository.save(sysUserLevelOther);
- } else {
- // 第二条记录
- SysUserLevelOther sysUserLevelOther1 = new SysUserLevelOther();
- sysUserLevelOther1.setUserId(resources.getId());
- sysUserLevelOther1.setLevelId(cmnLevel.getId());
- Calendar calendar1 = Calendar.getInstance();
- calendar1.add(Calendar.YEAR, 1);
- // 设置月份为一月
- calendar1.set(Calendar.MONTH, Calendar.JANUARY);
- calendar1.set(Calendar.DAY_OF_MONTH, 1);
- sysUserLevelOther1.setPersonalPerformanceProportion(Double.valueOf(0));
- sysUserLevelOther1.setAnnualLeaveDays(5.0);
- // 判断实习期结束日期的年份不是今年,年份加1
- if (formalYear != currentYear) {
- // 在增加一年
- calendar1.add(Calendar.YEAR, 1);
- }
- // 日期设置为 明年/后年 年初
- sysUserLevelOther1.setYearMonth(sdf.format(calendar1.getTime()));
- sysUserLevelOther1.setStartDate(new Timestamp(calendar1.getTimeInMillis()));
- sysUserLevelOtherRepository.save(sysUserLevelOther1);
- }
- }
+ sysUserLevelOtherRepository.save(sysUserLevelOther);
}
/**
@@ -1458,78 +1352,5 @@
calendar.set(Calendar.DAY_OF_MONTH, 1);
result = new Timestamp(calendar.getTimeInMillis());
return result;
- }
-
- /**
- * 获取年假
- * @param calendar
- * @return
- */
- private Double getAnnualLeave(Calendar calendar) {
- // 转正的月份
- int joinMonth = calendar.get(Calendar.MONTH);
- Double annualLeave = 0.0;
- int remainingMonths = 12 - joinMonth;
- // 计算年假天数
- annualLeave = (5.0 / 12) * remainingMonths;
- BigDecimal big = new BigDecimal(annualLeave);
- big = big.setScale(1, BigDecimal.ROUND_HALF_UP);
- annualLeave = big.doubleValue();
- return annualLeave;
- }
-
-
- /**
- * 创建用户级别工资(旧)
- *
- * @param userId
- * @param levelId
- */
- private void createSysUserLevelWage(Long userId, Long levelId) {
- // 级别
- SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new);
- // 用户级别工资
- SysUserLevelWage sysUserLevelWage = new SysUserLevelWage();
- sysUserLevelWage.setUserId(userId);
- sysUserLevelWage.setLevelId(levelId);
- sysUserLevelWage.setStartDate(new Timestamp(new Date().getTime()));
- sysUserLevelWage.setLevelWage(sysLevel.getLevelWage());
- sysUserLevelWage.setBasicWageProportion(sysLevel.getBasicWageProportion());
- sysUserLevelWage.setAchievementsWageProportion(sysLevel.getAchievementsWageProportion());
- sysUserLevelWage.setPerformanceWageProportion(sysLevel.getPerformanceWageProportion());
- sysUserLevelWage.setTeamWageProportion(sysLevel.getTeamWageProportion());
- // 保存
- sysUserLevelWageRepository.save(sysUserLevelWage);
- }
-
- // 创建用户级别保险(旧)
- private void createSysUserLevelInsurance(Long userId, Long levelId) {
- // 级别
- SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new);
- // 用户级别工资
- SysUserLevelInsurance sysUserLevelInsurance = new SysUserLevelInsurance();
- sysUserLevelInsurance.setUserId(userId);
- sysUserLevelInsurance.setLevelId(levelId);
- sysUserLevelInsurance.setStartDate(new Timestamp(new Date().getTime()));
- sysUserLevelInsurance.setAccumulationRadix(sysLevel.getAccumulationRadix());
- sysUserLevelInsurance.setAccumulationPersonalProportion(sysLevel.getAccumulationPersonalProportion());
- sysUserLevelInsurance.setAccumulationCompanyProportion(sysLevel.getAccumulationCompanyProportion());
- sysUserLevelInsurance.setPensionRadix(sysLevel.getPensionRadix());
- sysUserLevelInsurance.setPensionPersonalProportion(sysLevel.getPensionPersonalProportion());
- sysUserLevelInsurance.setPensionCompanyProportion(sysLevel.getPensionCompanyProportion());
- sysUserLevelInsurance.setMedicalRadix(sysLevel.getMedicalRadix());
- sysUserLevelInsurance.setMedicalPersonalProportion(sysLevel.getMedicalPersonalProportion());
- sysUserLevelInsurance.setMedicalCompanyProportion(sysLevel.getMedicalCompanyProportion());
- sysUserLevelInsurance.setUnemploymentRadix(sysLevel.getUnemploymentRadix());
- sysUserLevelInsurance.setUnemploymentPersonalProportion(sysLevel.getUnemploymentPersonalProportion());
- sysUserLevelInsurance.setUnemploymentCompanyProportion(sysLevel.getUnemploymentCompanyProportion());
- sysUserLevelInsurance.setMaternityRadix(sysLevel.getMaternityRadix());
- sysUserLevelInsurance.setMaternityPersonalProportion(sysLevel.getMaternityPersonalProportion());
- sysUserLevelInsurance.setMaternityCompanyProportion(sysLevel.getMaternityCompanyProportion());
- sysUserLevelInsurance.setIndustrialInjuryRadix(sysLevel.getIndustrialInjuryRadix());
- sysUserLevelInsurance.setIndustrialInjuryPersonalProportion(sysLevel.getIndustrialInjuryPersonalProportion());
- sysUserLevelInsurance.setIndustrialInjuryCompanyProportion(sysLevel.getIndustrialInjuryCompanyProportion());
- // 保存
- sysUserLevelInsuranceRepository.save(sysUserLevelInsurance);
}
}
--
Gitblit v1.9.3