package com.huijy.web.controller.management;

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.huijy.common.annotation.Log;
import com.huijy.common.core.controller.BaseController;
import com.huijy.common.core.domain.AjaxResult;
import com.huijy.common.enums.BusinessType;
import com.huijy.management.domain.TSensitiveWords;
import com.huijy.management.service.ITSensitiveWordsService;
import com.huijy.common.utils.poi.ExcelUtil;
import com.huijy.common.core.page.TableDataInfo;

/**
 * 敏感词Controller
 *
 * @author huijy
 * @date 2021-08-30
 */
@RestController
@RequestMapping("/management/words")
public class TSensitiveWordsController extends BaseController
{
    @Autowired
    private ITSensitiveWordsService tSensitiveWordsService;

    /**
     * 查询敏感词列表
     */
    @PreAuthorize("@ss.hasPermi('management:words:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSensitiveWords tSensitiveWords)
    {
        startPage();
        List<TSensitiveWords> list = tSensitiveWordsService.selectTSensitiveWordsList(tSensitiveWords);
        return getDataTable(list);
    }

    /**
     * 导出敏感词列表
     */
    @PreAuthorize("@ss.hasPermi('management:words:export')")
    @Log(title = "敏感词", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSensitiveWords tSensitiveWords)
    {
        List<TSensitiveWords> list = tSensitiveWordsService.selectTSensitiveWordsList(tSensitiveWords);
        ExcelUtil<TSensitiveWords> util = new ExcelUtil<TSensitiveWords>(TSensitiveWords.class);
        return util.exportExcel(list, "敏感词数据");
    }

    /**
     * 获取敏感词详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:words:query')")
    @GetMapping(value = "/{sensitiveWordsId}")
    public AjaxResult getInfo(@PathVariable("sensitiveWordsId") Long sensitiveWordsId)
    {
        return AjaxResult.success(tSensitiveWordsService.selectTSensitiveWordsBySensitiveWordsId(sensitiveWordsId));
    }

    /**
     * 新增敏感词
     */
    @PreAuthorize("@ss.hasPermi('management:words:add')")
    @Log(title = "敏感词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSensitiveWords tSensitiveWords)
    {
        return toAjax(tSensitiveWordsService.insertTSensitiveWords(tSensitiveWords));
    }

    /**
     * 修改敏感词
     */
    @PreAuthorize("@ss.hasPermi('management:words:edit')")
    @Log(title = "敏感词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSensitiveWords tSensitiveWords)
    {
        return toAjax(tSensitiveWordsService.updateTSensitiveWords(tSensitiveWords));
    }

    /**
     * 删除敏感词
     */
    @PreAuthorize("@ss.hasPermi('management:words:remove')")
    @Log(title = "敏感词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sensitiveWordsIds}")
    public AjaxResult remove(@PathVariable Long[] sensitiveWordsIds)
    {
        return toAjax(tSensitiveWordsService.deleteTSensitiveWordsBySensitiveWordsIds(sensitiveWordsIds));
    }
}
