|
|
@@ -0,0 +1,59 @@
|
|
|
+package cn.iocoder.byzs.module.system.job;
|
|
|
+
|
|
|
+import cn.iocoder.byzs.framework.quartz.core.handler.JobHandler;
|
|
|
+import cn.iocoder.byzs.framework.tenant.core.aop.TenantIgnore;
|
|
|
+import cn.iocoder.byzs.module.system.dal.dataobject.invitecode.InviteCodeDO;
|
|
|
+import cn.iocoder.byzs.module.system.dal.mysql.invitecode.InviteCodeMapper;
|
|
|
+import cn.iocoder.byzs.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 邀请码过期检查定时任务
|
|
|
+ *
|
|
|
+ * @author lyb
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class InviteCodeExpireJob implements JobHandler {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private InviteCodeMapper inviteCodeMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @TenantIgnore
|
|
|
+ public String execute(String param) {
|
|
|
+ log.info("开始执行邀请码过期检查任务");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 查询所有未使用且已过期的邀请码
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ List<InviteCodeDO> expiredInviteCodes = inviteCodeMapper.selectList(new LambdaQueryWrapperX<InviteCodeDO>()
|
|
|
+ .eq(InviteCodeDO::getStatus, "0") // 状态未使用
|
|
|
+ .le(InviteCodeDO::getExpireTime, now) // 过期时间小与于等于当前时间
|
|
|
+ );
|
|
|
+
|
|
|
+ log.info("发现 {} 个过期的邀请码", expiredInviteCodes.size());
|
|
|
+
|
|
|
+ // 2. 更新过期邀请码的状态
|
|
|
+ int updateCount = 0;
|
|
|
+ for (InviteCodeDO inviteCode : expiredInviteCodes) {
|
|
|
+ // 将状态设置为过期("3"表示过期状态)
|
|
|
+ inviteCode.setStatus("3");
|
|
|
+ inviteCodeMapper.updateById(inviteCode);
|
|
|
+ updateCount++;
|
|
|
+ log.info("邀请码 {} 已设置为过期状态", inviteCode.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("邀请码过期检查任务执行完成,共处理 {} 个过期邀请码", updateCount);
|
|
|
+ return String.format("成功处理 %d 个过期邀请码", updateCount);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("执行邀请码过期检查任务时发生错误", e);
|
|
|
+ return "执行任务时发生错误: " + e.getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|