<?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.wcs.mapper.WcsDeviceMapper">

    <resultMap type="WcsDevice" id="WcsDeviceResult">
        <result property="id" column="id"/>
        <result property="devNo" column="dev_no"/>
        <result property="devName" column="dev_name"/>
        <result property="devType" column="dev_type"/>
        <result property="devDirection" column="dev_direction"/>
        <result property="tunnel" column="tunnel"/>
        <result property="isActive" column="is_active"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectWcsDeviceVo">
        select id, dev_no, dev_name, dev_type, dev_direction, tunnel, is_active, remark from wcs_device where ifnull(is_del,0) !=1
    </sql>

    <select id="selectWcsDeviceList" parameterType="WcsDevice" resultMap="WcsDeviceResult">
        <include refid="selectWcsDeviceVo"/>

        <if test="devNo != null  and devNo != ''">and dev_no = #{devNo}</if>
        <if test="devName != null  and devName != ''">and dev_name like concat('%', #{devName}, '%')</if>
        <if test="devType != null  and devType != ''">and dev_type = #{devType}</if>
        <if test="devDirection != null  and devDirection != ''">and dev_direction = #{devDirection}</if>
        <if test="tunnel != null  and tunnel != ''">and tunnel = #{tunnel}</if>
        <if test="isActive != null  and isActive != ''">and ifnull(is_active,0) = #{isActive}</if>

    </select>

    <select id="selectWcsDeviceById" parameterType="Long" resultMap="WcsDeviceResult">
        <include refid="selectWcsDeviceVo"/>
        where id = #{id}
    </select>

    <select id="selectAllDeviceList" parameterType="WcsDevice" resultType="com.shkj.wcs.vo.BaseDeviceVo">
        SELECT id,dev_no,dev_name FROM	wcs_device WHERE ifnull( is_del, 0 ) != '1'

        <if test="devNo != null  and devNo != ''">and dev_no = #{devNo}</if>
        <if test="devName != null  and devName != ''">and dev_name like concat('%', #{devName}, '%')</if>

    </select>

    <insert id="insertWcsDevice" parameterType="WcsDevice" useGeneratedKeys="true" keyProperty="id">
        insert into wcs_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="devNo != null">dev_no,</if>
            <if test="devName != null">dev_name,</if>
            <if test="devType != null">dev_type,</if>
            <if test="devDirection != null">dev_direction,</if>
            <if test="tunnel != null">tunnel,</if>
            <if test="isActive != null">is_active,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="devNo != null">#{devNo},</if>
            <if test="devName != null">#{devName},</if>
            <if test="devType != null">#{devType},</if>
            <if test="devDirection != null">#{devDirection},</if>
            <if test="tunnel != null">#{tunnel},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateWcsDevice" parameterType="WcsDevice">
        update wcs_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="devNo != null">dev_no = #{devNo},</if>
            <if test="devName != null">dev_name = #{devName},</if>
            <if test="devType != null">dev_type = #{devType},</if>
            <if test="devDirection != null">dev_direction = #{devDirection},</if>
            <if test="tunnel != null">tunnel = #{tunnel},</if>
            <if test="isActive != null">is_active = #{isActive},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWcsDeviceById" parameterType="Long">
        delete from wcs_device where id = #{id}
    </delete>

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