package com.simuwang.manage.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.simuwang.base.mapper.EmailFundAssetMapper;
import com.simuwang.base.pojo.dos.AssetDO;
import com.simuwang.base.pojo.dos.EmailFundAssetDO;
import com.simuwang.base.pojo.dos.NavDO;
import com.simuwang.daq.service.EmailParseService;
import com.simuwang.manage.service.EmailFundAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * FileName: EmailFundAssetServiceImpl
 * Author:   chenjianhua
 * Date:     2024/9/15 12:43
 * Description: ${DESCRIPTION}
 */
@Service
public class EmailFundAssetServiceImpl implements EmailFundAssetService {

    @Autowired
    private EmailFundAssetMapper emailFundAssetMapper;

    @Autowired
    private EmailParseService emailParseService;

    @Override
    public void reparseFileAsset(String sourceFundName, String targetFundId) {
        List<EmailFundAssetDO> fundAssetDOList = emailFundAssetMapper.selectNotMappingAsset(sourceFundName);
        if(fundAssetDOList.size() > 0){
            //修改采集库的数据
            for(EmailFundAssetDO fundNavDO : fundAssetDOList){
                fundNavDO.setFundId(targetFundId);
                fundNavDO.setExceptionStatus(1);
                fundNavDO.setUpdateTime(new Date());
            }
            emailFundAssetMapper.batchUpdate(fundAssetDOList);
            //净值入库
            List<AssetDO> assetDOList = fundAssetDOList.stream().filter(e -> StrUtil.isNotBlank(e.getFundId()))
                    .map(e -> BeanUtil.copyProperties(e, AssetDO.class)).collect(Collectors.toList());
            emailParseService.saveAssetDo(assetDOList);
        }
    }
}
