package com.fs.chat.controller;

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.poi.ExcelUtil;
import com.fs.fastGpt.domain.FastGptRole;
import com.fs.fastGpt.service.IFastGptRoleService;
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/fastGptRole")
public class FastGptRoleController extends BaseController
{
    @Autowired
    private IFastGptRoleService fastGptRoleService;



    @GetMapping("/getAllRoleList")
    public R getAllRoleList()
    {
        FastGptRole role=new FastGptRole();
        role.setRoleType(3);
        List<FastGptRole> list = fastGptRoleService.selectFastGptRoleList(role);
        return R.ok().put("data",list);
    }

    /**
     * 查询应用列表
     */
    @PreAuthorize("@ss.hasPermi('shop:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(FastGptRole fastgptRole)
    {
        startPage();
        List<FastGptRole> list = fastGptRoleService.selectAiDoctorList(fastgptRole);
        return getDataTable(list);
    }


    /**
     * 导出应用列表
     */
    @PreAuthorize("@ss.hasPermi('shop:role:export')")
    @Log(title = "应用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FastGptRole fastgptRole)
    {
        List<FastGptRole> list = fastGptRoleService.selectFastGptRoleList(fastgptRole);
        ExcelUtil<FastGptRole> util = new ExcelUtil<FastGptRole>(FastGptRole.class);
        return util.exportExcel(list, "应用数据");
    }

    /**
     * 获取应用详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:role:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(fastGptRoleService.selectFastGptRoleByRoleId(roleId));
    }

    /**
     * 新增应用
     */
    @PreAuthorize("@ss.hasPermi('shop:role:add')")
    @Log(title = "应用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FastGptRole fastgptRole)
    {
        fastgptRole.setRoleType(3);
        return toAjax(fastGptRoleService.insertFastGptRole(fastgptRole));
    }

    /**
     * 修改应用
     */
    @PreAuthorize("@ss.hasPermi('shop:role:edit')")
    @Log(title = "应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FastGptRole fastgptRole)
    {
        return toAjax(fastGptRoleService.updateFastGptRole(fastgptRole));
    }

    /**
     * 删除应用
     */
    @PreAuthorize("@ss.hasPermi('shop:role:remove')")
    @Log(title = "应用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(fastGptRoleService.deleteFastGptRoleByRoleIds(roleIds));
    }

}
