Digital Office Automation System Backend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DkJob.java 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.ruoyi.zhushi.job;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ruoyi.zhushi.entity.DkAttendanceGroup;
  4. import com.ruoyi.zhushi.entity.DkCheckInRecord;
  5. import com.ruoyi.zhushi.mapper.DkRecordMapper;
  6. import com.ruoyi.zhushi.util.Constans;
  7. import com.ruoyi.zhushi.util.HolidayUtil;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.scheduling.annotation.Scheduled;
  10. import org.springframework.stereotype.Component;
  11. import java.text.ParseException;
  12. import java.time.LocalDate;
  13. import java.time.LocalDateTime;
  14. import java.util.List;
  15. @Component
  16. public class DkJob {
  17. @Autowired
  18. private DkRecordMapper dkRecordMapper;
  19. // 每天18执行
  20. @Scheduled(cron = "0 0 2 * * ?")
  21. // @Scheduled(cron = "0/10 * * * * ?")
  22. public void executeTask() throws ParseException {
  23. // 任务逻辑
  24. System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  25. try {
  26. // 判断当天时间是否为节假日,为0的时候是工作日
  27. // String yearHoliday = HolidayUtil.isWorkingDay(LocalDate.now().toString());
  28. // if(yearHoliday.equals("0")){
  29. // 获取所有员工
  30. List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers();
  31. for (JSONObject jsonObject : jsonObjects) {
  32. // 获取员工id
  33. Long userId = jsonObject.getLong("userId");
  34. // 如果没有员工id,则跳过
  35. if (userId == null){
  36. continue;
  37. }
  38. // 获取员工姓名
  39. String userName = jsonObject.getString("userName");
  40. // 获取员工昵称
  41. String nickName = jsonObject.getString("nickName");
  42. // 根据userId 查询考勤组信息
  43. DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId);
  44. // 如果没有考勤组信息,则跳过
  45. if(appDTO == null){
  46. continue;
  47. }
  48. // 获取员工打卡记录根据员工id
  49. // List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId);
  50. // if(records == null || records.size() == 0){
  51. DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
  52. dkCheckInRecord.setSysUserId(userId);
  53. dkCheckInRecord.setSysUserName(userName);
  54. dkCheckInRecord.setNickName(nickName);
  55. dkCheckInRecord.setCheckInTime(LocalDateTime.now());
  56. dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0);
  57. dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0);
  58. dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0);
  59. dkCheckInRecord.setAttendanceGroupId(appDTO.getId());
  60. dkCheckInRecord.setAttendanceGroupName(appDTO.getName());
  61. dkRecordMapper.insertOrUpdate(dkCheckInRecord);
  62. // }
  63. }
  64. // }
  65. System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  66. // 具体任务逻辑
  67. } catch (Exception e) {
  68. System.out.println("执行工作日18点定时任务失败:" + e.getMessage());
  69. }
  70. }
  71. // 每周一到周五18点执行
  72. // @Scheduled(cron = "0 0 18 ? * MON-FRI")
  73. public void executeWeekdayTask() {
  74. System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  75. try {
  76. // 获取所有员工
  77. List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers();
  78. for (JSONObject jsonObject : jsonObjects) {
  79. // 获取员工id
  80. Long userId = jsonObject.getLong("userId");
  81. // 如果没有员工id,则跳过
  82. if (userId == null){
  83. continue;
  84. }
  85. // 获取员工姓名
  86. String userName = jsonObject.getString("userName");
  87. // 根据userId 查询考勤组信息
  88. DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId);
  89. // 如果没有考勤组信息,则跳过
  90. if(appDTO == null){
  91. continue;
  92. }
  93. // 获取员工打卡记录根据员工id
  94. List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId);
  95. if(records == null || records.size() == 0){
  96. DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
  97. dkCheckInRecord.setSysUserId(userId);
  98. dkCheckInRecord.setSysUserName(userName);
  99. dkCheckInRecord.setCheckInTime(LocalDateTime.now());
  100. dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0);
  101. dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0);
  102. dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0);
  103. dkCheckInRecord.setAttendanceGroupId(appDTO.getId());
  104. dkCheckInRecord.setAttendanceGroupName(appDTO.getName());
  105. dkRecordMapper.insertOrUpdate(dkCheckInRecord);
  106. }
  107. }
  108. System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  109. // 具体任务逻辑
  110. } catch (Exception e) {
  111. System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  112. }
  113. }
  114. // @Scheduled(cron = "0/10 * * * * MON-FRI") // 每分钟执行
  115. // public void testTask() {
  116. // System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  117. // try {
  118. // // 获取所有员工
  119. // List<JSONObject> jsonObjects = dkRecordMapper.queryAllUsers();
  120. // for (JSONObject jsonObject : jsonObjects) {
  121. // // 获取员工id
  122. // Long userId = jsonObject.getLong("userId");
  123. // // 如果没有员工id,则跳过
  124. // if (userId == null){
  125. // continue;
  126. // }
  127. // // 获取员工姓名
  128. // String userName = jsonObject.getString("userName");
  129. //
  130. // // 根据userId 查询考勤组信息
  131. // DkAttendanceGroup appDTO = dkRecordMapper.queryConfigByUserId(userId);
  132. // // 如果没有考勤组信息,则跳过
  133. // if(appDTO == null){
  134. // continue;
  135. // }
  136. // // 获取员工打卡记录根据员工id
  137. // List<DkCheckInRecord> records = dkRecordMapper.getRecordHistory(userId);
  138. // if(records == null || records.size() == 0){
  139. // DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
  140. // dkCheckInRecord.setSysUserId(userId);
  141. // dkCheckInRecord.setSysUserName(userName);
  142. // dkCheckInRecord.setCheckInTime(LocalDateTime.now());
  143. // dkCheckInRecord.setCheckInStatus(Constans.CHECK_IN_STATUS_0);
  144. // dkCheckInRecord.setClockInStatus(Constans.CHECK_IN_STATUS_0);
  145. // dkCheckInRecord.setClockOutStatus(Constans.CHECK_IN_STATUS_0);
  146. // dkCheckInRecord.setAttendanceGroupId(appDTO.getId());
  147. // dkCheckInRecord.setAttendanceGroupName(appDTO.getName());
  148. // dkRecordMapper.insertOrUpdate(dkCheckInRecord);
  149. // }
  150. //
  151. // }
  152. //
  153. // System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  154. // // 具体任务逻辑
  155. // } catch (Exception e) {
  156. // System.out.println("执行工作日18点定时任务:" + System.currentTimeMillis());
  157. // }
  158. // }
  159. }