<?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.hw.ems.base.mapper.BaseMonitorPublicMapper">

    <resultMap type="BaseMonitorPublic" id="BaseMonitorPublicResult">
        <result property="monitorId"    column="monitor_id"    />
        <result property="publicShareId"    column="public_share_id"    />
        <result property="public_share_type"    column="publicShareType"    />
    </resultMap>

    <sql id="selectBaseMonitorPublicVo">
        select monitor_id, public_share_id,public_share_type from base_monitor_public
    </sql>

    <select id="selectBaseMonitorPublicList" parameterType="BaseMonitorPublic" resultMap="BaseMonitorPublicResult">
        <include refid="selectBaseMonitorPublicVo"/>
        <where>
            <if test="monitorId != null  and monitorId != ''"> and monitor_id = #{monitorId}</if>
            <if test="publicShareId != null "> and public_share_id = #{publicShareId}</if>
        </where>
    </select>

    <select id="selectBaseMonitorPublicByMonitorId" parameterType="String" resultMap="BaseMonitorPublicResult">
        <include refid="selectBaseMonitorPublicVo"/>
        where monitor_id = #{monitorId}
    </select>

    <insert id="insertBaseMonitorPublic" parameterType="BaseMonitorPublic">
        insert into base_monitor_public
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorId != null and monitorId != ''">monitor_id,</if>
            <if test="publicShareId != null">public_share_id,</if>
            <if test="publicShareType != null">public_share_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitorId != null and monitorId != ''">#{monitorId},</if>
            <if test="publicShareId != null">#{publicShareId},</if>
            <if test="publicShareType != null">#{publicShareType},</if>
         </trim>
    </insert>
    <insert id="batchMonitorPublic">
        insert into base_monitor_public(monitor_id, public_share_id,public_share_type) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.monitorId},#{item.publicShareId},#{item.publicShareType})
        </foreach>
    </insert>

    <update id="updateBaseMonitorPublic" parameterType="BaseMonitorPublic">
        update base_monitor_public
        <trim prefix="SET" suffixOverrides=",">
            <if test="publicShareId != null">public_share_id = #{publicShareId},</if>
            <if test="publicShareType != null">public_share_type = #{publicShareType},</if>
        </trim>
        where monitor_id = #{monitorId}
    </update>

    <delete id="deleteBaseMonitorPublicByMonitorId" parameterType="String">
        delete from base_monitor_public where monitor_id = #{monitorId}
    </delete>

    <delete id="deleteBaseMonitorPublicById" parameterType="Long">
        delete from base_monitor_public where public_share_id = #{id}
    </delete>

    <delete id="deleteBaseMonitorPublicByMonitorIds" parameterType="String">
        delete from base_monitor_public where monitor_id in
        <foreach item="monitorId" collection="array" open="(" separator="," close=")">
            #{monitorId}
        </foreach>
    </delete>

</mapper>
