package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.HotWordsLabel;
import com.ym.mec.biz.service.HotWordsLabelService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.QueryInfo;

/**
 * @Author Joburgess
 * @Date 2019/9/21
 */
@Api(tags = "热词标签管理")
@RequestMapping("hotWordLabelManage")
@RestController
public class HotWordLabelManageController extends BaseController {

    @Autowired
    private HotWordsLabelService hotWordsLabelService;

    @ApiOperation(value = "新增热词标签")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('hotWordLabelManage/add')")
    public Object add(HotWordsLabel hotWordsLabel) {
        hotWordsLabelService.insert(hotWordsLabel);
        return succeed();
    }

    @ApiOperation(value = "删除热词标签")
    @PostMapping("/del/{id}")
    @PreAuthorize("@pcs.hasPermissions('hotWordLabelManage/del')")
    public Object del(@ApiParam(value = "热词标签编号", required = true) @PathVariable("id") Integer id) {
        hotWordsLabelService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改热词标签")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('hotWordLabelManage/update')")
    public Object update(HotWordsLabel hotWordsLabel) {
        hotWordsLabel.setUpdateTime(new Date());
        hotWordsLabelService.update(hotWordsLabel);
        return succeed();
    }


    @ApiOperation("分页查询热词列表")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('hotWordLabelManage/queryPage')")
    public Object queryPage(QueryInfo queryInfo){
        return succeed(hotWordsLabelService.queryPage(queryInfo));
    }

}
