package com.fs.chat.controller;

import com.fs.chat.domain.ChatKeyword;
import com.fs.chat.service.IChatKeywordService;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关键字Controller
 *
 * @author fs
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/chat/chatKeyword")
public class ChatKeywordController extends BaseController
{
    @Autowired
    private IChatKeywordService chatKeywordService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询关键字列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatKeyword:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatKeyword chatKeyword)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        chatKeyword.setCompanyId(loginUser.getCompany().getCompanyId());
        List<ChatKeyword> list = chatKeywordService.selectChatKeywordList(chatKeyword);
        return getDataTable(list);
    }



    /**
     * 获取关键字详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:chatKeyword:query')")
    @GetMapping(value = "/{keywordId}")
    public AjaxResult getInfo(@PathVariable("keywordId") Long keywordId)
    {
        return AjaxResult.success(chatKeywordService.selectChatKeywordByKeywordId(keywordId));
    }

    /**
     * 新增关键字
     */
    @PreAuthorize("@ss.hasPermi('chat:chatKeyword:add')")
    @Log(title = "关键字", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatKeyword chatKeyword)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        chatKeyword.setCompanyId(loginUser.getCompany().getCompanyId());
        return toAjax(chatKeywordService.insertChatKeyword(chatKeyword));
    }

    /**
     * 修改关键字
     */
    @PreAuthorize("@ss.hasPermi('chat:chatKeyword:edit')")
    @Log(title = "关键字", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatKeyword chatKeyword)
    {
        return toAjax(chatKeywordService.updateChatKeyword(chatKeyword));
    }

    /**
     * 删除关键字
     */
    @PreAuthorize("@ss.hasPermi('chat:chatKeyword:remove')")
    @Log(title = "关键字", businessType = BusinessType.DELETE)
	@DeleteMapping("/{keywordIds}")
    public AjaxResult remove(@PathVariable Long[] keywordIds)
    {
        return toAjax(chatKeywordService.deleteChatKeywordByKeywordIds(keywordIds));
    }
}
