package com.fs.company.controller.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.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.company.domain.CompanyDept;
import com.fs.company.service.ICompanyDeptService;
import com.fs.fastGpt.domain.FastGptKeyword;
import com.fs.fastGpt.domain.FastGptKeywordSend;
import com.fs.fastGpt.service.IFastGptKeywordSendService;
import com.fs.framework.security.LoginUser;
import com.fs.framework.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;

/**
 * Ai事件表(根据关键字发送文本和图片)Controller
 * 
 * @author fs
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/fastGpt/fastGptKeywordSend")
public class FastGptKeywordSendController extends BaseController
{
    @Autowired
    private IFastGptKeywordSendService fastGptKeywordSendService;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private ICompanyDeptService companyDeptService;

    @GetMapping("/keywordList")
    public R keywordList()
    {
        List<FastGptKeyword> list = fastGptKeywordSendService.selectFastGptKeywordList(0);
        return R.ok().put("data",list);
    }
    /**
     * 查询Ai事件表(根据关键字发送文本和图片)列表
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptKeywordSend:list')")
    @GetMapping("/list")
    public TableDataInfo list(FastGptKeywordSend fastGptKeywordSend)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptKeywordSend.setCompanyId(loginUser.getUser().getCompanyId());
        CompanyDept companyDept = companyDeptService.selectCompanyDeptById(loginUser.getUser().getDept().getDeptId());
        //主账号能看整个公司的内容
        if(companyDept != null && companyDept.getParentId() != 0){
            fastGptKeywordSend.setCompanyUserId(loginUser.getUser().getUserId());
        }
        fastGptKeywordSend.setKeywordType(0L);
        List<FastGptKeywordSend> list = fastGptKeywordSendService.selectFastGptKeywordSendList(fastGptKeywordSend);
        return getDataTable(list);
    }

    /**
     * 导出Ai事件表(根据关键字发送文本和图片)列表
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptKeywordSend:export')")
    @Log(title = "Ai事件表(根据关键字发送文本和图片)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FastGptKeywordSend fastGptKeywordSend)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptKeywordSend.setCompanyId(loginUser.getCompany().getCompanyId());
        fastGptKeywordSend.setCompanyUserId(loginUser.getUser().getUserId());
        fastGptKeywordSend.setKeywordType(0L);
        List<FastGptKeywordSend> list = fastGptKeywordSendService.selectFastGptKeywordSendList(fastGptKeywordSend);
        ExcelUtil<FastGptKeywordSend> util = new ExcelUtil<FastGptKeywordSend>(FastGptKeywordSend.class);
        return util.exportExcel(list, "Ai事件表(根据关键字发送文本和图片)数据");
    }

    /**
     * 获取Ai事件表(根据关键字发送文本和图片)详细信息
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptKeywordSend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Long keywordType = 0L;
        return AjaxResult.success(fastGptKeywordSendService.selectFastGptKeywordSendById(id,keywordType));
    }

    /**
     * 新增Ai事件表(根据关键字发送文本和图片)
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptKeywordSend:add')")
    @Log(title = "Ai事件表(根据关键字发送文本和图片)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FastGptKeywordSend fastGptKeywordSend)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptKeywordSend.setCompanyId(loginUser.getCompany().getCompanyId());
        fastGptKeywordSend.setCompanyUserId(loginUser.getUser().getUserId());
        fastGptKeywordSend.setKeywordType(0L);
        return toAjax(fastGptKeywordSendService.insertFastGptKeywordSend(fastGptKeywordSend));
    }

    /**
     * 修改Ai事件表(根据关键字发送文本和图片)
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptKeywordSend:edit')")
    @Log(title = "Ai事件表(根据关键字发送文本和图片)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FastGptKeywordSend fastGptKeywordSend)
    {
        fastGptKeywordSend.setKeywordType(0L);
        return toAjax(fastGptKeywordSendService.updateFastGptKeywordSend(fastGptKeywordSend));
    }

    /**
     * 删除Ai事件表(根据关键字发送文本和图片)
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptKeywordSend:remove')")
    @Log(title = "Ai事件表(根据关键字发送文本和图片)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fastGptKeywordSendService.deleteFastGptKeywordSendByIds(ids));
    }
}
