<?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.fs.sop.mapper.QwSopTempRulesMapper">

    <resultMap type="QwSopTempRules" id="QwSopTempRulesResult">
        <result property="id"    column="id"    />
        <result property="tempId"    column="temp_id"    />
        <result property="name"    column="name"    />
        <result property="dayNum"    column="day_num"    />
        <result property="time"    column="time"    />
        <result property="contentType"    column="content_type"    />
        <result property="courseType"    column="course_type"    />
        <result property="courseId"    column="course_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="aiTouch"    column="ai_touch"    />
        <result property="addTag"    column="add_tag"    />
        <result property="delTag"    column="del_tag"    />
    </resultMap>

    <sql id="selectQwSopTempRulesVo">
        select id, temp_id, name, day_num,add_tag,del_tag, time, content_type, course_type, course_id, video_id, ai_touch from qw_sop_temp_rules
    </sql>

    <select id="selectQwSopTempRulesList" parameterType="QwSopTempRules" resultMap="QwSopTempRulesResult">
        <include refid="selectQwSopTempRulesVo"/>
        <where>
            <if test="tempId != null  and tempId != ''"> and temp_id = #{tempId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="dayNum != null "> and day_num = #{dayNum}</if>
            <if test="time != null  and time != ''"> and time = #{time}</if>
            <if test="contentType != null "> and content_type = #{contentType}</if>
            <if test="courseType != null "> and course_type = #{courseType}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="aiTouch != null  and aiTouch != ''"> and ai_touch = #{aiTouch}</if>
        </where>
    </select>

    <select id="selectQwSopTempRulesById" parameterType="String" resultMap="QwSopTempRulesResult">
        <include refid="selectQwSopTempRulesVo"/>
        where id = #{id}
    </select>
<!--    <select id="listByTempId" resultType="com.fs.sop.domain.QwSopTempRules">-->
<!--        select * from qw_sop_temp_rules where temp_id = CAST(#{id} AS UUID)-->
<!--    </select>-->
    <select id="listByTempId" resultType="com.fs.sop.domain.QwSopTempRules">
        select * from qw_sop_temp_rules where temp_id = #{id}
    </select>
<!--    <select id="listByTempIdAndNameAndDayNum" resultType="com.fs.sop.domain.QwSopTempRules">-->
<!--        select * from qw_sop_temp_rules where temp_id = CAST(#{id} AS UUID) and day_num = #{dayNum} order by `time`-->
<!--    </select>-->
    <select id="listByTempIdAndNameAndDayNum" resultType="com.fs.sop.domain.QwSopTempRules">
        select * from qw_sop_temp_rules where temp_id = #{id} and day_num = #{dayNum} order by `time`
    </select>

    <insert id="insertQwSopTempRules" parameterType="QwSopTempRules">
        insert into qw_sop_temp_rules
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="tempId != null and tempId != ''">temp_id,</if>
            <if test="name != null">name,</if>
            <if test="dayNum != null">day_num,</if>
            <if test="time != null">time,</if>
            <if test="contentType != null">content_type,</if>
            <if test="courseType != null">course_type,</if>
            <if test="courseId != null">course_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="aiTouch != null">ai_touch,</if>
            <if test="addTag != null">add_tag,</if>
            <if test="delTag != null">del_tag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="tempId != null and tempId != ''">#{tempId},</if>
            <if test="name != null">#{name},</if>
            <if test="dayNum != null">#{dayNum},</if>
            <if test="time != null">#{time},</if>
            <if test="contentType != null">#{contentType},</if>
            <if test="courseType != null">#{courseType},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="aiTouch != null">#{aiTouch},</if>
            <if test="addTag != null">#{addTag},</if>
            <if test="delTag != null">#{delTag},</if>
         </trim>
    </insert>
    <insert id="insertBatch" useGeneratedKeys="false">
        insert into qw_sop_temp_rules (id,temp_id,name,day_num,time, type,content_type,course_type,course_id,video_id,ai_touch)
        values
        <foreach collection="list" item="item" separator=",">
            ( CAST(#{item.id} AS UUID), CAST(#{item.tempId} AS UUID), #{item.name}, #{item.dayNum}, #{item.time}, #{item.type}, #{item.contentType}, #{item.courseType}, #{item.courseId}, #{item.videoId}, #{item.aiTouch})
        </foreach>
    </insert>

    <update id="updateQwSopTempRules" parameterType="QwSopTempRules">
        update qw_sop_temp_rules
        <trim prefix="SET" suffixOverrides=",">
            <if test="tempId != null and tempId != ''">temp_id = CAST(#{tempId} AS UUID),</if>
            <if test="name != null">name = #{name},</if>
            <if test="dayNum != null">day_num = #{dayNum},</if>
            <if test="time != null">time = #{time},</if>
            <if test="contentType != null">content_type = #{contentType},</if>
            <if test="courseType != null">course_type = #{courseType},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="aiTouch != null">ai_touch = #{aiTouch},</if>
            <if test="addTag != null">add_tag = #{addTag},</if>
            <if test="delTag != null">del_tag = #{delTag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwSopTempRulesById" parameterType="String">
        ALTER TABLE qw_sop_temp_rules DELETE where id = CAST(#{id} AS UUID)
    </delete>

    <delete id="deleteQwSopTempRulesByIds" parameterType="String">
        delete from qw_sop_temp_rules where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
<!--    <delete id="deleteByTempId">-->
<!--        ALTER TABLE qw_sop_temp_rules DELETE where temp_id = CAST(#{id} AS UUID)-->
<!--    </delete>-->
    <delete id="deleteByTempId">
        DELETE from qw_sop_temp_rules where temp_id = #{id}
    </delete>
    <delete id="deleteByIdList">
        ALTER TABLE qw_sop_temp_rules DELETE where id in
        <foreach item="item" collection="ids" open="(" separator="," close=")">
            CAST(#{item} AS UUID)
        </foreach>
    </delete>
</mapper>
