package com.tofly.scada.controller;

import cn.hutool.core.date.DateUtil;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.scada.entity.Scada;
import com.tofly.scada.service.ScadaService;
import com.tofly.scada.service.impl.ScadaApplicationRunner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author haiqiu
 * 动态获取scada数据库新增字段
 */
@Api(tags = "在线手动监控数据")
@Slf4j
@RequestMapping("/msg")
@RestController
public class ScadaMsgController {

    @Autowired
    private ScadaService scadaService;

    @Autowired
    private ScadaApplicationRunner scadaApplicationRunner;

    /**
     * 获取同步scada信息数据
     *
     * @return
     */
    @ApiOperation(value = "手动更新scada数据（数据测试）")
    @GetMapping("/scada")
    public ResultRespone getMsg() {
        scadaService.insertData();
        return ResultRespone.success();
    }

    /**
     * 更新缓存月份表数据
     *
     * @return
     */
    @ApiOperation(value = "更新缓存月份表数据")
    @GetMapping("/cache")
    public ResultRespone cache(@ApiParam("开始时间:2022-01-01 00:00:00") @RequestParam String star) {
        scadaApplicationRunner.autoMouthScada(DateUtil.parse(star, "yyyy-MM-dd"));
        return ResultRespone.success("缓存月份表数据更新中....");
    }




    /**
     * 更新缓存月份表数据-非异步
     *
     * @return
     */
    @ApiOperation(value = "更新缓存月份表数据-无异步，非常慢，稳定可靠")
    @GetMapping("/cacheSlow")
    public ResultRespone cacheSlow(@ApiParam("开始时间:2022-01-01 00:00:00") @RequestParam String star) {
        scadaApplicationRunner.autoMouthScadaSlow(DateUtil.parse(star, "yyyy-MM-dd"));
        return ResultRespone.success("缓存月份表" + DateUtil.parse(star, "yyyy-MM-dd") + "数据更新完成");
    }
}
