<?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.aucma.base.mapper.BaseMonitorInfoMapper">

    <resultMap type="BaseMonitorInfo" id="BaseMonitorInfoResult">
        <result property="objId" column="obj_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="monitorCode" column="monitor_code"/>
        <result property="monitorName" column="monitor_name"/>
        <result property="monitorAddress" column="monitor_address"/>
        <result property="monitorType" column="monitor_type"/>
        <result property="monitorStatus" column="monitor_status"/>
        <result property="pt" column="pt"/>
        <result property="ct" column="ct"/>
        <result property="monitorHierarchy" column="monitor_hierarchy"/>
        <result property="monitorNetwork" column="monitor_network"/>
        <result property="isFlag" column="is_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="isAmmeter" column="is_ammeter"/>
    </resultMap>

    <sql id="selectBaseMonitorInfoVo">
        select obj_id,
               parent_id,
               monitor_code,
               monitor_name,
               monitor_address,
               monitor_type,
               monitor_status,
               pt,
               ct,
               monitor_hierarchy,
               monitor_network,
               is_flag,
               created_by,
               created_time,
               updated_by,
               updated_time,
               is_ammeter
        from base_monitorinfo
    </sql>

    <select id="selectBaseMonitorInfoList" parameterType="BaseMonitorInfo" resultMap="BaseMonitorInfoResult">
        <include refid="selectBaseMonitorInfoVo"/>
        <where>
            <if test="parentId != null ">and parent_id = #{parentId}</if>
            <if test="monitorName != null  and monitorName != ''">and monitor_name like concat(concat('%',
                #{monitorName}), '%')
            </if>
            <if test="monitorAddress != null  and monitorAddress != ''">and monitor_address = #{monitorAddress}</if>
            <if test="monitorType != null ">and monitor_type = #{monitorType}</if>
            <if test="monitorStatus != null ">and monitor_status = #{monitorStatus}</if>
            <if test="pt != null ">and pt = #{pt}</if>
            <if test="ct != null ">and ct = #{ct}</if>
            <if test="monitorHierarchy != null ">and monitor_hierarchy = #{monitorHierarchy}</if>
            <if test="monitorNetwork != null  and monitorNetwork != ''">and monitor_network = #{monitorNetwork}</if>
            <if test="isFlag != null ">and is_flag = #{isFlag}</if>
            <if test="createdBy != null  and createdBy != ''">and created_by = #{createdBy}</if>
            <if test="createdTime != null ">and created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
            <if test="isAmmeter != null ">and is_ammeter = #{isAmmeter}</if>
        </where>
    </select>

    <select id="selectBaseMonitorInfoByObjId" parameterType="Long" resultMap="BaseMonitorInfoResult">
        <include refid="selectBaseMonitorInfoVo"/>
        where obj_id = #{objId}
    </select>
    <select id="selectBaseMonitorInfoByNameLike" parameterType="String" resultMap="BaseMonitorInfoResult">
        <include refid="selectBaseMonitorInfoVo"/>
        where monitor_name like CONCAT(CONCAT('%',#{monitorName}),'%')
    </select>

    <insert id="insertBaseMonitorInfo" parameterType="BaseMonitorInfo">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_base_monitorinfo.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into base_monitorinfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="monitorCode != null">monitor_code,</if>
            <if test="monitorName != null">monitor_name,</if>
            <if test="monitorAddress != null">monitor_address,</if>
            <if test="monitorType != null">monitor_type,</if>
            <if test="monitorStatus != null">monitor_status,</if>
            <if test="pt != null">pt,</if>
            <if test="ct != null">ct,</if>
            <if test="monitorHierarchy != null">monitor_hierarchy,</if>
            <if test="monitorNetwork != null">monitor_network,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="isAmmeter != null">is_ammeter,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="monitorCode != null">#{monitorCode},</if>
            <if test="monitorName != null">#{monitorName},</if>
            <if test="monitorAddress != null">#{monitorAddress},</if>
            <if test="monitorType != null">#{monitorType},</if>
            <if test="monitorStatus != null">#{monitorStatus},</if>
            <if test="pt != null">#{pt},</if>
            <if test="ct != null">#{ct},</if>
            <if test="monitorHierarchy != null">#{monitorHierarchy},</if>
            <if test="monitorNetwork != null">#{monitorNetwork},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="isAmmeter != null">#{isAmmeter},</if>
        </trim>
    </insert>

    <update id="updateBaseMonitorInfo" parameterType="BaseMonitorInfo">
        update base_monitorinfo
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="monitorCode != null">monitor_code = #{monitorCode},</if>
            <if test="monitorName != null">monitor_name = #{monitorName},</if>
            <if test="monitorAddress != null">monitor_address = #{monitorAddress},</if>
            <if test="monitorType != null">monitor_type = #{monitorType},</if>
            <if test="monitorStatus != null">monitor_status = #{monitorStatus},</if>
            <if test="pt != null">pt = #{pt},</if>
            <if test="ct != null">ct = #{ct},</if>
            <if test="monitorHierarchy != null">monitor_hierarchy = #{monitorHierarchy},</if>
            <if test="monitorNetwork != null">monitor_network = #{monitorNetwork},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
            <if test="isAmmeter != null">is_ammeter = #{isAmmeter},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBaseMonitorInfoByObjId" parameterType="Long">
        delete
        from base_monitorinfo
        where obj_id = #{objId}
    </delete>

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