package com.simuwang.manage.service.impl;

import com.simuwang.base.common.support.MybatisPage;
import com.simuwang.base.mapper.EmailFileInfoMapper;
import com.simuwang.base.mapper.EmailFundNavMapper;
import com.simuwang.base.pojo.dto.query.FundFilePageQuery;
import com.simuwang.base.pojo.vo.FundFileInfoVO;
import com.simuwang.daq.service.EmailParseApiService;
import com.simuwang.manage.service.EmailFundInfoService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FileName: EmailFundInfoServiceImpl
 * Author:   chenjianhua
 * Date:     2024/9/13 9:55
 * Description: ${DESCRIPTION}
 */
@Service
public class EmailFundInfoServiceImpl implements EmailFundInfoService {

    @Autowired
    private EmailFileInfoMapper emailFileInfoMapper;

    @Autowired
    private EmailFundNavMapper emailFundNavMapper;

    @Autowired
    private EmailParseApiService emailParseApiService;

    @Override
    public MybatisPage<FundFileInfoVO> searchFundFileInfo(FundFilePageQuery fundFilePageQuery) {
        List<FundFileInfoVO> fileList = emailFileInfoMapper.searchFundFileInfo(fundFilePageQuery);
        long total = emailFileInfoMapper.countFundFileInfo(fundFilePageQuery);
        return MybatisPage.of(total,fileList);
    }

    @Override
    public void reparseValuationFile(String sourceFundName) {
        List<Integer> fileIdList = emailFundNavMapper.selectFileIdByFundName(sourceFundName);
        if(fileIdList.size() < 0){
            //过滤其他文件类型，只保留估值表
            List<Integer> valuationFileId = emailFileInfoMapper.selectValuationFileId(fileIdList);
            emailParseApiService.reparseFile(valuationFileId);
        }
    }
}
