package com.tanpu.fund.service.impl;

import com.tanpu.fund.enums.ProStatusEnums;
import com.tanpu.fund.mapper.generator.custom.FundInfoCustomMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RunWith(SpringRunner.class)
 @SpringBootTest
 @ActiveProfiles("dev")
public class ProfitRateServiceImplTest {

    @Autowired
    FundCountService profitRateService;
    @Resource
    FundInfoCustomMapper fundInfoCustomMapper;
    @Resource
    FundNavMapper fundNavMapper;

    @Test
    public void sectionProfitRate() {
        //基金 HF0000000A
//        profitRateService.sectionProfitRate();

    }

    private void queryFundInfoNavVos(int pageSize, int proDisFre){
        //查询按周披露净值的基金
        List<Integer> statusList = new ArrayList<>();
        statusList.add(ProStatusEnums.OPENING.getType());
        statusList.add(ProStatusEnums.CHANGEMANGER.getType());
        statusList.add(ProStatusEnums.CLOSE.getType());
        List<String> fundInfoNavVos = fundInfoCustomMapper.queryFundNavByCondition(proDisFre, statusList, pageSize - 500, 500);

        //查询计算
        {
            if(!CollectionUtils.isEmpty(fundInfoNavVos)) {
                Date startDate = null;
                Date endDate = null;

                profitRateService.sectionProfitRate(proDisFre, startDate, endDate, fundInfoNavVos);
            }
        }

        if (!CollectionUtils.isEmpty(fundInfoNavVos) && fundInfoNavVos.size() == 500) {
            //递归每次取500条基金数据
            queryFundInfoNavVos(pageSize + 500, proDisFre);
        }
    }
}