package com.ruoyi.frequency.sensitiveword.controller;

import java.util.List;
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.frequency.sensitiveword.entity.SensitiveWord;
import com.ruoyi.frequency.sensitiveword.service.SensitiveWordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 敏感词Controller
 * 
 * @author liwenlong
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/frequency/sensitiveword")
public class SensitiveWordController extends BaseController
{
    @Autowired
    private SensitiveWordService sensitiveWordService;

    /**
     * 查询敏感词列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:sensitiveword:list')")
    @PostMapping("/list")
    public TableDataInfo<SensitiveWord> list(@RequestBody SensitiveWord sensitiveWord)
    {
        startPage();
        List<SensitiveWord> list = sensitiveWordService.selectSensitiveWordList(sensitiveWord);
        return getDataTable(list);
    }

    /**
     * 导出敏感词列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:sensitiveword:export')")
    @Log(title = "敏感词", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SensitiveWord sensitiveWord)
    {
        List<SensitiveWord> list = sensitiveWordService.selectSensitiveWordList(sensitiveWord);
        ExcelUtil<SensitiveWord> util = new ExcelUtil<SensitiveWord>(SensitiveWord.class);
        return util.exportExcel(list, "敏感词数据");
    }

    /**
     * 获取敏感词详细信息
     */
//    @PreAuthorize("@ss.hasPermi('frequency:sensitiveword:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<SensitiveWord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sensitiveWordService.selectSensitiveWordById(id));
    }

    /**
     * 新增敏感词
     */
//    @PreAuthorize("@ss.hasPermi('frequency:sensitiveword:add')")
    @Log(title = "敏感词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SensitiveWord sensitiveWord)
    {
        return toAjax(sensitiveWordService.insertSensitiveWord(sensitiveWord));
    }

    /**
     * 修改敏感词
     */
//    @PreAuthorize("@ss.hasPermi('frequency:sensitiveword:edit')")
    @Log(title = "敏感词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SensitiveWord sensitiveWord)
    {
        return toAjax(sensitiveWordService.updateSensitiveWord(sensitiveWord));
    }

    /**
     * 删除敏感词
     */
//    @PreAuthorize("@ss.hasPermi('frequency:sensitiveword:remove')")
    @Log(title = "敏感词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(sensitiveWordService.deleteSensitiveWordByIds(ids,delFlag));
    }
}
