package com.ningdatech.carapi.road.task;

import com.ningdatech.carapi.road.manage.RoadMonitorManage;
import com.ningdatech.carapi.road.model.entity.ComprehensiveSituation;
import com.ningdatech.carapi.road.model.req.RoadMonitorReq;
import com.ningdatech.carapi.road.model.vo.ComprehensiveSituationVO;
import com.ningdatech.carapi.road.service.IComprehensiveSituationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author FangShiBa
 * @apiNote
 * @since 2024/11/20
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class RoadMonitorRealTimeDataTask {

    @Value("${task.switch.is-open}")
    private boolean flag;

    private final RoadMonitorManage roadMonitorManage;
    private final IComprehensiveSituationService comprehensiveSituationService;

    //每分钟计算一次综合态势评分
    @Scheduled(cron = "0 */1 * * * ?")
    public void doTask(){
        if (!flag){
            log.info("综合态势评定时任务未开启！");
            return;
        }
        //黄山隧道道路综合数据
        RoadMonitorReq reqHS = new RoadMonitorReq();
        reqHS.setTunnel(1);
        ComprehensiveSituationVO comSitHSData = roadMonitorManage.getComSitData(reqHS);
        ComprehensiveSituation comprehensiveSituationHS = new ComprehensiveSituation();
        BeanUtils.copyProperties(comSitHSData,comprehensiveSituationHS);
        comprehensiveSituationHS.setTunnel(1);
        comprehensiveSituationHS.setCreateOn(LocalDateTime.now());
        comprehensiveSituationService.save(comprehensiveSituationHS);

        //何里隧道道路综合数据
        RoadMonitorReq reqHL = new RoadMonitorReq();
        reqHL.setTunnel(2);
        ComprehensiveSituationVO comSitHLData = roadMonitorManage.getComSitData(reqHL);
        ComprehensiveSituation comprehensiveSituationHL = new ComprehensiveSituation();
        BeanUtils.copyProperties(comSitHLData,comprehensiveSituationHL);
        comprehensiveSituationHL.setTunnel(2);
        comprehensiveSituationHL.setCreateOn(LocalDateTime.now());
        comprehensiveSituationService.save(comprehensiveSituationHL);

    }

}
