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

    <resultMap type="BaseMeterInfo" id="BaseMeterInfoResult">
        <result property="objid"    column="objid"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="buildNumber"    column="build_number"    />
        <result property="floorNumber"    column="floor_number"    />
        <result property="roomNumber"    column="room_number"    />
        <result property="physicalNumber"    column="physical_number"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="precisionValue"    column="precision_value"    />
        <result property="produceDate"    column="produce_date"    />
        <result property="meterId"    column="meter_id"    />
        <result property="model"    column="model"    />
        <result property="meterEnergyType"    column="meter_energy_type"    />
        <result property="meterAdress"    column="meter_adress"    />
        <result property="meterStatus"    column="meter_status"    />
        <result property="ctChange"    column="ct_change"    />
        <result property="collectId"    column="collect_id"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBaseMeterInfoVo">
        select objid, dept_id, dept_name, build_number, floor_number, room_number, physical_number, manufacturer, precision_value, produce_date, meter_id, model, meter_energy_type, meter_adress, meter_status, ct_change, collect_id, remark from base_meter_info
    </sql>

    <select id="selectBaseMeterInfoList" parameterType="BaseMeterInfo" resultMap="BaseMeterInfoResult">
        <include refid="selectBaseMeterInfoVo"/>
        <where>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="buildNumber != null  and buildNumber != ''"> and build_number = #{buildNumber}</if>
            <if test="floorNumber != null  and floorNumber != ''"> and floor_number = #{floorNumber}</if>
            <if test="roomNumber != null  and roomNumber != ''"> and room_number = #{roomNumber}</if>
            <if test="physicalNumber != null  and physicalNumber != ''"> and physical_number = #{physicalNumber}</if>
            <if test="manufacturer != null  and manufacturer != ''"> and manufacturer = #{manufacturer}</if>
            <if test="precisionValue != null "> and precision_value = #{precisionValue}</if>
            <if test="produceDate != null "> and produce_date = #{produceDate}</if>
            <if test="meterId != null  and meterId != ''"> and meter_id = #{meterId}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="meterEnergyType != null "> and meter_energy_type = #{meterEnergyType}</if>
            <if test="meterAdress != null  and meterAdress != ''"> and meter_adress = #{meterAdress}</if>
            <if test="meterStatus != null "> and meter_status = #{meterStatus}</if>
            <if test="ctChange != null  and ctChange != ''"> and ct_change = #{ctChange}</if>
            <if test="collectId != null  and collectId != ''"> and collect_id = #{collectId}</if>
            ${params.dataScope}
        </where>
    </select>

    <select id="selectBaseMeterInfoByObjid" parameterType="Long" resultMap="BaseMeterInfoResult">
        <include refid="selectBaseMeterInfoVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseMeterInfo" parameterType="BaseMeterInfo" useGeneratedKeys="true" keyProperty="objid">
        insert into base_meter_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="buildNumber != null">build_number,</if>
            <if test="floorNumber != null">floor_number,</if>
            <if test="roomNumber != null">room_number,</if>
            <if test="physicalNumber != null">physical_number,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="precisionValue != null">precision_value,</if>
            <if test="produceDate != null">produce_date,</if>
            <if test="meterId != null">meter_id,</if>
            <if test="model != null">model,</if>
            <if test="meterEnergyType != null">meter_energy_type,</if>
            <if test="meterAdress != null">meter_adress,</if>
            <if test="meterStatus != null">meter_status,</if>
            <if test="ctChange != null">ct_change,</if>
            <if test="collectId != null">collect_id,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="buildNumber != null">#{buildNumber},</if>
            <if test="floorNumber != null">#{floorNumber},</if>
            <if test="roomNumber != null">#{roomNumber},</if>
            <if test="physicalNumber != null">#{physicalNumber},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="precisionValue != null">#{precisionValue},</if>
            <if test="produceDate != null">#{produceDate},</if>
            <if test="meterId != null">#{meterId},</if>
            <if test="model != null">#{model},</if>
            <if test="meterEnergyType != null">#{meterEnergyType},</if>
            <if test="meterAdress != null">#{meterAdress},</if>
            <if test="meterStatus != null">#{meterStatus},</if>
            <if test="ctChange != null">#{ctChange},</if>
            <if test="collectId != null">#{collectId},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBaseMeterInfo" parameterType="BaseMeterInfo">
        update base_meter_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="buildNumber != null">build_number = #{buildNumber},</if>
            <if test="floorNumber != null">floor_number = #{floorNumber},</if>
            <if test="roomNumber != null">room_number = #{roomNumber},</if>
            <if test="physicalNumber != null">physical_number = #{physicalNumber},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="precisionValue != null">precision_value = #{precisionValue},</if>
            <if test="produceDate != null">produce_date = #{produceDate},</if>
            <if test="meterId != null">meter_id = #{meterId},</if>
            <if test="model != null">model = #{model},</if>
            <if test="meterEnergyType != null">meter_energy_type = #{meterEnergyType},</if>
            <if test="meterAdress != null">meter_adress = #{meterAdress},</if>
            <if test="meterStatus != null">meter_status = #{meterStatus},</if>
            <if test="ctChange != null">ct_change = #{ctChange},</if>
            <if test="collectId != null">collect_id = #{collectId},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseMeterInfoByObjid" parameterType="Long">
        delete from base_meter_info where objid = #{objid}
    </delete>

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

</mapper>
