From 1a4f300568a44f17153fb405efdee6baccb64869 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 29 一月 2026 14:25:55 +0800
Subject: [PATCH] 增加定时任务1.每个月清理一次已读数据2.每15分钟刷新培训计划状态
---
src/main/java/com/ruoyi/ScheduleTask.java | 58 +++++++++++++++++++++++++++++
src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java | 3 +
src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java | 31 ++++++++-------
src/main/java/com/ruoyi/safe/service/impl/SafeTrainingServiceImpl.java | 18 ++++++---
4 files changed, 90 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/ruoyi/ScheduleTask.java b/src/main/java/com/ruoyi/ScheduleTask.java
new file mode 100644
index 0000000..9913292
--- /dev/null
+++ b/src/main/java/com/ruoyi/ScheduleTask.java
@@ -0,0 +1,58 @@
+package com.ruoyi;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.project.system.domain.SysNotice;
+import com.ruoyi.project.system.mapper.SysNoticeMapper;
+import com.ruoyi.safe.mapper.SafeTrainingMapper;
+import com.ruoyi.safe.pojo.SafeTraining;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+@Component
+//瀹氭椂浠诲姟姹囨��
+public class ScheduleTask {
+
+ @Autowired
+ private SafeTrainingMapper safeTrainingMapper;
+
+ @Autowired
+ private SysNoticeMapper noticeMapper;
+
+ //瀹氭椂浠诲姟(15鍒嗛挓鎵ц涓�娆�--鍒ゆ柇鍩硅璁″垝鏁版嵁,鐘舵�佸仛鍙樻洿)
+ @Scheduled(cron = "0 0/15 * * * ?")
+ public void testScheduleTask() {
+ List<SafeTraining> safeTrainings = safeTrainingMapper.selectList(Wrappers.<SafeTraining>lambdaQuery().ne(SafeTraining::getState, 2));
+ if (safeTrainings.size() > 0) {
+ for (SafeTraining safeTraining : safeTrainings) {
+ //鏍规嵁鏃堕棿鍒ゆ柇鍩硅鐘舵��
+ String trainingDate = safeTraining.getTrainingDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+ LocalDateTime openingTime = LocalDateTime.parse((trainingDate + safeTraining.getOpeningTime()), DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss"));
+ LocalDateTime endTime = LocalDateTime.parse((trainingDate + safeTraining.getEndTime()), DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss"));
+ if (LocalDateTime.now().isBefore(openingTime)) {
+ //鏈紑濮�
+ safeTraining.setState(0);
+ } else if (LocalDateTime.now().isAfter(endTime)) {
+ //宸茬粨鏉�
+ safeTraining.setState(2);
+ } else {
+ //杩涜涓�
+ safeTraining.setState(1);
+ }
+ safeTrainingMapper.updateById(safeTraining);
+ }
+ }
+ }
+
+ //宸茶鏁版嵁鍋氫竴涓畾鏃朵换鍔�(姣忔湀1鍙�1鐐规竻鐞嗕竴娆′笂涓湀宸茶鏁版嵁)
+ @Scheduled(cron = "0 0 1 1 * ?")
+ public void cleanReadData() {
+ noticeMapper.delete(Wrappers.<SysNotice>lambdaQuery()
+ .eq(SysNotice::getStatus,"1")
+ .lt(SysNotice::getCreateTime, LocalDateTime.now()));
+ }
+}
diff --git a/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java b/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
index 0b4dae4..942a700 100644
--- a/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
+++ b/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
@@ -1,19 +1,22 @@
package com.ruoyi.project.system.mapper;
import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.project.system.domain.SysDept;
/**
* 閮ㄩ棬绠$悊 鏁版嵁灞�
- *
+ *
* @author ruoyi
*/
+@Mapper
public interface SysDeptMapper
{
/**
* 鏌ヨ閮ㄩ棬绠$悊鏁版嵁
- *
+ *
* @param dept 閮ㄩ棬淇℃伅
* @return 閮ㄩ棬淇℃伅闆嗗悎
*/
@@ -21,7 +24,7 @@
/**
* 鏍规嵁瑙掕壊ID鏌ヨ閮ㄩ棬鏍戜俊鎭�
- *
+ *
* @param roleId 瑙掕壊ID
* @param deptCheckStrictly 閮ㄩ棬鏍戦�夋嫨椤规槸鍚﹀叧鑱旀樉绀�
* @return 閫変腑閮ㄩ棬鍒楄〃
@@ -30,7 +33,7 @@
/**
* 鏍规嵁閮ㄩ棬ID鏌ヨ淇℃伅
- *
+ *
* @param deptId 閮ㄩ棬ID
* @return 閮ㄩ棬淇℃伅
*/
@@ -38,7 +41,7 @@
/**
* 鏍规嵁ID鏌ヨ鎵�鏈夊瓙閮ㄩ棬
- *
+ *
* @param deptId 閮ㄩ棬ID
* @return 閮ㄩ棬鍒楄〃
*/
@@ -46,7 +49,7 @@
/**
* 鏍规嵁ID鏌ヨ鎵�鏈夊瓙閮ㄩ棬锛堟甯哥姸鎬侊級
- *
+ *
* @param deptId 閮ㄩ棬ID
* @return 瀛愰儴闂ㄦ暟
*/
@@ -54,7 +57,7 @@
/**
* 鏄惁瀛樺湪瀛愯妭鐐�
- *
+ *
* @param deptId 閮ㄩ棬ID
* @return 缁撴灉
*/
@@ -62,7 +65,7 @@
/**
* 鏌ヨ閮ㄩ棬鏄惁瀛樺湪鐢ㄦ埛
- *
+ *
* @param deptId 閮ㄩ棬ID
* @return 缁撴灉
*/
@@ -70,7 +73,7 @@
/**
* 鏍¢獙閮ㄩ棬鍚嶇О鏄惁鍞竴
- *
+ *
* @param deptName 閮ㄩ棬鍚嶇О
* @param parentId 鐖堕儴闂↖D
* @return 缁撴灉
@@ -79,7 +82,7 @@
/**
* 鏂板閮ㄩ棬淇℃伅
- *
+ *
* @param dept 閮ㄩ棬淇℃伅
* @return 缁撴灉
*/
@@ -87,7 +90,7 @@
/**
* 淇敼閮ㄩ棬淇℃伅
- *
+ *
* @param dept 閮ㄩ棬淇℃伅
* @return 缁撴灉
*/
@@ -95,14 +98,14 @@
/**
* 淇敼鎵�鍦ㄩ儴闂ㄦ甯哥姸鎬�
- *
+ *
* @param deptIds 閮ㄩ棬ID缁�
*/
public void updateDeptStatusNormal(Long[] deptIds);
/**
* 淇敼瀛愬厓绱犲叧绯�
- *
+ *
* @param depts 瀛愬厓绱�
* @return 缁撴灉
*/
@@ -110,7 +113,7 @@
/**
* 鍒犻櫎閮ㄩ棬绠$悊淇℃伅
- *
+ *
* @param deptId 閮ㄩ棬ID
* @return 缁撴灉
*/
diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
index bf794b5..679514d 100644
--- a/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.project.system.service.impl;
+import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -22,6 +23,7 @@
import com.ruoyi.project.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.domain.SysNotice;
import com.ruoyi.project.system.mapper.SysNoticeMapper;
@@ -210,4 +212,5 @@
sysNotice.setTenantId(tenantId);
return sysNotice;
}
+
}
diff --git a/src/main/java/com/ruoyi/safe/service/impl/SafeTrainingServiceImpl.java b/src/main/java/com/ruoyi/safe/service/impl/SafeTrainingServiceImpl.java
index 0c1f1d1..0179898 100644
--- a/src/main/java/com/ruoyi/safe/service/impl/SafeTrainingServiceImpl.java
+++ b/src/main/java/com/ruoyi/safe/service/impl/SafeTrainingServiceImpl.java
@@ -10,6 +10,7 @@
import com.ruoyi.common.utils.HackLoopTableRenderPolicy;
import com.ruoyi.production.pojo.ProductOrder;
import com.ruoyi.production.pojo.ProductWorkOrder;
+import com.ruoyi.project.system.domain.SysNotice;
import com.ruoyi.safe.dto.SafeTrainingDetailsDto;
import com.ruoyi.safe.dto.SafeTrainingDto;
import com.ruoyi.safe.mapper.SafeTrainingDetailsMapper;
@@ -21,15 +22,20 @@
import com.ruoyi.safe.service.SafeTrainingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -106,12 +112,12 @@
@Override
public SafeTrainingDto getSafeTraining(Long id) {
//涓昏〃鏁版嵁
- SafeTrainingDto safeTrainingDto=safeTrainingMapper.getSafeTraining(id);
+ SafeTrainingDto safeTrainingDto = safeTrainingMapper.getSafeTraining(id);
//闄勪欢
List<SafeTrainingFile> safeTrainingFiles = safeTrainingFileMapper.selectList(Wrappers.<SafeTrainingFile>lambdaQuery().eq(SafeTrainingFile::getSafeTrainingId, id));
safeTrainingDto.setSafeTrainingFileList(safeTrainingFiles);
//鍩硅璁板綍璇︽儏
- List<SafeTrainingDetailsDto> safeTrainingDetailsDto=safeTrainingDetailsMapper.getSafeTraining(id);
+ List<SafeTrainingDetailsDto> safeTrainingDetailsDto = safeTrainingDetailsMapper.getSafeTraining(id);
safeTrainingDto.setSafeTrainingDetailsDtoList(safeTrainingDetailsDto);
return safeTrainingDto;
}
@@ -132,16 +138,16 @@
//鍒犻櫎涓昏〃
safeTrainingMapper.deleteBatchIds(ids);
//鍒犻櫎闄勪欢
- safeTrainingFileMapper.delete(Wrappers.<SafeTrainingFile>lambdaQuery().in(SafeTrainingFile::getSafeTrainingId,ids));
+ safeTrainingFileMapper.delete(Wrappers.<SafeTrainingFile>lambdaQuery().in(SafeTrainingFile::getSafeTrainingId, ids));
//鍒犻櫎鍩硅璁板綍
- safeTrainingDetailsMapper.delete(Wrappers.<SafeTrainingDetails>lambdaQuery().in(SafeTrainingDetails::getSafeTrainingId,ids));
+ safeTrainingDetailsMapper.delete(Wrappers.<SafeTrainingDetails>lambdaQuery().in(SafeTrainingDetails::getSafeTrainingId, ids));
return 0;
}
@Override
public void export(HttpServletResponse response, Long id) {
SafeTrainingDto safeTrainingDto = safeTrainingMapper.getSafeTraining(id);
- List<SafeTrainingDetailsDto> safeTrainingDetailsDtoList=safeTrainingDetailsMapper.getSafeTraining(id);
+ List<SafeTrainingDetailsDto> safeTrainingDetailsDtoList = safeTrainingDetailsMapper.getSafeTraining(id);
InputStream inputStream = this.getClass().getResourceAsStream("/static/safe-training.docx");
Configure configure = Configure.builder()
.bind("safeTrainingDetailsDtoList", new HackLoopTableRenderPolicy())
@@ -155,7 +161,7 @@
try {
response.setContentType("application/msword");
String fileName = URLEncoder.encode(
- safeTrainingDto.getCourseCode()+"鍩硅涓庤�冩牳璁″垝", "UTF-8");
+ safeTrainingDto.getCourseCode() + "鍩硅涓庤�冩牳璁″垝", "UTF-8");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-disposition",
"attachment;filename=" + fileName + ".docx");
--
Gitblit v1.9.3