新增定时器redis存储钱包余额
parent
b7ddaceb2d
commit
a1e102a9a6
|
@ -5,6 +5,7 @@ import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
|||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 系统模块
|
||||
|
@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
@EnableCustomSwagger2
|
||||
@EnableRyFeignClients
|
||||
@SpringBootApplication
|
||||
@EnableScheduling //定时器
|
||||
public class MyBasicApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.mybasic.service.Impl;
|
||||
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
import com.ruoyi.mybasic.api.domain.UserMoneyLogs;
|
||||
import com.ruoyi.mybasic.common.domain.Purse;
|
||||
import com.ruoyi.mybasic.common.domain.request.RequestInvitationRecord;
|
||||
|
@ -7,6 +8,7 @@ import com.ruoyi.mybasic.common.domain.response.PurseResponse;
|
|||
import com.ruoyi.mybasic.mapper.InvitationMapper;
|
||||
import com.ruoyi.mybasic.service.InvitationService;
|
||||
import com.ruoyi.mybasic.service.PurseServiceTwo;
|
||||
import com.ruoyi.mybasic.timer.SysUserPurse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -30,6 +32,8 @@ public class InvitationServiceImpl implements InvitationService {
|
|||
private InvitationMapper invitationMapper;
|
||||
@Autowired
|
||||
private PurseServiceTwo purseServiceTwo;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
|
||||
|
@ -131,5 +135,7 @@ public class InvitationServiceImpl implements InvitationService {
|
|||
if (i < 0){
|
||||
throw new RuntimeException("订单未生效!");
|
||||
}
|
||||
//清空redis中的钱包余额数据
|
||||
redisService.deleteObject(userId + SysUserPurse.PURSE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
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(){
|
||||
//获取用户的编号
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
//根据用户编号查询用户钱包
|
||||
PurseResponse purseResponse = purseServiceTwo.purseObject(userId);
|
||||
//钱包余额
|
||||
Integer balanceFee = purseResponse.getBalanceFee();
|
||||
//将余额存入redis
|
||||
redisService.setCacheObject(userId + PURSE_NAME,balanceFee);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue