package com.jxy.marketall.service.impl;

import com.jxy.common.core.utils.DateUtils;
import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.common.redis.service.RedisService;
import com.jxy.marketall.dto.*;
import com.jxy.marketall.enums.BTCRedisName;
import com.jxy.marketall.mapper.BTCMapper;
import com.jxy.marketall.service.BTCService;
import com.jxy.marketall.vo.QueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @Description Arh99查询业务处理
 * @Date 2022/6/2017:51
 * @Author 杜懿
 */
@Service
public class BTCServiceImpl implements BTCService {

    /** 132服务器上btcdb库 */
    @Autowired
    private BTCMapper btcMapper;

    /** 112服务器 4417端口 btcdb4库 */


    /** 112服务器 4418端口 btcdb库 */


    @Autowired
    private RedisService redisService;


    /***********************************************132服务器相关接口***********************************************/
    @Override
    public AjaxResult findMa730ByTime(QueryVo queryVo) {
        List<Ma730Dto> list = btcMapper.selectMa730ByTime(queryVo);

        return CheckData(list);
    }

    @Override
    public AjaxResult findMa730Day() {
        List<Ma730Dto> list = btcMapper.selectMa730Day();
        if(list.size()<1){
            return AjaxResult.success(list);
        }
        Collections.reverse(list);
        return AjaxResult.success(list);
    }

    /***********************************************112服务器 btcdb4数据库相关接口***********************************************/

    @Override
    public AjaxResult getCDDList(QueryVo vo) {

        List<CoinDayDesDto> list = redisService.getCacheList(BTCRedisName.BTC_CDD.getKey());

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        return CheckData(list);
    }


    /***********************************************112服务器 btcdb（4418端口）数据库相关接口***********************************************/
    @Override
    public AjaxResult getProfitRateList(QueryVo vo) {

        //通过缓存获取所有数据
        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_PROFITRATE.getKey(), vo.getSma());

