<?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.copy.trade.dao.FollowMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.copy.trade.entity.po.Follow">
    <result column="id" property="id" />
    <result column="created_time" property="createdTime" />
    <result column="updated_time" property="updatedTime" />
        <result column="customer_id" property="customerId" />
        <result column="trader_id" property="traderId" />
        <result column="status" property="status" />
    </resultMap>

    <resultMap id="traderMap" type="com.copy.trade.entity.vo.TraderVo">
        <result column="id" property="id" />
        <result column="member_id" property="memberId" />
        <result column="nickname" property="nickname" />
        <result column="avatar" property="avatar" />
        <result column="description" property="description" />
        <result column="trader_level_id" property="traderLevelId" />
        <result column="win_rate_14" property="winRate14" />
        <result column="day_yield_14" property="dayYield14" />
        <result column="maxFollow" property="maxFollow" />
        <result column="balance" property="balance" />
        <result column="levelName" property="levelName" />
        <result column="isFollow" property="isFollow" />
        <result column="team_profit14" property="teamProfit14" />
        <result column="default_follow_customer" property="defaultFollowCustomer" />
        <result column="default_register_days" property="defaultRegisterDays" />
    </resultMap>

    <select id="followingList" resultMap="traderMap">
        SELECT c.id,c.member_id,c.nickname,c.avatar,c.balance,c.description,c.trader_level_id,tl.name as levelName,tl.max_follow as maxFollow,
        c.default_follow_customer,c.default_register_days,td.team_profit14,
        td.win_rate_14,td.day_yield_14,td.profit_amount, td.follow_customer, td.trading_days
        FROM follow f
        LEFT JOIN customer c ON f.trader_id = c.id
        LEFT JOIN trader_data td ON td.trader_id = c.id
        LEFT JOIN trader_level tl ON c.trader_level_id = tl.id
        <where>
            f.customer_id = #{customerId} AND f.status = 10 ORDER BY c.trader_level_id = 5 desc,f.updated_time DESC
        </where>
    </select>

    <resultMap id="follower" type="com.copy.trade.entity.vo.FollowerVo">
    	<result column="id" property="id" />
    	<result column="member_id" property="memberId" />
        <result column="avatar" property="avatar" />
        <result column="nickname" property="nickname" />
        <result column="updated_time" property="followTime" />
        <result column="balance" property="balance" />
        <result column="total_profit_sharing" property="totalProfitSharing" />
        <result column="last_profit_sharing" property="lastProfitSharing" />
    </resultMap>
    <select id="followers" resultMap="follower">
        SELECT c.id,c.member_id,c.avatar,c.nickname,f.updated_time  FROM follow f LEFT JOIN customer c ON f.customer_id = c.id
        WHERE f.trader_id = #{traderId} AND f.status = 10 ORDER BY f.updated_time DESC
    </select>
    
   <!--  <select id="followerCount" resultMap="java.lang.Integer">
        SELECT COUNT(*)  FROM follow 
        WHERE trader_id = #{traderId} AND status = 10
    </select> -->
    <select id="isFollowSpecailTrader" resultType="java.lang.Integer">
        select COUNT(*) from follow f
			LEFT JOIN customer c on f.trader_id = c.id
			where f.customer_id =  #{customerId} and f.status = 10 and c.trader_level_id =4
    </select>
</mapper>
