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.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.fastGpt.domain.FastGptDataset;
import com.fs.fastGpt.service.IFastGptDatasetService;
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;

/**
 * 知识库列Controller
 *
 * @author fs
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/fastGpt/fastGptDataset")
public class FastGptDatasetController extends BaseController
{
    @Autowired
    private IFastGptDatasetService fastGptDatasetService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询知识库列列表
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptDataset:list')")
    @GetMapping("/list")
    public TableDataInfo list(FastGptDataset fastGptDataset)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptDataset.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FastGptDataset> list = fastGptDatasetService.selectFastGptDatasetList(fastGptDataset);
        return getDataTable(list);
    }


    /**
     * 同步知识库信息
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptDataset:edit')")
    @GetMapping(value = "/syncDataset")
    public R getInfo()
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        return fastGptDatasetService.syncDataset(loginUser.getCompany().getCompanyId());
    }

    /**
     * 新增知识库列
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptDataset:add')")
    @Log(title = "知识库列", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody FastGptDataset fastGptDataset)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptDataset.setCompanyId(loginUser.getCompany().getCompanyId());

        return fastGptDatasetService.insertFastGptDataset(fastGptDataset);
    }

//    /**
//     * 修改知识库列(没有API)
//     */
//    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptDataset:edit')")
//    @Log(title = "知识库列", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody FastGptDataset fastGptDataset)
//    {
//        return toAjax(fastGptDatasetService.updateFastGptDataset(fastGptDataset));
//    }

    /**
     * 删除知识库列
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptDataset:remove')")
    @Log(title = "知识库列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{datasetIds}")
    public R remove(@PathVariable String[] datasetIds)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        return fastGptDatasetService.deleteFastGptDatasetByDatasetIds(datasetIds,loginUser.getCompany().getCompanyId());
    }

    //获取所有的知识库
    @GetMapping("/getAllDataSetList")
    public R getAllDataSetList()
    {
        FastGptDataset fastGptDataset=new FastGptDataset();

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptDataset.setCompanyId(loginUser.getCompany().getCompanyId());

        List<FastGptDataset> fastGptDatasets = fastGptDatasetService.selectFastGptDatasetList(fastGptDataset);
        return R.ok().put("data",fastGptDatasets);
    }
}
