package com.pqs9000.serviceimpl.report;

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

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

@Service
public class GetPowerDataServiceImpl implements GetPowerDataService {
    @Autowired
    private GetPowerDataMapper getPowerDataMapper;

    @Override
    public List<ReportValue> getPowerData(Condition condition) {
        List<ReportValue> list = new ArrayList<>();
        //获取有功功率
        List<ReportValue> listP = getPowerDataMapper.getPowerP(condition);
        //获取无功功率
        List<ReportValue> listQ = getPowerDataMapper.getPowerQ(condition);
        //获取视在功率
        List<ReportValue> listS = getPowerDataMapper.getPowerS(condition);
        //获取功率因数
        List<ReportValue> listF = getPowerDataMapper.getPF(condition);

        RegroupData.regroupData(listP, true, false);
        RegroupData.regroupData(listQ, true, false);
        RegroupData.regroupData(listS, true, false);
        RegroupData.regroupData(listF, true, false);
        list.addAll(listP);
        list.addAll(listQ);
        list.addAll(listS);
        list.addAll(listF);

        return list;
    }

    @Override
    public List<ReportValue> getPower(Condition condition, String s) {
        List<ReportValue> list =new ArrayList<>();
        if(s.equalsIgnoreCase("p")){
            list = getPowerDataMapper.getPowerP(condition);
        }else if(s.equalsIgnoreCase("Q")){
            list = getPowerDataMapper.getPowerQ(condition);
        }else{
            list = getPowerDataMapper.getPowerS(condition);
        }
        RegroupData.regroupData(list, true);
        return list;
    }
}
