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

    <resultMap type="DmsBaseSpecialdeviceParam" id="DmsBaseSpecialdeviceParamResult">
        <result property="specialdeviceParamId"    column="specialdevice_param_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="paramCode"    column="param_code"    />
        <result property="paramName"    column="param_name"    />
        <result property="paramValue"    column="param_value"    />
        <result property="paramUnit"    column="param_unit"    />
        <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="selectDmsBaseSpecialdeviceParamVo">
        select specialdevice_param_id, device_id, param_code, param_name, param_value, param_unit, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_specialdevice_param
    </sql>

    <select id="selectDmsBaseSpecialdeviceParamList" parameterType="DmsBaseSpecialdeviceParam" resultMap="DmsBaseSpecialdeviceParamResult">
        select a.specialdevice_param_id, a.device_id, a.param_code, a.param_name, a.param_value, a.param_unit, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_specialdevice_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="paramValue != null  and paramValue != ''"> and a.param_value = #{paramValue}</if>
            <if test="paramUnit != null  and paramUnit != ''"> and a.param_unit = #{paramUnit}</if>
            <if test="isFlag != null "> and a.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBaseSpecialdeviceParamBySpecialdeviceParamId" parameterType="Long" resultMap="DmsBaseSpecialdeviceParamResult">
        <include refid="selectDmsBaseSpecialdeviceParamVo"/>
        where specialdevice_param_id = #{specialdeviceParamId}
    </select>

    <insert id="insertDmsBaseSpecialdeviceParam" parameterType="DmsBaseSpecialdeviceParam" useGeneratedKeys="true" keyProperty="specialdeviceParamId">
        insert into dms_base_specialdevice_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="paramValue != null">param_value,</if>
            <if test="paramUnit != null">param_unit,</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="paramValue != null">#{paramValue},</if>
            <if test="paramUnit != null">#{paramUnit},</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="updateDmsBaseSpecialdeviceParam" parameterType="DmsBaseSpecialdeviceParam">
        update dms_base_specialdevice_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="paramValue != null">param_value = #{paramValue},</if>
            <if test="paramUnit != null">param_unit = #{paramUnit},</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 specialdevice_param_id = #{specialdeviceParamId}
    </update>

    <delete id="deleteDmsBaseSpecialdeviceParamBySpecialdeviceParamId" parameterType="Long">
        delete from dms_base_specialdevice_param where specialdevice_param_id = #{specialdeviceParamId}
    </delete>

    <delete id="deleteDmsBaseSpecialdeviceParamBySpecialdeviceParamIds" parameterType="String">
        delete from dms_base_specialdevice_param where specialdevice_param_id in
        <foreach item="specialdeviceParamId" collection="array" open="(" separator="," close=")">
            #{specialdeviceParamId}
        </foreach>
    </delete>
</mapper>
