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

import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.harmonic.pojo.po.RMpPartHarmonicDetailD;
import com.njcn.harmonic.pojo.po.RMpSurplusHarmonicDetailD;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpPartHarmonicDetailDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.RMpSurplusHarmonicDetailDMapper;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.line.IRMpPartHarmonicDetailDService;
import com.njcn.prepare.harmonic.service.mysql.line.IRMpSurplusHarmonicDetailDService;
import com.njcn.prepare.harmonic.utils.PublicUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

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

/**
 * 类的介绍：
 *
 * @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})
    @Async("asyncExecutor")
    public void insertHarmonicDetailDayTwo(LineParam lineParam) {
        log.info(LocalDateTime.now()+"===>监测点稳态指标超标明细日表2开始执行");
        List<RMpSurplusHarmonicDetailD> result = new ArrayList<>();
        if (Objects.equals(lineParam.getType(),5)){
            result = this.baseMapper.getHarmonicDetailDayTwo(lineParam.getDataDate(),lineParam.getLineIds());
        } else if (Objects.equals(lineParam.getType(),3)){
            int year = Integer.parseInt(lineParam.getDataDate().split("-")[0]);
            int month = Integer.parseInt(lineParam.getDataDate().split("-")[1]);
            List<String> dayList = PublicUtil.getDayByMonth(year,month);
            for (String item : dayList) {
                result.addAll(this.baseMapper.getHarmonicDetailDayTwo(item,lineParam.getLineIds()));
            }
        }
        this.saveOrUpdateBatchByMultiId(result,50);
    }
}
