package com.njcn.serviceimpl.excelreport;

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

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

@Service
public class GetPowerServiceImpl implements GetPowerService {
    @Autowired
    private GetPowerMapper getPowerMapper;

    @Override
    public List<ReportValueData> getPowerData(ConditionData conditionData) {
        List<ReportValueData> list = new ArrayList<>();
        //获取有功功率
        List<ReportValueData> listP = getPowerMapper.getPower(conditionData, "P");
        //获取无功功率
        List<ReportValueData> listQ = getPowerMapper.getPower(conditionData, "Q");
        //获取视在功率
        List<ReportValueData> listS = getPowerMapper.getPower(conditionData, "S");

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

        return list;
    }

    @Override
    public List<ReportValueData> getPower(ConditionData conditionData, String s) {
        List<ReportValueData> list = getPowerMapper.getPower(conditionData, s);
        Regroup.regroupData(list, true);

        return list;
    }
}
