package com.njcn.influx.service.impl;

import com.njcn.common.utils.HarmonicTimesUtil;
import com.njcn.influx.imapper.DataVMapper;
import com.njcn.influx.pojo.po.DataV;
import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.influx.service.IDataVService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2023/5/5 14:38
 */
@Service
public class DataVServiceImpl implements IDataVService {

    @Resource
    private DataVMapper dataVMapper;

    @Override
    public List<DataV> getDataV(String lineIndex, String startTime, String endTime) {
        //最小值
        List<DataV> result1 ;
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.minSamePrefixAndSuffix("v_","", HarmonicTimesUtil.harmonicTimesList(1,50,1));
        influxQueryWrapper.eq(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, "MIN")
                .min(DataV::getFreq)
                .min(DataV::getFreqDev)
                .min(DataV::getRms)
                .min(DataV::getRmsLvr)
                .min(DataV::getVNeg)
                .min(DataV::getVPos)
                .min(DataV::getVThd)
                .min(DataV::getVUnbalance)
                .min(DataV::getVZero)
                .min(DataV::getVlDev)
                .min(DataV::getVuDev)
                .groupBy(DataV::getLineId,DataV::getPhasicType,DataV::getQualityFlag,DataV::getValueType)
                .between(DataV::getTime, startTime, endTime);
        result1 = dataVMapper.getStatisticsByWraper(influxQueryWrapper);
        System.out.println("result1==:" + result1);
        return result1;
    }

    @Override
    public List<DataV> getHarmonicDataV(String lineIndex, String startTime, String endTime) {
        List<DataV> result1 ;
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.eq(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, "CP95")
                .ne(DataV::getPhasicType, "T")
                .between(DataV::getTime, startTime, endTime);;
        result1 = dataVMapper.getStatisticsByWraper(influxQueryWrapper);
        return result1;
    }
}
