package com.copy.trade.service.impl;

import com.copy.trade.entity.po.TraderData;
import com.copy.trade.dao.TraderDataMapper;
import com.copy.trade.entity.vo.YieldVo;
import com.copy.trade.service.ITraderDataService;
import com.copy.trade.util.LocalDateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 交易员统计数据 服务实现类
 * </p>
 *
 * @author wz
 * @since 2022-12-01
 */
@Service
public class TraderDataServiceImpl extends ServiceImpl<TraderDataMapper, TraderData> implements ITraderDataService {

    @Override
    public List<YieldVo> yield14(Long traderId) {
        List<YieldVo> list = ((TraderDataMapper)baseMapper).yield14(traderId);
        //给数据补满到14个
        LocalDateTime now = LocalDateTime.now();
        int size = 0;
        if(list != null && list.size() > 0) {
        	size = list.size();
        }
        for(int i = size; i< 14;i++) {
        	//这里分为16点  ,16点后就有了当天的统计数据
        	Date endTime = null;
        	Calendar calendar=Calendar.getInstance();
        	int hour = calendar.get(Calendar.HOUR_OF_DAY);
        	if(hour >= 16) {
        		endTime = new Date(LocalDateUtils.getStartTimeOfDay(LocalDateUtils.minus(now, i, ChronoUnit.DAYS)));
        	} else {
        		endTime = new Date(LocalDateUtils.getStartTimeOfDay(LocalDateUtils.minus(now, i + 1, ChronoUnit.DAYS)));
        	}
        	YieldVo yieldVo = new YieldVo();
        	yieldVo.setDayYield14(new BigDecimal("0"));
        	yieldVo.setDateTime(endTime);
        	list.add(yieldVo);
        }
        
        return list;
    }
    public static void main(String[] args) {
    	LocalDateTime now = LocalDateTime.now();
    	Date endTime = new Date(LocalDateUtils.getStartTimeOfDay(LocalDateUtils.minus(now, 1, ChronoUnit.DAYS)));
    	System.out.println(endTime);
	}
}
