|
|
|
|
|
|
|
|
|
|
|
package com.ruoyi.zhushi.job; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.ruoyi.zhushi.entity.DkAttendanceGroup; |
|
|
|
|
|
import com.ruoyi.zhushi.entity.DkCheckInRecord; |
|
|
|
|
|
import com.ruoyi.zhushi.mapper.DkRecordMapper; |
|
|
|
|
|
import com.ruoyi.zhushi.util.Constans; |
|
|
|
|
|
import com.ruoyi.zhushi.util.TimeUtils; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
|
|
public class DkJob { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DkRecordMapper dkRecordMapper; |
|
|
|
|
|
|
|
|
|
|
|
// @Scheduled(cron = "0/1 0 0 ? * MON-FRI") |
|
|
|
|
|
// public void executeTask() { |
|
|
|
|
|
// // 任务逻辑 |
|
|
|
|
|
// System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 每周一到周五18点执行 |
|
|
|
|
|
@Scheduled(cron = "0 0 18 ? * MON-FRI") |
|
|
|
|
|
public void executeWeekdayTask() { |
|
|
|
|
|
System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
try { |
|
|
|
|
|
// 获取所有员工 |
|
|
|
|
|
List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers(); |
|
|
|
|
|
for (JSONObject jsonObject : jsonObjects) { |
|
|
|
|
|
// 获取员工id |
|
|
|
|
|
Long userId = jsonObject.getLong("userId"); |
|
|
|
|
|
// 如果没有员工id,则跳过 |
|
|
|
|
|
if (userId == null){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
// 获取员工姓名 |
|
|
|
|
|
String userName = jsonObject.getString("userName"); |
|
|
|
|
|
|
|
|
|
|
|
// 根据userId 查询考勤组信息 |
|
|
|
|
|
DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId); |
|
|
|
|
|
// 如果没有考勤组信息,则跳过 |
|
|
|
|
|
if(appDTO == null){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
// 获取员工打卡记录根据员工id |
|
|
|
|
|
List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId); |
|
|
|
|
|
if(records == null || records.size() == 0){ |
|
|
|
|
|
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); |
|
|
|
|
|
dkCheckInRecord.setSysUserId(userId); |
|
|
|
|
|
dkCheckInRecord.setSysUserName(userName); |
|
|
|
|
|
dkCheckInRecord.setCheckInTime(LocalDateTime.now()); |
|
|
|
|
|
dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0); |
|
|
|
|
|
dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0); |
|
|
|
|
|
dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0); |
|
|
|
|
|
dkCheckInRecord.setAttendanceGroupId(appDTO.getId()); |
|
|
|
|
|
dkCheckInRecord.setAttendanceGroupName(appDTO.getName()); |
|
|
|
|
|
dkRecordMapper.insertOrUpdate(dkCheckInRecord); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
// 具体任务逻辑 |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Scheduled(cron = "0/10 * * * * MON-FRI") // 每分钟执行 |
|
|
|
|
|
// public void testTask() { |
|
|
|
|
|
// System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
// try { |
|
|
|
|
|
// // 获取所有员工 |
|
|
|
|
|
// List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers(); |
|
|
|
|
|
// for (JSONObject jsonObject : jsonObjects) { |
|
|
|
|
|
// // 获取员工id |
|
|
|
|
|
// Long userId = jsonObject.getLong("userId"); |
|
|
|
|
|
// // 如果没有员工id,则跳过 |
|
|
|
|
|
// if (userId == null){ |
|
|
|
|
|
// continue; |
|
|
|
|
|
// } |
|
|
|
|
|
// // 获取员工姓名 |
|
|
|
|
|
// String userName = jsonObject.getString("userName"); |
|
|
|
|
|
// |
|
|
|
|
|
// // 根据userId 查询考勤组信息 |
|
|
|
|
|
// DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId); |
|
|
|
|
|
// // 如果没有考勤组信息,则跳过 |
|
|
|
|
|
// if(appDTO == null){ |
|
|
|
|
|
// continue; |
|
|
|
|
|
// } |
|
|
|
|
|
// // 获取员工打卡记录根据员工id |
|
|
|
|
|
// List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId); |
|
|
|
|
|
// if(records == null || records.size() == 0){ |
|
|
|
|
|
// DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); |
|
|
|
|
|
// dkCheckInRecord.setSysUserId(userId); |
|
|
|
|
|
// dkCheckInRecord.setSysUserName(userName); |
|
|
|
|
|
// dkCheckInRecord.setCheckInTime(LocalDateTime.now()); |
|
|
|
|
|
// dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0); |
|
|
|
|
|
// dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0); |
|
|
|
|
|
// dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0); |
|
|
|
|
|
// dkCheckInRecord.setAttendanceGroupId(appDTO.getId()); |
|
|
|
|
|
// dkCheckInRecord.setAttendanceGroupName(appDTO.getName()); |
|
|
|
|
|
// dkRecordMapper.insertOrUpdate(dkCheckInRecord); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
// // 具体任务逻辑 |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis()); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
} |