<?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.wzj.soopin.member.mapper.MemberAccountMapper">

    <select id="selectAccountWithMember" resultType="com.wzj.soopin.member.domain.vo.MemberAccountVO">
        SELECT
            a.*, a.integral AS integral, m.nickname, m.phone_encrypted AS phone
        FROM ums_account a
        LEFT JOIN ums_member m ON a.member_id = m.id
        <where>
            <if test="bo.id != null">
                AND a.id = #{bo.id}
            </if>
            <if test="bo.type != null">
                AND a.type = #{bo.type}
            </if>
            <if test="bo.memberId != null">
                AND a.member_id = #{bo.memberId}
            </if>
            <if test="bo.integral != null">
                AND a.integral_balance = #{bo.integral}
            </if>
            <if test="bo.wallet != null">
                AND a.wallet = #{bo.wallet}
            </if>
            <if test="bo.revenue != null">
                AND a.revenue = #{bo.revenue}
            </if>
            <if test="bo.nickname != null and bo.nickname != ''">
                AND (m.nickname LIKE CONCAT('%', #{bo.nickname}, '%') OR m.nickname IS NULL)
            </if>
            <if test="bo.phone != null and bo.phone != ''">
                AND (m.phone_encrypted LIKE CONCAT('%', #{bo.phone}, '%') OR m.phone_encrypted IS NULL)
            </if>
        </where>
    </select>

</mapper>
