<?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.gxwebsoft.love.mapper.UserPlanEquityMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.nickname,b.phone,b.avatar as userAvatar
        FROM love_user_plan_equity a
        LEFT JOIN sys_user b ON a.user_id = b.user_id
        <where>
            <if test="param.planEquityId != null">
                AND a.plan_equity_id = #{param.planEquityId}
            </if>
            <if test="param.type != null">
              AND a.type = #{param.type}
            </if>
            <if test="param.planId != null">
                AND a.plan_id = #{param.planId}
            </if>
            <if test="param.planName != null">
                AND a.plan_name LIKE CONCAT('%', #{param.planName}, '%')
            </if>
            <if test="param.realName != null">
              AND a.real_name = #{param.realName}
            </if>
            <if test="param.province != null">
              AND a.province = #{param.province}
            </if>
            <if test="param.city != null">
              AND a.city = #{param.city}
            </if>
            <if test="param.region != null">
              AND a.region = #{param.region}
            </if>
            <if test="param.area != null">
              AND a.area = #{param.area}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.expirationTime != null">
                AND a.expiration_time LIKE CONCAT('%', #{param.expirationTime}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
              AND (
              b.nickname LIKE CONCAT('%', #{param.keywords}, '%')
              OR b.phone LIKE CONCAT('%', #{param.keywords}, '%')
              )
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.love.entity.UserPlanEquity">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.love.entity.UserPlanEquity">
        <include refid="selectSql"></include>
    </select>

</mapper>
