<?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.wisenergy.mapper.RecommendUserMapper">
    <resultMap id="userMap" type="cn.wisenergy.model.app.RecommendUser">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="normal_user_num" property="normalUserNum"/>
        <result column="seedling_num" property="seedlingNum"/>
        <result column="bronze_tree_num" property="bronzeTreeNum"/>
        <result column="silver_tree_num" property="silverTreeNum"/>
        <result column="gold_tree_num" property="goldTreeNum"/>
        <result column="farmer_num" property="farmerNum"/>
        <result column="forest_start_num" property="forestStartNum"/>
        <result column="partner_num" property="partnerNum"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
        recommend_user
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        user_id,normal_user_num,seedling_num,bronze_tree_num,silver_tree_num,
        gold_tree_num,farmer_num,forest_start_num,partner_num,create_time,update_time
    </sql>

    <sql id="vals">
        #{userId},#{normalUserNum},#{seedlingNum},#{bronzeTreeNum},#{silverTreeNum},
        #{goldTreeNum},#{farmerNum},#{forestStartNum},#{partnerNum},now(),now()
    </sql>

    <sql id="updateCondition">
        <if test="normalUserNum != null">normal_user_num =#{normalUserNum},</if>
        <if test="seedlingNum != null">seedling_num =#{seedlingNum},</if>
        <if test="bronzeTreeNum != null">bronze_tree_num =#{bronzeTreeNum},</if>
        <if test="silverTreeNum != null">referrer_num =#{silverTreeNum},</if>
        <if test="goldTreeNum != null">referrer_num =#{goldTreeNum},</if>
        <if test="farmerNum != null">referrer_num =#{farmerNum},</if>
        <if test="forestStartNum != null">referrer_num =#{forestStartNum},</if>
        <if test="partnerNum != null">referrer_num =#{partnerNum},</if>
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="normalUserNum != null">and normal_user_num =#{normalUserNum},</if>
        <if test="seedlingNum != null">and seedling_num =#{seedlingNum},</if>
        <if test="bronzeTreeNum != null">and bronze_tree_num =#{bronzeTreeNum},</if>
        <if test="silverTreeNum != null">and referrer_num =#{silverTreeNum},</if>
        <if test="goldTreeNum != null">and referrer_num =#{goldTreeNum},</if>
        <if test="farmerNum != null">and referrer_num =#{farmerNum},</if>
        <if test="forestStartNum != null">and referrer_num =#{forestStartNum},</if>
        <if test="partnerNum != null">and referrer_num =#{partnerNum},</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

    <select id="getByUserId" resultType="cn.wisenergy.model.app.RecommendUser">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>
    <!--根据用户邀请码更新直推表-->
    <select id="zcByUserId" >
        select
            id
        from
        <include refid="table"/>
        <where>
            user_id=#{userid}
        </where>
    </select>
    <!--用户信息插入用户直推表-->

</mapper>