<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yushu.system.mapper.AiProviderMapper">
    
    <resultMap type="AiProvider" id="AiProviderResult">
        <result property="providerId"       column="provider_id"        />
        <result property="providerCode"     column="provider_code"      />
        <result property="providerName"     column="provider_name"      />
        <result property="providerNameEn"   column="provider_name_en"   />
        <result property="logoUrl"          column="logo_url"           />
        <result property="officialUrl"      column="official_url"       />
        <result property="apiDocUrl"        column="api_doc_url"        />
        <result property="description"      column="description"        />
        <result property="country"          column="country"            />
        <result property="status"           column="status"             />
        <result property="sortOrder"        column="sort_order"         />
        <result property="createBy"         column="create_by"          />
        <result property="createTime"       column="create_time"        />
        <result property="updateBy"         column="update_by"          />
        <result property="updateTime"       column="update_time"        />
        <result property="remark"           column="remark"             />
    </resultMap>

    <sql id="selectAiProviderVo">
        select provider_id, provider_code, provider_name, provider_name_en, logo_url, official_url, 
               api_doc_url, description, country, status, sort_order, create_by, create_time, 
               update_by, update_time, remark
        from ai_provider
    </sql>

    <select id="selectAiProviderList" parameterType="AiProvider" resultMap="AiProviderResult">
        <include refid="selectAiProviderVo"/>
        <where>  
            <if test="providerCode != null  and providerCode != ''"> and provider_code like concat('%', #{providerCode}, '%')</if>
            <if test="providerName != null  and providerName != ''"> and provider_name like concat('%', #{providerName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by sort_order asc, create_time desc
    </select>
    
    <select id="selectAiProviderByProviderId" parameterType="Long" resultMap="AiProviderResult">
        <include refid="selectAiProviderVo"/>
        where provider_id = #{providerId}
    </select>
        
    <insert id="insertAiProvider" parameterType="AiProvider" useGeneratedKeys="true" keyProperty="providerId">
        insert into ai_provider
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="providerCode != null and providerCode != ''">provider_code,</if>
            <if test="providerName != null and providerName != ''">provider_name,</if>
            <if test="providerNameEn != null">provider_name_en,</if>
            <if test="logoUrl != null">logo_url,</if>
            <if test="officialUrl != null">official_url,</if>
            <if test="apiDocUrl != null">api_doc_url,</if>
            <if test="description != null">description,</if>
            <if test="country != null">country,</if>
            <if test="status != null">status,</if>
            <if test="sortOrder != null">sort_order,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="providerCode != null and providerCode != ''">#{providerCode},</if>
            <if test="providerName != null and providerName != ''">#{providerName},</if>
            <if test="providerNameEn != null">#{providerNameEn},</if>
            <if test="logoUrl != null">#{logoUrl},</if>
            <if test="officialUrl != null">#{officialUrl},</if>
            <if test="apiDocUrl != null">#{apiDocUrl},</if>
            <if test="description != null">#{description},</if>
            <if test="country != null">#{country},</if>
            <if test="status != null">#{status},</if>
            <if test="sortOrder != null">#{sortOrder},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAiProvider" parameterType="AiProvider">
        update ai_provider
        <trim prefix="SET" suffixOverrides=",">
            <if test="providerCode != null and providerCode != ''">provider_code = #{providerCode},</if>
            <if test="providerName != null and providerName != ''">provider_name = #{providerName},</if>
            <if test="providerNameEn != null">provider_name_en = #{providerNameEn},</if>
            <if test="logoUrl != null">logo_url = #{logoUrl},</if>
            <if test="officialUrl != null">official_url = #{officialUrl},</if>
            <if test="apiDocUrl != null">api_doc_url = #{apiDocUrl},</if>
            <if test="description != null">description = #{description},</if>
            <if test="country != null">country = #{country},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sortOrder != null">sort_order = #{sortOrder},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where provider_id = #{providerId}
    </update>

    <delete id="deleteAiProviderByProviderId" parameterType="Long">
        delete from ai_provider where provider_id = #{providerId}
    </delete>

    <delete id="deleteAiProviderByProviderIds" parameterType="String">
        delete from ai_provider where provider_id in 
        <foreach item="providerId" collection="array" open="(" separator="," close=")">
            #{providerId}
        </foreach>
    </delete>
</mapper>

