package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.BaseAlarm;
import com.usky.iot.domain.BaseGgpFacility;
import com.usky.iot.service.BaseAlarmService;
import com.usky.iot.service.vo.BaseAlarmListVO;
import com.usky.iot.service.vo.BaseAlarmRequestVO;
import com.usky.iot.service.vo.BaseAlarmResponeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 统一告警表 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-07-13
 */
@RestController
@RequestMapping("/baseAlarm")
public class BaseAlarmController {
    @Autowired
    private BaseAlarmService baseAlarmService;

    /**
     * 统计
     * @param baseAlarmRequestVO
     * @return
     */
    @PostMapping("/statistic")
    public ApiResult<CommonPage<BaseAlarmResponeVO>> statistic(@RequestBody BaseAlarmRequestVO baseAlarmRequestVO){
        return ApiResult.success(baseAlarmService.statistic(baseAlarmRequestVO));
    }

    /**
     * 分页
     * @param baseAlarmListVO
     * @return
     */
    @PostMapping("/page")
    public ApiResult<CommonPage<BaseAlarm>> page(@RequestBody BaseAlarmListVO baseAlarmListVO){
        return ApiResult.success(baseAlarmService.page(baseAlarmListVO));
    }

    /**
     * 统计(白名单)
     * @param baseAlarmRequestVO
     * @return
     */
    @PostMapping("/statistic_notoken")
    public ApiResult<CommonPage<BaseAlarmResponeVO>> statistic_notoken(@RequestBody BaseAlarmRequestVO baseAlarmRequestVO){
        return ApiResult.success(baseAlarmService.statistic_notoken(baseAlarmRequestVO));
    }

    /**
     * 分页(白名单)
     * @param baseAlarmListVO
     * @return
     */
    @PostMapping("/page_notoken")
    public ApiResult<CommonPage<BaseAlarm>> page_notoken(@RequestBody BaseAlarmListVO baseAlarmListVO){
        return ApiResult.success(baseAlarmService.page_notoken(baseAlarmListVO));
    }

    /**
     * 大屏最新6条告警信息
     * @return
     */
    @PostMapping("/getScreenAlarmList")
    public ApiResult<List<BaseAlarm>> getScreenAlarmList(){
        return ApiResult.success(baseAlarmService.getScreenAlarmList());
    }

    /**
     * 修改
     * @param baseAlarm
     * @return
     */
    @PutMapping
    public ApiResult<Void> update(@RequestBody BaseAlarm baseAlarm){
        baseAlarmService.update(baseAlarm);
        return ApiResult.success();
    }

    /**
     * 新增
     * @param baseAlarm
     * @return
     */
    @PostMapping("/alarmInfo")
    public ApiResult<Void> add(@RequestBody BaseAlarm baseAlarm){
        baseAlarmService.add(baseAlarm);
        return ApiResult.success();
    }

    /**
     * 综合云图-告警统计
     * @param deptId 部门ID
     * @return
     */
    @GetMapping("/alarmStatistic")
    public ApiResult<List<Object>> alarmStatistic(@RequestParam(value = "deptId", required = false) Integer deptId){
        return ApiResult.success(baseAlarmService.alarmStatistic(deptId));
    }

    /**
     * 实时报警-报警统计
     * @param startTime 开始时间
     * @param endTime 开始时间
     * @return
     */
    @GetMapping("/alarmStatisticDay")
    public ApiResult<List<Map<String,Object>>> alarmStatisticDay(@RequestParam(value = "startTime", required = false) String startTime,
                                                                 @RequestParam(value = "endTime", required = false) String endTime){
        return ApiResult.success(baseAlarmService.alarmStatisticDay(startTime,endTime));
    }
}

