package com.copy.trade.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.copy.trade.entity.po.TraderData;
import com.copy.trade.entity.vo.TraderVo;

public class TraderConfiguration {
	
    public static Integer getDefaultCount(Long memberId,Long traderLevelId) {
    	
    	Long[] memberIds = {801477L, 801478L, 801479L, 801480L,801481L,801482L,
    			801487L,801488L,801489L,801491L,801492L,801493L};
    	Integer defaultCount = 0 ;
		switch(memberId.intValue()) {
		//801375  801376  801377 801378 801379 801473 当时直接指定的具体值,没有区分初级和高级,801473为特级
			case 801375:
				defaultCount = 142;
				break;
			case 801376:
				defaultCount = 75;
				break;
			case 801377:
				defaultCount = 125;
				break;
			case 801378:
				defaultCount = 88;
				break;
			case 801379:
				defaultCount = 131;
				break;
			case 801473:
				defaultCount = 718;
				break;
		}
		if(Arrays.asList(memberIds).contains(memberId)) {
				
			switch(traderLevelId.intValue()) {
			//初级人数:55-110之间吧 高级人数:80-170之间吧
	    	case 1:
	    		//55~105
	    		defaultCount = 55 + (int)(memberId % 6)*10 ;
	    		break;
	    	case 2:
	    		//80-170
	    		defaultCount = 80 + (int)(memberId % 10)*10;
	    		break;
	    	}
		}
		return defaultCount;
	}
    
    public static BigDecimal getDefaultFollowAmountCount(Long traderLevelId,Long memberId) {
    	BigDecimal defaultCount = new BigDecimal("0") ;
    	String member = memberId.toString();
    	switch(traderLevelId.intValue()) {
    	case 1:
    		defaultCount = new BigDecimal("6000.51").add(new BigDecimal(member.substring(member.length() -3)));
    		break;
    	case 2:
    		defaultCount = new BigDecimal("9000.27").add(new BigDecimal(member.substring(member.length() -3)));
    		break;
    	}
    	return defaultCount;
    }
    
    public static String  getSpecailName(Long memberId,String name) {
    	switch(memberId.intValue()) {
	    	case 801473:
	    		name = "对冲基金交易大师";
	    		break;
	    		
    	}
    	return name;
    }
    
    public static List<String>  getSpecailTagList(Long memberId,List<String> list) {
    	switch(memberId.intValue()) {
	    	case 801473:
	    		list.clear();
	    		list.add("对冲策略");
	    		list.add("稳健型");
	    		list.add("保障收益");
	    		list.add("零亏损");
	    		break;
    		
    	}
    	return list;
    }
    
    public static Integer getSpecailTraderMinFollowAmount(Long memberId) {
    	Integer minFollowAmount = 2000;
    	switch(memberId.intValue()) {
    	//后面其他用户可能是3000,5000
    	case 801473:
    		minFollowAmount = 2000;
    		break;
    	}
    	return minFollowAmount;
    }
    
    public static BigDecimal getDefaultProfitAmount(Long memberId) {
    	//累计盈利在500~2000
    	BigDecimal profitAmount = new BigDecimal("0") ;
    	String member = memberId.toString();
    	profitAmount = new BigDecimal("681.35").add(new BigDecimal(member.substring(member.length() -1)).multiply(new BigDecimal(100)));
    	return profitAmount;
    }
    
    public static Long getDefaultRegisterDays(Long memberId) {
    	//入住天数17-22天
    	Long registerDays = 17L + memberId % 6;
    	return registerDays;
    }
    
    public static String getSpecialTraderAmoutString(BigDecimal amount) {
    	//  <1K, <1W, <10W, <100W
    	String amountString = "<1K";
    	if(amount == null) {
    		amountString = "<1K";
    	} else if(amount.compareTo(new BigDecimal(1000)) < 0) {
    		amountString = "<1K";
    	} else if(amount.compareTo(new BigDecimal(10000)) < 0) {
    		amountString = "<10K";
    	} else if(amount.compareTo(new BigDecimal(100000)) < 0) {
    		amountString = "<100K";
    	} else if(amount.compareTo(new BigDecimal(1000000)) < 0) {
    		amountString = "<1000K";
    	} else {
    		//≥   ≤
    		amountString = "≥1000K";
    	}
    	
    	return amountString;
    }
    
