package com.zksy.environmentHJ212.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksy.environmentHJ212.domain.po.MinuteDataInfo;
import com.zksy.environmentHJ212.mapper.MinuteDataInfoMapper;
import com.zksy.environmentHJ212.service.MinuteDataInfoService;
import com.zksy.environmentHJ212.utils.DateTimeUtil;
import com.zksy.environmentHJ212.utils.MonitorDatasynch;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Service
public class MinuteDataInfoServiceImpl extends ServiceImpl<MinuteDataInfoMapper, MinuteDataInfo> implements MinuteDataInfoService {
    @Override
    public void saveMonitordata(String oldDataStr,String[] dataArr) {
        List<MinuteDataInfo> minuteDataInfos = MonitorDatasynch.parseData(oldDataStr, dataArr, MinuteDataInfo::new,
                builder -> {
                    builder.addFieldMapper("Cou", MinuteDataInfo::setDataCouValue, BigDecimal::new);
                    builder.addFieldMapper("Min", MinuteDataInfo::setDataMinValue, BigDecimal::new);
                    builder.addFieldMapper("Avg", MinuteDataInfo::setDataAvgValue, BigDecimal::new);
                    builder.addFieldMapper("Max", MinuteDataInfo::setDataMaxValue, BigDecimal::new);
                    builder.addFieldMapper("Flag", MinuteDataInfo::setDataFlag, String::valueOf);
                    builder.setCodeMapper(MinuteDataInfo::setCode);
                    builder.setRemarkMapper(MinuteDataInfo::setRemark);
                    builder.setMnMapper(MinuteDataInfo::setMn);
                    builder.setFlagMapper(MinuteDataInfo::setFlag);
                    builder.setDataTimeMapper((entity, timeStr) ->
                            entity.setDataTime(DateTimeUtil.parseDateTime(timeStr)));
                    builder.setCreateTimeMapper(MinuteDataInfo::setCreateTime);
                    builder.setIdMapper(MinuteDataInfo::setId);
                });
        System.out.println("minuteDataInfos=="+minuteDataInfos);
        super.saveBatch(minuteDataInfos);
    }
}
