package cn.exploring.engine.server.admin.web;

import cn.exploring.engine.server.admin.annotation.RequiresPermissionsDesc;
import cn.exploring.engine.server.core.validator.Order;
import cn.exploring.engine.server.core.validator.Sort;
import cn.exploring.engine.server.db.domain.WxSensitiveWords;
import cn.exploring.engine.server.db.service.WxSensitiveWordsService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

//敏感词汇
@RestController
@RequestMapping("/admin/sensitive/words")
@Validated
public class AdminSensitiveWordsController {
    private final Log logger = LogFactory.getLog(AdminSensitiveWordsController.class);

    @Autowired
    private WxSensitiveWordsService sensitiveWordsService;

    //分页查询
    @RequiresPermissions("admin:sensitive:words:list")
    @RequiresPermissionsDesc(menu={"系统管理" , "敏感词汇管理"}, button="查询")
    @GetMapping("/list")
    public Object list(WxSensitiveWords object,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        return sensitiveWordsService.list(object, page, limit, sort, order);
    }

    //根据id查询
    @RequiresPermissions("admin:sensitive:words:read")
    @RequiresPermissionsDesc(menu={"系统管理" , "敏感词汇管理"}, button="详情")
    @GetMapping("/read")
    public Object read(@NotNull Integer id) {
        return sensitiveWordsService.selectByPrimaryKey(id);
    }

    //添加
    @RequiresPermissions("admin:sensitive:words:create")
    @RequiresPermissionsDesc(menu={"系统管理" , "敏感词汇管理"}, button="添加")
    @PostMapping("/create")
    public Object create(@RequestBody WxSensitiveWords object) {
        return sensitiveWordsService.add(object);
    }

    //修改
    @RequiresPermissions("admin:sensitive:words:update")
    @RequiresPermissionsDesc(menu={"系统管理" , "敏感词汇管理"}, button="编辑")
    @PostMapping("/update")
    public Object update(@RequestBody WxSensitiveWords object) {
        return sensitiveWordsService.updateById(object) ;
    }

    //批量删除
    @RequiresPermissions("admin:sensitive:words:delete")
    @RequiresPermissionsDesc(menu={"系统管理" , "敏感词汇管理"}, button="删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody Integer[] ids) {
        return sensitiveWordsService.deleteByIds(ids);
    }
}
