package com.zhgd.xmgl.task; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zhgd.xmgl.modules.car.entity.CarInfo; import com.zhgd.xmgl.modules.car.mapper.CarInfoMapper; import com.zhgd.xmgl.modules.car.service.impl.CarInfoServiceImpl; import com.zhgd.xmgl.modules.project.entity.Project; import com.zhgd.xmgl.modules.project.mapper.ProjectMapper; import com.zhgd.xmgl.modules.car.mapper.CarInfoApprovalFlowMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.List; @Slf4j @Component public class CarInfoTask { @Lazy @Autowired private CarInfoServiceImpl carInfoService; @Lazy @Autowired private CarInfoMapper carInfoMapper; @Lazy @Autowired private ProjectMapper projectMapper; @Lazy @Autowired private CarInfoApprovalFlowMapper carInfoApprovalFlowMapper; /** * 定时删除/更新过期的车辆,并下发新的预约时间的车辆到海康 */ @Scheduled(cron = "*/30 * * * * ?") public void deleteOrUpdateExpiredCar() { List projects = projectMapper.selectList(new LambdaQueryWrapper().eq(Project::getSyncHikvision, 1)); for (Project project : projects) { List carInfos = carInfoMapper.selectList(new LambdaQueryWrapper() .ne(CarInfo::getCarModuleType, 1) .eq(CarInfo::getProjectSn, project.getProjectSn()) .lt(CarInfo::getReserveEndTime, DateUtil.now()) ); if (CollUtil.isEmpty(carInfos)) { return; } for (CarInfo carInfo : carInfos) { carInfoService.deleteOrUpdateExpiredCar(project, carInfo); } } } }