| | |
| | | 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;
|
| | |
| | | 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){
|
| | |
| | | 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));
|
| | | }
|
| | |
| | | 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();
|
| | |
| | | userList.add(user);
|
| | | }
|
| | | // 调用0时定时任务
|
| | | dingTalkService.getDingTalkAttendanceList(attendance.getAttendanceDate(), userList);
|
| | | weComService.getWeComAttendanceList(attendance.getAttendanceDate(), userList);
|
| | | // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人
|
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate ,userList);
|
| | | weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
|
| | | }
|
| | |
|
| | | @Autowired
|
| | |
| | | LocalDateTime rosteringLunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime();
|
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime();
|
| | |
|
| | | // 出差信息(出差时无打卡信息,用出差信息补充)
|
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(userId, startOfDate, endOfDate);
|
| | | if (attendanceBusinessTravel != null) {
|
| | | actualWorkStartTime = rosteringWorkStartTime;
|
| | | actualWorkEndTime = rosteringWorkEndTime;
|
| | | }
|
| | |
|
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) {
|
| | | actualWorkStartTime = rosteringWorkStartTime;
|
| | | }
|
| | |
| | | // 休息时间管理
|
| | | List<Calculate> breakParts = new ArrayList<>();
|
| | | breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime));
|
| | |
|
| | | // 出差信息
|
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, startOfDate, endOfDate);
|
| | | attendanceParts.addAll(
|
| | | attendanceBusinessTravelList.stream().map(attendanceBusinessTravel ->
|
| | | new Calculate(attendanceBusinessTravel.getTravelStartTime().toLocalDateTime(), attendanceBusinessTravel.getTravelEndTime().toLocalDateTime())
|
| | | ).collect(Collectors.toList())
|
| | | );
|
| | |
|
| | | // 外出信息
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, startOfDate, endOfDate);
|
| | |
| | | || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType())
|
| | | // || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())
|
| | | ).map(attendanceLeave -> BigDecimal.valueOf(attendanceLeave.getLeaveDuration())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
| | | // TODO: 此方法只用于计算指定日期工时,不可用于钱款统计的工时计算
|
| | | return result.add(annualLeaveHours).doubleValue();
|
| | | }
|
| | |
|
| | |
| | | System.out.print("localDate : " + localDate);
|
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0);
|
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59);
|
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | | if (attendanceBusinessTravel != null) {
|
| | | System.out.println("\t hours1 : " + 8);
|
| | | return BigDecimal.valueOf(8.0);
|
| | | }
|
| | | Attendance attendanceDate = attendanceRepository.findAllByUserIdAndAttendanceDate(criteria.getUserId(), localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
| | | if (attendanceDate == null) {
|
| | | System.out.println("\t hours2 : " + 0);
|
| | |
| | | }
|
| | | return result;
|
| | | }, (o1, o2) -> null);
|
| | |
|
| | | // 出差信息
|
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | | attendanceParts.addAll(
|
| | | attendanceBusinessTravelList.stream().map(attendanceBusinessTravel -> {
|
| | | LocalDateTime attendanceBusinessTravelStart = attendanceBusinessTravel.getTravelStartTime().toLocalDateTime();
|
| | | LocalDateTime attendanceBusinessTravelEnd = attendanceBusinessTravel.getTravelEndTime().toLocalDateTime();
|
| | | if (attendanceBusinessTravelStart.isBefore(rosteringWorkStartTime)) {
|
| | | attendanceBusinessTravelStart = rosteringWorkStartTime;
|
| | | }
|
| | | if (attendanceBusinessTravelEnd.isAfter(rosteringWorkEndTime)) {
|
| | | attendanceBusinessTravelEnd = rosteringWorkEndTime;
|
| | | }
|
| | | return new Calculate(attendanceBusinessTravelStart, attendanceBusinessTravelEnd);
|
| | | }).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList())
|
| | | );
|
| | |
|
| | | // 外出信息
|
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate);
|
| | |
| | | return BigDecimal.valueOf(8.0);
|
| | | }
|
| | | System.out.println("\t hours4 : " + result.add(annualLeaveHours));
|
| | | return result.add(annualLeaveHours);
|
| | | return result.add(annualLeaveHours).min(new BigDecimal(8));
|
| | | }).reduce(BigDecimal::add).get().doubleValue();
|
| | | }
|
| | |
|