<?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.willalp.device.mapper.DeviceMapper">

    <resultMap type="com.willalp.device.domain.Device" id="DeviceResult">
        <result property="deviceId" column="device_id"/>
        <result property="deviceNo" column="device_no"/>
        <result property="deviceOrgId" column="device_org_id"/>
        <result property="deviceUseId" column="device_use_id"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceInitCode" column="device_init_code"/>
        <result property="deviceIpAddr" column="device_ip_addr"/>
        <result property="deviceLocationAddr" column="device_location_addr"/>
        <result property="deviceState" column="device_state"/>
        <result property="expirationDate" column="expiration_date"/>
        <result property="sort" column="sort"/>
        <result property="isDelete" column="is_delete"/>
        <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"/>
        <result property="placeNumber" column="place_number"/>
    </resultMap>

    <sql id="selectDeviceVo">
        select device_id,
               device_no,
               device_org_id,
               device_use_id,
               device_name,
               device_init_code,
               device_ip_addr,
               device_location_addr,
               device_state,
               expiration_date,
               sort,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               place_number
        from pns_device
    </sql>

    <select id="selectDeviceList" parameterType="Device" resultMap="DeviceResult">
        <include refid="selectDeviceVo"/>
        <where>
            is_delete = 0
            <if test="deviceNo != null  and deviceNo != ''">
                  and device_no = #{deviceNo}</if>
            <if test="deviceOrgId != null  and deviceOrgId != ''">
                  and device_org_id = #{deviceOrgId}</if>
            <if test="deviceUseId != null  and deviceUseId != ''">
                  and device_use_id = #{deviceUseId}</if>
            <if test="deviceName != null  and deviceName != ''">
                  and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceIpAddr != null  and deviceIpAddr != ''">
                  and device_ip_addr = #{deviceIpAddr}</if>
            <if test="deviceLocationAddr != null  and deviceLocationAddr != ''">
                  and device_location_addr = #{deviceLocationAddr}</if>
            <if test="deviceState != null ">
                  and device_state = #{deviceState}</if>
            <if test="expirationDate != null ">
                  and expiration_date = #{expirationDate}</if>
            <if test="sort != null ">
                  and sort = #{sort}</if>
        </where>
    </select>
    <select id="getDeviceBindingUsers" resultType="java.lang.String">
        select
        device_use_id
        from pns_device
        <where>
            device_id = #{deviceId,jdbcType=VARCHAR}
        </where>
    </select>
</mapper>
