<?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.QwSopTempContentMapper">

    <resultMap type="QwSopTempContent" id="QwSopTempContentResult">
        <result property="id"    column="id"    />
        <result property="rulesId"    column="rules_id"    />
        <result property="sendType"    column="send_type"    />
        <result property="content"    column="content"    />
        <result property="isBindUrl"    column="is_bind_url"    />
        <result property="expiresDays"    column="expires_days"    />
    </resultMap>

    <sql id="selectQwSopTempContentVo">
        select id, rules_id, send_type, content, is_bind_url, expires_days from qw_sop_temp_content
    </sql>

    <select id="selectQwSopTempContentList" parameterType="QwSopTempContent" resultMap="QwSopTempContentResult">
        <include refid="selectQwSopTempContentVo"/>
        <where>
            <if test="rulesId != null  and rulesId != ''"> and rules_id = #{rulesId}</if>
            <if test="sendType != null "> and send_type = #{sendType}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="isBindUrl != null "> and is_bind_url = #{isBindUrl}</if>
            <if test="expiresDays != null  and expiresDays != ''"> and expires_days = #{expiresDays}</if>
        </where>
    </select>

    <select id="selectQwSopTempContentById" parameterType="String" resultMap="QwSopTempContentResult">
        <include refid="selectQwSopTempContentVo"/>
        where id = #{id}
    </select>
<!--    <select id="listByRulesIds" resultType="com.fs.sop.domain.QwSopTempContent">-->
<!--        select * from qw_sop_temp_content where rules_id in-->
<!--        <foreach collection="ids" open="(" close=")" item="item" separator=",">CAST(#{item} AS UUID)</foreach>-->
<!--    </select>-->
    <select id="listByRulesIds" resultType="com.fs.sop.domain.QwSopTempContent">
        select * from qw_sop_temp_content where rules_id in
        <foreach collection="ids" open="(" close=")" item="item" separator=",">#{item}</foreach>
    </select>
    <select id="listVoice" resultType="com.fs.sop.domain.QwSopTempContent">
        SELECT  a.*  FROM qw_sop_temp_content a inner join qw_sop_temp_rules b on a.rules_id = b.id WHERE a.temp_id = #{tempId} AND a.content_type = 7
    </select>
    <select id="listByTempAndDay" resultType="com.fs.sop.domain.QwSopTempContent">
        SELECT  a.*  FROM qw_sop_temp_content a WHERE a.temp_id = #{tempId} and a.day_id = #{dayId} AND a.content_type = 7
    </select>

    <insert id="insertQwSopTempContent" parameterType="QwSopTempContent">
        insert into qw_sop_temp_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="rulesId != null">rules_id,</if>
            <if test="sendType != null">send_type,</if>
            <if test="content != null">content,</if>
            <if test="isBindUrl != null">is_bind_url,</if>
            <if test="expiresDays != null">expires_days,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="rulesId != null">#{rulesId},</if>
            <if test="sendType != null">#{sendType},</if>
            <if test="content != null">#{content},</if>
            <if test="isBindUrl != null">#{isBindUrl},</if>
            <if test="expiresDays != null">#{expiresDays},</if>
         </trim>
    </insert>
    <insert id="insertBatch" useGeneratedKeys="false">
        insert into qw_sop_temp_content (id, temp_id,rules_id,content_type,content,is_bind_url,expires_days)
        values
        <foreach collection="list" item="item" separator=",">
            ( CAST(#{item.id} AS UUID), CAST(#{item.tempId} AS UUID), CAST(#{item.rulesId} AS UUID), #{item.contentType}, #{item.content}, #{item.isBindUrl}, #{item.expiresDays})
        </foreach>
    </insert>

    <update id="updateQwSopTempContent" parameterType="QwSopTempContent">
        update qw_sop_temp_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="rulesId != null">rules_id = #{rulesId},</if>
            <if test="sendType != null">send_type = #{sendType},</if>
            <if test="content != null">content = #{content},</if>
            <if test="isBindUrl != null">is_bind_url = #{isBindUrl},</if>
            <if test="expiresDays != null">expires_days = #{expiresDays},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateDay">
        update qw_sop_temp_content set day_id = #{dayId} where id = #{id}
    </update>

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

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