<?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.pm.subsystem.mapper.IbmsBroadcastZoneMapper">

    <resultMap type="pd" id="IbmsBroadcastZoneResult">
        <result property="id"    column="id"    />
        <result property="zoneCode"    column="zone_code"    />
        <result property="zoneName"    column="zone_name"    />
        <result property="zoneType"    column="zone_type"    />
        <result property="buildingName"    column="building_name"    />
        <result property="floorName"    column="floor_name"    />
        <result property="spaceLocation"    column="space_location"    />
        <result property="deviceCount"    column="device_count"    />
        <result property="volume"    column="volume"    />
        <result property="isMute"    column="is_mute"    />
        <result property="isOnline"    column="is_online"    />
        <result property="broadcastStatus"    column="broadcast_status"    />
        <result property="currentContent"    column="current_content"    />
        <result property="contentCode"    column="content_code"    />
        <result property="priority"    column="priority"    />
        <result property="positionX"    column="position_x"    />
        <result property="positionY"    column="position_y"    />
        <result property="positionZ"    column="position_z"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectIbmsBroadcastZoneVo">
        select id, zone_code, zone_name, zone_type, building_name, floor_name, space_location,
               device_count, volume, is_mute, is_online, broadcast_status, current_content,
               content_code, priority, position_x, position_y, position_z, create_time, update_time
        from ibms_broadcast_zone
    </sql>

    <select id="selectIbmsBroadcastZoneList" parameterType="pd" resultMap="IbmsBroadcastZoneResult">
        <include refid="selectIbmsBroadcastZoneVo"/>
        <where>
            <if test="zoneCode != null and zoneCode != ''">
                and zone_code like concat('%', #{zoneCode}, '%')
            </if>
            <if test="zoneName != null and zoneName != ''">
                and zone_name like concat('%', #{zoneName}, '%')
            </if>
            <if test="zoneType != null and zoneType != ''">
                and zone_type = #{zoneType}
            </if>
            <if test="buildingName != null and buildingName != ''">
                and building_name = #{buildingName}
            </if>
            <if test="floorName != null and floorName != ''">
                and floor_name = #{floorName}
            </if>
            <if test="isOnline != null">
                and is_online = #{isOnline}
            </if>
            <if test="broadcastStatus != null">
                and broadcast_status = #{broadcastStatus}
            </if>
        </where>
        order by building_name, floor_name, zone_code
    </select>

    <select id="selectIbmsBroadcastZoneById" parameterType="Long" resultMap="IbmsBroadcastZoneResult">
        <include refid="selectIbmsBroadcastZoneVo"/>
        where id = #{id}
    </select>

    <insert id="insertIbmsBroadcastZone" parameterType="pd" useGeneratedKeys="true" keyProperty="id">
        insert into ibms_broadcast_zone
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="zoneCode != null and zoneCode != ''">zone_code,</if>
            <if test="zoneName != null and zoneName != ''">zone_name,</if>
            <if test="zoneType != null and zoneType != ''">zone_type,</if>
            <if test="buildingName != null and buildingName != ''">building_name,</if>
            <if test="floorName != null and floorName != ''">floor_name,</if>
            <if test="spaceLocation != null and spaceLocation != ''">space_location,</if>
            <if test="deviceCount != null">device_count,</if>
            <if test="volume != null">volume,</if>
            <if test="isMute != null">is_mute,</if>
            <if test="isOnline != null">is_online,</if>
            <if test="broadcastStatus != null">broadcast_status,</if>
            <if test="currentContent != null and currentContent != ''">current_content,</if>
            <if test="contentCode != null and contentCode != ''">content_code,</if>
            <if test="priority != null">priority,</if>
            <if test="positionX != null">position_x,</if>
            <if test="positionY != null">position_y,</if>
            <if test="positionZ != null">position_z,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="zoneCode != null and zoneCode != ''">#{zoneCode},</if>
            <if test="zoneName != null and zoneName != ''">#{zoneName},</if>
            <if test="zoneType != null and zoneType != ''">#{zoneType},</if>
            <if test="buildingName != null and buildingName != ''">#{buildingName},</if>
            <if test="floorName != null and floorName != ''">#{floorName},</if>
            <if test="spaceLocation != null and spaceLocation != ''">#{spaceLocation},</if>
            <if test="deviceCount != null">#{deviceCount},</if>
            <if test="volume != null">#{volume},</if>
            <if test="isMute != null">#{isMute},</if>
            <if test="isOnline != null">#{isOnline},</if>
            <if test="broadcastStatus != null">#{broadcastStatus},</if>
            <if test="currentContent != null and currentContent != ''">#{currentContent},</if>
            <if test="contentCode != null and contentCode != ''">#{contentCode},</if>
            <if test="priority != null">#{priority},</if>
            <if test="positionX != null">#{positionX},</if>
            <if test="positionY != null">#{positionY},</if>
            <if test="positionZ != null">#{positionZ},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateIbmsBroadcastZone" parameterType="pd">
        update ibms_broadcast_zone
        <trim prefix="SET" suffixOverrides=",">
            <if test="zoneCode != null and zoneCode != ''">zone_code = #{zoneCode},</if>
            <if test="zoneName != null and zoneName != ''">zone_name = #{zoneName},</if>
            <if test="zoneType != null and zoneType != ''">zone_type = #{zoneType},</if>
            <if test="buildingName != null and buildingName != ''">building_name = #{buildingName},</if>
            <if test="floorName != null and floorName != ''">floor_name = #{floorName},</if>
            <if test="spaceLocation != null and spaceLocation != ''">space_location = #{spaceLocation},</if>
            <if test="deviceCount != null">device_count = #{deviceCount},</if>
            <if test="volume != null">volume = #{volume},</if>
            <if test="isMute != null">is_mute = #{isMute},</if>
            <if test="isOnline != null">is_online = #{isOnline},</if>
            <if test="broadcastStatus != null">broadcast_status = #{broadcastStatus},</if>
            <if test="currentContent != null">current_content = #{currentContent},</if>
            <if test="contentCode != null">content_code = #{contentCode},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="positionX != null">position_x = #{positionX},</if>
            <if test="positionY != null">position_y = #{positionY},</if>
            <if test="positionZ != null">position_z = #{positionZ},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <!-- 更新音量和静音状态 -->
    <update id="updateZoneVolume" parameterType="pd">
        update ibms_broadcast_zone
        set volume = #{volume},
            is_mute = #{isMute},
            update_time = #{updateTime}
        where id = #{id}
    </update>

    <!-- 更新广播状态 -->
    <update id="updateBroadcastStatus" parameterType="pd">
        update ibms_broadcast_zone
        set broadcast_status = #{broadcastStatus},
            current_content = #{currentContent},
            content_code = #{contentCode},
            update_time = #{updateTime}
        where id = #{id}
    </update>

    <delete id="deleteIbmsBroadcastZoneById" parameterType="Long">
        delete from ibms_broadcast_zone where id = #{id}
    </delete>

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



