package com.pqs9000.serviceimpl.report;

import com.pqs9000.mapper.report.GetDistortionDataMapper;
import com.pqs9000.pojo.report.Condition;
import com.pqs9000.pojo.report.ReportValue;
import com.pqs9000.service.report.GetDistortionDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GetDistortionDataServiceImpl implements GetDistortionDataService {
    @Autowired
    private GetDistortionDataMapper getDistortionDataMapper;

    @Override
    public List<ReportValue> getDistortionData(Condition condition) {
        List<ReportValue> list = new ArrayList<>();
        //获取电压畸变率
        List<ReportValue> listU = getDistortionDataMapper.getDistortionDataV(condition);

        //获取电流畸变率
        List<ReportValue> listI = getDistortionDataMapper.getDistortionDataI(condition);

        //添加之前判断数据库是否有数据，如果没有数据模拟数据添加到集合中
        RegroupData.regroupData(listU, true);
        RegroupData.regroupData(listI, true);
        list.addAll(listU);
        list.addAll(listI);

        return list;
    }

    @Override
    public List<ReportValue> getDistortionData(Condition condition, String s) {
        List<ReportValue> list = getDistortionDataMapper.getHDistortionData(condition, s);
        return list;
    }
}
