package com.yeejoin.equipmanage.quartz;

import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.equipmanage.common.entity.dto.EquipQrDateDto;
import com.yeejoin.equipmanage.service.ICarService;
import com.yeejoin.equipmanage.service.impl.CarServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 定时监控车辆相关指标
 * @author xxz
 */
@Component
@EnableScheduling
@Slf4j
public class CarPropertyJob {

    @Autowired
    private ICarService carService;

    @Autowired
    private RuleTrigger ruleTrigger;

    /**
     * 车辆赋红码。定时查询车辆启停更新时间，
     */
    @Scheduled(cron = "${update.car.qrCode}")
    public void UpdateCarQrCode() {

        List<Map<String, String>> list = carService.updateCarStartStatus();
        EquipQrDateDto equipQrDateDto = new EquipQrDateDto();
        equipQrDateDto.setContrast("updateDate");
        equipQrDateDto.setSource("car");
        equipQrDateDto.setData(list);
        try {
            ruleTrigger.publish(equipQrDateDto, "中心配置赋码规则/update-qr-code", null);
        } catch (Exception e) {
            log.error("调用规则失败: {}", e.getMessage());
        }
    }

}
