<?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.dcs.hnyz.mapper.PlcInfoMapper">
    
    <resultMap type="PlcInfo" id="PlcInfoResult">
        <result property="plcId"    column="plc_id"    />
        <result property="plcName"    column="plc_name"    />
        <result property="ipAddress"    column="ip_address"    />
        <result property="port"    column="port"    />
        <result property="scanInterval"    column="scan_interval"    />
        <result property="connectTimeout"    column="connect_timeout"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_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="selectPlcInfoVo">
        select plc_id, plc_name, ip_address, port, scan_interval, connect_timeout, status, del_flag, create_by, create_time, update_by, update_time, remark from plc_info
    </sql>

    <select id="selectPlcInfoList" parameterType="PlcInfo" resultMap="PlcInfoResult">
        <include refid="selectPlcInfoVo"/>
        <where>  
            <if test="plcName != null  and plcName != ''"> and plc_name like concat('%', #{plcName}, '%')</if>
            <if test="port != null "> and port = #{port}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectPlcInfoByPlcId" parameterType="Long" resultMap="PlcInfoResult">
        <include refid="selectPlcInfoVo"/>
        where plc_id = #{plcId}
    </select>

    <insert id="insertPlcInfo" parameterType="PlcInfo" useGeneratedKeys="true" keyProperty="plcId">
        insert into plc_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plcName != null and plcName != ''">plc_name,</if>
            <if test="ipAddress != null and ipAddress != ''">ip_address,</if>
            <if test="port != null">port,</if>
            <if test="scanInterval != null">scan_interval,</if>
            <if test="connectTimeout != null">connect_timeout,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_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="plcName != null and plcName != ''">#{plcName},</if>
            <if test="ipAddress != null and ipAddress != ''">#{ipAddress},</if>
            <if test="port != null">#{port},</if>
            <if test="scanInterval != null">#{scanInterval},</if>
            <if test="connectTimeout != null">#{connectTimeout},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</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="updatePlcInfo" parameterType="PlcInfo">
        update plc_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="plcName != null and plcName != ''">plc_name = #{plcName},</if>
            <if test="ipAddress != null and ipAddress != ''">ip_address = #{ipAddress},</if>
            <if test="port != null">port = #{port},</if>
            <if test="scanInterval != null">scan_interval = #{scanInterval},</if>
            <if test="connectTimeout != null">connect_timeout = #{connectTimeout},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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 plc_id = #{plcId}
    </update>

    <delete id="deletePlcInfoByPlcId" parameterType="Long">
        delete from plc_info where plc_id = #{plcId}
    </delete>

    <delete id="deletePlcInfoByPlcIds" parameterType="String">
        delete from plc_info where plc_id in 
        <foreach item="plcId" collection="array" open="(" separator="," close=")">
            #{plcId}
        </foreach>
    </delete>
</mapper>