package com.njcn.serviceimpl.excelreport;

import com.njcn.mapper.excelreport.GetDistortionMapper;
import com.njcn.pojo.excelreport.ConditionData;
import com.njcn.pojo.excelreport.ReportValueData;
import com.njcn.service.excelreport.GetDistortionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class GetDistortionServiceImpl implements GetDistortionService {
    @Autowired
    private GetDistortionMapper getDistortionMapper;

    @Override
    public List<ReportValueData> getDistortionData(ConditionData conditionData) {
        List<ReportValueData> list = new ArrayList<>();
        //获取电压畸变率
        List<ReportValueData> listU = getDistortionMapper.getDistortionData(conditionData, "V");

        //获取电流畸变率
        List<ReportValueData> listI = getDistortionMapper.getDistortionData(conditionData, "I");

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

        return list;
    }

    @Override
    public List<ReportValueData> getDistortionData(ConditionData conditionData, String s) {
        List<ReportValueData> list = getDistortionMapper.getDistortionData(conditionData, s);
        Regroup.regroupData(list, true);
        return list;
    }
}
