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

/**
 * 用户留言Controller
 *
 * @author zf
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/tuya/leavewords")
public class TuyaLeaveWordsController extends BaseController
{
    @Autowired
    private ITuyaLeaveWordsService tuyaLeaveWordsService;

    /**
     * 查询用户留言列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:leavewords:list')")
    @GetMapping("/list")
    public TableDataInfo list(TuyaLeaveWords tuyaLeaveWords)
    {
        startPage();
        List<TuyaLeaveWords> list = tuyaLeaveWordsService.selectTuyaLeaveWordsList(tuyaLeaveWords);
        return getDataTable(list);
    }

    /**
     * 导出用户留言列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:leavewords:export')")
    @Log(title = "用户留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TuyaLeaveWords tuyaLeaveWords)
    {
        List<TuyaLeaveWords> list = tuyaLeaveWordsService.selectTuyaLeaveWordsList(tuyaLeaveWords);
        ExcelUtil<TuyaLeaveWords> util = new ExcelUtil<TuyaLeaveWords>(TuyaLeaveWords.class);
        util.exportExcel(response, list, "用户留言数据");
    }

    /**
     * 获取用户留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('tuya:leavewords:query')")
    @GetMapping(value = "/{wordsId}")
    public AjaxResult getInfo(@PathVariable("wordsId") Long wordsId)
    {
        return AjaxResult.success(tuyaLeaveWordsService.selectTuyaLeaveWordsByWordsId(wordsId));
    }

    /**
     * 新增用户留言
     */
    @PreAuthorize("@ss.hasPermi('tuya:leavewords:add')")
    @Log(title = "用户留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TuyaLeaveWords tuyaLeaveWords)
    {
        return toAjax(tuyaLeaveWordsService.insertTuyaLeaveWords(tuyaLeaveWords));
    }

    /**
     * 修改用户留言
     */
    @PreAuthorize("@ss.hasPermi('tuya:leavewords:edit')")
    @Log(title = "用户留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TuyaLeaveWords tuyaLeaveWords)
    {
        return toAjax(tuyaLeaveWordsService.updateTuyaLeaveWords(tuyaLeaveWords));
    }

    /**
     * 删除用户留言
     */
    @PreAuthorize("@ss.hasPermi('tuya:leavewords:remove')")
    @Log(title = "用户留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wordsIds}")
    public AjaxResult remove(@PathVariable Long[] wordsIds)
    {
        return toAjax(tuyaLeaveWordsService.deleteTuyaLeaveWordsByWordsIds(wordsIds));
    }
}
