package com.fs.chat.mapper;

import java.util.List;
import com.fs.chat.domain.ChatDataset;
import com.fs.chat.param.ChatDatasetCParam;
import com.fs.chat.vo.ChatDatasetListCVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

/**
 * 知识库Mapper接口
 *
 * @author fs
 * @date 2024-04-21
 */
public interface ChatDatasetMapper
{
    /**
     * 查询知识库
     *
     * @param datasetId 知识库主键
     * @return 知识库
     */
    public ChatDataset selectChatDatasetByDatasetId(Long datasetId);

    /**
     * 查询知识库列表
     *
     * @param chatDataset 知识库
     * @return 知识库集合
     */
    public List<ChatDataset> selectChatDatasetList(ChatDataset chatDataset);

    /**
     * 新增知识库
     *
     * @param chatDataset 知识库
     * @return 结果
     */
    public int insertChatDataset(ChatDataset chatDataset);

    /**
     * 修改知识库
     *
     * @param chatDataset 知识库
     * @return 结果
     */
    public int updateChatDataset(ChatDataset chatDataset);

    /**
     * 删除知识库
     *
     * @param datasetId 知识库主键
     * @return 结果
     */
    public int deleteChatDatasetByDatasetId(Long datasetId);

    /**
     * 批量删除知识库
     *
     * @param datasetIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteChatDatasetByDatasetIds(Long[] datasetIds);
    @Select("select ifnull(count(1),0) from chat_dataset where role_id=#{roleId}")
    int check(Long roleId);

//    @Select({"<script> " +
//            "select d.*,r.role_name  from chat_dataset d left join chat_role r on r.role_id=d.role_id    " +
//            "where 1=1  " +
//            "<if test = 'maps.companyId != null  '> " +
//            "and d.company_id = #{maps.companyId}" +
//            "</if>" +
//            "<if test = 'maps.datasetName != null and  maps.datasetName !=\"\"     '> " +
//            "and d.dataset_name like CONCAT('%',#{maps.datasetName},'%') " +
//            "</if>" +
//            "<if test = ' maps.roleId!=null  '> " +
//            "and d.role_id = #{maps.roleId} " +
//            "</if>" +
//            " order by d.dataset_id desc "+
//            "</script>"})
@Select({"<script> " +
        "select d.*, r.role_name from chat_dataset d left join chat_role r on r.role_id = d.role_id " +
        "where 1=1 " +
        "<if test='maps.companyId != null'> " +
        "and d.company_id = #{maps.companyId} " +
        "</if> " +
        "<if test='maps.datasetName != null and maps.datasetName != \"\"'> " +
        "and d.dataset_name like CONCAT('%', #{maps.datasetName}, '%') " +
        "</if> " +
        "<if test='maps.roleId != null'> " +
        "and d.role_id = #{maps.roleId} " +
        "</if> " +
        "order by d.dataset_id desc " +
        "</script>"})
    List<ChatDatasetListCVO> selectChatDatasetListCVO(@Param("maps")ChatDatasetCParam chatDataset);
}