        //根据时间过滤
        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getFeesList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_FEES.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getAddressList(QueryVo vo) {

        List<AddressDto> list = redisService.getCacheList(BTCRedisName.BTC_ADDRESS.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        //todo sma

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }


        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getVolumeList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_VOLUME.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult geteaVolumeList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_EAVOLUME.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getSoprList(QueryVo vo) {

        List<SoprDto> list = redisService.getCacheList(BTCRedisName.BTC_SOPR.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);

    }

    @Override
    public AjaxResult getAsolList(QueryVo vo) {

        List<ASOLDto> list = redisService.getCacheList(BTCRedisName.BTC_ASOL.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getDormancyList(QueryVo vo) {

        List<DormancyDto> list = redisService.getCacheList(BTCRedisName.BTC_DORMANCY.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getSoagList(QueryVo vo) {

        List<SOAGDto> list = redisService.getCacheList(BTCRedisName.BTC_SOAG.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        for(int i=0 ;i<list.size();i++){
            SOAGDto soagDto = list.get(i);
            BigDecimal total = soagDto.getDay1().add(soagDto.getDay7()).add(soagDto.getDay30()).add(soagDto.getDay60()).add(soagDto.getDay90()).add(soagDto.getDay180()).add(soagDto.getDay365()).add(soagDto.getDay730());

            if(total.intValue() != 0){
                soagDto.setDay1(soagDto.getDay1().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay7(soagDto.getDay7().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay30(soagDto.getDay30().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay60(soagDto.getDay60().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay90(soagDto.getDay90().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay180(soagDto.getDay180().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay365(soagDto.getDay365().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
                soagDto.setDay730(soagDto.getDay730().multiply(BigDecimal.valueOf(100)).divide(total,3,BigDecimal.ROUND_HALF_UP));
            }
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getCSupplyList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_CIRCULATING_SUPPLY.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getSumCSupplyList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_SUM_CIRCULATING_SUPPLY.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getSumCddList(QueryVo vo) {

        List<DateBigDecimalDto> list = redisService.getCacheList(BTCRedisName.BTC_SUM_CDD.getKey());

        list = filterByTime(list,vo);

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getSumEaCddList(QueryVo vo) {
        List<DateBigDecimalDto> list = redisService.getCacheList(BTCRedisName.BTC_SUM_ENTITY_ADJUSTED_CDD.getKey());

        list = filterByTime(list,vo);
        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getLiveLinessList(QueryVo vo) {

        List<LiveLinessDto> list = redisService.getCacheList(BTCRedisName.BTC_LIVELINESS.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getRealizedProfitList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_REALIZED_PROFIT.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getRealizedLossList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_REALIZED_LOSS.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getRplRateList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_RPL_RATE.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getMarketCapList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_MARKETCAP.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getRealizedCapList(QueryVo vo) {
        if(StringUtils.isNull(vo)){
            vo = new QueryVo();
        }

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_REALIZED_CAP.getKey(), vo.getSma());

        list = filterByTime(list,vo);

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getEntityAdjustedRealizedCapList(QueryVo vo) {
        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_ENTIT_ADJUSTED_REALIZED_CAP.getKey(), vo.getSma());

        list = filterByTime(list,vo);

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getMVRVList(QueryVo vo) {

        List<DataDto> list = redisService.getCacheList(BTCRedisName.BTC_MVRV.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getTime().after(start) || dto.getTime().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getTime().before(end) || dto.getTime().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getMVRVZList(QueryVo vo) {

        List<RCapAndMCapDto> list = redisService.getCacheList(BTCRedisName.BTC_MVRVZ.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        List<DateBigDecimalDto> returnList = list.stream().map(dto ->{
            BigDecimal mcap = dto.getMarketcap();
            BigDecimal rcap = dto.getRcap();
            DateBigDecimalDto returnDto = new DateBigDecimalDto();
            returnDto.setDate(dto.getDate());
            if (mcap.intValue() != 0){
                BigDecimal result = mcap.subtract(rcap).divide(mcap, 8, BigDecimal.ROUND_HALF_UP);
                returnDto.setValue(result.stripTrailingZeros());
            }else {
                returnDto.setValue(BigDecimal.valueOf(0));
            }
           return  returnDto;
        }).collect(Collectors.toList());

        if(vo.getSma() > 0){
            returnList = getSMA(returnList, vo.getSma());
        }

        //按开始时间过滤
        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            returnList = returnList.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        //按结束时间过滤
        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            returnList = returnList.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }
        //异常数据处理 主要是对0数据
        return AjaxResult.success(returnList);
    }

    @Override
    public AjaxResult getLthMVRVList(QueryVo vo) {

        List<TermHoldermvrvDto> list = redisService.getCacheList(BTCRedisName.BTC_LTH_MVRV.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }
        //sma

        //按开始时间过滤
        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        //按结束时间过滤
        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getSthMVRVList(QueryVo vo) {

        List<TermHoldermvrvDto> list = redisService.getCacheList(BTCRedisName.BTC_STH_MVRV.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }
        //sma

        //按开始时间过滤
        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        //按结束时间过滤
        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getNuplList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_NUPL.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getUnrealizedProfitList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_UNREALIZED_PROFIT.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getUnrealizedLossList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_UNREALIZED_LOSS.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getLthNuplList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_LTH_NUPL.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getSthNuplList(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_STH_NUPL.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getMintusd(QueryVo vo) {

        List<DateBigDecimalDto> list = redisService.getCacheList(BTCRedisName.BTC_MINTUSD.getKey());

        if(list.size()<1){
            return AjaxResult.success(list);
        }

        //List<DateBigDecimalDto> avgList = getList(BTCRedisName.BTC_MINTUSD.getKey(), 365);
        //
        //Map<Date, DateBigDecimalDto> map = list.stream().collect(Collectors.toMap(DateBigDecimalDto::getDate, DateBigDecimalDto -> DateBigDecimalDto));
        //
        //avgList.forEach(e ->{
        //    if(map.containsKey(e.getDate())){
        //        DateBigDecimalDto dto = map.get(e.getDate());
        //        if(e.getValue().compareTo(BigDecimal.ZERO) == 0){
        //            e.setValue(BigDecimal.ZERO);
        //        }else {
        //            e.setValue(dto.getValue().divide(e.getValue(),8,BigDecimal.ROUND_HALF_UP));
        //        }
        //    }else {
        //        e.setValue(BigDecimal.ZERO);
        //    }
        //});
        //if(StringUtils.isNotEmpty(vo.getStart())){
        //    Date start = DateUtils.parseDate(vo.getStart());
        //    avgList = avgList.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        //}
        //
        //if(StringUtils.isNotEmpty(vo.getEnd())){
        //    Date end = DateUtils.parseDate(vo.getEnd());
        //    avgList = avgList.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        //}

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }
        //异常数据处理 主要是对0数据
        return  CheckData(list);
    }

    @Override
    public AjaxResult getPuellMultiple(QueryVo vo) {
        return null;
    }

    @Override
    public AjaxResult getVDDList(QueryVo vo) {
        List<DateBigDecimalDto> list = redisService.getCacheList(BTCRedisName.BTC_VDD.getKey());
        if(list.size()<1){
            return AjaxResult.error("没有查询到数据");
        }

        list = filterByTime(list, vo);

        return AjaxResult.success(list);
    }

    @Override
    public AjaxResult getPrice(QueryVo vo) {

        List<PriceDataDto> list = redisService.getCacheList(BTCRedisName.BTC_PRICE.getKey());

        if(list.size()<1){
            return AjaxResult.error("没有查询到数据");
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getTime().after(start) || dto.getTime().equals(start))).collect(Collectors.toList());
        }

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getTime().before(end) || dto.getTime().equals(end))).collect(Collectors.toList());
        }

        //if(list.size()<1){
        //    return AjaxResult.s("该时间段内无数据");
        //}
        return AjaxResult.success(list);

    }

    @Override
    public AjaxResult getMinerAddress(QueryVo vo) {

        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_MINER_ADDRESS.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }

    @Override
    public AjaxResult getMinerBalance(QueryVo vo) {
        List<DateBigDecimalDto> list = getList(BTCRedisName.BTC_MINER_BALANCE.getKey(), vo.getSma());

        list = filterByTime(list, vo);

        return  CheckData(list);
    }
    /**
     * 通过缓存获取所有数据 如果传递了sma则做sma处理
     * @param key
     * @param sma
     * @return
     */
    public List<DateBigDecimalDto> getList(String key,int sma){

        List<DateBigDecimalDto> list = new ArrayList<>();

        if(redisService.hasKey(key)){
            list = redisService.getCacheList(key);
        }

        if(sma > 0){
            //todo sma处理
            //返回处理过的数据
            list = getSMA(list,sma);
        }

        return list;
    }

    /**
     * 验证list是否为空
     * @param list
     * @return
     */
    public AjaxResult CheckData(List list) {

        if(list.size() < 1){
            return AjaxResult.success(list);
        }
        return AjaxResult.success(list);
    }

    /**
     * sma处理
     * @param list
     * @return
     */
    public List<DateBigDecimalDto> getSMA(List<DateBigDecimalDto> list,int day) {

        if (list.size()< day){
            return new ArrayList<>();
        }
        if(list.size() < 1){
            return list;
        }

        BigDecimal total = BigDecimal.ZERO;
        BigDecimal divideNumber = new BigDecimal(day);
        for(int i = 0 ; i < day ;i++){
            total =  list.get(i).getValue().add(total);
        }
        BigDecimal startY = total.divide(divideNumber, 8, BigDecimal.ROUND_HALF_UP);
        DateBigDecimalDto startDto = new DateBigDecimalDto();
        startDto.setDate(list.get(day-1).getDate());
        startDto.setValue(startY.stripTrailingZeros());

        List<DateBigDecimalDto> returnList = new ArrayList<>();
        returnList.add(startDto);
        for (int i = day; i < list.size(); i++) {

            total = total.add(list.get(i).getValue()).subtract(list.get(i-day).getValue());

            startY = total.divide(divideNumber,8,BigDecimal.ROUND_HALF_UP);

            DateBigDecimalDto dto = new DateBigDecimalDto();
            dto.setDate(list.get(i).getDate());
            dto.setValue(startY.stripTrailingZeros());

            returnList.add(dto);
        }
        return returnList;
    }
    /**
     * 通过时间筛选list
     * @param list
     * @param vo
     * @return
     */
    public List<DateBigDecimalDto> filterByTime(List<DateBigDecimalDto> list,QueryVo vo){

        if(StringUtils.isNull(vo)){
            return list;
        }

        if(StringUtils.isNotEmpty(vo.getStart())){
            Date start = DateUtils.parseDate(vo.getStart());
            list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());
        }
        //todo
        Date start = DateUtils.parseDate("2010-10-01");
        list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());

        if(StringUtils.isNotEmpty(vo.getEnd())){
            Date end = DateUtils.parseDate(vo.getEnd());
            list = list.stream().filter(dto -> (dto.getDate().before(end) || dto.getDate().equals(end))).collect(Collectors.toList());
        }

        return list;
    }

}
