<?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.ruoyi.ai.mapper.AiTemplateMapper">
    
    <resultMap type="AiTemplate" id="AiTemplateResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="chineseContent"    column="chinese_content"    />
        <result property="englishContent"    column="english_content"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="aiId"    column="ai_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectAiTemplateVo">
        select id, name, chinese_content, english_content, image_url, ai_id, status, remark, create_time, create_by, update_by, update_time, del_flag from ai_template
    </sql>

    <select id="selectAiTemplateList" parameterType="AiTemplate" resultMap="AiTemplateResult">
        <include refid="selectAiTemplateVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="chineseContent != null  and chineseContent != ''"> and chinese_content = #{chineseContent}</if>
            <if test="englishContent != null  and englishContent != ''"> and english_content = #{englishContent}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="aiId != null  and aiId != ''"> and ai_id = #{aiId}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAiTemplateById" parameterType="Long" resultMap="AiTemplateResult">
        <include refid="selectAiTemplateVo"/>
        where id = #{id}
    </select>

    <insert id="insertAiTemplate" parameterType="AiTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into ai_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="chineseContent != null">chinese_content,</if>
            <if test="englishContent != null">english_content,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="aiId != null">ai_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="chineseContent != null">#{chineseContent},</if>
            <if test="englishContent != null">#{englishContent},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="aiId != null">#{aiId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateAiTemplate" parameterType="AiTemplate">
        update ai_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="chineseContent != null">chinese_content = #{chineseContent},</if>
            <if test="englishContent != null">english_content = #{englishContent},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="aiId != null">ai_id = #{aiId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAiTemplateById" parameterType="Long">
        delete from ai_template where id = #{id}
    </delete>

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