<?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.xzzn.ems.mapper.EmsPcsSettingMapper">
    
    <resultMap type="EmsPcsSetting" id="EmsPcsSettingResult">
        <result property="id"    column="id"    />
        <result property="deviceSettingId"    column="device_setting_id"    />
        <result property="pointAddress"    column="point_address"    />
        <result property="powerAddress"    column="power_address"    />
        <result property="startCommand"    column="start_command"    />
        <result property="stopCommand"    column="stop_command"    />
        <result property="startPower"    column="start_power"    />
        <result property="stopPower"    column="stop_power"    />
        <result property="powerMultiplier"    column="power_multiplier"    />
        <result property="clusterNum"    column="cluster_num"    />
        <result property="clusterPointAddress"    column="cluster_point_address"    />
        <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="selectEmsPcsSettingVo">
        select id, device_setting_id, point_address, power_address, start_command, stop_command, start_power, stop_power, power_multiplier, cluster_num, cluster_point_address, create_by, create_time, update_by, update_time, remark from ems_pcs_setting
    </sql>

    <select id="selectEmsPcsSettingList" parameterType="EmsPcsSetting" resultMap="EmsPcsSettingResult">
        <include refid="selectEmsPcsSettingVo"/>
        <where>  
            <if test="deviceSettingId != null "> and device_setting_id = #{deviceSettingId}</if>
            <if test="pointAddress != null  and pointAddress != ''"> and point_address = #{pointAddress}</if>
            <if test="powerAddress != null  and powerAddress != ''"> and power_address = #{powerAddress}</if>
            <if test="startCommand != null  and startCommand != ''"> and start_command = #{startCommand}</if>
            <if test="stopCommand != null  and stopCommand != ''"> and stop_command = #{stopCommand}</if>
            <if test="startPower != null "> and start_power = #{startPower}</if>
            <if test="stopPower != null "> and stop_power = #{stopPower}</if>
            <if test="powerMultiplier != null "> and power_multiplier = #{powerMultiplier}</if>
            <if test="clusterNum != null "> and cluster_num = #{clusterNum}</if>
            <if test="clusterPointAddress != null  and clusterPointAddress != ''"> and cluster_point_address = #{clusterPointAddress}</if>
        </where>
    </select>
    
    <select id="selectEmsPcsSettingById" parameterType="Long" resultMap="EmsPcsSettingResult">
        <include refid="selectEmsPcsSettingVo"/>
        where id = #{id}
    </select>

    <select id="selectEmsPcsSettingByDeviceId" parameterType="Long" resultMap="EmsPcsSettingResult">
        <include refid="selectEmsPcsSettingVo"/>
        where device_setting_id = #{deviceSettingId}
    </select>

    <insert id="insertEmsPcsSetting" parameterType="EmsPcsSetting" useGeneratedKeys="true" keyProperty="id">
        insert into ems_pcs_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceSettingId != null">device_setting_id,</if>
            <if test="pointAddress != null">point_address,</if>
            <if test="powerAddress != null">power_address,</if>
            <if test="startCommand != null">start_command,</if>
            <if test="stopCommand != null">stop_command,</if>
            <if test="startPower != null">start_power,</if>
            <if test="stopPower != null">stop_power,</if>
            <if test="powerMultiplier != null">power_multiplier,</if>
            <if test="clusterNum != null">cluster_num,</if>
            <if test="clusterPointAddress != null">cluster_point_address,</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="deviceSettingId != null">#{deviceSettingId},</if>
            <if test="pointAddress != null">#{pointAddress},</if>
            <if test="powerAddress != null">#{powerAddress},</if>
            <if test="startCommand != null">#{startCommand},</if>
            <if test="stopCommand != null">#{stopCommand},</if>
            <if test="startPower != null">#{startPower},</if>
            <if test="stopPower != null">#{stopPower},</if>
            <if test="powerMultiplier != null">#{powerMultiplier},</if>
            <if test="clusterNum != null">#{clusterNum},</if>
            <if test="clusterPointAddress != null">#{clusterPointAddress},</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="updateEmsPcsSetting" parameterType="EmsPcsSetting">
        update ems_pcs_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceSettingId != null">device_setting_id = #{deviceSettingId},</if>
            <if test="pointAddress != null">point_address = #{pointAddress},</if>
            <if test="powerAddress != null">power_address = #{powerAddress},</if>
            <if test="startCommand != null">start_command = #{startCommand},</if>
            <if test="stopCommand != null">stop_command = #{stopCommand},</if>
            <if test="startPower != null">start_power = #{startPower},</if>
            <if test="stopPower != null">stop_power = #{stopPower},</if>
            <if test="powerMultiplier != null">power_multiplier = #{powerMultiplier},</if>
            <if test="clusterNum != null">cluster_num = #{clusterNum},</if>
            <if test="clusterPointAddress != null">cluster_point_address = #{clusterPointAddress},</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 id = #{id}
    </update>

    <delete id="deleteEmsPcsSettingById" parameterType="Long">
        delete from ems_pcs_setting where id = #{id}
    </delete>

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

    <update id="updateByDeviceSettingId" parameterType="EmsPcsSetting">
        update ems_pcs_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceSettingId != null">device_setting_id = #{deviceSettingId},</if>
            <if test="pointAddress != null">point_address = #{pointAddress},</if>
            <if test="powerAddress != null">power_address = #{powerAddress},</if>
            <if test="startCommand != null">start_command = #{startCommand},</if>
            <if test="stopCommand != null">stop_command = #{stopCommand},</if>
            <if test="startPower != null">start_power = #{startPower},</if>
            <if test="stopPower != null">stop_power = #{stopPower},</if>
            <if test="powerMultiplier != null">power_multiplier = #{powerMultiplier},</if>
            <if test="clusterNum != null">cluster_num = #{clusterNum},</if>
            <if test="clusterPointAddress != null">cluster_point_address = #{clusterPointAddress},</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 device_setting_id = #{deviceSettingId}
    </update>

</mapper>
