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

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.prepare.harmonic.mapper.mysql.line.RStatAbnormalDMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.mysql.RStatAbnormalDPO;
import com.njcn.prepare.harmonic.service.mysql.line.RStatAbnormalDService;
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: 2023/4/21  9:07【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
@RequiredArgsConstructor
public class RStatAbnormalDServiceImpl extends MppServiceImpl<RStatAbnormalDMapper, RStatAbnormalDPO> implements RStatAbnormalDService{

    @Override
    public void handlerMonitorAbnormal(CalculatedParam calculatedParam) {
        String  beginDay = LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)),DatePattern.NORM_DATETIME_PATTERN);
        String endDay = LocalDateTimeUtil.format(LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)),DatePattern.NORM_DATETIME_PATTERN);
        //以尺寸1000分片
        List<List<String>> pendingIds = ListUtils.partition(calculatedParam.getIdList(), 1000);
        for (List<String> pendingId : pendingIds) {
            //查询
            List<RStatAbnormalDPO> rMpEventDetailDPOList = this.baseMapper.handlerMonitorAbnormal(
                    pendingId
                    ,calculatedParam.getDataDate()
                    ,beginDay
                    ,endDay);
            //入库
            this.saveOrUpdateBatchByMultiId(rMpEventDetailDPOList);
        }
    }
}
