package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
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.SysMqttUser;
import com.ruoyi.system.service.ISysMqttUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * mqtt用户Controller
 *
 * @author Duke_yzl
 * @date 2023-06-30
 */
@RestController
@RequestMapping("/system/mqttUser")
public class SysMqttUserController extends BaseController
{
    @Autowired
    private ISysMqttUserService sysMqttUserService;

    /**
     * 查询mqtt用户列表
     */
    @SaCheckPermission("system:mqttUser:list")
    @GetMapping("/list")
    public TableDataInfo list(SysMqttUser sysMqttUser)
    {
        startPage();
        List<SysMqttUser> list = sysMqttUserService.selectSysMqttUserList(sysMqttUser);
        return getDataTable(list);
    }

    /**
     * 导出mqtt用户列表
     */
    @SaCheckPermission("system:mqttUser:export")
    @Log(title = "mqtt用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMqttUser sysMqttUser)
    {
        List<SysMqttUser> list = sysMqttUserService.selectSysMqttUserList(sysMqttUser);
        ExcelUtil<SysMqttUser> util = new ExcelUtil<SysMqttUser>(SysMqttUser.class);
        util.exportExcel(response, list, "mqtt用户数据");
    }

    /**
     * 获取mqtt用户详细信息
     */
    @SaCheckPermission("system:mqttUser:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysMqttUserService.selectSysMqttUserById(id));
    }

    /**
     * 新增mqtt用户
     */
    @SaCheckPermission("system:mqttUser:add")
    @Log(title = "mqtt用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMqttUser sysMqttUser)
    {
        return toAjax(sysMqttUserService.insertSysMqttUser(sysMqttUser));
    }

    /**
     * 修改mqtt用户
     */
    @SaCheckPermission("system:mqttUser:edit")
    @Log(title = "mqtt用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMqttUser sysMqttUser)
    {
        return toAjax(sysMqttUserService.updateSysMqttUser(sysMqttUser));
    }

    /**
     * 删除mqtt用户
     */
    @SaCheckPermission("system:mqttUser:remove")
    @Log(title = "mqtt用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMqttUserService.deleteSysMqttUserByIds(ids));
    }
}
