package com.ruoyi.web.controller.hardware;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.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.hardware.domain.DoumuHardware;
import com.ruoyi.hardware.service.IDoumuHardwareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author boman
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/hardware/hardware")
public class DoumuHardwareController extends BaseController
{
    @Autowired
    private IDoumuHardwareService doumuHardwareService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('hardware:hardware:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoumuHardware doumuHardware)
    {
        startPage();
        List<DoumuHardware> list = doumuHardwareService.selectDoumuHardwareList(doumuHardware);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('hardware:hardware:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoumuHardware doumuHardware)
    {
        List<DoumuHardware> list = doumuHardwareService.selectDoumuHardwareList(doumuHardware);
        ExcelUtil<DoumuHardware> util = new ExcelUtil<DoumuHardware>(DoumuHardware.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('hardware:hardware:query')")
    @GetMapping(value = "/{hardwareId}")
    public AjaxResult getInfo(@PathVariable("hardwareId") Long hardwareId)
    {
        return success(doumuHardwareService.selectDoumuHardwareByHardwareId(hardwareId));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('hardware:hardware:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoumuHardware doumuHardware)
    {
        return toAjax(doumuHardwareService.insertDoumuHardware(doumuHardware));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('hardware:hardware:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody DoumuHardware doumuHardware)
    {
        return toAjax(doumuHardwareService.updateDoumuHardware(doumuHardware));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('hardware:hardware:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{hardwareIds}")
    public AjaxResult remove(@PathVariable Long[] hardwareIds)
    {
        return toAjax(doumuHardwareService.deleteDoumuHardwareByHardwareIds(hardwareIds));
    }


    /**
     * 一键开启/关闭
     * @return 结果
     */

    @PreAuthorize("@ss.hasPermi('hardware:hardware:type')")
    @GetMapping("/setType/{type}")
    public AjaxResult setType(@PathVariable String type)
    {
        return doumuHardwareService.setType(type);
    }

    /**
     * 根据id一键开启/关闭
     * @return 结果
     */

    @PreAuthorize("@ss.hasPermi('hardware:hardware:type')")
    @PostMapping("/open")
    public AjaxResult setTypeOpen(@RequestBody DoumuHardware doumuHardware)
    {
        return doumuHardwareService.setTypeOpen(doumuHardware);
    }
}
