From a015fa8520cb9991379b7e4a5599d298900e0ef1 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Mon, 5 Aug 2024 14:54:53 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E6=AF=8F=E6=99=9A=E4=B8=80=E7=82=B9?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BC=9A=E5=91=98=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/luoo/user/UserApplication.java | 2 ++ .../java/com/luoo/user/dao/UserInfoDao.java | 4 +++ .../luoo/user/quartz/MembershipQuartz.java | 31 +++++++++++++++++++ .../luoo/user/service/UserInfoService.java | 9 ++++++ 4 files changed, 46 insertions(+) create mode 100644 luoo_user/src/main/java/com/luoo/user/quartz/MembershipQuartz.java diff --git a/luoo_user/src/main/java/com/luoo/user/UserApplication.java b/luoo_user/src/main/java/com/luoo/user/UserApplication.java index caf5e89..8283c7c 100644 --- a/luoo_user/src/main/java/com/luoo/user/UserApplication.java +++ b/luoo_user/src/main/java/com/luoo/user/UserApplication.java @@ -11,6 +11,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import util.IdWorker; import util.JwtUtil; @@ -24,6 +25,7 @@ import java.net.UnknownHostException; @EnableEurekaClient @EnableJpaAuditing @EnableAsync +@EnableScheduling public class UserApplication { static Logger logger= LoggerFactory.getLogger(UserApplication.class); public static void main(String[] args) throws UnknownHostException { diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java index d0e8e84..abe09af 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java @@ -50,4 +50,8 @@ public interface UserInfoDao extends JpaRepository, JpaSpecifi public List findAllByIsAuthor(int isAuthor); public UserInfo findByInvitationCode(String invitationCode); + + @Query(value = "select * from tb_user_info where vip_status = 1\n" + + " and vip_expire_time < now()", nativeQuery = true) + public List getExpireVipList(); } diff --git a/luoo_user/src/main/java/com/luoo/user/quartz/MembershipQuartz.java b/luoo_user/src/main/java/com/luoo/user/quartz/MembershipQuartz.java new file mode 100644 index 0000000..419d74f --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/quartz/MembershipQuartz.java @@ -0,0 +1,31 @@ +package com.luoo.user.quartz; + +import com.luoo.user.service.UserInfoService; +import enums.UserVipStatusEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * @program: luoo_parent + * @description: 每晚处理过期会员 + * @author: yawei.huang + * @create: 2024-08-05 14:47 + **/ +@Component +public class MembershipQuartz { + + @Autowired + private UserInfoService userInfoService; + + /** + * 每晚一点更新会员状态 + */ + @Scheduled(cron = "0 0 1 * * *") + public void updateVip() { + userInfoService.getExpireVipList().forEach(userInfo -> { + userInfo.setVipStatus(UserVipStatusEnum.EXPIRED.getCode()); + userInfoService.update(userInfo); + }); + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index b688f8b..619cc18 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -872,4 +872,13 @@ public class UserInfoService { return invitationCode; } + + /** + * 获取已过期的会员 + * + * @return 列表 + */ + public List getExpireVipList() { + return userInfoDao.getExpireVipList(); + } }