package com.simuwang.daq.components.report.writer;

import cn.hutool.core.collection.CollUtil;
import com.simuwang.base.mapper.report.ReportBaseInfoMapper;
import com.simuwang.base.mapper.report.ReportFundInfoMapper;
import com.simuwang.base.mapper.report.ReportNetReportMapper;
import com.simuwang.base.pojo.dos.report.ReportNetReportDO;
import com.simuwang.base.pojo.dto.report.MonthlyReportData;
import com.simuwang.base.pojo.dto.report.ReportNetReportDTO;
import org.springframework.stereotype.Component;

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

@Component(ReportWriterConstant.WRITER_MONTHLY)
public class MonthlyReportWriter extends AbstractReportWriter<MonthlyReportData> {
    private final ReportNetReportMapper netReportMapper;

    public MonthlyReportWriter(ReportBaseInfoMapper baseInfoMapper,
                               ReportFundInfoMapper fundInfoMapper,
                               ReportNetReportMapper netReportMapper) {
        super(baseInfoMapper, fundInfoMapper);
        this.netReportMapper = netReportMapper;
    }

    @Override
    protected void writeExtData(MonthlyReportData reportData) {
        List<ReportNetReportDTO> netReport = reportData.getNetReport();
        if (CollUtil.isNotEmpty(netReport)) {
            List<ReportNetReportDO> entityList = netReport.stream()
                    .map(ReportNetReportDTO::toEntity).collect(Collectors.toList());
            this.netReportMapper.insert(entityList);
        }
    }
}
