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(); + } }