package com.tofly.spire.handle;

import cn.hutool.core.date.DateUtil;
import com.tofly.common.constant.CalendarHelper;
import com.tofly.scada.service.ScadaHistorySynService;
import com.tofly.scada.service.impl.ScadaServiceImpl;
import com.tofly.spire.service.SpireBigGridService;
import com.tofly.spire.service.SpireBigGridXxlJobService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * @author HaiQiu
 * @since 2023/3/24
 */
@Component
public class SpireHandle {

    @Autowired
    private SpireBigGridXxlJobService spireBigGridXxlJobService;

    /**
     * 定时任务--管网数据分发到历史表和实时表，5分钟1次
     * @param params
     * @return
     */
    @XxlJob("getBulkMSynData")
    public ReturnT getBulkMSynData(String params) {
        spireBigGridXxlJobService.synData();
        return ReturnT.SUCCESS;
    }

    /**
     * 同步管网数据，昨天的
     *
     * @param params
     * @return
     */
    @XxlJob("getBulkMeterDataLastDay")
//    @Scheduled(cron = "0 0/1 * * * ?")
    public ReturnT getBulkMeterDataLastDay(String params) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        String format = DateUtil.format(calendar.getTime(), "yyyy-MM-dd");
        spireBigGridXxlJobService.synBulkMeterThread(format, null);
        return ReturnT.SUCCESS;
    }
    /**
     * 同步管网数据，实时数据，每5分钟一次
     *
     * @param params
     * @return
     */
    @XxlJob("getBulkMeterDataMonitor")
    public ReturnT getBulkMeterDataMonitor(String params) {
        spireBigGridXxlJobService.synBulkMeterMonitorDataThread();
        return ReturnT.SUCCESS;
    }


    /**
     * 同步管网数据，今天的
     *
     * @param params
     * @return
     */
    @XxlJob("getBulkMeterData")
//    @Scheduled(cron = "0 0/1 * * * ?")
    public ReturnT getBulkMeterData(String params) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String format = DateUtil.format(calendar.getTime(), "yyyy-MM-dd");
        spireBigGridXxlJobService.synBulkMeterThread(format, null);
        return ReturnT.SUCCESS;
    }

    /**
     * 定时任务--同步管网基础数据，并且转换成高德地图坐标同步到设备表
     * @param params
     * @return
     */
    @XxlJob("getBulkMeterBigBaseData")
    public ReturnT synBulkMeterBigBaseData(String params) {
        spireBigGridXxlJobService.getBulkMeterBigBaseData();
        spireBigGridXxlJobService.getMapGdDataNew();
        spireBigGridXxlJobService.synDeviceArchiveManage();
        return ReturnT.SUCCESS;
    }
}
