<?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.UserProfileMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT  a.*,b.nickname,b.age,b.city as userCity
        FROM love_user_profile a
        LEFT JOIN sys_user b ON a.user_id = b.user_id

        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.interest != null">
                AND a.interest LIKE CONCAT('%', #{param.interest}, '%')
            </if>
            <if test="param.height != null">
                AND a.height LIKE CONCAT('%', #{param.height}, '%')
            </if>
            <if test="param.monthlyPay != null">
                AND a.monthly_pay LIKE CONCAT('%', #{param.monthlyPay}, '%')
            </if>
            <if test="param.yearlyPay != null">
              AND a.yearly_pay LIKE CONCAT('%', #{param.yearlyPay}, '%')
            </if>
            <if test="param.education != null">
                AND a.education LIKE CONCAT('%', #{param.education}, '%')
            </if>
            <if test="param.vocation != null">
                AND a.vocation LIKE CONCAT('%', #{param.vocation}, '%')
            </if>
            <if test="param.maritalStatus != null">
                AND a.marital_status LIKE CONCAT('%', #{param.maritalStatus}, '%')
            </if>
            <if test="param.hasChildren != null">
                AND a.has_children LIKE CONCAT('%', #{param.hasChildren}, '%')
            </if>
            <if test="param.haveChild != null">
                AND a.have_child LIKE CONCAT('%', #{param.haveChild}, '%')
            </if>
            <if test="param.position != null">
                AND a.position LIKE CONCAT('%', #{param.position}, '%')
            </if>
            <if test="param.weight != null">
                AND a.weight LIKE CONCAT('%', #{param.weight}, '%')
            </if>
            <if test="param.hasCar != null">
                AND a.has_car LIKE CONCAT('%', #{param.hasCar}, '%')
            </if>
            <if test="param.whenMarried != null">
                AND a.when_married LIKE CONCAT('%', #{param.whenMarried}, '%')
            </if>
            <if test="param.ageMate != null">
                AND a.age_mate LIKE CONCAT('%', #{param.ageMate}, '%')
            </if>
            <if test="param.heightMate != null">
                AND a.height_mate LIKE CONCAT('%', #{param.heightMate}, '%')
            </if>
            <if test="param.monthlyPayMate != null">
                AND a.monthly_pay_mate LIKE CONCAT('%', #{param.monthlyPayMate}, '%')
            </if>
            <if test="param.yearlyPayMate != null">
              AND a.yearly_pay_mate LIKE CONCAT('%', #{param.yearlyPayMate}, '%')
            </if>
            <if test="param.regionMate != null">
                AND a.region_mate LIKE CONCAT('%', #{param.regionMate}, '%')
            </if>
            <if test="param.country != null">
                AND a.country LIKE CONCAT('%', #{param.country}, '%')
            </if>
            <if test="param.province != null">
                AND a.province LIKE CONCAT('%', #{param.province}, '%')
            </if>
            <if test="param.city != null">
                AND b.city LIKE CONCAT('%', #{param.city}, '%')
            </if>
            <if test="param.region != null">
                AND a.region LIKE CONCAT('%', #{param.region}, '%')
            </if>
            <if test="param.area != null">
              AND a.area LIKE CONCAT('%', #{param.area}, '%')
            </if>
            <if test="param.provinceMate != null">
              AND a.province_mate LIKE CONCAT('%', #{param.provinceMate}, '%')
            </if>
            <if test="param.cityMate != null">
              AND b.city LIKE CONCAT('%', #{param.cityMate}, '%')
            </if>
            <if test="param.regionMate != null">
              AND a.region_mate LIKE CONCAT('%', #{param.regionMate}, '%')
            </if>
            <if test="param.areaMate != null">
              AND a.area_mate LIKE CONCAT('%', #{param.areaMate}, '%')
            </if>
            <if test="param.educationMate != null">
                AND a.education_mate LIKE CONCAT('%', #{param.educationMate}, '%')
            </if>
            <if test="param.maritalStatusMate != null">
                AND a.marital_status_mate LIKE CONCAT('%', #{param.maritalStatusMate}, '%')
            </if>
            <if test="param.hasChildrenMate != null">
                AND a.has_children_mate LIKE CONCAT('%', #{param.hasChildrenMate}, '%')
            </if>
            <if test="param.haveChildMate != null">
                AND a.have_child_mate LIKE CONCAT('%', #{param.haveChildMate}, '%')
            </if>
            <if test="param.vocationMate != null">
                AND a.vocation_mate LIKE CONCAT('%', #{param.vocationMate}, '%')
            </if>
            <if test="param.weightMate != null">
                AND a.weight_mate LIKE CONCAT('%', #{param.weightMate}, '%')
            </if>
            <if test="param.shapeMate != null">
                AND a.shape_mate LIKE CONCAT('%', #{param.shapeMate}, '%')
            </if>
            <if test="param.isSmokingMate != null">
                AND a.is_smoking_mate LIKE CONCAT('%', #{param.isSmokingMate}, '%')
            </if>
            <if test="param.isDrinkMate != null">
                AND a.is_drink_mate LIKE CONCAT('%', #{param.isDrinkMate}, '%')
            </if>
            <if test="param.hasCarMate != null">
                AND a.has_car_mate LIKE CONCAT('%', #{param.hasCarMate}, '%')
            </if>
            <if test="param.hasHouseMate != null">
                AND a.has_house_mate LIKE CONCAT('%', #{param.hasHouseMate}, '%')
            </if>
            <if test="param.whenMarriedMate != null">
                AND a.when_married_mate LIKE CONCAT('%', #{param.whenMarriedMate}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </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.recommend != null">
              AND b.recommend = 1
            </if>
            <if test="param.userIds != null and param.userIds.size > 0 ">
              AND a.user_id IN
              <foreach collection="param.userIds" item="item" separator="," open="(" close=")">
                #{item}
              </foreach>
            </if>
            <if test="param.nUserIds != null and param.nUserIds.size > 0 ">
                AND a.user_id NOT IN
                <foreach collection="param.nUserIds" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.sex != null">
              AND b.sex = #{param.sex}
            </if>
            <if test="param.albums == true">
              AND a.images != '[]'
            </if>
            <if test="param.keywords != null">
              AND (
              b.nickname LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.age_mate = #{param.keywords}
              OR a.user_id = #{param.keywords}
              OR b.phone = #{param.keywords}
              )
            </if>
            AND b.deleted = 0
        </where>
        <if test="param.random == true">
             ORDER BY rand()
        </if>
    </sql>

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

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

</mapper>
