package com.ruoyi.tuya.controller;

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.tuya.domain.SysUsers;
import com.ruoyi.tuya.service.ISysUsersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台用户Controller
 *
 * @author ruoyi
 * @date 2022-07-19
 */
@RestController
@RequestMapping("/tuya/tuyausers")
public class SysUsersController extends BaseController
{
    @Autowired
    private ISysUsersService sysUsersService;

    /**
     * 查询平台用户列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:users:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUsers sysUsers)
    {
        startPage();
        List<SysUsers> list = sysUsersService.selectSysUsersList(sysUsers);
        return getDataTable(list);
    }

    /**
     * 导出平台用户列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:users:export')")
    @Log(title = "平台用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUsers sysUsers)
    {
        List<SysUsers> list = sysUsersService.selectSysUsersList(sysUsers);
        ExcelUtil<SysUsers> util = new ExcelUtil<SysUsers>(SysUsers.class);
        util.exportExcel(response, list, "平台用户数据");
    }

    /**
     * 获取平台用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('tuya:users:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysUsersService.selectSysUsersById(id));
    }

    /**
     * 新增平台用户
     */
    @PreAuthorize("@ss.hasPermi('tuya:users:add')")
    @Log(title = "平台用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUsers sysUsers)
    {
        return toAjax(sysUsersService.insertSysUsers(sysUsers));
    }

    /**
     * 修改平台用户
     */
    @PreAuthorize("@ss.hasPermi('tuya:users:edit')")
    @Log(title = "平台用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUsers sysUsers)
    {
        return toAjax(sysUsersService.updateSysUsers(sysUsers));
    }

    /**
     * 删除平台用户
     */
    @PreAuthorize("@ss.hasPermi('tuya:users:remove')")
    @Log(title = "平台用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUsersService.deleteSysUsersByIds(ids));
    }
}
