package com.gyee.wisdom.alarm.sharding.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.wisdom.alarm.sharding.config.AjaxResult;
import com.gyee.wisdom.alarm.sharding.entity.AlarmHistory;
import com.gyee.wisdom.alarm.sharding.entity.AlarmSnap;
import com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo;
import com.gyee.wisdom.alarm.sharding.service.AlarmHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/alarm")
@CrossOrigin
public class AlarmHistoryController {

    @Autowired
    private AlarmHistoryService alarmHistoryService;

    @GetMapping(value = "/history/{historyId}")
    public AlarmHistory queryById(@PathVariable("historyId")  Long historyId ){
            return alarmHistoryService.queryById(historyId);
    }


    @GetMapping(value = "/history/page2")
    public AjaxResult queryByPage(
            @RequestParam(value = "pagenum")Integer pageNum,
            @RequestParam(value = "pagesize")Integer pageSize,
            @RequestParam(value = "stationid", required = false) String stId,
            @RequestParam(value = "windturbineid",required = false) String wtId,
            @RequestParam(value = "category1",required = false) String category1,
            @RequestParam(value = "category2",required = false) String category2,
            @RequestParam(value = "rank",required = false) String rank,
            @RequestParam(value = "modelid",required = false) String modelId,
            @RequestParam(value = "snapid",required = false) Long snapId,
            @RequestParam(value = "messagetype",required = false) Integer messageType,
            @RequestParam(value = "keyword",required = false) String keyWord,
            @RequestParam(value = "starttime", required = false) String startTime,
            @RequestParam(value = "endtime", required = false) String endTime
    ){
        Page<AlarmSnap> page =new Page(pageNum,pageSize);
        try {
            IPage<AlarmHistoryInfo> pages = alarmHistoryService.pageQueryAll(page,stId,wtId,category1,category2,rank,modelId,snapId,messageType,keyWord,startTime,endTime);
            return AjaxResult.successData(pages);
        } catch (Exception e) {
            log.error("操作失败",e);
           return AjaxResult.error();
        }

    }

    @GetMapping(value = "/history/page")
    public IPage<AlarmHistoryInfo> queryByPage1(
            @RequestParam(value = "pagenum")Integer pageNum,
            @RequestParam(value = "pagesize")Integer pageSize,
            @RequestParam(value = "stationid", required = false) String stId,
            @RequestParam(value = "windturbineid",required = false) String wtId,
            @RequestParam(value = "category1",required = false) String category1,
            @RequestParam(value = "category2",required = false) String category2,
            @RequestParam(value = "rank",required = false) String rank,
            @RequestParam(value = "modelid",required = false) String modelId,
            @RequestParam(value = "snapid",required = false) Long snapId,
            @RequestParam(value = "messagetype",required = false) Integer messageType,
            @RequestParam(value = "keyword",required = false) String keyWord,
            @RequestParam(value = "starttime", required = false) String startTime,
            @RequestParam(value = "endtime", required = false) String endTime
    ){
        Page<AlarmSnap> page =new Page(pageNum,pageSize);
        try {
            IPage<AlarmHistoryInfo> pages = alarmHistoryService.pageQueryAll(page,stId,wtId,category1,category2,rank,modelId,snapId,messageType,keyWord,startTime,endTime);
            return pages;
        } catch (Exception e) {
            log.error("操作失败",e);
            return null;
        }
    }

    //宁夏定制功能干掉
//    @GetMapping(value = "/count/todaycount")
//    public AjaxResult getTodayCount(@RequestParam(value = "stId", required = false) String stId ){
//        Map<String, String> map = new HashMap<>();
//
//        try {
//            map = alarmHistoryService.getListmap();
//            if (null == map){
//                map =  alarmHistoryService.getTodayCount();
//            }
//
//            return  AjaxResult.successData(200,map);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return null;
//    }


}
