BAOLH
2025-05-26 7628b8c8aac18c74d84d202d0c8a86d73b6a3ee4
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
@@ -23,15 +23,9 @@
import me.zhengjie.modules.attendance.service.dto.*;
import me.zhengjie.modules.attendance.service.mapstruct.AttendanceMapper;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl;
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.SysRosteringRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
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;
@@ -74,7 +68,7 @@
    private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
    private final AttendanceGoOutRepository attendanceGoOutRepository;
    private final AttendanceOvertimeRepository attendanceOvertimeRepository;
    private final DingTalkServiceImpl dingTalkService;
    private final WeComServiceImpl weComService;
    @Override
    public Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable){
@@ -91,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));
    }
@@ -172,6 +189,68 @@
                time += StartSeconds.intValue() - 3600;
            }else if(calculate.getStart().toLocalTime().compareTo(LocalTime.NOON) >= 0 && calculate.getStart().toLocalTime().compareTo(calculate.getStart().toLocalDate().atTime(sysRostering.getLunchEndTime()).toLocalTime()) < 0){
                //补充,请假开始时间大于等于中午基准休息时间小于休息结束时间
                time += StartSeconds.intValue() - 3600;
            } else {
                time += StartSeconds.intValue();
            }
        }
        if (endDays > 0) {
            Duration endDuration = Duration.between(calculate.getEnd().toLocalDate().atTime(sysRostering.getWorkStartTime()), calculate.getEnd());
            Long endSeconds = endDuration.getSeconds();
            if (calculate.getEnd().toLocalTime().isAfter(LocalTime.NOON)) {
                time += endSeconds.intValue() - 3600;
            } else {
                time += endSeconds.intValue();
            }
        }
        return time;
    }
    /**
     * 计算时间(小时)包含假期
     * @param userId
     * @return
     */
    @Override
    public Integer calcTimesIncludeHoliday(Calculate calculate, Long userId) {
        User userInfo = userRepository.getOne(userId);
        SysRostering sysRostering = userInfo.getSysRostering();
        // 计算天数
        Integer count = 0;
        Long chronoUnit =  ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate());
        for (Integer i = 0; i <= chronoUnit; i++) {
            count++;
        }
        Calculate startCalculate = new Calculate();
        startCalculate.setStart(calculate.getStart());
        startCalculate.setEnd(calculate.getStart());
        Integer startDays = 0;
        Long startChronoUnit =  ChronoUnit.DAYS.between(startCalculate.getStart().toLocalDate(), startCalculate.getEnd().toLocalDate());
        for (Integer i = 0; i <= startChronoUnit; i++) {
            startDays++;
        }
        Calculate endCalculate = new Calculate();
        endCalculate.setStart(calculate.getEnd());
        endCalculate.setEnd(calculate.getEnd());
        Integer endDays = 0;
        Long endChronoUnit =  ChronoUnit.DAYS.between(endCalculate.getStart().toLocalDate(), endCalculate.getEnd().toLocalDate());
        for (Integer i = 0; i <= endChronoUnit; i++) {
            endDays++;
        }
        Integer time = 0;
        time = (count - startDays - endDays) * 8 * 3600;
        calculate.setStart(formateDateTime(calculate.getStart(), sysRostering));
        calculate.setEnd(formateDateTime(calculate.getEnd(), sysRostering));
        if (startDays > 0) {
            Duration startDuration = Duration.between(calculate.getStart(), calculate.getStart().toLocalDate().atTime(sysRostering.getWorkEndTime()));
            Long StartSeconds = startDuration.getSeconds();
            if (calculate.getStart().toLocalTime().isBefore(LocalTime.NOON)) {
                time += StartSeconds.intValue() - 3600;
            }else if(calculate.getStart().toLocalTime().compareTo(LocalTime.NOON) >= 0 && calculate.getStart().toLocalTime().compareTo(calculate.getStart().toLocalDate().atTime(sysRostering.getLunchEndTime()).toLocalTime()) < 0){
                // 补充,请假开始时间大于等于中午基准休息时间小于休息结束时间
                time += StartSeconds.intValue() - 3600;
            } else {
                time += StartSeconds.intValue();
@@ -286,9 +365,9 @@
            userList.add(user);
        }
        // 调用0时定时任务
        dingTalkService.getDingTalkAttendanceList(attendance.getAttendanceDate(), userList);
        weComService.getWeComAttendanceList(attendance.getAttendanceDate(), userList);
        // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人
        dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate ,userList);
        weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
    }
    @Autowired