    public static TraderVo getAddDefault(TraderVo traderVo,TraderData traderData)  {
    	if(traderData != null) {
    		Date updatedTime = traderData.getUpdatedTime();
    		if(new Date().getTime() < updatedTime.getTime()) {
    			return traderVo;
    		}
    		
    		
    		traderVo.setDayYield14((traderVo.getDayYield14() == null ? new BigDecimal(0) : traderVo.getDayYield14()).add(traderData.getDayYield14() == null ? new BigDecimal(0) : traderData.getDayYield14()));
    		traderVo.setDayYield30((traderVo.getDayYield30() == null ? new BigDecimal(0) : traderVo.getDayYield30()).add(traderData.getDayYield30() == null ? new BigDecimal(0) : traderData.getDayYield30()));
    		
    		//胜率取大的一个值
    		if((traderVo.getWinRate14() == null ? new BigDecimal(0) : traderVo.getWinRate14()).compareTo(traderData.getWinRate14() == null ? new BigDecimal(0) : traderData.getWinRate14())  < 0) {
    			traderVo.setWinRate14(traderData.getWinRate14() == null ? new BigDecimal(0) : traderData.getWinRate14());
    		}
    		
    		traderVo.setProfitAmount((traderVo.getProfitAmount() == null ? new BigDecimal(0) : traderVo.getProfitAmount()).add(traderData.getProfitAmount() == null ? new BigDecimal(0) : traderData.getProfitAmount()));
    		traderVo.setFollowCustomer((traderVo.getFollowCustomer() == null ? 0 : traderVo.getFollowCustomer()) + (traderData.getFollowCustomer() == null ? 0 : traderData.getFollowCustomer()));
    		traderVo.setOrderDeal14((traderVo.getOrderDeal14() == null ? 0 : traderVo.getOrderDeal14()) + (traderData.getOrderDeal14() == null ? 0 : traderData.getOrderDeal14()));
    		
    		//回撤取小的一个值
    		if((traderVo.getRetractionRate14() == null ? new BigDecimal(0) : traderVo.getRetractionRate14()).compareTo(traderData.getRetractionRate14() == null ? new BigDecimal(0) : traderData.getRetractionRate14())  > 0) {
    			traderVo.setRetractionRate14(traderData.getRetractionRate14() == null ? new BigDecimal(0) : traderData.getRetractionRate14());
    		}
    		
    		
    		//traderVo.setTradingDays((traderVo.getTradingDays() == null ? 0 : traderVo.getTradingDays()) + (traderData.getTradingDays() == null ? 0 : traderData.getTradingDays()));
    		//traderVo.setProfitDays((traderVo.getProfitDays() == null ? 0 : traderVo.getProfitDays()) + (traderData.getProfitDays() == null ? 0 : traderData.getProfitDays()));
    		
    		traderVo.setCurrentMonthFollow((traderVo.getCurrentMonthFollow() == null ? 0 : traderVo.getCurrentMonthFollow()) + (traderData.getCurrentMonthFollow() == null ? 0 : traderData.getCurrentMonthFollow()));
    		traderVo.setTeamProfit14((traderVo.getTeamProfit14() == null ? new BigDecimal(0) : traderVo.getTeamProfit14()).add(traderData.getTeamProfit14() == null ? new BigDecimal(0) : traderData.getTeamProfit14()));
    	}
    	return traderVo;
    }
    
    public static TraderVo getAddDefaultDays(TraderVo traderVo,TraderData traderData)  {
    	if(traderData != null) {
    		Date updatedTime = traderData.getUpdatedTime();
    		
    		//判断当前时间和最后更新时间的关系:如果在还在今天16点钱则加0,之后就累加
    		Long days = 0L;
    		if(new Date().getTime() >= updatedTime.getTime()) {
    			days = (new Date().getTime() - updatedTime.getTime())/(24*3600*1000) + 1;
    		}
    		
    		traderVo.setTradingDays((traderData.getTradingDays() == null ? 0 : traderData.getTradingDays()) + days);
    		traderVo.setProfitDays((traderData.getProfitDays() == null ? 0 : traderData.getProfitDays()) + days);
    		
    	}
    	return traderVo;
    }
    
    // 处理三个字符串字段取初始设定值,不取真实值
    public static TraderVo getDefaultStringField(TraderVo traderVo,TraderData traderData) {
    	if(traderData != null) {
    		traderVo.setTeamProfit14String(getSpecialTraderAmoutString(traderData.getTeamProfit14()));
        	traderVo.setProfitAmountString(getSpecialTraderAmoutString(traderData.getProfitAmount()));
    	} else {
    		traderVo.setTeamProfit14String(getSpecialTraderAmoutString(traderVo.getTeamProfit14()));
    		traderVo.setProfitAmountString(getSpecialTraderAmoutString(traderVo.getProfitAmount()));
    	}
    	return traderVo;
    }
    
    public static void main(String[] args) {

		
		Calendar calendar=Calendar.getInstance();
        int month=calendar.get(Calendar.MONTH);
        calendar.set(Calendar.MONTH, month-1);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        calendar.set(Calendar.HOUR_OF_DAY, 16);
        calendar.set(Calendar.MINUTE, 00);
        calendar.set(Calendar.SECOND,00);
    	//Long a = new Date().getTime() - calendar.getTime().getTime();
    	//System.out.println(a/(3600*24*1000) + 1);
    	//String specailName  = getSpecailName(801473L,"xixi");
    	//System.out.println(specailName);
        List<String> arrayList = new ArrayList<String>();
    	List<String> list  = getSpecailTagList(80147L,arrayList);
    	System.out.println(list);
	}
    
}
