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.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.FastGptCollentionData;
import com.fs.fastGpt.service.IFastGptCollentionDataService;
import com.fs.fastgptApi.param.FastGptCollentionDataParam;
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.text.ParseException;
import java.util.List;

/**
 * 集合里数据Controller
 *
 * @author fs
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/fastGpt/fastGptCollentionData")
public class FastGptCollentionDataController extends BaseController
{
    @Autowired
    private IFastGptCollentionDataService fastGptCollentionDataService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询集合里数据列表
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptCollentionData:list')")
    @GetMapping("/list")
    public TableDataInfo list(FastGptCollentionData fastGptCollentionData)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptCollentionData.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FastGptCollentionData> list = fastGptCollentionDataService.selectFastGptCollentionDataList(fastGptCollentionData);
        return getDataTable(list);
    }



    /**
     * 获取集合里数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptCollentionData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(fastGptCollentionDataService.selectFastGptCollentionDataById(id));
    }

    /**
     * 新增(批量)集合里数据
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptCollentionData:add')")
    @Log(title = "集合里数据", businessType = BusinessType.INSERT)
    @PostMapping
    public  R add(@RequestBody FastGptCollentionDataParam param)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId(loginUser.getUser().getCompanyId());
        return fastGptCollentionDataService.insertFastGptCollentionData(param);
    }

    /**
     * 修改集合里数据
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptCollentionData:edit')")
    @Log(title = "集合里数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody FastGptCollentionData fastGptCollentionData)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fastGptCollentionData.setCompanyId(loginUser.getUser().getCompanyId());
        return fastGptCollentionDataService.updateFastGptCollentionData(fastGptCollentionData);
    }

    /**
     * 删除集合里数据
     */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptCollentionData:remove')")
    @Log(title = "集合里数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        return fastGptCollentionDataService.deleteFastGptCollentionDataByIds(ids,loginUser.getCompany().getCompanyId());
    }

    /**
    * 同步集合内数据
    */
    @PreAuthorize("@ss.hasPermi('fastGpt:fastGptCollentionData:sync')")
    @GetMapping("/SyncCollentionData/{collectionId}")
    public R syncCollentionData(@PathVariable String collectionId) throws ParseException {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        return fastGptCollentionDataService.syncCollentionData(collectionId,loginUser.getCompany().getCompanyId());
    }
}
