<?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.dms.mapper.DmsBaseDeviceParamMapper">

    <resultMap type="DmsBaseDeviceParam" id="DmsBaseDeviceParamResult">
        <result property="deviceParamId"    column="device_param_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="paramCode"    column="param_code"    />
        <result property="paramName"    column="param_name"    />
        <result property="paramIp"    column="param_ip"    />
        <result property="paramAddress"    column="param_address"    />
        <result property="paramType"    column="param_type"    />
        <result property="readFrequency"    column="read_frequency"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDmsBaseDeviceParamVo">
        select device_param_id, device_id, param_code, param_name, param_ip, param_address, param_type, read_frequency, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_device_param
    </sql>

    <select id="selectDmsBaseDeviceParamList" parameterType="DmsBaseDeviceParam" resultMap="DmsBaseDeviceParamResult">
        select a.device_param_id, a.device_id, a.param_code, a.param_name, a.param_ip, a.param_address, a.param_type, a.read_frequency, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_device_param a
        left join dms_base_device_ledger b on a.device_id = b.device_id
        <where>
            <if test="deviceId != null "> and a.device_id = #{deviceId}</if>
            <if test="deviceName != null "> and b.device_name like concat('%', #{deviceName},'%')</if>
            <if test="paramCode != null  and paramCode != ''"> and a.param_code = #{paramCode}</if>
            <if test="paramName != null  and paramName != ''"> and a.param_name like concat('%', #{paramName}, '%')</if>
            <if test="paramIp != null  and paramIp != ''"> and a.param_ip = #{paramIp}</if>
            <if test="paramAddress != null  and paramAddress != ''"> and a.param_address = #{paramAddress}</if>
            <if test="paramType != null  and paramType != ''"> and a.param_type = #{paramType}</if>
            <if test="readFrequency != null "> and a.read_frequency = #{readFrequency}</if>
            <if test="isFlag != null "> and a.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBaseDeviceParamByDeviceParamId" parameterType="Long" resultMap="DmsBaseDeviceParamResult">
        <include refid="selectDmsBaseDeviceParamVo"/>
        where device_param_id = #{deviceParamId}
    </select>

    <insert id="insertDmsBaseDeviceParam" parameterType="DmsBaseDeviceParam" useGeneratedKeys="true" keyProperty="deviceParamId">
        insert into dms_base_device_param
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="paramCode != null">param_code,</if>
            <if test="paramName != null and paramName != ''">param_name,</if>
            <if test="paramIp != null">param_ip,</if>
            <if test="paramAddress != null">param_address,</if>
            <if test="paramType != null">param_type,</if>
            <if test="readFrequency != null">read_frequency,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="remark != null">remark,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="paramCode != null">#{paramCode},</if>
            <if test="paramName != null and paramName != ''">#{paramName},</if>
            <if test="paramIp != null">#{paramIp},</if>
            <if test="paramAddress != null">#{paramAddress},</if>
            <if test="paramType != null">#{paramType},</if>
            <if test="readFrequency != null">#{readFrequency},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="remark != null">#{remark},</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>
         </trim>
    </insert>

    <update id="updateDmsBaseDeviceParam" parameterType="DmsBaseDeviceParam">
        update dms_base_device_param
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="paramCode != null">param_code = #{paramCode},</if>
            <if test="paramName != null and paramName != ''">param_name = #{paramName},</if>
            <if test="paramIp != null">param_ip = #{paramIp},</if>
            <if test="paramAddress != null">param_address = #{paramAddress},</if>
            <if test="paramType != null">param_type = #{paramType},</if>
            <if test="readFrequency != null">read_frequency = #{readFrequency},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where device_param_id = #{deviceParamId}
    </update>

    <delete id="deleteDmsBaseDeviceParamByDeviceParamId" parameterType="Long">
        delete from dms_base_device_param where device_param_id = #{deviceParamId}
    </delete>

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