package com.zksy.environmentHJ212.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksy.environmentHJ212.domain.DayDataInfo;
import com.zksy.environmentHJ212.domain.HourDataInfo;
import com.zksy.environmentHJ212.service.DayDataInfoService;
import com.zksy.environmentHJ212.mapper.DayDataInfoMapper;
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 针对表【day_data_info(hj212-日数据)】的数据库操作Service实现
* @createDate 2025-05-30 10:25:30
*/
@Service
public class DayDataInfoServiceImpl extends ServiceImpl<DayDataInfoMapper, DayDataInfo>
    implements DayDataInfoService{

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




