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.prepare.harmonic.mapper.mysql.line.RMpEventDetailQMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.line.RMpEventDetailQService;
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 RMpEventDetailQServiceImpl extends MppServiceImpl<RMpEventDetailQMapper, RMpEventDetailQPO> implements RMpEventDetailQService{


    private final RMpEventDetailQMapper rMpEventDetailQMapper;

    @Override
    public void handleQuarter(CalculatedParam calculatedParam) {
        List<String> lineIds = calculatedParam.getIdList();
        //以尺寸1000分片
        List<List<String>> pendingIds = ListUtils.partition(lineIds, 1000);
        DateTime beginQuarter = DateUtil.beginOfQuarter(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        DateTime endQuarter = DateUtil.endOfQuarter(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        for (List<String> pendingId : pendingIds) {
            List<RMpEventDetailQPO> rMpEventDetailQPOList = rMpEventDetailQMapper.handleQuarter(pendingId, DateUtil.format(beginQuarter, DatePattern.NORM_DATE_PATTERN), beginQuarter, endQuarter);
            this.saveOrUpdateBatchByMultiId(rMpEventDetailQPOList);
        }
    }
}
