<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.3//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zw.platform.repository.modules.FenceTTSConfigDao">

    <insert id="addFenceConfigTTsInfo">
        INSERT INTO zw_m_fence_config_tts(fence_config_id, message_template, type, create_data_username) VALUES
        <foreach collection="fenceTTSConfigList" item="tts" separator=",">
            (#{tts.fenceConfigId}, #{tts.messageTemplateId}, #{tts.type}, #{tts.createDataUsername})
        </foreach>
    </insert>

    <update id="updateTTSByFenceConfigId">
        UPDATE zw_m_fence_config_tts SET message_template = #{messageId}, update_time = now(), update_data_username = #{userName}
        WHERE fence_config_id = #{fenceConfigId} AND type = #{type}
    </update>

    <delete id="deleteFenceTTS">
        DELETE FROM zw_m_fence_config_tts WHERE
        fence_config_id IN
        <foreach collection="fenceConfigIds" item="configId" separator="," open="(" close=")">
            #{configId}
        </foreach>
    </delete>

    <delete id="deleteFenceTTSByType">
        DELETE FROM zw_m_fence_config_tts WHERE fence_config_id = #{fenceConfigId} AND type = #{type}
    </delete>

    <select id="listFenceTTSContent"
            resultType="com.zw.platform.domain.functionconfig.FenceTTSContentDO">
        SELECT tem.id AS messageId, tem.content AS content,  tts.type AS type, tts.fence_config_id AS fenceConfigId
        FROM zw_m_fence_config_tts tts
        INNER JOIN zw_m_message_template tem ON tts.message_template = tem.id AND tem.flag = 1
        where tts.fence_config_id IN
        <foreach collection="fenceConfigIds" item="configId" separator="," open="(" close=")">
            #{configId}
        </foreach>
    </select>

    <select id="getFenceTTSByConfigId" resultType="com.zw.platform.domain.functionconfig.FenceTTSContentDO">
        SELECT tem.id AS messageId, tem.content AS content,  tts.type AS type, tts.fence_config_id AS fenceConfigId
        FROM zw_m_fence_config_tts tts
        INNER JOIN zw_m_message_template tem ON tts.message_template = tem.id AND tem.flag = 1
        where tts.fence_config_id = #{fenceConfigId}
    </select>
</mapper>