定时器失效

pull/2/head
ZhiShuo_Lou 2023-10-29 10:02:29 +08:00
parent 1fef9d675d
commit 1ec02df246
1 changed files with 47 additions and 47 deletions

View File

@ -1,47 +1,47 @@
package com.ruoyi.mybasic.timer;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.mybasic.common.domain.response.PurseResponse;
import com.ruoyi.mybasic.service.PurseServiceTwo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
*
* @author Lou_Zs
*/
@Component
public class SysUserPurse {
@Autowired
private PurseServiceTwo purseServiceTwo;
@Autowired
private RedisService redisService;
//常量
public final static String PURSE_NAME = "PURSE";
/**
*
*/
@Scheduled(cron = "0 0/5 * * * ?")
public void userPurse(){
System.out.println("~~~~~~定时器开始扫描钱包余额~~~~~~");
//获取用户的编号
Long userId = SecurityUtils.getUserId();
//根据用户编号查询用户钱包
PurseResponse purseResponse = purseServiceTwo.purseObject(userId);
if (null == purseResponse){
throw new RuntimeException("查无此用户!");
}
//钱包余额
Integer balanceFee = purseResponse.getBalanceFee();
//将余额存入redis
redisService.setCacheObject(userId + PURSE_NAME,balanceFee);
}
}
//package com.ruoyi.mybasic.timer;
//
//import com.ruoyi.common.redis.service.RedisService;
//import com.ruoyi.common.security.utils.SecurityUtils;
//import com.ruoyi.mybasic.common.domain.response.PurseResponse;
//import com.ruoyi.mybasic.service.PurseServiceTwo;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
///**
// * 钱包余额定时器
// * @author Lou_Zs
// */
//@Component
//public class SysUserPurse {
//
// @Autowired
// private PurseServiceTwo purseServiceTwo;
// @Autowired
// private RedisService redisService;
//
// //常量
// public final static String PURSE_NAME = "PURSE";
//
//
// /**
// * 定时器每五分钟执行
// */
// @Scheduled(cron = "0 0/5 * * * ?")
// public void userPurse(){
// System.out.println("~~~~~~定时器开始扫描钱包余额~~~~~~");
// //获取用户的编号
// Long userId = SecurityUtils.getUserId();
//
// //根据用户编号查询用户钱包
// PurseResponse purseResponse = purseServiceTwo.purseObject(userId);
//
// if (null == purseResponse){
// throw new RuntimeException("查无此用户!");
// }
// //钱包余额
// Integer balanceFee = purseResponse.getBalanceFee();
// //将余额存入redis
// redisService.setCacheObject(userId + PURSE_NAME,balanceFee);
// }
//}