package com.simuwang.manage.service.impl;

import com.simuwang.base.mapper.FundReportFrequencyMapper;
import com.simuwang.base.pojo.dos.FundReportFrequencyDO;
import com.simuwang.base.pojo.vo.FundReportFrequencyVO;
import com.simuwang.manage.service.FundReportFrequencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * FileName: FundReportFrequencyService
 * Author:   chenjianhua
 * Date:     2024/9/6 17:14
 * Description: ${DESCRIPTION}
 *
 */
@Service
public class FundReportFrequencyServiceImpl implements FundReportFrequencyService {
    @Autowired
    private FundReportFrequencyMapper fundReportFrequencyMapper;
    @Override
    public void saveFundReportFrequency(FundReportFrequencyVO fundReportFrequency) {
        String fundIds = fundReportFrequency.getFundId();
        String[] fundIdList = fundIds.split(",");
        for(String fundId : fundIdList){
            FundReportFrequencyDO fundReportFrequencyDO = new FundReportFrequencyDO();
            fundReportFrequencyDO.setFundId(fundId);
            fundReportFrequencyDO.setAssetFrequency(fundReportFrequency.getAssetFrequency());
            fundReportFrequencyDO.setNavFrequency(fundReportFrequency.getNavFrequency());
            fundReportFrequencyDO.setUpdateTime(new Date());
            fundReportFrequencyDO.setFrequencyRemark(fundReportFrequency.getFrequencyRemark());
            FundReportFrequencyDO oldFrequency = fundReportFrequencyMapper.getFrequencyByFundId(fundId);
            if(oldFrequency == null){
                fundReportFrequencyDO.setCreateTime(new Date());
                fundReportFrequencyDO.setIsvalid(1);
                fundReportFrequencyMapper.insert(fundReportFrequencyDO);
            }else{
                fundReportFrequencyMapper.updateById(fundReportFrequencyDO);
            }
        }
    }
}
