| | |
| | | package com.ruoyi.web.controller.tool; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.system.service.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.Instant; |
| | | import java.util.*; |
| | | |
| | | |
| | | /** |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class TaskUtil { |
| | | |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void message() { |
| | | try { |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * 每隔一分钟去处理的定时任务 |
| | | */ |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void taskMinute(){ |
| | | try { |
| | | // List<Message> list = messageService.list(); |
| | | // Map<Integer,List<Message>> map = new LinkedHashMap<>(); |
| | | // for (Message message : list) { |
| | | // if (map.get(message.getUserId())==null){ |
| | | // List<Message> messages = new ArrayList<>(); |
| | | // messages.add(message); |
| | | // map.put(message.getUserId(),messages); |
| | | // System.err.println("为空"); |
| | | // }else { |
| | | // List<Message> messages = map.get(message.getUserId()); |
| | | // messages.add(message); |
| | | // map.put(message.getUserId(),messages); |
| | | // } |
| | | // } |
| | | // Object cacheObject = redisCache.getCacheObject("1"); |
| | | // Set<Integer> integers = map.keySet(); |
| | | // for (Integer integer : integers) { |
| | | // redisCache.deleteObject(String.valueOf(integer)); |
| | | // redisCache.setCacheList(String.valueOf(integer),map.get(integer)); |
| | | // List<Message> cacheList = redisCache.getCacheList(String.valueOf(integer)); |
| | | // System.err.println("====="+cacheList); |
| | | // } |
| | | // |
| | | // |
| | | // System.err.println("======="+map); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 每天的凌晨执行的任务 |
| | | */ |
| | | @Scheduled(cron = "0 0 0 * * *") |
| | | public void taskDay(){ |
| | | |
| | | // List<SysRole> sysRoles = roleService.selectListByDelFlag(2); |
| | | // if(CollectionUtils.isEmpty(sysRoles)){ |
| | | // return; |
| | | // } |
| | | // for (SysRole sysRole : sysRoles) { |
| | | // if(sysRole.getRemoveDays()>0){ |
| | | // sysRole.setRemoveDays(sysRole.getRemoveDays()-1); |
| | | // roleService.updateRole(sysRole); |
| | | // }else { |
| | | // roleService.deleteRoleById(sysRole.getRoleId()); |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | /** |
| | | * 每天的凌晨执行的任务 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ? ") |
| | | public void taskDayOne(){ |
| | | } |
| | | |
| | | |
| | | } |