<?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.control.mapper.HsControlUsenoConfigMapper">

    <resultMap type="com.willalp.control.domain.HsControlUsenoConfig" id="HsControlUsenoConfigResult">
        <result property="useNoId" column="use_no_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="useNoName" column="use_no_name"/>
        <result property="commandDefault" column="command_default"/>
        <result property="commandOpen" column="command_open"/>
        <result property="commandClose" column="command_close"/>
        <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"/>
    </resultMap>

    <sql id="selectHsControlUsenoConfigVo">
        select use_no_id,
               device_id,
               use_no_name,
               command_default,
               command_open,
               command_close,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_control_useno_config
    </sql>

    <select id="selectHsControlUsenoConfigList" parameterType="HsControlUsenoConfig"
            resultMap="HsControlUsenoConfigResult">
        <include refid="selectHsControlUsenoConfigVo"/>
        <where>
            is_delete = 0
            <if test="deviceId != null ">
                  and device_id = #{deviceId}
            </if>
            <if test="useNoName != null  and useNoName != ''">
                  and use_no_name like concat('%', #{useNoName}, '%')
            </if>
            <if test="commandDefault != null  and commandDefault != ''">
                  and command_default = #{commandDefault}
            </if>
            <if test="commandOpen != null  and commandOpen != ''">
                  and command_open = #{commandOpen}
            </if>
            <if test="commandClose != null  and commandClose != ''">
                  and command_close = #{commandClose}
            </if>
            <if test="isDelete != null ">
                  and is_delete = #{isDelete}
                        </if>
        </where>
    </select>
    <select id="canAddUseNoListList" resultMap="HsControlUsenoConfigResult">
        SELECT use_no_id,
               use_no_name
        FROM hs_control_useno_config uc,
             pns_device pd
        WHERE uc.device_id = pd.device_id
          AND pd.device_use_id LIKE concat('%', #{userId,jdbcType=BIGINT}, '%')
          AND uc.use_no_id NOT IN (
            SELECT device_use_no
            FROM hs_control_device_info
        )
    </select>
</mapper>
