package vip.xiaonuo.biz.modular.task;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import vip.xiaonuo.biz.modular.bizappointmentrecord.entity.BizAppointmentRecord;
import vip.xiaonuo.biz.modular.bizappointmentrecord.mapper.BizAppointmentRecordMapper;
import vip.xiaonuo.biz.modular.bizappointmentrecord.service.BizAppointmentRecordService;
import vip.xiaonuo.biz.modular.bizappointmenttime.entity.BizAppointmentTime;
import vip.xiaonuo.biz.modular.bizappointmenttime.service.BizAppointmentTimeService;
import vip.xiaonuo.common.timer.CommonTimerTaskRunner;

import java.util.List;

@Slf4j
@Component
public class AppointmentTimeOutTask implements CommonTimerTaskRunner {

    @Resource
    private BizAppointmentTimeService bizAppointmentTimeService;
    @Resource
    private BizAppointmentRecordService bizAppointmentRecordService;
    @Resource
    private BizAppointmentRecordMapper bizAppointmentRecordMapper;

    @Override
    public void action(String extJson) {
        String format = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss");
        //根据时间段查询还未入场预约记录
        QueryWrapper<BizAppointmentRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.lt("bgc.CONF_END_TIME",format)
                .in("bar.STATUS","1","2","3","4")
                .eq("bar.delete_flag","NOT_DELETE");
        List<BizAppointmentRecord> recordList = bizAppointmentRecordMapper.getRecord(queryWrapper);
        for(BizAppointmentRecord bizAppointmentRecord : recordList){
            //超期作废
            bizAppointmentRecord.setStatus("15");
            bizAppointmentRecordService.updateById(bizAppointmentRecord);
            log.info("车牌号："+bizAppointmentRecord.getLicenseNumber()+"的预约记录超期作废成功！");
        }

    }
}
