package com.njcn.prepare.harmonic.service.mysql.Impl.line;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.harmonic.pojo.po.RMpEventDetailQPO;
import com.njcn.harmonic.pojo.po.RMpEventDetailYPO;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpEventDetailQMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpEventDetailYMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.line.RMpEventDetailYService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2022/12/28  14:58【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
@RequiredArgsConstructor
public class RMpEventDetailYServiceImpl extends MppServiceImpl<RMpEventDetailYMapper, RMpEventDetailYPO> implements RMpEventDetailYService{

    private final RMpEventDetailYMapper rMpEventDetailYMapper;


    @Override
    public void handleYear(CalculatedParam calculatedParam) {
        List<String> lineIds = calculatedParam.getIdList();
        //以尺寸1000分片
        List<List<String>> pendingIds = ListUtils.partition(lineIds, 1000);
        DateTime beginYear = DateUtil.beginOfYear(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        DateTime endYear = DateUtil.endOfYear(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        for (List<String> pendingId : pendingIds) {
            List<RMpEventDetailYPO> rMpEventDetailYPOList = rMpEventDetailYMapper.handleYear(pendingId, DateUtil.format(beginYear, DatePattern.NORM_DATE_PATTERN), beginYear, endYear);
            this.saveOrUpdateBatchByMultiId(rMpEventDetailYPOList);
        }
    }
}
