<?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.fuyuanshen.app.mapper.AppDeviceShareMapper">
    <delete id="deleteByDeviceIds">
        delete from app_device_share where  device_id in
        <foreach item="item" collection="deviceIds" separator="," open="(" close=")">
            #{item}
        </foreach>
    </delete>

    <select id="otherDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
        select d.device_name,
               d.device_mac,
               d.device_sn,
               d.device_imei,
               d.device_pic,
               dt.type_name,
               dt.communication_mode,
               dt.app_model_dictionary detailPageUrl,
               d.bluetooth_name,
               c.binding_time,
               ad.*,
               u.user_name             otherPhonenumber
        from app_device_share ad
                 left join device d on ad.device_id = d.id
                 left join app_user u on ad.create_by = u.user_id
                 inner join device_type dt on d.device_type = dt.id
                 inner join app_device_bind_record c on d.id = c.device_id
        where ad.phonenumber = #{bo.phonenumber}
    </select>
    <select id="selectAppDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
        select d.device_name,
        d.device_mac,
        d.device_sn,
        d.device_imei,
        d.device_pic,
        dt.type_name,
        dt.communication_mode,
        d.bluetooth_name,
        dt.app_model_dictionary detailPageUrl,
        c.binding_time,
        ad.*,u.user_name otherPhonenumber
        from
        app_device_share ad
        left join device d on ad.device_id = d.id
        left join app_user u on ad.create_by = u.user_id
        inner join device_type dt on d.device_type = dt.id
        inner join app_device_bind_record c on d.id = c.device_id
        where ad.create_by = #{bo.createBy}
        <if test="bo.deviceId != null">
            and ad.device_id = #{bo.deviceId}
        </if>
    </select>

    <!-- 查询设备分享列表(web) -->
    <select id="selectWebDeviceShareList" resultType="com.fuyuanshen.app.domain.vo.AppDeviceShareVo">
        select d.device_name,
        d.device_mac,
        d.device_sn,
        d.device_imei,
        d.device_pic,
        dt.type_name,
        dt.communication_mode,
        d.bluetooth_name,
        dt.app_model_dictionary detailPageUrl,
        c.binding_time,
        ad.*,u.user_name otherPhonenumber
        from
        app_device_share ad
        left join device d on ad.device_id = d.id
        left join app_user u on ad.create_by = u.user_id
        inner join device_type dt on d.device_type = dt.id
        inner join app_device_bind_record c on d.id = c.device_id
        <where>
            <if test="bo.deviceId != null">
                and ad.device_id = #{bo.deviceId}
            </if>
            <if test="bo.shareUser != null">
                and ad.phonenumber like concat('%',#{bo.shareUser},'%')
            </if>
            <if test="bo.phonenumber != null">
                and ad.phonenumber like concat('%',#{bo.phonenumber},'%')
            </if>
            <if test="bo.shareStartTime != null and bo.shareEndTime != null">
                and ad.create_time between #{bo.shareStartTime} and #{bo.shareEndTime}
            </if>
        </where>

    </select>
</mapper>
