package com.gyee.alarm.controller;

import com.gyee.alarm.model.vo.AjaxResult;
import com.gyee.alarm.model.vo.AjaxStatus;
import com.gyee.alarm.model.vo.AlarmVo;
import com.gyee.alarm.service.AlarmHistoryService;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.text.SimpleDateFormat;
import java.util.*;



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


    Logger logger = LogManager.getLogger(AlarmHistoryController.class);

    @Resource
    private AlarmHistoryService alarmHistoryService;


    @GetMapping(value = "/history/findAlarmlist")
    public AjaxResult findAlarmlist(
            @RequestParam(value = "begin", required = true) String begin,
            @RequestParam(value = "end", required = true) String end,
            @RequestParam(value = "alarmType", required = true) String alarmType,
            @RequestParam(value = "stationid", required = false) String stationid,
            @RequestParam(value = "deviceid", required = false) String deviceid,
            @RequestParam(value = "description", required = false) String description,
            @RequestParam(value = "modelId", required = false) String modelId,
            @RequestParam(value = "pageNum", required = true) Integer pageNum,
            @RequestParam(value = "pageSize", required = true) Integer pageSize
    ) throws Exception {

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = df.parse(begin);
        Date endDate = df.parse(end);
        Map<String,Object> map = alarmHistoryService.findAlarmlist(modelId,beginDate.getTime(), endDate.getTime(), alarmType, stationid,deviceid, description, pageNum, pageSize);
        return AjaxResult.successData(AjaxStatus.success.code, map);

    }



}




