<?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.AiWorkMapper">
    
    <resultMap type="AiWork" id="AiWorkResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <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"    />
        <result property="url"    column="url"    />
        <result property="text"    column="text"    />
        <result property="userId"    column="user_id"    />
        <result property="type"    column="type"    />
        <result property="source"    column="source"    />
        <result property="isTop"    column="is_top"    />
    </resultMap>

    <sql id="selectAiWorkVo">
        select id, del_flag, create_by, create_time, update_by, update_time, remark, url, text, user_id, type, source, is_top from ai_work
    </sql>

    <select id="selectAiWorkList" parameterType="AiWork" resultMap="AiWorkResult">
        <include refid="selectAiWorkVo"/>
        <where>  
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="text != null  and text != ''"> and text = #{text}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="isTop != null  and isTop != ''"> and is_top = #{isTop}</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectAiWorkById" parameterType="Long" resultMap="AiWorkResult">
        <include refid="selectAiWorkVo"/>
        where id = #{id}
    </select>

    <insert id="insertAiWork" parameterType="AiWork" useGeneratedKeys="true" keyProperty="id">
        insert into ai_work
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="url != null">url,</if>
            <if test="text != null">text,</if>
            <if test="userId != null">user_id,</if>
            <if test="type != null">type,</if>
            <if test="source != null">source,</if>
            <if test="isTop != null">is_top,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="url != null">#{url},</if>
            <if test="text != null">#{text},</if>
            <if test="userId != null">#{userId},</if>
            <if test="type != null">#{type},</if>
            <if test="source != null">#{source},</if>
            <if test="isTop != null">#{isTop},</if>
         </trim>
    </insert>

    <update id="updateAiWork" parameterType="AiWork">
        update ai_work
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="url != null">url = #{url},</if>
            <if test="text != null">text = #{text},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="source != null">type = #{source},</if>
            <if test="isTop != null">is_top = #{isTop},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAiWorkById" parameterType="Long">
        delete from ai_work where id = #{id}
    </delete>

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