调整VIP检查
This commit is contained in:
parent
473980b028
commit
ff023a2909
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.module.system.service.person.PersonService;
|
||||
import cn.iocoder.yudao.module.system.service.device.DeviceService;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -14,19 +14,19 @@ public class vip implements JobHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(vip.class);
|
||||
|
||||
@Resource
|
||||
private PersonService personService;
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Override
|
||||
public String execute(String param) {
|
||||
log.info("开始执行VIP过期检查定时任务");
|
||||
log.info("开始执行设备VIP过期检查定时任务");
|
||||
try {
|
||||
// 批量处理过期VIP用户
|
||||
personService.processExpiredVipUsers();
|
||||
log.info("VIP过期检查定时任务执行成功");
|
||||
return "VIP过期检查执行成功";
|
||||
// 批量处理过期的VIP设备
|
||||
deviceService.processExpiredVipDevices();
|
||||
log.info("设备VIP过期检查定时任务执行成功");
|
||||
return "设备VIP过期检查执行成功";
|
||||
} catch (Exception e) {
|
||||
log.error("VIP过期检查定时任务执行失败", e);
|
||||
return "VIP过期检查执行失败: " + e.getMessage();
|
||||
log.error("设备VIP过期检查定时任务执行失败", e);
|
||||
return "设备VIP过期检查执行失败: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,4 +100,10 @@ public interface DeviceService {
|
||||
* @param devicecode 设备编号
|
||||
*/
|
||||
void restartDevice(String devicecode);
|
||||
|
||||
/**
|
||||
* 批量处理过期VIP设备
|
||||
* 将过期的VIP设备的isvip字段设为0,devicestatus设为2
|
||||
*/
|
||||
void processExpiredVipDevices();
|
||||
}
|
||||
@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.system.service.device;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -14,6 +17,9 @@ import cn.iocoder.yudao.module.system.dal.mysql.device.DeviceMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
@ -25,6 +31,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class DeviceServiceImpl implements DeviceService {
|
||||
|
||||
@Resource
|
||||
@ -180,4 +187,38 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
deviceMapper.update(updateObj, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processExpiredVipDevices() {
|
||||
// 获取当前时间
|
||||
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
log.info("开始检查VIP过期设备,当前时间: {}", currentTime);
|
||||
|
||||
// 查询所有过期的VIP设备
|
||||
List<DeviceDO> expiredVipDevices = deviceMapper.selectList(new LambdaQueryWrapper<DeviceDO>()
|
||||
.eq(DeviceDO::getIsvip, 1) // 当前是VIP设备
|
||||
.isNotNull(DeviceDO::getVipendtime) // VIP结束时间不为空
|
||||
.lt(DeviceDO::getVipendtime, currentTime)); // VIP结束时间小于当前时间
|
||||
|
||||
if (expiredVipDevices.isEmpty()) {
|
||||
log.info("没有发现过期的VIP设备");
|
||||
return; // 没有过期设备,直接返回
|
||||
}
|
||||
|
||||
log.info("发现 {} 个过期的VIP设备,开始批量处理", expiredVipDevices.size());
|
||||
|
||||
// 提取所有过期设备的ID
|
||||
List<Integer> expiredDeviceIds = expiredVipDevices.stream()
|
||||
.map(DeviceDO::getId)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
// 批量更新过期VIP设备
|
||||
deviceMapper.update(null, new LambdaUpdateWrapper<DeviceDO>()
|
||||
.in(DeviceDO::getId, expiredDeviceIds)
|
||||
.set(DeviceDO::getIsvip, 0) // 设置为非会员状态
|
||||
.set(DeviceDO::getDevicestatus, 2) // 设置为离线状态
|
||||
.set(DeviceDO::getUpdatetime, LocalDateTime.now())); // 更新时间
|
||||
|
||||
log.info("成功处理 {} 个过期的VIP设备", expiredVipDevices.size());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user