package com.fs.qw.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwForbiddenWords;
import com.fs.qw.service.IQwForbiddenWordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企微违禁词管理Controller
 *
 * @author fs
 * @date 2023-11-22
 */
@RestController
@RequestMapping("/qw/words")
public class QwForbiddenWordsController extends BaseController
{
    @Autowired
    private IQwForbiddenWordsService qwForbiddenWordsService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询企微违禁词管理列表
     */
    @PreAuthorize("@ss.hasPermi('qw:words:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwForbiddenWords qwForbiddenWords)
    {
        startPage();
        List<QwForbiddenWords> list = qwForbiddenWordsService.selectQwForbiddenWordsList(qwForbiddenWords);
        return getDataTable(list);
    }

    /**
     * 导出企微违禁词管理列表
     */
    @PreAuthorize("@ss.hasPermi('qw:words:export')")
    @Log(title = "企微违禁词管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwForbiddenWords qwForbiddenWords)
    {
        List<QwForbiddenWords> list = qwForbiddenWordsService.selectQwForbiddenWordsList(qwForbiddenWords);
        ExcelUtil<QwForbiddenWords> util = new ExcelUtil<QwForbiddenWords>(QwForbiddenWords.class);
        return util.exportExcel(list, "words");
    }

    /**
     * 获取企微违禁词管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:words:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwForbiddenWordsService.selectQwForbiddenWordsById(id));
    }

    /**
     * 新增企微违禁词管理
     */
    @PreAuthorize("@ss.hasPermi('qw:words:add')")
    @Log(title = "企微违禁词管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwForbiddenWords qwForbiddenWords)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwForbiddenWords.setOperator(loginUser.getUser().getNickName());
        return toAjax(qwForbiddenWordsService.insertQwForbiddenWords(qwForbiddenWords));
    }

    /**
     * 修改企微违禁词管理
     */
    @PreAuthorize("@ss.hasPermi('qw:words:edit')")
    @Log(title = "企微违禁词管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwForbiddenWords qwForbiddenWords)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwForbiddenWords.setOperator(loginUser.getUser().getNickName());
        return toAjax(qwForbiddenWordsService.updateQwForbiddenWords(qwForbiddenWords));
    }

    /**
     * 删除企微违禁词管理
     */
    @PreAuthorize("@ss.hasPermi('qw:words:remove')")
    @Log(title = "企微违禁词管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwForbiddenWordsService.deleteQwForbiddenWordsByIds(ids));
    }
}
