package com.ruoyi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.app.domain.Monitor;
import com.ruoyi.app.service.IMonitorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监控设备Controller
 * 
 * @author coede
 * @date 2025-03-19
 */
@Api("监控设备信息管理")
@RestController
@RequestMapping("/app/monitor")
public class MonitorController extends BaseController
{
    @Autowired
    private IMonitorService monitorService;

    /**
     * 查询监控设备列表
     */
    @ApiOperation("查询监控设备列表")
    @PreAuthorize("@ss.hasPermi('app:monitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Monitor monitor)
    {
        startPage();
        List<Monitor> list = monitorService.selectMonitorList(monitor);
        return getDataTable(list);
    }

    /**
     * 导出监控设备列表
     */
    @ApiOperation("导出监控设备列表")
    @PreAuthorize("@ss.hasPermi('app:monitor:export')")
    @Log(title = "监控设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Monitor monitor)
    {
        List<Monitor> list = monitorService.selectMonitorList(monitor);
        ExcelUtil<Monitor> util = new ExcelUtil<Monitor>(Monitor.class);
        util.exportExcel(response, list, "监控设备数据");
    }

    /**
     * 获取监控设备详细信息
     */
    @ApiOperation("获取监控设备详细信息")
    @PreAuthorize("@ss.hasPermi('app:monitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(monitorService.selectMonitorById(id));
    }

    /**
     * 新增监控设备
     */
    @ApiOperation("新增监控设备")
    @PreAuthorize("@ss.hasPermi('app:monitor:add')")
    @Log(title = "监控设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated  @RequestBody Monitor monitor)
    {
        monitor.setCreateBy(getUsername());
        return toAjax(monitorService.insertMonitor(monitor));
    }

    /**
     * 修改监控设备
     */
    @ApiOperation("修改监控设备")
    @PreAuthorize("@ss.hasPermi('app:monitor:edit')")
    @Log(title = "监控设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Monitor monitor)
    {
        monitor.setUpdateBy(getUsername());
        return toAjax(monitorService.updateMonitor(monitor));
    }

    /**
     * 删除监控设备
     */
    @ApiOperation("删除监控设备")
    @PreAuthorize("@ss.hasPermi('app:monitor:remove')")
    @Log(title = "监控设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(monitorService.deleteMonitorByIds(ids));
    }
}
