package com.yuchen.saas.park.service.pull.input;

import com.yuchen.saas.park.api.entity.park.PmgBatParkInfo;
import com.yuchen.saas.park.service.pull.untils.StompClient;
import com.yuchen.saas.park.service.service.PmgBatParkInfoService;
import org.nest.springwrap.core.tool.utils.Func;
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;

/**
 * 定时推送统计数据
 *
 * @author 刘通
 * @version 1.0
 * @date 2021/2/4 16:36
 */
@Component
@EnableScheduling
public class PushStatisticsInput {

    @Autowired
    StompClient stompClient;

    @Autowired
    private PmgBatParkInfoService pmgBatParkInfoService;

//    @Autowired
//    private DeviceConnectInput deviceConnectInput;

    /**
     * 10秒钟推一次
     */
    //@Scheduled(fixedRate = 10000)
    public void getStatisticsSchedule() {
        // 获取园区
        List<PmgBatParkInfo> allParkList = pmgBatParkInfoService.getAllPark();
        if (Func.isNotEmpty(allParkList)) {
            for (PmgBatParkInfo info : allParkList) {
                // 行为事件、测温事件、异常事件（陌生人和高频人员） 的总数、已处理、未处理(已处理和未处理有的事件没有)
                stompClient.getStatistics(String.valueOf(info.getId()));
            }
        }

    }

    /**
     * 摄像头在离线
     * 2分钟推一次
     */
    @Scheduled(cron = "0 */2 * * * ?")
    public void getCountOnlineCamera() {
        // 获取园区
        List<PmgBatParkInfo> allParkList = pmgBatParkInfoService.getAllPark();
        if (Func.isNotEmpty(allParkList)) {
            for (PmgBatParkInfo info : allParkList) {
                stompClient.getCountOnlineCamera(String.valueOf(info.getId()));
                stompClient.getDeviceAnalysis(String.valueOf(info.getId()));
            }
        }
    }

    /**
     * 每天0点1秒推送今日用水量、用电量 为零
     */
    // @Scheduled(cron = "1 0 0 * * ?") modify by qianjiang
    public void sendZeroPointData() {
        // 获取园区
        List<PmgBatParkInfo> allParkList = pmgBatParkInfoService.getAllPark();
        if (Func.isNotEmpty(allParkList)) {
            for (PmgBatParkInfo info : allParkList) {
                stompClient.sendZeroPointData(String.valueOf(info.getId()));
            }
        }
    }

    /**
     * 60秒钟推一次
     * 这个定时任务移到sass-mqtt-iot
     */
//    @Scheduled(fixedRate = 60000)
//    public void opsForVirtualGw() {
//        this.deviceConnectInput.scheduledOps();
//    }
}
