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.RMpVThd;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpVThdMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.line.IRMpVThdService;
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/24 17:58
 */
@Service
@Slf4j
public class RMpVThdServiceImpl extends MppServiceImpl<RMpVThdMapper, RMpVThd> implements IRMpVThdService {

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void insertHarmonicVThdDay(CalculatedParam calculatedParam) {
        log.info(LocalDateTime.now()+"===>监测点谐波畸变率开始执行");
        List<String> lineIds = calculatedParam.getIdList();
        //以尺寸100分片,查询数据
        List<List<String>> pendingIds =  ListUtils.partition(lineIds,5);
        for (List<String> pendingId : pendingIds) {
            List<RMpVThd> result = this.baseMapper.getVThdData(calculatedParam.getDataDate(),pendingId);
            if (CollectionUtil.isNotEmpty(result)){
                this.saveOrUpdateBatchByMultiId(result);
            }
        }
    }
}
