From 6ce655e8911e0b1fd54c3b73cc393154e6045dae Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Fri, 25 Apr 2025 01:15:23 +0000
Subject: [PATCH] Merge branch 'wcd' into wcd-2411-update
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java | 138 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 127 insertions(+), 11 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 85d34bc..d246573 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
@@ -24,16 +24,12 @@
import me.zhengjie.modules.attendance.service.mapstruct.AttendanceMapper;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
-import me.zhengjie.modules.system.domain.Role;
-import me.zhengjie.modules.system.domain.SysConfigHoliday;
-import me.zhengjie.modules.system.domain.SysRostering;
-import me.zhengjie.modules.system.domain.User;
-import me.zhengjie.modules.system.repository.DictDetailRepository;
-import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
-import me.zhengjie.modules.system.repository.UserRepository;
+import me.zhengjie.modules.system.domain.*;
+import me.zhengjie.modules.system.repository.*;
import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria;
import me.zhengjie.utils.*;
import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -89,6 +85,29 @@
attendanceDto.setUserName(user.getNickName());
return attendanceDto;
}
+ };
+ return PageUtil.toPage(page.map(func));
+ }
+
+ @Override
+ public Map<String,Object> queryAllNotNormal(AttendanceQueryCriteria criteria, Pageable pageable) {
+
+ if (criteria.getUserId() == null) {
+ List<String> wecomExcludeList = dictDetailRepository.findByDictName("wecom_exclude_list").stream().map(DictDetail::getValue).collect(Collectors.toList());
+ criteria.setUserIds(userRepository.findAllByEnabled(true).stream().filter(user ->!wecomExcludeList.contains(user.getWeComId())).map(User::getId).collect(Collectors.toList()));
+ }
+
+ criteria.setStartClockResultsList(Arrays.asList(Constant.ATTENDANCE_START_EARLY, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME));
+ criteria.setEndClockResultsList(Arrays.asList(Constant.ATTENDANCE_START_EARLY, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME));
+ Page<Attendance> page = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
+ //将实体转换为Dto(重写)
+ Function<Attendance, AttendanceDto> func = attendance -> {
+ // 将实体类转换成DTO
+ AttendanceDto attendanceDto = attendanceMapper.toDto(attendance);
+ //查询用户信息
+ User user = userRepository.findById(attendanceDto.getUserId()).orElseGet(User::new);
+ attendanceDto.setUserName(user.getNickName());
+ return attendanceDto;
};
return PageUtil.toPage(page.map(func));
}
@@ -287,6 +306,74 @@
weComService.getWeComAttendanceList(attendance.getAttendanceDate(), userList);
// 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人
weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
+ }
+
+ @Autowired
+ private SysRosteringRepository sysRosteringRepository;
+
+ @Override
+ public void generateAttendance(Long id, String startDate, String endDate) {
+ Stream.iterate(LocalDate.parse(startDate), date -> date.plusDays(1))
+ .limit(ChronoUnit.DAYS.between(LocalDate.parse(startDate), LocalDate.parse(endDate)) + 1).forEach(date -> {
+ User user = userRepository.findById(id).get();
+ // 用户排班
+ SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getSysRostering().getId());
+ // 考勤记录
+ Attendance attendance = new Attendance();
+
+ SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+
+ // 时间格式化
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+
+ // 考勤记录
+ attendance.setUserId(user.getId());
+ attendance.setAttendanceDate(Timestamp.valueOf(date.atStartOfDay()));
+ // 考勤日期类是否是周末、节假日、工作日
+ if (sysConfigHoliday == null && (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY)) {
+ attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST);
+ attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST);
+ attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST);
+ attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST);
+ // 考勤记录:日期类型-双休
+ attendance.setDateType(Constant.DATE_TYPE_WEEKEND);
+ } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) {
+ attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST);
+ attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST);
+ attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST);
+ attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST);
+ // 考勤记录:日期类型-节假日
+ attendance.setDateType(Constant.DATE_TYPE_LEGAL_HOLIDAYS);
+ } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) {
+ attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST);
+ attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST);
+ attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST);
+ attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST);
+ // 考勤记录:日期类型-法定节假日
+ attendance.setDateType(Constant.DATE_TYPE_HOLIDAYS);
+ } else {
+ attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NORMAL);
+ attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NORMAL);
+ attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL);
+ attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL);
+
+ attendance.setActualWorkStartTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime())));
+ attendance.setActualWorkEndTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime())));
+
+ // 考勤记录:日期类型-工作日
+ attendance.setDateType(Constant.DATE_TYPE_WEEKDAY);
+ }
+
+ // 考勤记
+ attendance.setRosteringWorkStartTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime())));
+ attendance.setRosteringWorkEndTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime())));
+ attendance.setRosteringLunchStartTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getLunchStartTime())));
+ attendance.setRosteringLunchEndTime(Timestamp.valueOf(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " " + dateTimeFormatter.format(sysRostering.getLunchEndTime())));
+
+ // 保存
+ attendanceRepository.save(attendance);
+ });
+
}
@Override
@@ -617,6 +704,38 @@
List<Calculate> breakParts = new ArrayList<>();
breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime));
+ // 请假信息
+ List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(criteria.getUserId(), startOfDate, endOfDate);
+ breakParts.addAll(
+ attendanceLeaveList.stream().map(attendanceLeave -> {
+ LocalDateTime attendanceLeaveStart = attendanceLeave.getLeaveStartTime().toLocalDateTime();
+ LocalDateTime attendanceLeaveEnd = attendanceLeave.getLeaveEndTime().toLocalDateTime();
+ if (attendanceLeaveStart.isBefore(rosteringWorkStartTime)) {
+ attendanceLeaveStart = rosteringWorkStartTime;
+ }
+ if (attendanceLeaveEnd.isAfter(rosteringWorkEndTime)) {
+ attendanceLeaveEnd = rosteringWorkEndTime;
+ }
+ return new Calculate(attendanceLeaveStart, attendanceLeaveEnd);
+ }
+ ).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<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate);
attendanceParts.addAll(
@@ -650,7 +769,7 @@
return result;
}, (o1, o2) -> null).forEach(calculate -> {
// 去除休息时间:午休等
- for (Calculate breakPart : breakParts) {
+ 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());
@@ -674,9 +793,6 @@
(total, current) -> total.add(BigDecimal.valueOf(current)),
(o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP
);
-
- // 请假信息
- List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(criteria.getUserId(), startOfDate, endOfDate);
// 年假不扣工时
BigDecimal annualLeaveHours = attendanceLeaveList.stream()
.filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType())
--
Gitblit v1.9.3