release: 每晚一点更新会员状态

release-2024-08-08
huangyw 4 months ago
parent 9062ab23d5
commit a015fa8520

@ -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 {

@ -50,4 +50,8 @@ public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecifi
public List<UserInfo> 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<UserInfo> getExpireVipList();
}

@ -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);
});
}
}

@ -872,4 +872,13 @@ public class UserInfoService {
return invitationCode;
}
/**
*
*
* @return
*/
public List<UserInfo> getExpireVipList() {
return userInfoDao.getExpireVipList();
}
}

Loading…
Cancel
Save