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

/**
 * 用户投诉Controller
 * 
 * @author zf
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/tuya/talkno")
public class TuyaTalkNoController extends BaseController
{
    @Autowired
    private ITuyaTalkNoService tuyaTalkNoService;

    /**
     * 查询用户投诉列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:talkno:list')")
    @GetMapping("/list")
    public TableDataInfo list(TuyaTalkNo tuyaTalkNo)
    {
        startPage();
        List<TuyaTalkNo> list = tuyaTalkNoService.selectTuyaTalkNoList(tuyaTalkNo);
        return getDataTable(list);
    }

    /**
     * 导出用户投诉列表
     */
    @PreAuthorize("@ss.hasPermi('tuya:talkno:export')")
    @Log(title = "用户投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TuyaTalkNo tuyaTalkNo)
    {
        List<TuyaTalkNo> list = tuyaTalkNoService.selectTuyaTalkNoList(tuyaTalkNo);
        ExcelUtil<TuyaTalkNo> util = new ExcelUtil<TuyaTalkNo>(TuyaTalkNo.class);
        util.exportExcel(response, list, "用户投诉数据");
    }

    /**
     * 获取用户投诉详细信息
     */
    @PreAuthorize("@ss.hasPermi('tuya:talkno:query')")
    @GetMapping(value = "/{noId}")
    public AjaxResult getInfo(@PathVariable("noId") Long noId)
    {
        return AjaxResult.success(tuyaTalkNoService.selectTuyaTalkNoByNoId(noId));
    }

    /**
     * 新增用户投诉
     */
    @PreAuthorize("@ss.hasPermi('tuya:talkno:add')")
    @Log(title = "用户投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TuyaTalkNo tuyaTalkNo)
    {
        return toAjax(tuyaTalkNoService.insertTuyaTalkNo(tuyaTalkNo));
    }

    /**
     * 修改用户投诉
     */
    @PreAuthorize("@ss.hasPermi('tuya:talkno:edit')")
    @Log(title = "用户投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TuyaTalkNo tuyaTalkNo)
    {
        return toAjax(tuyaTalkNoService.updateTuyaTalkNo(tuyaTalkNo));
    }

    /**
     * 删除用户投诉
     */
    @PreAuthorize("@ss.hasPermi('tuya:talkno:remove')")
    @Log(title = "用户投诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noIds}")
    public AjaxResult remove(@PathVariable Long[] noIds)
    {
        return toAjax(tuyaTalkNoService.deleteTuyaTalkNoByNoIds(noIds));
    }
}
