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

    <resultMap type="BaseDeviceParam" id="BaseDeviceParamResult">
            <result property="objId"    column="obj_id"    />
            <result property="paramCode"    column="param_code"    />
            <result property="paramName"    column="param_name"    />
            <result property="paramNetwork"    column="param_network"    />
            <result property="paramAddress"    column="param_address"    />
            <result property="paramType"    column="param_type"    />
            <result property="deviceCode"    column="device_code"    />
            <result property="readFrequency"    column="read_frequency"    />
            <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"    />
    </resultMap>

    <sql id="selectBaseDeviceParamVo">
        select obj_id, param_code, param_name, param_network, param_address, param_type, device_code, read_frequency, is_flag, created_by, created_time, updated_by, updated_time from base_deviceparam
    </sql>

    <select id="selectBaseDeviceParamList" parameterType="BaseDeviceParam" resultMap="BaseDeviceParamResult">
        <include refid="selectBaseDeviceParamVo"/>
        <where>
                        <if test="paramCode != null  and paramCode != ''"> and param_code = #{paramCode}</if>
                        <if test="paramName != null  and paramName != ''"> and param_name like concat(concat('%', #{paramName}), '%')</if>
                        <if test="paramNetwork != null  and paramNetwork != ''"> and param_network = #{paramNetwork}</if>
                        <if test="paramAddress != null  and paramAddress != ''"> and param_address = #{paramAddress}</if>
                        <if test="paramType != null  and paramType != ''"> and param_type = #{paramType}</if>
                        <if test="deviceCode != null  and deviceCode != ''"> and device_code = #{deviceCode}</if>
                        <if test="readFrequency != null "> and read_frequency = #{readFrequency}</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>
        </where>
    </select>

    <select id="selectBaseDeviceParamByObjId" parameterType="Long" resultMap="BaseDeviceParamResult">
            <include refid="selectBaseDeviceParamVo"/>
            where obj_id = #{objId}
    </select>

    <insert id="insertBaseDeviceParam" parameterType="BaseDeviceParam">
            <selectKey keyProperty="objId" resultType="long" order="BEFORE">
                SELECT seq_base_deviceparam.NEXTVAL as objId FROM DUAL
            </selectKey>
        insert into base_deviceparam
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="objId != null">obj_id,</if>
                <if test="paramCode != null">param_code,</if>
                <if test="paramName != null">param_name,</if>
                <if test="paramNetwork != null">param_network,</if>
                <if test="paramAddress != null">param_address,</if>
                <if test="paramType != null">param_type,</if>
                <if test="deviceCode != null">device_code,</if>
                <if test="readFrequency != null">read_frequency,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="objId != null">#{objId},</if>
                <if test="paramCode != null">#{paramCode},</if>
                <if test="paramName != null">#{paramName},</if>
                <if test="paramNetwork != null">#{paramNetwork},</if>
                <if test="paramAddress != null">#{paramAddress},</if>
                <if test="paramType != null">#{paramType},</if>
                <if test="deviceCode != null">#{deviceCode},</if>
                <if test="readFrequency != null">#{readFrequency},</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>
        </trim>
    </insert>

    <update id="updateBaseDeviceParam" parameterType="BaseDeviceParam">
        update base_deviceparam
        <trim prefix="SET" suffixOverrides=",">
                    <if test="paramCode != null">param_code = #{paramCode},</if>
                    <if test="paramName != null">param_name = #{paramName},</if>
                    <if test="paramNetwork != null">param_network = #{paramNetwork},</if>
                    <if test="paramAddress != null">param_address = #{paramAddress},</if>
                    <if test="paramType != null">param_type = #{paramType},</if>
                    <if test="deviceCode != null">device_code = #{deviceCode},</if>
                    <if test="readFrequency != null">read_frequency = #{readFrequency},</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>
        </trim>
        where obj_id = #{objId}
    </update>

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

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