<?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.shkj.wms.mapper.WcsPlcPropertyMapper">

    <resultMap type="WcsPlcProperty" id="WcsPlcPropertyResult">
        <result property="id"    column="id"    />
        <result property="plcId"    column="plc_id"    />
        <result property="devCode"    column="dev_code"    />
        <result property="devpName"    column="devp_name"    />
        <result property="valueType"    column="value_type"    />
        <result property="valueLength"    column="value_length"    />
        <result property="address"    column="address"    />
        <result property="fieldName"    column="field_name"    />
        <result property="unit"    column="unit"    />
    </resultMap>

    <sql id="selectWcsPlcPropertyVo">
        select id, plc_id, dev_code, devp_name, value_type, address, field_name, unit,point_type,rel_dev,rel_point,tunnel from wcs_plc_property
    </sql>

    <select id="selectWcsPlcPropertyList" parameterType="WcsPlcProperty" resultMap="WcsPlcPropertyResult">
        <include refid="selectWcsPlcPropertyVo"/>
        <where>
            <if test="plcId != null  and plcId != ''"> and plc_id = #{plcId}</if>
            <if test="devCode != null  and devCode != ''"> and dev_code = #{devCode}</if>
            <if test="devpName != null  and devpName != ''"> and devp_name like concat('%', #{devpName}, '%')</if>
            <if test="valueType != null  and valueType != ''"> and value_type = #{valueType}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="fieldName != null  and fieldName != ''"> and field_name like concat('%', #{fieldName}, '%')</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
        </where>
    </select>

    <select id="selectWcsPlcPropertyById" parameterType="Long" resultMap="WcsPlcPropertyResult">
        <include refid="selectWcsPlcPropertyVo"/>
        where id = #{id}
    </select>

    <select id="getWcsPlcPropertyByPlcId"  resultMap="WcsPlcPropertyResult">
        <include refid="selectWcsPlcPropertyVo"/>
        where plc_id = #{plcId}
    </select>

    <select id="getWcsPlcPropertyByPlcIdAndPoint" parameterType="com.shkj.wms.bo.WcsPlcPropertyQueryBo" resultMap="WcsPlcPropertyResult">
        <include refid="selectWcsPlcPropertyVo"/>
        where plc_id = #{plcId} and point_type =#{pointType}
        limit 1
    </select>

    <insert id="insertWcsPlcProperty" parameterType="WcsPlcProperty" useGeneratedKeys="true" keyProperty="id">
        insert into wcs_plc_property
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plcId != null">plc_id,</if>
            <if test="devCode != null">dev_code,</if>
            <if test="devpName != null">devp_name,</if>
            <if test="valueType != null">value_type,</if>
            <if test="valueLength != null">value_length,</if>
            <if test="address != null">address,</if>
            <if test="fieldName != null">field_name,</if>
            <if test="unit != null">unit,</if>
            <if test="pointType != null">point_type,</if>
            <if test="rel_dev != null">rel_dev,</if>
            <if test="rel_point != null">rel_point,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="plcId != null">#{plcId},</if>
            <if test="devCode != null">#{devCode},</if>
            <if test="devpName != null">#{devpName},</if>
            <if test="valueType != null">#{valueType},</if>
            <if test="valueLength != null">#{valueLength},</if>
            <if test="address != null">#{address},</if>
            <if test="fieldName != null">#{fieldName},</if>
            <if test="unit != null">#{unit},</if>
            <if test="pointType != null">#{pointType},</if>
            <if test="rel_dev != null">#{relDev},</if>
            <if test="rel_point != null">#{relPoint},</if>
         </trim>
    </insert>

    <update id="updateWcsPlcProperty" parameterType="WcsPlcProperty">
        update wcs_plc_property
        <trim prefix="SET" suffixOverrides=",">
            <if test="plcId != null">plc_id = #{plcId},</if>
            <if test="devCode != null">dev_code = #{devCode},</if>
            <if test="devpName != null">devp_name = #{devpName},</if>
            <if test="valueType != null">value_type = #{valueType},</if>
            <if test="valueLength != null">value_length = #{valueLength},</if>
            <if test="address != null">address = #{address},</if>
            <if test="fieldName != null">field_name = #{fieldName},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="pointType != null">#{pointType},</if>
            <if test="relDev != null">#{relDev},</if>
            <if test="relPoint != null">#{relPoint},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWcsPlcPropertyById" parameterType="Long">
        delete from wcs_plc_property where id = #{id}
    </delete>

    <delete id="deleteWcsPlcPropertyByPlcId" parameterType="Long">
        delete from wcs_plc_property where plc_id = #{plcId}
    </delete>
</mapper>
