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

import cn.hutool.core.collection.CollectionUtil;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.harmonic.pojo.po.RMpSurplusHarmonicDetailD;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpSurplusHarmonicDetailDMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.line.IRMpSurplusHarmonicDetailDService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2023/4/23 15:08
 */
@Slf4j
@Service
public class RMpSurplusHarmonicDetailDServiceImpl extends MppServiceImpl<RMpSurplusHarmonicDetailDMapper, RMpSurplusHarmonicDetailD> implements IRMpSurplusHarmonicDetailDService {

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void insertHarmonicDetailDayTwo(CalculatedParam calculatedParam) {
        log.info(LocalDateTime.now()+"===>监测点稳态指标超标明细日表2开始执行");
        List<String> lineIds = calculatedParam.getIdList();
        //以尺寸100分片,查询数据
        List<List<String>> pendingIds =  ListUtils.partition(lineIds,5);
        for (List<String> pendingId : pendingIds) {
            List<RMpSurplusHarmonicDetailD> result = this.baseMapper.getHarmonicDetailDayTwo(calculatedParam.getDataDate(),pendingId);
            if (CollectionUtil.isNotEmpty(result)){
                this.saveOrUpdateBatchByMultiId(result);
            }
        }
    }

}
