<?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.limap.core.basic.mapper.BasicUserBindInfoMapper">


    <select id="selectAppUserInfo" resultType="com.limap.core.basic.domain.BasicUserBindInfo">
        SELECT serial_num as device_name,iot_id as iot_id,device_type as type,bind_time as bind_time,ad.id as device_id,
               au.id app_user,user_name app_user_name,mobile_phone app_user_tel
        FROM aqu_device ad
        left join aqu_user au on ad.user_id = au.id
        <where>
            <if test="deviceName != null and deviceName != ''"> and serial_num = #{deviceName}</if>
        </where>
    </select>
    <select id="getcControlInfo" resultType="com.limap.core.screen.vo.ControlSwitch">
        SELECT a.id id,a.device_id deviceId ,a."index" "index",a.switch_name	switchName, a.detect_electric_value detectElectricValue,
        a.detect_voltage_value	detectVoltageValue,a.connect_voltage_type	connectVoltageType,a.pond_id pondId,a.rate_electric_value rateElectricValue,
        a.is_open openStatus
        FROM aqu_device_switch a
        left join aqu_device ad on a.device_id = ad.id
        <where>
            <if test="deviceId!= null"> and ad.serial_num = #{deviceName}    </if>
        </where>
    </select>
    <select id="selectBasicUserBindInfoList" resultType="com.limap.core.basic.domain.BasicUserBindInfo">
        select *
        from basic_user_bind_info
        <where>
            <if test="userId != null "> and user_id in ( SELECT dept_id FROM sys_dept WHERE dept_id = #{userId} or find_in_set( #{userId} , ancestors ) )</if>
            <if test="deviceName != null and deviceName != ''"> and device_name = #{deviceName}</if>
            <if test="type != null and type != ''"> and type = #{type}</if>
            <if test="appUserTel != null and appUserTel != ''"> and app_user_tel = #{appUserTel}</if>
            <if test="userName != null and userName != ''"> and user_name like CONCAT('%',#{userName},'%')</if>
        </where>
        order by create_time desc
    </select>
</mapper>
