package com.njcn.influx.service.impl;

import com.njcn.influx.imapper.HaronicRatioMapper;
import com.njcn.influx.pojo.po.HarmonicRatioData;
import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.influx.service.HaronicRatioService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description:
 * Date: 2023/5/24  9:22【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
@RequiredArgsConstructor
public class HaronicRatioServiceImpl implements HaronicRatioService {

    private final HaronicRatioMapper haronicRatioMapper;
    @Override
    public List<HarmonicRatioData> getFirstHaronicRatio(List<String> lineIds, String columnName) {
        List<HarmonicRatioData> result1 ;
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(HarmonicRatioData.class);
        influxQueryWrapper.or(HarmonicRatioData::getLineId, lineIds)
                .last(columnName,columnName).groupBy(HarmonicRatioData::getLineId, HarmonicRatioData::getStatMethod, HarmonicRatioData::getPhase);

        result1 = haronicRatioMapper.getHaronicRatio(influxQueryWrapper);
        return result1;
    }

    @Override
    public List<HarmonicRatioData> getHaronicRatio(List<String> lineIds, String columnName, String startTime, String endTime) {
        List<HarmonicRatioData> result1;

        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(HarmonicRatioData.class);
        influxQueryWrapper.or(HarmonicRatioData::getLineId, lineIds)
                .percentile(columnName, 95)
                .between(HarmonicRatioData::getTime, startTime, endTime)
                .groupBy(HarmonicRatioData::getLineId,HarmonicRatioData::getStatMethod,HarmonicRatioData::getPhase);
        result1 = haronicRatioMapper.getHaronicRatio(influxQueryWrapper);

        return result1;
    }
}
