package com.ics.quartz.task;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.ics.admin.domain.meeting.Reservation;
import com.ics.admin.domain.meeting.UserEquipment;
import com.ics.admin.service.meeting.IUserEquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Slf4j
@Component("deviceTask")
public class DeviceTask {


    @Autowired
    private IUserEquipmentService userEquipmentService;

    // 定时删除用户与设备关联数据
    public void removeUserDevice() {
        log.info("定时删除用户与设备关联数据...");
        UserEquipment userEquipment = new UserEquipment();
        List<UserEquipment> equipments = userEquipmentService.selectUserEquipmentList(userEquipment);
        for (UserEquipment userEquipment1 : equipments) {
            Date endDate = userEquipment1.getEndDate();
            int compare = DateUtil.compare(DateUtil.date(), endDate);
            if (compare > 0) {
                userEquipmentService.deleteUserEquipmentById(userEquipment1.getId());
                log.info("删除用户与设备关联数据成功");
                log.info("定时删除用户与设备关联数据");
            }


        }

    }
}
