<?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.ruoyi.ems.base.mapper.EmsBaseCollectDeviceInfoMapper">

    <resultMap type="EmsBaseCollectDeviceInfo" id="EmsBaseCollectDeviceInfoResult">
        <result property="objId" column="obj_id"/>
        <result property="collectDeviceId" column="collect_device_id"/>
        <result property="collectDeviceName" column="collect_device_name"/>
        <result property="energyTypeId" column="energy_type_id"/>
        <result property="energyTypeName" column="energy_name"/>
        <result property="model" column="model"/>
        <result property="manufacturer" column="manufacturer"/>
        <result property="ipAddress" column="ip_address"/>
        <result property="produceDate" column="produce_date"/>
        <result property="settingAddress" column="setting_address"/>
        <result property="isFlag" column="is_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectEmsBaseCollectDeviceInfoVo">
        select ebcdi.obj_id,
               ebcdi.collect_device_id,
               ebcdi.collect_device_name,
               ebcdi.energy_type_id,
               ebet.energy_name,
               ebcdi.model,
               ebcdi.manufacturer,
               ebcdi.ip_address,
               ebcdi.produce_date,
               ebcdi.setting_address,
               ebcdi.is_flag,
               ebcdi.create_by,
               ebcdi.create_time,
               ebcdi.update_by,
               ebcdi.update_time,
               ebcdi.remark
        from ems_base_collect_device_info ebcdi
                 left join ems_base_energy_type ebet on ebcdi.energy_type_id = ebet.energy_type_id
    </sql>

    <select id="selectEmsBaseCollectDeviceInfoList" parameterType="EmsBaseCollectDeviceInfo"
            resultMap="EmsBaseCollectDeviceInfoResult">
        <include refid="selectEmsBaseCollectDeviceInfoVo"/>
        <where>
            <if test="collectDeviceId != null  and collectDeviceId != ''">and ebcdi.collect_device_id = #{collectDeviceId}
            </if>
            <if test="collectDeviceName != null  and collectDeviceName != ''">and ebcdi.collect_device_name like concat('%',
                #{collectDeviceName}, '%')
            </if>
            <if test="energyTypeId != null ">and ebcdi.energy_type_id = #{energyTypeId}</if>
            <if test="model != null  and model != ''">and ebcdi.model = #{model}</if>
            <if test="manufacturer != null  and manufacturer != ''">and ebcdi.manufacturer = #{manufacturer}</if>
            <if test="ipAddress != null  and ipAddress != ''">and ebcdi.ip_address = #{ipAddress}</if>
            <if test="produceDate != null ">and ebcdi.produce_date = #{produceDate}</if>
            <if test="settingAddress != null  and settingAddress != ''">and ebcdi.setting_address = #{settingAddress}</if>
            <if test="isFlag != null  and isFlag != ''">and ebcdi.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectEmsBaseCollectDeviceInfoByObjId" parameterType="Long" resultMap="EmsBaseCollectDeviceInfoResult">
        <include refid="selectEmsBaseCollectDeviceInfoVo"/>
        where ebcdi.obj_id = #{objId}
    </select>

    <insert id="insertEmsBaseCollectDeviceInfo" parameterType="EmsBaseCollectDeviceInfo" useGeneratedKeys="true"
            keyProperty="objId">
        insert into ems_base_collect_device_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="collectDeviceId != null">collect_device_id,</if>
            <if test="collectDeviceName != null">collect_device_name,</if>
            <if test="energyTypeId != null">energy_type_id,</if>
            <if test="model != null">model,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="ipAddress != null">ip_address,</if>
            <if test="produceDate != null">produce_date,</if>
            <if test="settingAddress != null">setting_address,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="collectDeviceId != null">#{collectDeviceId},</if>
            <if test="collectDeviceName != null">#{collectDeviceName},</if>
            <if test="energyTypeId != null">#{energyTypeId},</if>
            <if test="model != null">#{model},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="ipAddress != null">#{ipAddress},</if>
            <if test="produceDate != null">#{produceDate},</if>
            <if test="settingAddress != null">#{settingAddress},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateEmsBaseCollectDeviceInfo" parameterType="EmsBaseCollectDeviceInfo">
        update ems_base_collect_device_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="collectDeviceId != null">collect_device_id = #{collectDeviceId},</if>
            <if test="collectDeviceName != null">collect_device_name = #{collectDeviceName},</if>
            <if test="energyTypeId != null">energy_type_id = #{energyTypeId},</if>
            <if test="model != null">model = #{model},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="ipAddress != null">ip_address = #{ipAddress},</if>
            <if test="produceDate != null">produce_date = #{produceDate},</if>
            <if test="settingAddress != null">setting_address = #{settingAddress},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where obj_id = #{objId}
    </update>

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

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