package com.ruoyi.invest.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.DictUtils;
import com.ruoyi.invest.domain.dto.*;
import com.ruoyi.invest.domain.vo.*;
import com.ruoyi.invest.mapper.*;
import com.ruoyi.invest.service.IStatisticAnalysisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class StatisticAnalysisImpl implements IStatisticAnalysisService {

    @Resource
    private BankCardLendMapper bankCardLendMapper;

    @Resource
    private CreditCardBillMapper creditCardBillMapper;

    @Resource
    private FutureStocksBillMapper futureStocksBillMapper;

    @Resource
    private FutureStocksMapper futureStocksMapper;

    @Resource
    private PosMachineMapper posMachineMapper;

    @Resource
    private InstallmentHistoryMapper installmentHistoryMapper;

    @Resource
    private InstallmentHistoryDetailMapper installmentHistoryDetailMapper;

    @Resource
    private StatisticAnalysisMapper statisticAnalysisMapper;

    @Resource
    private CreditReportQueryRecordMapper creditReportQueryRecordMapper;

    @Resource
    private AccountsMapper accountsMapper;

    @Resource
    private AccountsTransferRecordMapper accountsTransferRecordMapper;

    @Resource
    private AccountsDealRecordMapper accountsDealRecordMapper;


    @Override
    public Map<String, Object> getIncomeInfo() {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        //期货收益
        FutureStocksBillDto futureStocksBillDto=new FutureStocksBillDto();
        futureStocksBillDto.setType("1");
        List<FutureStocksBillVo> futureStocksBillList=futureStocksBillMapper.selectFutureStocksBillList(futureStocksBillDto);
        double futuresIncome =   futureStocksBillList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).sum();
        map.put("futuresIncome",decimalFormat.format(futuresIncome));
        //股票收益
        futureStocksBillDto.setType("2");
        futureStocksBillList=futureStocksBillMapper.selectFutureStocksBillList(futureStocksBillDto);
        double stocksIncome =   futureStocksBillList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).sum();
        map.put("stocksIncome",decimalFormat.format(stocksIncome));
        //其他收益
        map.put("otherIncome","0");
        //总收益
        map.put("totalIncome",decimalFormat.format(futuresIncome+stocksIncome));

        return map;
    }


    @Override
    public Map<String, Object> getBaseAccountInfo() {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        //Pos机
        map.put("posCount",posMachineMapper.selectPosMachineList(new PosMachineDto()).size());
         BankCardLendDto bankCardLendDto=new BankCardLendDto();
        bankCardLendDto.setType("2");
        //信用卡
        map.put("creditCount",bankCardLendMapper.selectBankCardLendList(bankCardLendDto).size());
        bankCardLendDto.setType("1");
        //储蓄卡
        map.put("debitCount",bankCardLendMapper.selectBankCardLendList(bankCardLendDto).size());
        bankCardLendDto.setType("3");
        bankCardLendDto.setLendType("1");
        //网贷
        map.put("onlineLendCount",bankCardLendMapper.selectBankCardLendList(bankCardLendDto).size());
        bankCardLendDto.setLendType("2");
        //人情
        bankCardLendDto.setLendType("2");

        map.put("peopleLendCount",bankCardLendMapper.selectBankCardLendList(bankCardLendDto).size());
         FutureStocksDto  futureStocksDto=new FutureStocksDto();
        futureStocksDto.setType("1");
        //期货
        map.put("futuresCount",futureStocksMapper.selectFutureStocksList(futureStocksDto).size());
        //股票
        futureStocksDto.setType("2");
        map.put("stocksCount",futureStocksMapper.selectFutureStocksList(futureStocksDto).size());
        return map;
    }

    @Override
    public Map<String, Object> getDebetInfo() {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("#.##");

        AccountsDto dto=new AccountsDto();
        dto.setState("1");
        //储蓄卡
        dto.setType("1");
        List<AccountsVo> accountsList=accountsMapper.selectAccountsList(dto);
        double debetBalance =0;
        if(accountsList.size()>0){
            debetBalance=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
        }
        map.put("debetBalance",decimalFormat.format(debetBalance));

        dto.setState("1");
        //信用卡
        dto.setType("2");
        accountsList=accountsMapper.selectAccountsList(dto);
        double creditBalance =0;
        if(accountsList.size()>0){
            creditBalance=accountsList.stream().mapToDouble(AccountsVo::getBalance).sum()*(-1);
        }
        map.put("creditBalance",decimalFormat.format(creditBalance));

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatterMonth = new SimpleDateFormat("yyyy-MM");
        //未结清网贷数据
        InstallmentHistoryDto installmentHistoryDto=new InstallmentHistoryDto();
        InstallmentHistoryDetailDto detailDto=new InstallmentHistoryDetailDto();
        detailDto.setType("3");
        detailDto.setState("0");
        List<InstallmentHistoryDetailVo> detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double unClearedOnlineDebt =   0;
        double unClearedOnlineDebtPrinciple =   0;
        double unClearedOnlineDebtInterest =   0;
        if(detailList.size()>0){
            unClearedOnlineDebtPrinciple=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getPrincipal).sum();
            unClearedOnlineDebtInterest=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getInterest).sum();
            unClearedOnlineDebt=unClearedOnlineDebtPrinciple+unClearedOnlineDebtInterest;
        }
        map.put("unClearedOnlineDebt",decimalFormat.format(unClearedOnlineDebt));
        map.put("unClearedOnlineDebtPrinciple",decimalFormat.format(unClearedOnlineDebtPrinciple));
        map.put("unClearedOnlineDebtInterest",decimalFormat.format(unClearedOnlineDebtInterest));

        //信用卡分期账单
        detailDto.setType("2");
        detailDto.setState("0");
        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double creditInstallmentHistory =0;
        if(detailList.size()>0){
            creditInstallmentHistory =   detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        }
        map.put("creditInstallmentHistory",decimalFormat.format(creditInstallmentHistory));


        //人情
        installmentHistoryDto.setType("4");
        installmentHistoryDto.setState("0");
        List<InstallmentHistoryVo> installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        double peopleLendHistory =0;
        if(installmentHistoryList.size()>0){
            peopleLendHistory =   installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getInstallmentAmount).sum();
        }
        map.put("peopleLendHistory",decimalFormat.format(peopleLendHistory));

        //总负债
        map.put("totalDebt",decimalFormat.format(unClearedOnlineDebt+creditBalance+peopleLendHistory));
        //净资产
        map.put("netAsset",decimalFormat.format(debetBalance-unClearedOnlineDebt-creditBalance-peopleLendHistory));

        //未结清账户数
        installmentHistoryDto.setState("0");
        installmentHistoryDto.setType("3");
        installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        int unclearedOnlineDebtCount =   installmentHistoryList.size();
        map.put("unclearedOnlineDebtCount",unclearedOnlineDebtCount);

        //已结清账户数
        installmentHistoryDto.setState("1");
        installmentHistoryDto.setType("3");
        installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        int clearedOnlineDebtCount =   installmentHistoryList.size();
        map.put("clearedOnlineDebtCount",clearedOnlineDebtCount);

        //已结清网贷数据
        installmentHistoryDto.setState("1");
        installmentHistoryDto.setType("3");
        installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        double clearedOnlineDebt =0;
        double clearedOnlineDebtPrinciple =0;
        double clearedOnlineDebtInterest =0;
        if(installmentHistoryList.size()>0){
            clearedOnlineDebtPrinciple =   installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getInstallmentAmount).sum();
            clearedOnlineDebtInterest =   installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getTotalInterest).sum();
            clearedOnlineDebt=clearedOnlineDebtPrinciple+clearedOnlineDebtInterest;
        }
        map.put("clearedOnlineDebt",decimalFormat.format(clearedOnlineDebt));
        map.put("clearedOnlineDebtPrinciple",decimalFormat.format(clearedOnlineDebtPrinciple));
        map.put("clearedOnlineDebtInterest",decimalFormat.format(clearedOnlineDebtInterest));
        //网贷当月应还款

        detailDto.setRepaymentMonth(formatterMonth.format(new Date()));
        detailDto.setState("");
        detailDto.setType("3");
        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double dueOnlineDebt  =0;
        if(detailList.size()>0){
            dueOnlineDebt =   detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        }
        map.put("dueOnlineDebt",decimalFormat.format(dueOnlineDebt));

        //网贷当月已还款
        detailDto.setState("1");
        detailDto.setRepaymentMonth(formatterMonth.format(new Date()));
        detailDto.setType("3");
        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double repaidOnlineDebt =0;
        if(detailList.size()>0){
            repaidOnlineDebt =   detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        }
        map.put("repaidOnlineDebt",decimalFormat.format(repaidOnlineDebt));

        //网贷剩余还款
        map.put("leftOnlineDebt",decimalFormat.format(dueOnlineDebt-repaidOnlineDebt));

        return map;
    }

    @Override
    public Map<String, Object> getCreditInfo() {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        SimpleDateFormat formatterMonth = new SimpleDateFormat("yyyy-MM");

        //当月信用卡账单
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月账单");
        CreditCardBillDto creditCardBillDto=new CreditCardBillDto();
        creditCardBillDto.setName(simpleDateFormat.format(DateUtils.getNowDate()));
        List<CreditCardBillVo> creditCardBillList=creditCardBillMapper.selectCreditCardBillList(creditCardBillDto);
        double currentCreditBill =   creditCardBillList.stream().mapToDouble(CreditCardBillVo::getBillAmount).sum();
        map.put("currentCreditBill",decimalFormat.format(currentCreditBill));

        //信用卡分期当月应还款
        InstallmentHistoryDetailDto detailDto=new InstallmentHistoryDetailDto();
        detailDto.setRepaymentMonth(formatterMonth.format(new Date()));
        detailDto.setType("2");
        List<InstallmentHistoryDetailVo> detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double creditInstallment =   detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        map.put("creditInstallment",decimalFormat.format(creditInstallment));

        detailDto.setState("0");
        detailDto.setRepaymentMonth("");
        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double unclearedCreditInstallment =   0;
        double unclearedCreditInstallmentPrinciple =   0;
        double unclearedCreditInstallmentInterest =   0;
        if(detailList.size()>0){

            unclearedCreditInstallmentPrinciple=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getPrincipal).sum();
            unclearedCreditInstallmentInterest=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getInterest).sum();
            unclearedCreditInstallment=unclearedCreditInstallmentPrinciple+unclearedCreditInstallmentInterest;
        }
        map.put("unclearedCreditInstallment",decimalFormat.format(unclearedCreditInstallment));
        map.put("unclearedCreditInstallmentPrinciple",decimalFormat.format(unclearedCreditInstallmentPrinciple));
        map.put("unclearedCreditInstallmentInterest",decimalFormat.format(unclearedCreditInstallmentInterest));

        //已结清信用卡分期数据
        InstallmentHistoryDto installmentHistoryDto=new InstallmentHistoryDto();
        installmentHistoryDto.setState("1");
        installmentHistoryDto.setType("2");
        List<InstallmentHistoryVo> installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        double clearedCreditInstallmentDebt =0;
        double clearedCreditInstallmentPrinciple =0;
        double clearedCreditInstallmentInterest =0;
        if(installmentHistoryList.size()>0){
            clearedCreditInstallmentPrinciple =   installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getInstallmentAmount).sum();
            clearedCreditInstallmentInterest =   installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getTotalInterest).sum();
            clearedCreditInstallmentDebt=clearedCreditInstallmentPrinciple+clearedCreditInstallmentInterest;
        }
        map.put("clearedCreditInstallmentDebt",decimalFormat.format(clearedCreditInstallmentDebt));
        map.put("clearedCreditInstallmentPrinciple",decimalFormat.format(clearedCreditInstallmentPrinciple));
        map.put("clearedCreditInstallmentInterest",decimalFormat.format(clearedCreditInstallmentInterest));

        int clearedCreditInstallmentCount =   installmentHistoryList.size();
        map.put("clearedCreditInstallmentCount",clearedCreditInstallmentCount);

        installmentHistoryDto.setState("0");
        installmentHistoryDto.setType("2");
        installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        int unclearedCreditInstallmentCount =   installmentHistoryList.size();
        map.put("unclearedCreditInstallmentCount",unclearedCreditInstallmentCount);


        //信用卡额度
        BankCardLendDto bankCardLendDto=new BankCardLendDto();
        bankCardLendDto.setType("2");
        List<BankCardLendVo> bankCardLendVoList=statisticAnalysisMapper.selectBankCardLendList(bankCardLendDto);
        int creditLimit =   bankCardLendVoList.stream().mapToInt(BankCardLendVo::getCreditLimit).sum();
        map.put("creditLimit",creditLimit);

        AccountsDto dto=new AccountsDto();
        dto.setState("1");
        //信用卡
        dto.setType("2");
        List<AccountsVo> accountsList=accountsMapper.selectAccountsList(dto);
        double creditAvailableLimit =0;
        double creditBalance =0;
        if(accountsList.size()>0){
            creditAvailableLimit=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
            creditBalance=accountsList.stream().mapToDouble(AccountsVo::getBalance).sum()*(-1);
        }
        map.put("creditAvailableLimit",decimalFormat.format(creditAvailableLimit));
        map.put("creditBalance",decimalFormat.format(creditBalance));
        //使用率
        double creditBillRate;
        if (creditLimit != 0) {
            creditBillRate= ((creditBalance) * 100) /creditLimit;
        }else {
            creditBillRate= 0;
        }
        map.put("creditBillRate", decimalFormat.format(creditBillRate));

        //上月信用卡账单
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtils.getNowDate());
        calendar.add(Calendar.MONTH, -1);
        creditCardBillDto.setName(simpleDateFormat.format(calendar.getTime()));
        creditCardBillList=creditCardBillMapper.selectCreditCardBillList(creditCardBillDto);
        double lastMonthUsedLimit =   creditCardBillList.stream().mapToDouble(CreditCardBillVo::getBillAmount).sum();
        map.put("lastMonthUsedLimit",decimalFormat.format(lastMonthUsedLimit));


        map.put("lastMonthUsedRate",decimalFormat.format(lastMonthUsedLimit*100/creditLimit));


        //近6个月月信用卡账单
        creditCardBillDto.setName("");
        Calendar startMonth = Calendar.getInstance();
        startMonth.setTime(DateUtils.getNowDate());
        startMonth.add(Calendar.MONTH, -6);
        creditCardBillDto.setStartMonth(formatterMonth.format(startMonth.getTime()));
        Calendar endMonth = Calendar.getInstance();
        endMonth.setTime(DateUtils.getNowDate());
        endMonth.add(Calendar.MONTH, -1);
        creditCardBillDto.setEndMonth(formatterMonth.format(endMonth.getTime()));
        creditCardBillList=creditCardBillMapper.selectCreditCardBillList(creditCardBillDto);
        double lastSixMonthUsedLimit =   creditCardBillList.stream().mapToDouble(CreditCardBillVo::getBillAmount).sum();
        map.put("lastSixMonthUsedLimit",decimalFormat.format(lastSixMonthUsedLimit/6));
       //近6个月月信用卡使用率
        map.put("lastSixMonthUsedRate",decimalFormat.format(lastSixMonthUsedLimit*100/(6*creditLimit)));

        return map;
    }



    @Override
    public Map<String, Object> getCreditAnalysis(AnalysisDto analysisDto) {
//返回数据
        HashMap<String, Object> map = new HashMap<>();

        List<CreditCardBillVo> creditCardBillVoList=new ArrayList<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-1));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-6));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
            }
        }
        DecimalFormat decimalFormat = new DecimalFormat("#.##");

        //根据日期，获取按日获取的数据，按月按年分组列表，单独处理
        CreditCardBillDto creditCardBillDto=new CreditCardBillDto();
        creditCardBillDto.setStartMonth(analysisDto.getStartTime().substring(0,7));
        creditCardBillDto.setEndMonth(analysisDto.getEndTime().substring(0,7));
        creditCardBillDto.setCreditCardId(analysisDto.getId());
        creditCardBillVoList=creditCardBillMapper.selectCreditCardBillList(creditCardBillDto);
       //修改名称加卡号
        for (CreditCardBillVo creditCardBill : creditCardBillVoList) {
            if(creditCardBill.getBankName()!=null){
                creditCardBill.setBankNameCode(creditCardBill.getBankName()+"（"+ StringUtils.getLastNumberChars(4,creditCardBill.getBankCode()+"）"));
            }
        }
        //信用卡额度
        BankCardLendDto bankCardLendDto=new BankCardLendDto();
        bankCardLendDto.setType("2");
        bankCardLendDto.setCreditCardId(analysisDto.getId());
        List<BankCardLendVo> bankCardLendVoList=statisticAnalysisMapper.selectBankCardLendList(bankCardLendDto);
        int creditLimit =   bankCardLendVoList.stream().mapToInt(BankCardLendVo::getCreditLimit).sum();
        map.put("creditLimit",creditLimit);
        //信用卡
        map.put("creditCardCount",bankCardLendMapper.selectBankCardLendList(bankCardLendDto).size());

        AccountsDto dto=new AccountsDto();
        dto.setState("1");
        //信用卡
        dto.setType("2");
        List<AccountsVo> accountsList=accountsMapper.selectAccountsList(dto);
        double creditAvailableLimit =0;
        double creditBalance =0;
        if(accountsList.size()>0){
            creditAvailableLimit=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
            creditBalance=accountsList.stream().mapToDouble(AccountsVo::getBalance).sum()*(-1);
        }
        map.put("creditAvailableLimit",decimalFormat.format(creditAvailableLimit));
        map.put("creditBalance",decimalFormat.format(creditBalance));


        //实际账单
        double actualCreditBill = creditCardBillVoList.stream().mapToDouble(CreditCardBillVo::getBillAmount).sum();
        map.put("actualCreditBill",  decimalFormat.format(actualCreditBill));


        List<CreditCardBillVo> creditAnalysisList=new ArrayList<>();

        if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (CreditCardBillVo creditCardBillVo:creditCardBillVoList
            ) {
                String monthString=dateFormat.format(creditCardBillVo.getBillDate()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                String details="";
                double actualCreditBillMonth=0;
                for (CreditCardBillVo creditCardBillVo:creditCardBillVoList
                ) {
                    String monthString=dateFormat.format(creditCardBillVo.getBillDate()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        actualCreditBillMonth+=creditCardBillVo.getBillAmount();
                        details+=creditCardBillVo.getBankNameCode()+"账单"+creditCardBillVo.getBillAmount()+"；<br/>";
                    }
                }
                CreditCardBillVo analysisVo=new CreditCardBillVo();
                analysisVo.setBillAmount(Double.parseDouble(decimalFormat.format(actualCreditBillMonth)));
                analysisVo.setName(staticsTime);
                analysisVo.setRemark(details);
                creditAnalysisList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (CreditCardBillVo creditCardBillVo:creditCardBillVoList
            ) {
                String yearString=dateFormat.format(creditCardBillVo.getBillDate()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillYear=0;
                for (CreditCardBillVo creditCardBillVo:creditCardBillVoList
                ) {
                    String yearString=dateFormat.format(creditCardBillVo.getBillDate()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        actualCreditBillYear+=creditCardBillVo.getBillAmount();
                    }
                }
                CreditCardBillVo analysisVo=new CreditCardBillVo();
                analysisVo.setBillAmount(Double.parseDouble(decimalFormat.format(actualCreditBillYear)));
                analysisVo.setName(staticsTime);
                creditAnalysisList.add(analysisVo);

            }

        }
        //平均账单
        int timesCount=creditAnalysisList.size();
        double averageCreditBill=0;
        if(timesCount!=0){
            averageCreditBill= actualCreditBill /timesCount;
        }
        //使用率
        double creditBillRate;
        if (creditLimit != 0) {
            creditBillRate= ((creditBalance) * 100) /creditLimit;
        }else {
            creditBillRate= 0;
        }
        map.put("creditBillRate", decimalFormat.format(creditBillRate));
        map.put("averageCreditBill", decimalFormat.format(averageCreditBill));
        ArrayList<Map<String, Object>> creditBillList = new ArrayList<>();
        ArrayList<Map<String, Object>> tableCreditBillList = new ArrayList<>();
        for (CreditCardBillVo creditCardBillVo:creditAnalysisList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", creditCardBillVo.getName());
            datamap.put("detail", creditCardBillVo.getRemark());
            datamap.put("value", decimalFormat.format(creditCardBillVo.getBillAmount()));
            tableCreditBillList.add(datamap);
        }
        Collections.reverse(creditAnalysisList);
        for (CreditCardBillVo creditCardBillVo:creditAnalysisList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", creditCardBillVo.getName());
            datamap.put("value", decimalFormat.format(creditCardBillVo.getBillAmount()));
            creditBillList.add(datamap);
        }
        //列表
        map.put("creditBillList",creditBillList);
        map.put("tableCreditBillList",tableCreditBillList);

        return map;
    }

    @Override
    public Map<String, Object> getFuturesStocksAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-1));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-24));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
            }
        }
        DecimalFormat decimalFormat = new DecimalFormat("#.##");

        //获取数据
        List<FutureStocksBillVo>  futureStocksBillVoList=new ArrayList<>();
        FutureStocksBillDto futureStocksBillDto=new FutureStocksBillDto();
        futureStocksBillDto.setStartMonth(analysisDto.getStartTime().substring(0,7));
        futureStocksBillDto.setEndMonth(analysisDto.getEndTime().substring(0,7));
        futureStocksBillDto.setFutureStocksId(analysisDto.getId());
        if(analysisDto.getDataType()==null){
            futureStocksBillDto.setType("1");
            futureStocksBillVoList=futureStocksBillMapper.selectFutureStocksBillList(futureStocksBillDto);
            //期货累计收益
            double accumulateFutures = futureStocksBillVoList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).sum();
            map.put("accumulateFutures",  decimalFormat.format(accumulateFutures));

            futureStocksBillDto.setType("2");
            futureStocksBillVoList=futureStocksBillMapper.selectFutureStocksBillList(futureStocksBillDto);
            //股票累计收益
            double accumulateStocks = futureStocksBillVoList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).sum();
            map.put("accumulateStocks",  decimalFormat.format(accumulateStocks));
        }

        futureStocksBillDto.setType(analysisDto.getDataType());
        futureStocksBillVoList=futureStocksBillMapper.selectFutureStocksBillList(futureStocksBillDto);
        //修改名称加卡号
        for (FutureStocksBillVo futureStocksBill : futureStocksBillVoList) {
            if(futureStocksBill.getFutureStocksCode()!=null){
                futureStocksBill.setFutureStocksNameCode(futureStocksBill.getFutureStocksName()+"（"+ futureStocksBill.getFutureStocksCode()+"）");
            }else {
                futureStocksBill.setFutureStocksNameCode(futureStocksBill.getFutureStocksName());
            }
        }
        //累计收益
        double accumulateIncome = futureStocksBillVoList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).sum();
        map.put("accumulateIncome",  decimalFormat.format(accumulateIncome));

        List<FutureStocksBillVo> futureStocksBillList=new ArrayList<>();

        if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (FutureStocksBillVo futureStocksBillVo:futureStocksBillVoList
            ) {

                String monthString=dateFormat.format(futureStocksBillVo.getBillDate()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);

                }
            }
            for (String staticsTime :staticsTimeList
            ) {
                String  details="";
                double actualCreditBillMonth=0;
                for (FutureStocksBillVo futureStocksBillVo:futureStocksBillVoList
                ) {
                    String monthString=dateFormat.format(futureStocksBillVo.getBillDate()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        actualCreditBillMonth+=futureStocksBillVo.getBillAmount();
                        details+=futureStocksBillVo.getFutureStocksNameCode()+"收益"+futureStocksBillVo.getBillAmount()+"；<br/>";
                    }
                }
                FutureStocksBillVo analysisVo=new FutureStocksBillVo();
                analysisVo.setBillAmount(Double.parseDouble(decimalFormat.format(actualCreditBillMonth)));
                analysisVo.setName(staticsTime);
                analysisVo.setRemark(details);
                futureStocksBillList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (FutureStocksBillVo futureStocksBillVo:futureStocksBillVoList
            ) {
                String yearString=dateFormat.format(futureStocksBillVo.getBillDate()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillYear=0;
                for (FutureStocksBillVo futureStocksBillVo:futureStocksBillVoList
                ) {
                    String yearString=dateFormat.format(futureStocksBillVo.getBillDate()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        actualCreditBillYear+=futureStocksBillVo.getBillAmount();
                    }
                }
                FutureStocksBillVo analysisVo=new FutureStocksBillVo();
                analysisVo.setBillAmount(Double.parseDouble(decimalFormat.format(actualCreditBillYear)));
                analysisVo.setName(staticsTime);
                futureStocksBillList.add(analysisVo);

            }

        }
        //平均收益
        int timesCount=futureStocksBillList.size();
        double averageIncome=0;
        if(timesCount!=0){
            averageIncome= accumulateIncome /timesCount;
        }
        map.put("averageIncome",  decimalFormat.format(averageIncome));
        // 最大值,最小值
        double maxRevenue=0;
        double maxLoss=0;
        if(futureStocksBillList.size()>0){
            maxRevenue = futureStocksBillList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).max().getAsDouble();
            maxLoss = futureStocksBillList.stream().mapToDouble(FutureStocksBillVo::getBillAmount).min().getAsDouble();
        }
        map.put("maxRevenue",  decimalFormat.format(maxRevenue));
        map.put("maxLoss",  decimalFormat.format(maxLoss));

        ArrayList<Map<String, Object>> futuresStocksList = new ArrayList<>();
        ArrayList<Map<String, Object>> tableFuturesStocksList = new ArrayList<>();
        for (FutureStocksBillVo futureStocksBillVo:futureStocksBillList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", futureStocksBillVo.getName());
            datamap.put("detail", futureStocksBillVo.getRemark());
            datamap.put("value", decimalFormat.format(futureStocksBillVo.getBillAmount()));
            tableFuturesStocksList.add(datamap);
        }
        Collections.reverse(futureStocksBillList);
        for (FutureStocksBillVo futureStocksBillVo:futureStocksBillList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", futureStocksBillVo.getName());
            datamap.put("value", decimalFormat.format(futureStocksBillVo.getBillAmount()));
            futuresStocksList.add(datamap);
        }
        //列表
        map.put("futuresStocksList",futuresStocksList);
        map.put("tableFuturesStocksList",tableFuturesStocksList);

        return map;
    }

    @Override
    public Map<String, Object> getInstallmentHistoryAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-1));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-24));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
            }
        }
        DecimalFormat decimalFormat = new DecimalFormat("#.##");

        //未结清网贷数据
        InstallmentHistoryDto installmentHistoryDto=new InstallmentHistoryDto();
        InstallmentHistoryDetailDto detailDto=new InstallmentHistoryDetailDto();
        detailDto.setType(analysisDto.getDataType());
        detailDto.setState("0");
        detailDto.setBankCardLendId(analysisDto.getId());
        List<InstallmentHistoryDetailVo> detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double unClearedDetail = 0;
        if(detailList.size()>0){
            unClearedDetail=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        }
        map.put("unClearedDetail",decimalFormat.format(unClearedDetail));

        //未结清账户数
        installmentHistoryDto.setState("0");
        installmentHistoryDto.setType(analysisDto.getDataType());
        installmentHistoryDto.setBankCardLendId(analysisDto.getId());
        List<InstallmentHistoryVo> installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        int unclearedDetailCount =   installmentHistoryList.size();
        map.put("unclearedDetailCount",unclearedDetailCount);

        //网贷当月应还款
        detailDto.setStartDate(analysisDto.getStartTime());
        detailDto.setEndDate(analysisDto.getEndTime());
        detailDto.setState("");
        detailDto.setType(analysisDto.getDataType());

        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double dueDetail =0;
        if(detailList.size()>0){
            dueDetail=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        }
        map.put("dueDetail",decimalFormat.format(dueDetail));

        //网贷当月已还款
        detailDto.setState("1");
        detailDto.setType(analysisDto.getDataType());
        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);
        double repaidDetail =0;
        if(detailList.size()>0){
            repaidDetail=detailList.stream().mapToDouble(InstallmentHistoryDetailVo::getCurrentAmount).sum();
        }
        map.put("repaidDetail",decimalFormat.format(repaidDetail));

        //网贷剩余还款
        map.put("leftDetail",decimalFormat.format(dueDetail-repaidDetail));


        //获取数据,未还款
        detailDto.setStartDate(analysisDto.getStartTime());
        detailDto.setEndDate(analysisDto.getEndTime());
        detailDto.setState("0");
        detailDto.setType(analysisDto.getDataType());
        detailList=installmentHistoryDetailMapper.selectInstallmentHistoryDetailList(detailDto);


        List<InstallmentHistoryDetailVo> installmentHistoryDetailList =new ArrayList<>();
        if("1".equals(analysisDto.getType())){
            //日列表
            List <String> staticsTimeList=new ArrayList<>();
            for (InstallmentHistoryDetailVo vo:detailList
            ) {
                String dayString=dateFormat.format(vo.getRepaymentDate());

                if(!staticsTimeList.contains(dayString)){
                    staticsTimeList.add(dayString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                String  details="";
                double actualCreditBillDay=0;
                for (InstallmentHistoryDetailVo vo:detailList
                ) {
                    String dayString=dateFormat.format(vo.getRepaymentDate());

                    if(staticsTime.equals(dayString)){
                        actualCreditBillDay+=vo.getCurrentAmount();
                        details+=vo.getBankCardLendName()+"于"+dateFormat.format(vo.getCreateTime())+"应还款总额"+vo.getCurrentAmount()+"，其中本金"+vo.getPrincipal()+"，利息"+vo.getInterest()+"；<br/>";
                    }
                }
                InstallmentHistoryDetailVo analysisVo=new InstallmentHistoryDetailVo();
                analysisVo.setCurrentAmount(actualCreditBillDay);
                analysisVo.setRemark(staticsTime);
                analysisVo.setBankCardLendName(details);
                installmentHistoryDetailList.add(analysisVo);
            }

            //年查询
        }
        else
        if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (InstallmentHistoryDetailVo vo:detailList
            ) {
                String monthString=dateFormat.format(vo.getRepaymentDate()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillMonth=0;
                for (InstallmentHistoryDetailVo vo:detailList
                ) {
                    String monthString=dateFormat.format(vo.getRepaymentDate()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        actualCreditBillMonth+=vo.getCurrentAmount();
                    }
                }
                InstallmentHistoryDetailVo analysisVo=new InstallmentHistoryDetailVo();
                analysisVo.setCurrentAmount(Double.parseDouble(decimalFormat.format(actualCreditBillMonth)));
                analysisVo.setRemark(staticsTime);
                installmentHistoryDetailList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (InstallmentHistoryDetailVo vo:detailList
            ) {
                String yearString=dateFormat.format(vo.getRepaymentDate()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillYear=0;
                for (InstallmentHistoryDetailVo vo:detailList
                ) {
                    String yearString=dateFormat.format(vo.getRepaymentDate()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        actualCreditBillYear+=vo.getCurrentAmount();
                    }
                }
                InstallmentHistoryDetailVo analysisVo=new InstallmentHistoryDetailVo();
                analysisVo.setCurrentAmount(Double.parseDouble(decimalFormat.format(actualCreditBillYear)));
                analysisVo.setRemark(staticsTime);
                installmentHistoryDetailList.add(analysisVo);

            }

        }

        ArrayList<Map<String, Object>> historyDetailList = new ArrayList<>();
        ArrayList<Map<String, Object>> tableHistoryDetailList = new ArrayList<>();
        for (InstallmentHistoryDetailVo vo:installmentHistoryDetailList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getCurrentAmount()));
            datamap.put("detail", vo.getBankCardLendName());
            tableHistoryDetailList.add(datamap);
        }
        Collections.reverse(installmentHistoryDetailList);
        for (InstallmentHistoryDetailVo vo:installmentHistoryDetailList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getCurrentAmount()));
            historyDetailList.add(datamap);
        }
        //列表
        map.put("historyDetailList",historyDetailList);
        map.put("tableHistoryDetailList",tableHistoryDetailList);

        return map;
    }


    @Override
    public Map<String, Object> getCreditRecordAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatterMonth = new SimpleDateFormat("yyyy-MM");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),0));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-24));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                if(analysisDto.getEndTime().equals(formatterMonth.format(new Date()))){
                    SimpleDateFormat sdf = new SimpleDateFormat("dd");
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
                }else {
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
                }

            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
                if(analysisDto.getEndTime().equals(sdfYear.format(new Date()))){
                    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
                }else {
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
                }

            }
        }
        CreditReportQueryRecordDto dto=new CreditReportQueryRecordDto();
        dto.setQueryDateStart(analysisDto.getEndTime());
        Date queryDate=DateUtils.getNowDate();
        if(dto.getQueryDateStart()!=null){
            try {
                queryDate=dateFormat.parse(dto.getQueryDateStart());
                dto.setQueryDateEnd(dto.getQueryDateStart());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
        dto.setQueryType("1");

        Calendar calendarStart = Calendar.getInstance();
        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -1);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        map.put("lastOneMonths",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());


        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -2);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        map.put("lastTwoMonths",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());

        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -3);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        map.put("lastThreeMonths",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());

        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -6);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        map.put("lastSixMonths",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());


        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -12);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        map.put("lastOneYears",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());

        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -24);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        map.put("lastTwoYears",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());

        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -6);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        dto.setType("5");
        dto.setQueryType("2");
        map.put("lastSixMonthPersonalCount",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());


        dto.setQueryDateStart("");
        dto.setType("5");
        dto.setQueryType("2");
        map.put("totalPersonalCount",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());

        calendarStart.setTime(queryDate);
        calendarStart.add(Calendar.MONTH, -24);
        dto.setQueryDateStart(dateFormat.format(calendarStart.getTime()));
        dto.setType("4");
        map.put("lastTwoYearsAfterLoan",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());


        dto.setQueryDateStart("");
        dto.setType("4");
        map.put("totalAfterLoan",creditReportQueryRecordMapper.selectCreditReportQueryRecordList(dto).size());

        CreditReportQueryRecordDto detailDto=new CreditReportQueryRecordDto();
        //获取数据
        detailDto.setQueryDateEnd(analysisDto.getEndTime());
        detailDto.setQueryDateStart(analysisDto.getStartTime());
        detailDto.setQueryType("1");
        List<CreditReportQueryRecordVo> detailList=creditReportQueryRecordMapper.selectCreditReportQueryRecordList(detailDto);

        List<CreditReportQueryRecordVo> queryRecordList =new ArrayList<>();

        if("1".equals(analysisDto.getType())){
            //日列表
            List <String> staticsTimeList=new ArrayList<>();
            for (CreditReportQueryRecordVo vo:detailList
            ) {
                String dayString=dateFormat.format(vo.getQueryDate());

                if(!staticsTimeList.contains(dayString)){
                    staticsTimeList.add(dayString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                String  details="";
                int actualCreditBillDay=0;
                for (CreditReportQueryRecordVo vo:detailList
                ) {
                    String dayString=dateFormat.format(vo.getQueryDate());

                    if(staticsTime.equals(dayString)){
                        actualCreditBillDay+=vo.getQueryCount();
                        details+=vo.getQueryInstitution()+"查询"+vo.getQueryCount()+"次；<br/>";
                    }
                }
                CreditReportQueryRecordVo analysisVo=new CreditReportQueryRecordVo();
                analysisVo.setQueryCount(actualCreditBillDay);
                analysisVo.setRemark(staticsTime);
                analysisVo.setQueryInstitution(details);
                queryRecordList.add(analysisVo);
            }

            //年查询
        }
        else if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (CreditReportQueryRecordVo vo:detailList
            ) {
                String monthString=dateFormat.format(vo.getQueryDate()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                int actualCreditBillMonth=0;
                for (CreditReportQueryRecordVo vo:detailList
                ) {
                    String monthString=dateFormat.format(vo.getQueryDate()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        actualCreditBillMonth+=vo.getQueryCount();
                    }
                }
                CreditReportQueryRecordVo analysisVo=new CreditReportQueryRecordVo();
                analysisVo.setQueryCount(actualCreditBillMonth);
                analysisVo.setRemark(staticsTime);
                queryRecordList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (CreditReportQueryRecordVo vo:detailList
            ) {
                String yearString=dateFormat.format(vo.getQueryDate()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                int actualCreditBillYear=0;
                for (CreditReportQueryRecordVo vo:detailList
                ) {
                    String yearString=dateFormat.format(vo.getQueryDate()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        actualCreditBillYear+=vo.getQueryCount();
                    }
                }
                CreditReportQueryRecordVo analysisVo=new CreditReportQueryRecordVo();
                analysisVo.setQueryCount(actualCreditBillYear);
                analysisVo.setRemark(staticsTime);
                queryRecordList.add(analysisVo);

            }

        }

        ArrayList<Map<String, Object>> creditRecordsList = new ArrayList<>();
        ArrayList<Map<String, Object>> creditTableRecordsList = new ArrayList<>();
        for (CreditReportQueryRecordVo vo:queryRecordList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", vo.getQueryCount());
            datamap.put("detail", vo.getQueryInstitution());
            creditTableRecordsList.add(datamap);
        }
        Collections.reverse(queryRecordList);
        for (CreditReportQueryRecordVo vo:queryRecordList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", vo.getQueryCount());
            creditRecordsList.add(datamap);
        }
        //列表
        map.put("creditRecordsList",creditRecordsList);
        map.put("tableCreditRecordsList",creditTableRecordsList);

        return map;
    }


    @Override
    public Map<String, Object> getInstallmentSettledAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-1));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-59));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-10));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
            }
        }
        DecimalFormat decimalFormat = new DecimalFormat("#.##");

        //已结清网贷数据
        InstallmentHistoryDto installmentHistoryDto=new InstallmentHistoryDto();
        installmentHistoryDto.setStartMonth(analysisDto.getStartTime().substring(0,7));
        installmentHistoryDto.setEndMonth(analysisDto.getEndTime().substring(0,7));
        installmentHistoryDto.setState("1");
        installmentHistoryDto.setType(analysisDto.getDataType());
        installmentHistoryDto.setBankCardLendId(analysisDto.getId());
        List<InstallmentHistoryVo> installmentHistoryList=installmentHistoryMapper.selectInstallmentHistoryList(installmentHistoryDto);
        for (InstallmentHistoryVo installmentHistory : installmentHistoryList) {
            if(installmentHistory.getBankCode()!=null){
                installmentHistory.setBankNameCode(installmentHistory.getBankName()+"（"+ StringUtils.getLastNumberChars(4,installmentHistory.getBankCode()+"）"));
            }else {
                installmentHistory.setBankNameCode(installmentHistory.getBankName());
            }
        }
        double clearedPrincipal = 0;
        double totalInterest = 0;
        if(installmentHistoryList.size()>0){
            clearedPrincipal=installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getInstallmentAmount).sum();
            totalInterest=installmentHistoryList.stream().mapToDouble(InstallmentHistoryVo::getTotalInterest).sum();
        }
        map.put("clearedPrincipal",decimalFormat.format(clearedPrincipal));
        map.put("totalInterest",decimalFormat.format(totalInterest));

        map.put("clearedTotal",decimalFormat.format(totalInterest+clearedPrincipal));
        int clearedCount =   installmentHistoryList.size();
        map.put("clearedCount",clearedCount);


        List<InstallmentHistoryVo> installmentHistoryVoList =new ArrayList<>();

        if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (InstallmentHistoryVo vo:installmentHistoryList
            ) {
                String monthString=dateFormat.format(vo.getInstallmentDate()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);
                }
            }
            for (String staticsTime :staticsTimeList
            ) {
                String  details="";
                double actualCreditBillMonth=0;
                for (InstallmentHistoryVo vo:installmentHistoryList
                ) {
                    String monthString=dateFormat.format(vo.getInstallmentDate()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        double  total=vo.getInstallmentAmount()+vo.getTotalInterest();
                        BigDecimal bigDecimal=new BigDecimal(decimalFormat.format( total));
                        actualCreditBillMonth+=bigDecimal.doubleValue();
                        details+=vo.getBankNameCode()+"借款金额（本息）"+bigDecimal.doubleValue()+"；<br/>";

                    }
                }
                InstallmentHistoryVo analysisVo=new InstallmentHistoryVo();
                analysisVo.setInstallmentAmount(Double.parseDouble(decimalFormat.format(actualCreditBillMonth)));
                analysisVo.setRemark(staticsTime);
                analysisVo.setName(details);
                installmentHistoryVoList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (InstallmentHistoryVo vo:installmentHistoryList
            ) {
                String yearString=dateFormat.format(vo.getInstallmentDate()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillYear=0;
                for (InstallmentHistoryVo vo:installmentHistoryList
                ) {
                    String yearString=dateFormat.format(vo.getInstallmentDate()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        actualCreditBillYear+=vo.getInstallmentAmount()+vo.getTotalInterest();
                    }
                }
                InstallmentHistoryVo analysisVo=new InstallmentHistoryVo();
                analysisVo.setInstallmentAmount(Double.parseDouble(decimalFormat.format(actualCreditBillYear)));
                analysisVo.setRemark(staticsTime);
                installmentHistoryVoList.add(analysisVo);

            }

        }

        ArrayList<Map<String, Object>> historyList = new ArrayList<>();
        ArrayList<Map<String, Object>> tableHistoryList = new ArrayList<>();
        for (InstallmentHistoryVo vo:installmentHistoryVoList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("detail", vo.getName());
            datamap.put("value", decimalFormat.format(vo.getInstallmentAmount()));
            tableHistoryList.add(datamap);
        }
        Collections.reverse(installmentHistoryVoList);
        for (InstallmentHistoryVo vo:installmentHistoryVoList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getInstallmentAmount()));
            historyList.add(datamap);
        }
        //列表
        map.put("historyList",historyList);
        map.put("tableHistoryList",tableHistoryList);

        return map;
    }

    @Override
    public Map<String, Object> getAccountsAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        AccountsDto dto=new AccountsDto();
        dto.setState("1");
        //储蓄卡
        dto.setType("1");
        List<AccountsVo> accountsList=accountsMapper.selectAccountsList(dto);
        double debetBalance =0;
        if(accountsList.size()>0){
            debetBalance=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
        }
        map.put("debetBalance",decimalFormat.format(debetBalance));

        //信用卡
        dto.setType("2");
        accountsList=accountsMapper.selectAccountsList(dto);
        double creditAvailableLimit =0;
        double creditBalance =0;
        if(accountsList.size()>0){
            creditAvailableLimit=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
            creditBalance=accountsList.stream().mapToDouble(AccountsVo::getBalance).sum();
        }
        map.put("creditAvailableLimit",decimalFormat.format(creditAvailableLimit));
        map.put("creditBalance",decimalFormat.format(creditBalance));

        //投资账户
        dto.setType("5");
         accountsList=accountsMapper.selectAccountsList(dto);
        double investBalance =0;
        if(accountsList.size()>0){
            investBalance=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
        }
        map.put("investBalance",decimalFormat.format(investBalance));

        //借贷账户
        dto.setType("3");
        accountsList=accountsMapper.selectAccountsList(dto);
        double debitBalance =0;
        if(accountsList.size()>0){
            debitBalance=accountsList.stream().mapToDouble(AccountsVo::getAvailableLimit).sum();
        }
        map.put("debitBalance",decimalFormat.format(debitBalance));

        dto.setType(analysisDto.getDataType());

        accountsList=accountsMapper.selectAccountsList(dto);

        //修改名称加卡号
        for (AccountsVo accounts : accountsList) {

            if(accounts.getCode()!=null){
                accounts.setNameCode(accounts.getName()+"（"+ StringUtils.getLastNumberChars(4,accounts.getCode()+"）"));
            }else {
                accounts.setNameCode(accounts.getName());
            }
        }
        ArrayList<Map<String, Object>> accountsBalancesList = new ArrayList<>();

        for (AccountsVo vo:accountsList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("account", vo.getNameCode());
            datamap.put("availableLimit", vo.getAvailableLimit());
            accountsBalancesList.add(datamap);
        }
        //列表
        map.put("accountsBalancesList",accountsBalancesList);


        return map;
    }

    @Override
    public Map<String, Object> getPosAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("#.###");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatSecond = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat formatterMonth = new SimpleDateFormat("yyyy-MM");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),0));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-24));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                if(analysisDto.getEndTime().equals(formatterMonth.format(new Date()))){
                    SimpleDateFormat sdf = new SimpleDateFormat("dd");
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
                }else {
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
                }

            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
                if(analysisDto.getEndTime().equals(sdfYear.format(new Date()))){
                    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
                }else {
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
                }

            }
        }
        AccountsTransferRecordDto dto=new AccountsTransferRecordDto();
        //获取数据
        dto.setEndTime(analysisDto.getEndTime());
        dto.setStartTime(analysisDto.getStartTime());
        dto.setType("1");
        dto.setPosId(analysisDto.getId());
        List<AccountsTransferRecordVo> transferList=accountsTransferRecordMapper.selectAccountsTransferRecordList(dto);

        double amount =0;
        double commission =0;
        int count =0;
        double actualAmount =0;
        if(transferList.size()>0){
            commission=transferList.stream().mapToDouble(AccountsTransferRecordVo::getCommission).sum();
            actualAmount=transferList.stream().mapToDouble(AccountsTransferRecordVo::getActualAmount).sum();
            amount=transferList.stream().mapToDouble(AccountsTransferRecordVo::getAmount).sum();
        }
        count=transferList.size();
        map.put("amount",decimalFormat.format(amount));
        map.put("commission",decimalFormat.format(commission));
        map.put("actualAmount",decimalFormat.format(actualAmount));
        map.put("count",count);
        List<AccountsTransferRecordVo> queryList =new ArrayList<>();

        if("1".equals(analysisDto.getType())){
            //日列表
            List <String> staticsTimeList=new ArrayList<>();
            for (AccountsTransferRecordVo vo:transferList
            ) {
                String dayString=dateFormat.format(vo.getCreateTime());

                if(!staticsTimeList.contains(dayString)){
                    staticsTimeList.add(dayString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                String  details="";
                double actualCreditBillDay=0;

                for (AccountsTransferRecordVo vo:transferList
                ) {
                    String dayString=dateFormat.format(vo.getCreateTime());
                    if(staticsTime.equals(dayString)){
                        actualCreditBillDay+=vo.getAmount();
                        details+=vo.getOutAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"刷卡"+vo.getAmount()+"；<br/>";
                    }
                }
                AccountsTransferRecordVo analysisVo=new AccountsTransferRecordVo();
                analysisVo.setAmount(actualCreditBillDay);
                analysisVo.setRemark(staticsTime);
                analysisVo.setName(details);
                queryList.add(analysisVo);
            }

            //年查询
        }
        else if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (AccountsTransferRecordVo vo:transferList
            ) {
                String monthString=dateFormat.format(vo.getCreateTime()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillMonth=0;
                for (AccountsTransferRecordVo vo:transferList
                ) {
                    String monthString=dateFormat.format(vo.getCreateTime()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        actualCreditBillMonth+=vo.getAmount();
                    }
                }
                AccountsTransferRecordVo analysisVo=new AccountsTransferRecordVo();
                analysisVo.setAmount(actualCreditBillMonth);
                analysisVo.setRemark(staticsTime);
                queryList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (AccountsTransferRecordVo vo:transferList
            ) {
                String yearString=dateFormat.format(vo.getCreateTime()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillYear=0;
                for (AccountsTransferRecordVo vo:transferList
                ) {
                    String yearString=dateFormat.format(vo.getCreateTime()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        actualCreditBillYear+=vo.getAmount();
                    }
                }
                AccountsTransferRecordVo analysisVo=new AccountsTransferRecordVo();
                analysisVo.setAmount(actualCreditBillYear);
                analysisVo.setRemark(staticsTime);
                queryList.add(analysisVo);

            }

        }

        ArrayList<Map<String, Object>> posList = new ArrayList<>();
        ArrayList<Map<String, Object>> tablePosList = new ArrayList<>();
        for (AccountsTransferRecordVo vo:queryList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getAmount()));
            datamap.put("detail", vo.getName());
            tablePosList.add(datamap);
        }
        Collections.reverse(queryList);
        for (AccountsTransferRecordVo vo:queryList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getAmount()));
            posList.add(datamap);
        }
        //列表
        map.put("posList",posList);
        map.put("tablePosList",tablePosList);

        return map;
    }


    @Override
    public Map<String, Object> getAccountsDealAnalysis(AnalysisDto analysisDto) {
        //返回数据
        HashMap<String, Object> map = new HashMap<>();
        DecimalFormat decimalFormat = new DecimalFormat("#.###");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatSecond = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat formatterMonth = new SimpleDateFormat("yyyy-MM");
        //月查询
        if(analysisDto.getType().equals("2")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),0));
                String startTime=dateFormat.format(DateUtils.addMonths(DateUtils.getNowDate(),-24));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01");
                if(analysisDto.getEndTime().equals(formatterMonth.format(new Date()))){
                    SimpleDateFormat sdf = new SimpleDateFormat("dd");
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
                }else {
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-31");
                }

            }

            //年查询
        }else  if(analysisDto.getType().equals("3")){
            if(StringUtils.isEmpty(analysisDto.getStartTime())&&StringUtils.isEmpty(analysisDto.getEndTime())){
                String endTime=dateFormat.format(DateUtils.getNowDate());
                String startTime=dateFormat.format(DateUtils.addYears(DateUtils.getNowDate(),-5));
                analysisDto.setStartTime(startTime);
                analysisDto.setEndTime(endTime);
            }else {
                analysisDto.setStartTime(analysisDto.getStartTime()+"-01-01");
                SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
                if(analysisDto.getEndTime().equals(sdfYear.format(new Date()))){
                    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-"+sdf.format(new Date()));
                }else {
                    analysisDto.setEndTime(analysisDto.getEndTime()+"-12-31");
                }

            }
        }
        AccountsDealRecordDto dto=new AccountsDealRecordDto();
        //获取数据
        dto.setEndTime(analysisDto.getEndTime());
        dto.setStartTime(analysisDto.getStartTime());
        dto.setType(analysisDto.getDataType());
        dto.setAccountId(analysisDto.getId());
        dto.setDealType(analysisDto.getDealType());
        dto.setDealCategory(analysisDto.getDealCategory());
        List<AccountsDealRecordVo> accountsDealRecordVoList=accountsDealRecordMapper.selectAccountsDealRecordList(dto);

        double income =0;
        double expenses =0;
        double posExpenses =0;
        double realExpenses =0;
        double posIncome=0;
        int incomeCount =0;
        int posIncomeCount =0;
        int expensesCount =0;
        int posExpensesCount =0;
        int realExpensesCount =0;
        for (AccountsDealRecordVo vo:accountsDealRecordVoList
        ) {

            if(vo.getDealType().equals("1")){
                income+=vo.getAmount();
                incomeCount++;
                if(vo.getDealCategory().equals("5")){
                    posIncome+=vo.getAmount();
                    posIncomeCount++;
                }
            }
            //支出
            if(vo.getDealType().equals("2")){
                expenses+=vo.getAmount();
                expensesCount++;
                if(vo.getDealCategory().equals("5")){
                    posExpenses+=vo.getAmount();
                    posExpensesCount++;
                }
                if(vo.getDealCategory().equals("1")){
                    realExpenses+=vo.getAmount();
                    realExpensesCount++;
                }
            }
        }
        //交易金额
        map.put("amount",decimalFormat.format(income-expenses));
        //收入
        map.put("income",decimalFormat.format(income));
        //pos收入
        map.put("posIncome",decimalFormat.format(posIncome-posExpenses));
        //非pos收入
        map.put("notPosIncome",decimalFormat.format(income-posIncome-posExpenses));
        //支出
        map.put("expenses",decimalFormat.format(expenses));
        //pos支出
        map.put("posExpenses",decimalFormat.format(posExpenses));
        //真实消费
        map.put("realExpenses",decimalFormat.format(realExpenses));
        //收入笔数
        map.put("incomeCount",incomeCount);
        //pos收入笔数
        map.put("posIncomeCount",posIncomeCount);
        //非pos收入笔数
        map.put("notPosIncomeCount",incomeCount-posIncomeCount);
        //支出笔数
        map.put("expensesCount",expensesCount);
        //pos支出笔数
        map.put("posExpensesCount",posExpensesCount);
        //日常支出消费笔数
        map.put("realExpensesCount",realExpensesCount);
        //其他支出笔数
        map.put("otherExpensesCount",expensesCount-posExpensesCount-realExpensesCount);
        List<AccountsDealRecordVo> queryList =new ArrayList<>();

        if("1".equals(analysisDto.getType())){
            //日列表
            List <String> staticsTimeList=new ArrayList<>();
            for (AccountsDealRecordVo vo:accountsDealRecordVoList
            ) {
                if (null != vo.getDealCategory()) {
                    vo.setDealCategory(DictUtils.getDictLabel("deal_category", vo.getDealCategory().toString()));
                }
                String dayString=dateFormat.format(vo.getCreateTime());

                if(!staticsTimeList.contains(dayString)){
                    staticsTimeList.add(dayString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillDay=0;
                String  details="";
                for (AccountsDealRecordVo vo:accountsDealRecordVoList
                ) {
                    String dayString=dateFormat.format(vo.getCreateTime());

                    if(staticsTime.equals(dayString)){
                        if(vo.getDealType().equals("1")){
                            actualCreditBillDay+=vo.getAmount();
                            details+=vo.getAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"因交易类别【"+vo.getDealCategory()+"】收入"+vo.getAmount()+"；<br/>";
                        }
                        if(vo.getDealType().equals("2")){
                            actualCreditBillDay-=vo.getAmount();
                            details+=vo.getAccountName()+"于"+dateFormatSecond.format(vo.getCreateTime())+"因交易类别【"+vo.getDealCategory()+"】支出"+vo.getAmount()+"；<br/>";
                        }

                    }
                }
                AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
                analysisVo.setAmount(actualCreditBillDay);
                analysisVo.setRemark(staticsTime);
                analysisVo.setName(details);
                queryList.add(analysisVo);
            }

            //年查询
        }
        else if("2".equals(analysisDto.getType())){
            //月列表
            List <String> staticsTimeList=new ArrayList<>();
            for (AccountsDealRecordVo vo:accountsDealRecordVoList
            ) {
                String monthString=dateFormat.format(vo.getCreateTime()).substring(0,7);

                if(!staticsTimeList.contains(monthString)){
                    staticsTimeList.add(monthString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillMonth=0;
                for (AccountsDealRecordVo vo:accountsDealRecordVoList
                ) {
                    String monthString=dateFormat.format(vo.getCreateTime()).substring(0,7);

                    if(staticsTime.equals(monthString)){
                        if(vo.getDealType().equals("1")){
                            actualCreditBillMonth+=vo.getAmount();
                        }
                        if(vo.getDealType().equals("2")){
                            actualCreditBillMonth-=vo.getAmount();
                        }
                    }
                }
                AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
                analysisVo.setAmount(actualCreditBillMonth);
                analysisVo.setRemark(staticsTime);
                queryList.add(analysisVo);
            }

            //年查询
        }else  if("3".equals(analysisDto.getType())){
            List <String> staticsTimeList=new ArrayList<>();
            for (AccountsDealRecordVo vo:accountsDealRecordVoList
            ) {
                String yearString=dateFormat.format(vo.getCreateTime()).substring(0,4);

                if(!staticsTimeList.contains(yearString)){
                    staticsTimeList.add(yearString);
                }
            }

            for (String staticsTime :staticsTimeList
            ) {
                double actualCreditBillYear=0;
                for (AccountsDealRecordVo vo:accountsDealRecordVoList
                ) {
                    String yearString=dateFormat.format(vo.getCreateTime()).substring(0,4);
                    if(staticsTime.equals(yearString)){
                        if(vo.getDealType().equals("1")){
                            actualCreditBillYear+=vo.getAmount();
                        }
                        if(vo.getDealType().equals("2")){
                            actualCreditBillYear-=vo.getAmount();
                        }
                    }
                }
                AccountsDealRecordVo analysisVo=new AccountsDealRecordVo();
                analysisVo.setAmount(actualCreditBillYear);
                analysisVo.setRemark(staticsTime);
                queryList.add(analysisVo);

            }

        }

        ArrayList<Map<String, Object>> acccountsList = new ArrayList<>();
        ArrayList<Map<String, Object>> tableAccountsList = new ArrayList<>();
        for (AccountsDealRecordVo vo:queryList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getAmount()));
            datamap.put("detail", vo.getName());
            tableAccountsList.add(datamap);
        }
        Collections.reverse(queryList);
        for (AccountsDealRecordVo vo:queryList
        ) {
            Map<String, Object> datamap = new HashMap<>();
            datamap.put("time", vo.getRemark());
            datamap.put("value", decimalFormat.format(vo.getAmount()));
            acccountsList.add(datamap);
        }
        //列表
        map.put("acccountsList",acccountsList);
        map.put("tableAccountsList",tableAccountsList);

        return map;
    }

}
