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

import com.gyee.wisdom.alarm.sharding.entity.FaultSnap;
import com.gyee.wisdom.alarm.sharding.mapper.FaultSnapMapper;
import com.gyee.wisdom.alarm.sharding.service.FaultSnapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/fault")
@CrossOrigin
public class FaultSnapController {

    @Autowired
    private FaultSnapService faultSnapService;

    /**
     * 根据条件查询所有数据
     *
     * @return
     */
    @GetMapping("/snap/list")
    public List<FaultSnap> queryAll(
            @RequestParam(value = "stationid", required = false) String stationId,
            @RequestParam(value = "windturbineid", required = false) String windturbineId,
            @RequestParam(value = "category1", required = false) String category1,
            @RequestParam(value = "category2", required = false) String category2,
            @RequestParam(value = "category3", required = false) String category3,
            @RequestParam(value = "rank", required = false) String rank,
            @RequestParam(value = "starttime", required = false) String startTime,
            @RequestParam(value = "endtime", required = false) String endTime,
            @RequestParam(value = "isopened", required = false) String isOpened,
            @RequestParam(value = "alerttext", required = false) String alertText) {

        List<FaultSnap> list;

        try {
            list = faultSnapService.queryAll(stationId, windturbineId, category1, category2, category3,
                    rank, startTime, endTime, isOpened, alertText);

            return list;

        } catch (Exception e) {
            log.error("查询失败: ", e);
            return null;
        }
    }

    @GetMapping(value = "/snap/top")
    public List<FaultSnap> getTopNumFault(
            @RequestParam(value = "topnum", required = true) String topNum
    ) {
        try {
            return faultSnapService.getTopNumFault(topNum);
        } catch (Exception e) {
            log.error("操作失败",e);
            return null;
        }
    }
}
