package com.ruoyi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
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.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.HwMonitorUnit;
import com.ruoyi.business.service.IHwMonitorUnitService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 监控单元Controller
 * 
 * @author xins
 * @date 2023-09-14
 */
@RestController
@RequestMapping("/monitorUnit")
public class HwMonitorUnitController extends BaseController
{
    @Autowired
    private IHwMonitorUnitService hwMonitorUnitService;

    /**
     * 查询监控单元列表
     */
    @RequiresPermissions("business:monitorUnit:list")
    @GetMapping("/list")
    public AjaxResult list(HwMonitorUnit hwMonitorUnit)
    {
        List<HwMonitorUnit> list = hwMonitorUnitService.selectHwMonitorUnitList(hwMonitorUnit);
        return success(list);
    }

    /**
     * 导出监控单元列表
     */
    @RequiresPermissions("business:monitorUnit:export")
    @Log(title = "监控单元", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwMonitorUnit hwMonitorUnit)
    {
        List<HwMonitorUnit> list = hwMonitorUnitService.selectHwMonitorUnitList(hwMonitorUnit);
        ExcelUtil<HwMonitorUnit> util = new ExcelUtil<HwMonitorUnit>(HwMonitorUnit.class);
        util.exportExcel(response, list, "监控单元数据");
    }

    /**
     * 获取监控单元详细信息
     */
    @RequiresPermissions("business:monitorUnit:query")
    @GetMapping(value = "/{monitorUnitId}")
    public AjaxResult getInfo(@PathVariable("monitorUnitId") Long monitorUnitId)
    {
        return success(hwMonitorUnitService.selectHwMonitorUnitByMonitorUnitId(monitorUnitId));
    }

    /**
     * 新增监控单元
     */
    @RequiresPermissions("business:monitorUnit:add")
    @Log(title = "监控单元", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HwMonitorUnit hwMonitorUnit)
    {
        return toAjax(hwMonitorUnitService.insertHwMonitorUnit(hwMonitorUnit));
    }

    /**
     * 修改监控单元
     */
    @RequiresPermissions("business:monitorUnit:edit")
    @Log(title = "监控单元", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwMonitorUnit hwMonitorUnit)
    {
        return toAjax(hwMonitorUnitService.updateHwMonitorUnit(hwMonitorUnit));
    }

    /**
     * 删除监控单元
     */
    @RequiresPermissions("business:monitorUnit:remove")
    @Log(title = "监控单元", businessType = BusinessType.DELETE)
	@DeleteMapping("/{monitorUnitIds}")
    public AjaxResult remove(@PathVariable Long[] monitorUnitIds)
    {
        return toAjax(hwMonitorUnitService.deleteHwMonitorUnitByMonitorUnitIds(monitorUnitIds));
    }
}
