package com.fs.fastGpt.mapper;

import com.fs.fastGpt.domain.FastGptRole;
import com.fs.fastGpt.vo.FastGptRoleVO;
import com.fs.his.vo.OptionsVO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 应用Mapper接口
 *
 * @author fs
 * @date 2024-09-30
 */
public interface FastGptRoleMapper
{
    /**
     * 查询应用
     *
     * @param roleId 应用主键
     * @return 应用
     */
    public FastGptRole selectFastGptRoleByRoleId(Long roleId);

    /**
     * 查询应用列表
     *
     * @param fastGptRole 应用
     * @return 应用集合
     */
    public List<FastGptRole> selectFastGptRoleList(FastGptRole fastGptRole);

    @Select("<script> " +
            "select fr.*,qc.corp_name as corpName  from fastgpt_role fr left join qw_company qc on fr.bind_corp_id=qc.corp_id " +
            "         <where>  \n" +
            "            <if test=\"roleName != null  and roleName != ''\"> and role_name like concat('%', #{roleName}, '%')</if>\n" +
            "            <if test=\"companyId != null \"> and company_id = #{companyId}</if>\n" +
            "            <if test=\"roleType != null \"> and role_type = #{roleType}</if>\n" +
            "            <if test=\"modeConfigJson != null  and modeConfigJson != ''\"> and mode_config_json = #{modeConfigJson}</if>\n" +
            "            <if test=\"mode != null \"> and mode = #{mode}</if>\n" +
            "            <if test=\"kfId != null  and kfId != ''\"> and kf_id = #{kfId}</if>\n" +
            "            <if test=\"kfUrl != null  and kfUrl != ''\"> and kf_url = #{kfUrl}</if>\n" +
            "            <if test=\"avatar != null  and avatar != ''\"> and avatar = #{avatar}</if>\n" +
            "            <if test=\"kfMediaId != null  and kfMediaId != ''\"> and kf_media_id = #{kfMediaId}</if>\n" +
            "            <if test=\"reminderWords != null  and reminderWords != ''\"> and reminder_words = #{reminderWords}</if>\n" +
            "            <if test=\"bindCorpId != null  and bindCorpId != ''\"> and bind_corp_id = #{bindCorpId}</if>\n" +
            "        </where>" +
            "</script> ")
    public List<FastGptRoleVO> selectFastGptRoleListVO(FastGptRole fastGptRole);

    /**
     * 新增应用
     *
     * @param fastGptRole 应用
     * @return 结果
     */
    public int insertFastGptRole(FastGptRole fastGptRole);

    /**
     * 修改应用
     *
     * @param fastGptRole 应用
     * @return 结果
     */
    public int updateFastGptRole(FastGptRole fastGptRole);

    /**
     * 删除应用
     *
     * @param roleId 应用主键
     * @return 结果
     */
    public int deleteFastGptRoleByRoleId(Long roleId);

    /**
     * 批量删除应用
     *
     * @param roleIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFastGptRoleByRoleIds(Long[] roleIds);

    @Update("update fastgpt_role set bind_corp_id = null where role_id = #{roleId}")
    public int relieveFastGptRole(Long roleId);

    @Select("select id dictValue,name dictLabel from fastgpt_role_type ")
    List<OptionsVO> selectFastGptRoleType();
    @Select("select r.role_id, r.role_name,t.contact_info,r.company_id, r.create_time, r.update_time, r.role_type, r.mode_config_json, r.mode, r.kf_id, r.kf_url, r.avatar, r.kf_media_id,r.reminder_words, r.bind_corp_id from fastgpt_role r LEFT JOIN fastgpt_role_type t on t.id =r.role_type where role_id = #{roleId}")
    FastGptRole selectFastGptRoleTypeByRoleId(Long roleId);
}
