package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.biz.EntityController;
import com.ruoyi.system.core.DeviceInstructType;
import org.springframework.http.server.reactive.ServerHttpResponse;
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.system.domain.SysDeviceCommand;
import com.ruoyi.system.service.ISysDeviceCommandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 设备命令Controller
 * 
 * @author ruoyi
 * @date 2023-08-14
 */
@RestController
@RequestMapping("/system/command")
public class SysDeviceCommandController extends EntityController<SysDeviceCommand, Long, ISysDeviceCommandService>
{
    /**
     * 查询设备命令列表
     */
    @PreAuthorize("@ss.hasPermi('system:command:list')")
    @GetMapping("/list")
    public Mono<TableDataInfo> list(ServerWebExchange exchange, SysDeviceCommand cond)
    {
        return super.list(exchange, cond);
    }

    /**
     * 导出设备命令列表
     */
    @PreAuthorize("@ss.hasPermi('system:command:export')")
    @Log(title = "设备命令", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public Mono<Void> export(ServerHttpResponse response, SysDeviceCommand cond)
    {
        return super.export(response, cond, SysDeviceCommand.class, "设备命令数据");
    }

    /**
     * 获取设备命令详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:command:query')")
    @GetMapping(value = "/{id}")
    public Mono<AjaxResult> getInfo(@PathVariable("id") Long id)
    {
        return super.getInfo(id);
    }

    /**
     * 新增设备命令
     */
    @PreAuthorize("@ss.hasPermi('system:command:add')")
    @Log(title = "设备命令", businessType = BusinessType.INSERT)
    @PostMapping
    public Mono<AjaxResult> insert(@RequestBody SysDeviceCommand data)
    {
        return startMono(() -> service.insert(data).map(this::toAjax));
    }

    /**
     * 修改设备命令
     */
    @PreAuthorize("@ss.hasPermi('system:command:edit')")
    @Log(title = "设备命令", businessType = BusinessType.UPDATE)
    @PutMapping
    public Mono<AjaxResult> update(@RequestBody SysDeviceCommand data)
    {
        return startMono(() -> {
            return service.update(data).map(this::toAjax);
        });
    }

    /**
     * 删除设备命令
     */
    @PreAuthorize("@ss.hasPermi('system:command:remove')")
    @Log(title = "设备命令", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Mono<AjaxResult> deleteByIds(@PathVariable Long[] ids)
    {
        return startMono(() -> {
            return service.deleteByIds(ids).map(this::toAjax);
        });
    }
}
