package com.inspect.system.controller;

import com.inspect.base.core.domain.SysWarning;
import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.system.service.SysWarningService;

import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/warningLog"})
public class SysWarningController extends BaseController {
    @Resource
    SysWarningService sysWarningService;

    @GetMapping({"/list"})
    public TableDataInfo list(SysWarning sysWarning) {
        this.startPage();
        List<SysWarning> warningList = this.sysWarningService.queryWarningList(sysWarning);
        return this.getDataTable(warningList);
    }

    @PostMapping({"/saveWarning"})
    public AjaxResult saveWarning(@RequestBody SysWarning sysWarning) {
        this.sysWarningService.saveWarningLog(sysWarning);
        return AjaxResult.success();
    }

    @PostMapping({"/export"})
    public void export(SysWarning sysWarning, HttpServletResponse response) throws UnsupportedEncodingException {
        List<SysWarning> warningList = this.sysWarningService.queryWarningList(sysWarning);
        ExcelUtil<SysWarning> excelUtil = new ExcelUtil<>(SysWarning.class);
        excelUtil.exportExcelWithFileName(response, warningList, "系统告警", "系统告警");
    }
}
