package com.eitc.quartz.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eitc.common.utils.spring.SpringUtils;
import com.eitc.patient.domain.PatientAppointment;
import com.eitc.patient.service.IPatientAppointmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * PatientAppointmentTask
 *
 * @author mtx
 * @date: 2024/05/28 16:16
 */
@Component("patientAppointmentTask")
@Slf4j
public class PatientAppointmentTask {

    public void checkAppointmentStatus() {
        log.info("checkAppointmentStatus start");
        IPatientAppointmentService patientAppointmentService = SpringUtils.getBean(IPatientAppointmentService.class);
        LambdaQueryWrapper<PatientAppointment> lt = Wrappers.<PatientAppointment>lambdaQuery()
                .eq(PatientAppointment::getAppointmentStatus, 1)
                .lt(PatientAppointment::getAppointmentStartTime, new Date());
        List<PatientAppointment> list = patientAppointmentService.list(lt);
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(item -> item.setAppointmentStatus(8));
            patientAppointmentService.updateBatchById(list);
        }
    }
}
