| | |
| | | package me.zhengjie.modules.quartz.task; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceRepository; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.dto.OapiDingTalkAccessToken; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.quartz.service.dto.OapiDingTalkRecordResult; |
| | | import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl; |
| | | 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.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.SysRosteringRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 钉钉定时任务(取考勤记录) |
| | | */ |
| | |
| | | @Async |
| | | public class OapiDingTalkMethod { |
| | | |
| | | private final AttendanceRepository attendanceRepository; |
| | | |
| | | private final UserRepository userRepository; |
| | | |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | |
| | | private final SysRosteringRepository sysRosteringRepository; |
| | | |
| | | private final DingTalkServiceImpl dingTalkService; |
| | | |
| | | |
| | | /** |
| | | * 每天0点执行,新增用户考勤信息 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | public void getDingTalkAttendanceList() throws Exception { |
| | | //查询状态正常的员工 |
| | | List<User> userList = getUserList(); |
| | | //获取今天时间 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String todayDate = df.format(new Date()); |
| | | //获取当前时间 |
| | | Calendar calTodayDay = Calendar.getInstance(); |
| | | calTodayDay.setTime(Timestamp.valueOf(todayDate + " 00:00:00")); |
| | | //查询节假日表是否有记录 |
| | | SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(todayDate); |
| | | //遍历在职员工向考勤记录添加数据 |
| | | for (User user : userList){ |
| | | if(ObjectUtils.isNotEmpty(user.getDingding())){ |
| | | //查询当前用户的排班 |
| | | SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getSysRostering().getId()); |
| | | //查询考勤记录是否存在 |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), todayDate); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | if (ObjectUtil.isEmpty(attendance)) { |
| | | attendance = new Attendance(); |
| | | } |
| | | //添加记录 |
| | | attendance.setUserId(user.getId()); |
| | | Date date = df.parse(todayDate); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String today=sdf.format(date); |
| | | attendance.setAttendanceDate(Timestamp.valueOf(today)); |
| | | //状态为等待 |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_WAITFOR); |
| | | if(calTodayDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && sysConfigHoliday == null || calTodayDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY && sysConfigHoliday == null){ |
| | | //双休 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND); |
| | | }else if(sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)){ |
| | | //法定 |
| | | attendance.setDateType(Constant.DATE_TYPE_LEGAL_HOLIDAYS); |
| | | }else{ |
| | | //除了法定节假日和双休都属于工作日 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY); |
| | | } |
| | | |
| | | attendance.setRosteringWorkStartTime(Timestamp.valueOf(todayDate + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime()))); |
| | | attendance.setRosteringWorkEndTime(Timestamp.valueOf(todayDate + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime()))); |
| | | attendance.setRosteringLunchStartTime(Timestamp.valueOf(todayDate + " " + dateTimeFormatter.format(sysRostering.getLunchStartTime()))); |
| | | attendance.setRosteringLunchEndTime(Timestamp.valueOf(todayDate + " " + dateTimeFormatter.format(sysRostering.getLunchEndTime()))); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } |
| | | dingTalkService.getDingTalkAttendanceList(null); |
| | | } |
| | | |
| | | /** |
| | | * 定时任务调用 |
| | | *中午晚上定时任务调用 |
| | | */ |
| | | public void getDingTalkAttendance() throws Exception { |
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(null,null); |
| | | } |
| | | |
| | | /** |
| | | * 查询用户 |
| | | */ |
| | | public List<User> getUserList(){ |
| | | List<User> userList = userRepository.findAllByEnabled(true); |
| | | return userList; |
| | | } |
| | | } |