package com.yunyan.web.controller.business;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.yunyan.business.pojo.admin.dto.AlertWordCheckContentDto;
import com.yunyan.business.pojo.admin.vo.AlertWordCheckContentVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yunyan.common.annotation.Log;
import com.yunyan.common.core.controller.BaseController;
import com.yunyan.common.core.domain.AjaxResult;
import com.yunyan.common.enums.BusinessType;
import com.yunyan.business.domain.AlertWord;
import com.yunyan.business.service.IAlertWordService;
import com.yunyan.common.utils.poi.ExcelUtil;
import com.yunyan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.yunyan.common.core.domain.AjaxResultVo;
import com.yunyan.common.utils.SecurityUtils;
import java.util.Date;

/**
 * 敏感词管理Controller
 *
 * @author yunyan
 * @date 2023-07-27
 */
@Api(tags = "4.0.1敏感词管理")
@RestController
@RequestMapping("/business/word")
public class AlertWordController extends BaseController
{
    @Autowired
    private IAlertWordService alertWordService;

    /**
     * 查询敏感词管理列表
     */
    @ApiOperation(value="查询敏感词管理列表", notes="查询敏感词管理列表")
    @PreAuthorize("@ss.hasPermi('business:word:list')")
    @GetMapping("/list")
    public TableDataInfo<AlertWord> list(AlertWord alertWord)
    {
        startPage();
        List<AlertWord> list = alertWordService.selectAlertWordList(alertWord);
        return getDataTable(list);
    }

    /**
     * 导出敏感词管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:word:export')")
    @Log(title = "敏感词管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlertWord alertWord)
    {
        List<AlertWord> list = alertWordService.selectAlertWordList(alertWord);
        ExcelUtil<AlertWord> util = new ExcelUtil<AlertWord>(AlertWord.class);
        util.exportExcel(response, list, "敏感词管理数据");
    }

    /**
     * 获取敏感词管理详细信息
     */
    @ApiOperation(value="获取敏感词管理详细信息", notes="获取敏感词管理详细信息")
    @PreAuthorize("@ss.hasPermi('business:word:query')")
    @GetMapping(value = "/{id}")
    public AjaxResultVo getInfo(@PathVariable("id") Long id)
    {
        return AjaxResultVo.success(alertWordService.getById(id));
    }

    /**
     * 新增敏感词管理
     */
    @ApiOperation(value="新增敏感词管理", notes="新增敏感词管理")
    @PreAuthorize("@ss.hasPermi('business:word:add')")
    @Log(title = "敏感词管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AlertWord dto)
    {
        return toAjax(alertWordService.save(dto));
    }

    /**
     * 修改敏感词管理
     */
    @ApiOperation(value="修改敏感词管理", notes="修改敏感词管理")
    @PreAuthorize("@ss.hasPermi('business:word:edit')")
    @Log(title = "敏感词管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody AlertWord dto)
    {
        return toAjax(alertWordService.updateById(dto));
    }

    /**
     * 删除敏感词管理
     */
    @ApiOperation(value="删除敏感词管理", notes="删除敏感词管理")
    @PreAuthorize("@ss.hasPermi('business:word:remove')")
    @Log(title = "敏感词管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(alertWordService.removeByIds(Arrays.asList(ids)));
    }
    @ApiOperation(value="敏感词匹配", notes="敏感词匹配")
    //@PreAuthorize("@ss.hasPermi('business:word:checkContent')")
    @PostMapping("/checkContent")
    public AjaxResultVo<AlertWordCheckContentVo> checkContent(@RequestBody @Valid AlertWordCheckContentDto dto ) {

        String content = dto.getContent();
        return alertWordService.checkContent(content);

    }

}
