package com.simuwang.manage.service.impl;

import com.simuwang.base.common.support.MybatisPage;
import com.simuwang.base.common.util.DateUtils;
import com.simuwang.base.common.util.StringUtil;
import com.simuwang.base.mapper.*;
import com.simuwang.base.pojo.dos.*;
import com.simuwang.base.pojo.dto.query.ParseDetailPageQuery;
import com.simuwang.base.pojo.vo.*;
import com.simuwang.manage.service.ParseEmailDetailService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * FileName: ParseEmailDetailServiceImpl
 * Author:   chenjianhua
 * Date:     2024/9/12 23:08
 * Description: ${DESCRIPTION}
 */
@Service
public class ParseEmailDetailServiceImpl implements ParseEmailDetailService {

    @Autowired
    private EmailFundNavMapper emailFundNavMapper;

    @Autowired
    private FundInfoMapper fundInfoMapper;

    @Autowired
    private EmailFundAssetMapper emailFundAssetMapper;

    @Autowired
    private EmailParseInfoMapper emailParseInfoMapper;
    @Override
    public MybatisPage<EmailFundNavVO> searchNavDetail(ParseDetailPageQuery parseDetailPageQuery) {
        List<EmailFundNavDO> dataList = emailFundNavMapper.searchNavDetail(parseDetailPageQuery);
        List<EmailFundNavVO> voList = dataList.stream().map(EmailFundNavDO::toVo).collect(Collectors.toList());
        for(EmailFundNavVO vo : voList){
            //查找匹配基金
            if(vo.getFundId() != null){
                vo.setTargetFundId(vo.getFundId());
                vo.setTargetFundName(fundInfoMapper.getFundNameByFundId(vo.getFundId()));
            }
        }
        long total = emailFundNavMapper.countNavDetail(parseDetailPageQuery);
        return MybatisPage.of(total,voList);
    }

    @Override
    public MybatisPage<EmailFundAssetVO> searchAssetDetail(ParseDetailPageQuery parseDetailPageQuery) {
        List<EmailFundAssetDO> dataList = emailFundAssetMapper.searchAssetDetail(parseDetailPageQuery);
        List<EmailFundAssetVO> voList = dataList.stream().map(EmailFundAssetDO::toVo).collect(Collectors.toList());
        for(EmailFundAssetVO vo : voList){
            //查找匹配基金
            if(vo.getFundId() != null){
                vo.setTargetFundId(vo.getFundId());
                vo.setTargetFundName(fundInfoMapper.getFundNameByFundId(vo.getFundId()));
            }
        }
        long total = emailFundAssetMapper.countAssetDetail(parseDetailPageQuery);
        return MybatisPage.of(total,voList);
    }
}
