package com.platform.modules.sensitiveword.controller;

import java.util.Map;

import org.apache.http.HttpStatus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.platform.common.annotation.SysLog;
import com.platform.common.utils.PageUtils;
import com.platform.common.utils.R;
import com.platform.common.validator.ValidatorUtils;
import com.platform.modules.sensitiveword.entity.SensitiveStopWordEntity;
import com.platform.modules.sensitiveword.service.SensitiveStopWordService;
import com.platform.modules.sensitiveword.service.SensitiveWordService;
import com.platform.modules.sys.controller.AbstractController;

import io.swagger.annotations.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 敏感停顿符
 *
 * @author Anine
 * @date 2019-03-11 16:43:20
 */
@RestController
@RequestMapping("/sensitive/stopword")
@Api(value = "敏感词-停顿符", tags = "敏感词-停顿符")
public class SensitiveStopWordController extends AbstractController {

	@Autowired
	private SensitiveWordService sensitiveWordService;

	@Autowired
	private SensitiveStopWordService sensitiveStopWordService;

	/**
	 * 列表
	 */
	@GetMapping("/list")
	@RequiresPermissions("sensitive:stopword:list")
	@ApiOperation("列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "页数", defaultValue = "1", paramType = "query", dataType = "Integer"),
			@ApiImplicitParam(name = "limit", value = "显示行数", defaultValue = "10", paramType = "query", dataType = "Integer"),
			@ApiImplicitParam(name = "sidx", value = "排序字段", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "order", value = "排序顺序", allowableValues = "ASC,DESC", paramType = "query")})
	@ApiResponses({
			@ApiResponse(code = HttpStatus.SC_OK, message = "success", response = SensitiveStopWordEntity.class, responseContainer = "List")})
	public R list(@ApiIgnore @RequestParam(required = false) Map<String, Object> params) {
		PageUtils page = sensitiveWordService.queryStopWordsPage(params);

		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@GetMapping("/info/{id}")
	@RequiresPermissions("sensitive:stopword:info")
	@ApiOperation("信息")
	@ApiResponses({
			@ApiResponse(code = HttpStatus.SC_OK, message = "success", response = SensitiveStopWordEntity.class)})
	public R info(@PathVariable("id") Integer id) {
		SensitiveStopWordEntity sensitiveStopWord = sensitiveStopWordService.selectById(id);

		return R.ok().put("sensitiveStopWord", sensitiveStopWord);
	}

	/**
	 * 保存
	 */
	@SysLog("保存停顿词")
	@PostMapping("/save")
	@RequiresPermissions("sensitive:stopword:save")
	@ApiOperation("保存")
	public R save(@RequestBody SensitiveStopWordEntity sensitiveStopWord) {
		ValidatorUtils.validateEntity(sensitiveStopWord);
		return sensitiveWordService.addStopWord(sensitiveStopWord, getUserId());
	}

	/**
	 * 修改
	 */
	@SysLog("修改停顿词")
	@PostMapping("/update")
	@RequiresPermissions("sensitive:stopword:update")
	@ApiOperation("修改")
	public R update(@RequestBody SensitiveStopWordEntity sensitiveStopWord) {
		ValidatorUtils.validateEntity(sensitiveStopWord);
		return sensitiveWordService.updateStopWord(sensitiveStopWord);
	}

	/**
	 * 删除
	 */
	@SysLog("删除停顿词")
	@PostMapping("/delete")
	@RequiresPermissions("sensitive:stopword:delete")
	@ApiOperation("删除")
	public R delete(@RequestBody Integer[] ids) {
		sensitiveWordService.deleteStopWordsByIds(ids);

		return R.ok();
	}

}
