package com.zksy.environmentHJ212.service.impl;

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

import java.math.BigDecimal;
import java.util.List;

/**
* @author Administrator
* @description 针对表【hour_data_info(hj212-小时数据)】的数据库操作Service实现
* @createDate 2025-05-30 10:05:04
*/
@Service
public class HourDataInfoServiceImpl extends ServiceImpl<HourDataInfoMapper, HourDataInfo>
    implements HourDataInfoService{

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




