package com.fs.fastGpt;

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.fastGpt.domain.FastGptChatKeyword;
import com.fs.fastGpt.service.IFastGptChatKeywordService;
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-09-30
 */
@RestController
@RequestMapping("/fastGpt/fastGptChatKeyword")
public class FastGptChatKeywordController extends BaseController
{
    @Autowired
    private IFastGptChatKeywordService fastgptChatKeywordService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询关键字列表
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptChatKeyword:list')")
    @GetMapping("/list")
    public TableDataInfo list(FastGptChatKeyword fastgptChatKeyword)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastgptChatKeyword.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FastGptChatKeyword> list = fastgptChatKeywordService.selectFastGptChatKeywordList(fastgptChatKeyword);
        return getDataTable(list);
    }

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

    /**
     * 新增关键字
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptChatKeyword:add')")
    @Log(title = "关键字", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FastGptChatKeyword fastgptChatKeyword)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastgptChatKeyword.setCompanyId(loginUser.getCompany().getCompanyId());
        return toAjax(fastgptChatKeywordService.insertFastGptChatKeyword(fastgptChatKeyword));
    }

    /**
     * 修改关键字
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptChatKeyword:edit')")
    @Log(title = "关键字", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FastGptChatKeyword fastgptChatKeyword)
    {
        return toAjax(fastgptChatKeywordService.updateFastGptChatKeyword(fastgptChatKeyword));
    }

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