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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.copy.trade.entity.po.Favorite">
    <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" />
    </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="day_yield_30" property="dayYield30" />
        <result column="order_deal_14" property="orderDeal14" />
        <result column="retraction_rate_14" property="retractionRate14" />
        <result column="follow_customer" property="followCustomer" />
        <result column="profit_amount" property="profitAmount" />
        <result column="trading_days" property="tradingDays" />
        <result column="maxFollow" property="maxFollow" />
        <result column="balance" property="balance" />
        <result column="registerDays" property="registerDays" />
        <result column="min_follow_amount" property="minFollowAmount" />
        <result column="dividend_percent" property="dividendPercent" />
        <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="inFocus" resultMap="traderMap">
        SELECT c.id, c.member_id, c.nickname, c.trader_level_id, c.avatar, c.balance,
               DATEDIFF(NOW(), c.trader_time)+1 as registerDays, c.description, c.min_follow_amount,
               c.default_follow_customer, c.default_register_days,
               tl.name as levelName, tl.max_follow as maxFollow, tl.dividend_percent,
               td.win_rate_14, td.day_yield_14, td.day_yield_30,
               td.profit_amount, td.trading_days, td.order_deal_14, td.retraction_rate_14,
               td.follow_customer, td.team_profit14
        FROM favorite f
        LEFT JOIN customer c ON f.trader_id = c.id
        LEFT JOIN trader_level tl ON c.trader_level_id = tl.id
        LEFT JOIN trader_data td ON td.trader_id = c.id
        WHERE f.customer_id = #{customerId}
        ORDER BY c.trader_level_id = 5 DESC, f.updated_time DESC
    </select>

</mapper>
