yaozc2021
2025-04-01 379dc731efb3dbe2f4fb5dc4e2fa38a99360bab9
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
@@ -14,6 +14,7 @@
import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
import me.zhengjie.modules.system.repository.SysRosteringRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.modules.system.service.DictDetailService;
import me.zhengjie.utils.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
@@ -35,7 +36,7 @@
@RequiredArgsConstructor
public class WeComServiceImpl {
    private final WxCpService wxCpService;
    private final NewAttendanceRepository attendanceRepository;
    private final AttendanceRepository attendanceRepository;
    private final UserRepository userRepository;
    private final SysConfigHolidayRepository sysConfigHolidayRepository;
    private final SysRosteringRepository sysRosteringRepository;
@@ -43,6 +44,7 @@
    private final AttendanceLeaveRepository attendanceLeaveRepository;
    private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
    private final AttendanceGoOutRepository attendanceGoOutRepository;
    private final DictDetailService dictDetailService;
    /**
     * 凌晨0点执行,新增用户考勤信息
@@ -69,14 +71,16 @@
        if (ObjectUtils.isEmpty(attendDate) || attendDate.compareTo(Timestamp.valueOf(strTodayDate + " 00:00:00")) <= 0) {
            // 用户列表
            List<User> userList = new ArrayList<>();
            // 获取企业微信考勤白名单
            List<String> excludeList = dictDetailService.getDictByName("wecom_exclude_list").stream().map(i -> i.getValue()).collect(Collectors.toList());
            // 参数用户不为空(考勤按钮调用)
            if (ObjectUtils.isNotEmpty(attUser)) {
                // 用户列表
                userList = attUser;
                userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList());
                userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList());
            } else {
                // 用户列表:查询状态正常的员工
                userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList());
                userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList());
            }
            // 参数日期
            String strAttendDate = "";
@@ -97,11 +101,11 @@
                // 用户排班
                SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getSysRostering().getId());
                // 考勤记录
                NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), (ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate));
                Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), (ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate));
                // 考勤记录为null
                if (ObjectUtil.isEmpty(attendance)) {
                    // 新建考勤记录
                    attendance = new NewAttendance();
                    attendance = new Attendance();
                }
                // 考勤记录
                attendance.setUserId(user.getId());
@@ -164,19 +168,21 @@
            calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00"));
            // 用户列表
            List<User> userList;
            // 获取企业微信考勤白名单
            List<String> excludeList = dictDetailService.getDictByName("wecom_exclude_list").stream().map(i -> i.getValue()).collect(Collectors.toList());
            // 参数用户不为空(考勤按钮调用)
            if (ObjectUtils.isNotEmpty(attUser)) {
                // 用户列表
                userList = attUser;
                userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList());
                userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList());
            } else {
                // 用户列表:查询状态正常的员工
                userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList());
                userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList());
            }
            // 遍历用户列表
            for (User user : userList) {
                // 考勤记录:根据用户和日期查询
                NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate);
                Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate);
                Boolean isHoliday = false;
                if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) {
                    isHoliday = true;
@@ -281,19 +287,21 @@
            calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00"));
            // 用户列表
            List<User> userList;
            // 获取企业微信考勤白名单
            List<String> excludeList = dictDetailService.getDictByName("wecom_exclude_list").stream().map(i -> i.getValue()).collect(Collectors.toList());
            // 参数用户不为空(考勤按钮调用)
            if (ObjectUtils.isNotEmpty(attUser)) {
                // 用户列表
                userList = attUser;
                userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList());
                userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList());
            } else {
                // 用户列表:查询状态正常的员工
                userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList());
                userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList());
            }
            // 遍历用户列表
            for (User user : userList) {
                // 考勤记录:根据用户和日期查询
                NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate);
                Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate);
                Boolean isHoliday = false;
                if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) {
                    isHoliday = true;
@@ -381,7 +389,7 @@
     *
     * @param user
     */
    public NewAttendance updateRecord(User user, NewAttendance attendance, Boolean day, String attendDate) {
    public Attendance updateRecord(User user, Attendance attendance, Boolean day, String attendDate) {
        // 查询考勤请假表
        List<AttendanceLeave> attendanceLeaveLists = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
        for (AttendanceLeave attendanceLeave : attendanceLeaveLists) {
@@ -424,7 +432,7 @@
     * @param startDate
     * @param endDate
     */
    public void getMornOrNoon(User user, NewAttendance attendance, String attendDate, Timestamp startDate, Timestamp endDate, Boolean day) {
    public void getMornOrNoon(User user, Attendance attendance, String attendDate, Timestamp startDate, Timestamp endDate, Boolean day) {
        // 查询考勤请假表
        List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime());
        Double leaveDuration = new Double(0.00);//计算的总时长
@@ -511,7 +519,7 @@
     * @param attendance
     * @param type
     */
    public void updateAttendanceRecord(Double duration, NewAttendance attendance, String type, Boolean day, Double stDuration, Double enDuration) {
    public void updateAttendanceRecord(Double duration, Attendance attendance, String type, Boolean day, Double stDuration, Double enDuration) {
        // 上午排班开始时间到排班午休开始时间的时长
        Integer workMorningTime = calculateTimes(attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime());
        Double result = Double.valueOf(new BigDecimal((float) workMorningTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
@@ -671,7 +679,7 @@
     * @param attendance
     * @param type
     */
    public void setAttendance(Double sDuration, Double eDuration, Double result, Double noonResult, NewAttendance attendance, String type) {
    public void setAttendance(Double sDuration, Double eDuration, Double result, Double noonResult, Attendance attendance, String type) {
        if (ObjectUtils.isEmpty(eDuration) && ObjectUtils.isEmpty(noonResult)) {
            // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时
            if (sDuration >= result) {
@@ -702,7 +710,7 @@
     * @param attendance
     * @param type
     */
    public void setAttendanceStart(Double sDuration, Double eDuration, Double result1, Double result, Double noonResult, NewAttendance attendance, String type) {
    public void setAttendanceStart(Double sDuration, Double eDuration, Double result1, Double result, Double noonResult, Attendance attendance, String type) {
        if (ObjectUtils.isEmpty(eDuration) && sDuration > 0) {
            if ((sDuration + result1) >= result) {
                attendance.setStartClockResults(type);
@@ -746,7 +754,7 @@
     * @param attendance
     * @return
     */
    public Double getDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance, Boolean day) {
    public Double getDuration(Timestamp startDate, Timestamp endDate, Attendance attendance, Boolean day) {
        Double duration = new Double(0.00);
        // 上午总时长
        if (day) {
@@ -773,7 +781,7 @@
        return duration;
    }
    public Double getStartDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance) {
    public Double getStartDuration(Timestamp startDate, Timestamp endDate, Attendance attendance) {
        Double duration = new Double(0.00);
        // 上午总时长
        if (startDate.toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) {
@@ -788,7 +796,7 @@
        return duration;
    }
    public Double getEndDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance) {
    public Double getEndDuration(Timestamp startDate, Timestamp endDate, Attendance attendance) {
        Double duration = new Double(0.00);
        // 下午总时长
        if (startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0) {
@@ -802,6 +810,12 @@
        return duration;
    }
    /**
     * Unix时间戳转Timestamp
     *
     * @param unixtime Unix时间戳
     * @return
     */
    private Timestamp unixtimeToTimestamp(Long unixtime) {
        if (ObjectUtils.isNotEmpty(unixtime)) {
            return new Timestamp(unixtime * 1000);