package com.project.zcustom.controller.crontab;

import com.project.common.core.controller.BaseController;
import com.project.zcustom.domain.basics.PlatAppOrg;
import com.project.zcustom.service.service.basics.IPlatAppOrgService;
import com.project.zcustom.tools.BuildingService;
import com.project.zcustom.tools.CarService;
import com.project.zcustom.tools.GuaranteeService;
import com.project.zcustom.tools.LogisticsService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 *  定时任务控制器
 * @author change
 * @date 2024-04-07
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@Component("crontabTask")
public class PlatCrontabTaskController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(PlatCrontabTaskController.class);
    @Resource
    private GuaranteeService guaranteeService;
    @Resource
    private IPlatAppOrgService iPlatAppOrgService;
    @Resource
    private BuildingService buildingService;
    @Resource
    private LogisticsService logisticsService;

    @Resource
    private CarService carService;



    /**
     * 定时任务 服务保障中心
     * 每10分钟统计
     */
    public void serviceData() {
        synchronized (this) {
            logger.info("开始获取接口数据");
            List<PlatAppOrg> platAppOrgList = iPlatAppOrgService.selectPlatAppOrgList(new PlatAppOrg());
            if(!platAppOrgList.isEmpty()){
                for (PlatAppOrg platAppOrg : platAppOrgList){
                    guaranteeService.getServiceData(platAppOrg.getAppOrg(),platAppOrg.getAppName());
                }
            }
            logger.info("获取接口数据完成");
        }
    }


    /**
     * 定时任务 后勤运行监控中心
     */
    public void logisticsData() {
        synchronized (this) {
            logger.info("开始后勤运行监控中心获取接口数据");
            logisticsService.getLogisticsData();
            logger.info("后勤运行监控中心获取接口数据完成");
        }
    }

    /**
     * 楼宇运行监控(左)
     */
    public void leftBuildingData() {
        synchronized (this) {
            logger.info("开始楼宇运行获取接口数据");
            buildingService.getLeftBuildingData();
            logger.info("楼宇运行获取接口数据完成");
        }
    }

    /**
     * 楼宇运行监控(左：明细)
     * 30分钟
     */
    public void leftBuildingDataDetail() {
        synchronized (this) {
            logger.info("开始楼宇运行获取接口数据");
            buildingService.getLeftBuildingDataDetail();
            logger.info("楼宇运行获取接口数据完成");
        }
    }

    /**
     * 楼宇运行监控(右)
     */
    public void rightBuildingDataFirstHalf() {
        synchronized (this) {
            logger.info("开始楼宇运行获取接口数据");
            buildingService.getRightBuildingDataFirstHalf();
            logger.info("楼宇运行获取接口数据完成");
        }
    }

    /**
     * 楼宇运行监控(右：空气质量)
     */
    public void rightBuildingDataSecondHalf() {
        synchronized (this) {
            logger.info("开始楼宇运行获取接口数据");
            buildingService.getRightBuildingDataSecondHalf();
            logger.info("楼宇运行获取接口数据完成");
        }
    }

    /**
     * 公务用车
     */
    public void publicCarData() {
        synchronized (this) {
            logger.info("开始获取公务用车接口数据");
            carService.getPublicCarData();
            logger.info("获取公务用车接口数据完成");
        }
    }

}
