<?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="cn.pluss.platform.mapper.DeviceTransferMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.DeviceTransfer">
        <id column="id" property="id" />
        <result column="userId" property="userId" />
        <result column="acceptUserId" property="acceptUserId" />
        <result column="status" property="status" />
        <result column="transferTime" property="transferTime" />
        <result column="acceptTime" property="acceptTime" />
        <result column="batchNo" property="batchNo" />
        <result column="remark" property="remark" />
    </resultMap>

    <select id="pageInfo" parameterType="cn.pluss.platform.dto.DeviceTransferDTO" resultType="cn.pluss.platform.vo.DeviceTransferVO">
        SELECT
               dt.*,
               ui1.phone,
               ua1.userName,
               ui2.phone as acceptPhone,
               ua2.userName as acceptName
        FROM tb_pluss_device_transfer dt
        left join tb_pluss_user_info ui1 on dt.userId = ui1.id
        left join tb_pluss_user_app ua1 on dt.userId = ua1.userId

        left join tb_pluss_user_info ui2 on dt.acceptUserId = ui2.id
        left join tb_pluss_user_app ua2 on dt.acceptUserId = ua2.userId
        <where>
            <if test="dto.userId != null">
                and dt.userId = #{dto.userId}
            </if>
            <if test="dto.acceptUserId != null">
                and dt.acceptUserId = #{dto.acceptUserId}
            </if>
        </where>
    </select>

    <select id="selectByIdVo" resultType="cn.pluss.platform.vo.DeviceTransferVO">
        SELECT
        dt.*,
        ui1.phone,
        ua1.userName,
        ui2.phone as acceptPhone,
        ua2.userName as acceptName
        FROM tb_pluss_device_transfer dt
        left join tb_pluss_user_info ui1 on dt.userId = ui1.id
        left join tb_pluss_user_app ua1 on dt.userId = ua1.userId

        left join tb_pluss_user_info ui2 on dt.acceptUserId = ui2.id
        left join tb_pluss_user_app ua2 on dt.acceptUserId = ua2.userId
        where dt.id  = #{id}
    </select>
</mapper>
