package com.hw.ems.report.service.impl;


import com.hw.common.core.utils.DateUtils;
import com.hw.ems.base.domain.BaseBuildInfo;
import com.hw.ems.base.domain.BaseMonitorInfo;
import com.hw.ems.base.domain.BaseTypeRelation;
import com.hw.ems.base.mapper.BaseBuildInfoMapper;
import com.hw.ems.base.mapper.BaseTypeRelationMapper;
import com.hw.ems.base.service.IBaseMonitorInfoService;
import com.hw.ems.report.mapper.ReportPointDnbMapper;
import com.hw.ems.report.mapper.ReportPointWaterMapper;
import com.hw.ems.report.service.IEnergyPreviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hw.common.core.utils.sortReportUitls;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 水整点数据Service业务层处理
 *
 * @author YinQ
 * @date 2023-04-09
 */
@Service
public class EnergyPreviewServiceImpl implements IEnergyPreviewService {
    @Autowired
    private ReportPointWaterMapper reportPointWaterMapper;

    @Autowired
    private ReportPointDnbMapper reportPointDnbMapper;

    @Autowired
    private IBaseMonitorInfoService baseMonitorInfoService;

    @Autowired
    private BaseTypeRelationMapper baseTypeRelationMapper;

    @Autowired
    private BaseBuildInfoMapper baseBuildInfoMapper;
    /**
     * 电能源预览返回数据
     *
     * @param map
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public List<Map<String, String>> indexDataReport(Map map, Long energyType) {
        List<Map<String, String>> resultList = new ArrayList<>();
        if (String.valueOf(map.get("startTime")).equals("") || String.valueOf(map.get("endTime")).equals("")) {
            return resultList;
        }
        map.remove("pageSize");
        String unit = String.valueOf(0);
//        String unit = String.valueOf(map.get("unit"));
        String unitId = String.valueOf(map.get("unitId"));
        String type = String.valueOf(map.get("type"));
//        String startTime = String.valueOf(map.get("startTime"));
//        String endTime = String.valueOf(map.get("endTime"));
        try {
            BaseTypeRelation relation = new BaseTypeRelation();
            relation.setMonitorType(energyType);
//            if (!unitId.equals("")){
//                relation.setRelationId(Long.parseLong(unitId));
//            }
//            switch (unit) {
            switch ("0") {
                case "":
                    relation.setType(0L);
                    relation.setRelationId(1L);
                    break;
                case "0":
                    if (!unitId.equals("")){
                        BaseBuildInfo buildInfo = new BaseBuildInfo();
                        buildInfo.setParentId(Long.parseLong(unitId));
                        List<BaseBuildInfo> baseBuildInfos = baseBuildInfoMapper.selectBaseBuildInfoList(buildInfo);
                        if (baseBuildInfos.size() > 0){
                            List<Long> buildList = new ArrayList<>();
                            for (BaseBuildInfo baseBuildInfo : baseBuildInfos) {
                                buildList.add(baseBuildInfo.getObjid());
//                                buildInfo.setParentId(baseBuildInfo.getObjid());
//                                List<BaseBuildInfo> baseBuildInfoss = baseBuildInfoMapper.selectBaseBuildInfoList(buildInfo);
//                                if (baseBuildInfoss.size() > 0){
//                                    for (BaseBuildInfo buildInfoss : baseBuildInfoss) {
//                                        buildList.add(buildInfoss.getObjid());
//                                    }
//                                }
                            }
                            relation.setRelationIdList(buildList);
                        }else {
                            relation.setRelationId(Long.parseLong(unitId));
                        }
                    }
                    relation.setType(0L);
                    break;
                case "1":
                    relation.setType(1L);
                    break;
                case "2":
                    relation.setType(2L);
                    break;
            }
            List<BaseTypeRelation> baseTypeRelations = baseTypeRelationMapper.selectBaseTypeRelationList(relation);
            LinkedHashMap<Long, Map<Long, List<BaseTypeRelation>>> typeCollect =
                    baseTypeRelations.stream()
                            .collect(Collectors.groupingBy(BaseTypeRelation::getType,
                                    LinkedHashMap::new,
                                    Collectors.groupingBy(BaseTypeRelation::getRelationId, LinkedHashMap::new, Collectors.toList())));
            for (Long unitType : typeCollect.keySet()) {
                Map<Long, List<BaseTypeRelation>> relationIdListMap = typeCollect.get(unitType);
                for (Long relationId : relationIdListMap.keySet()) {
                    HashMap<String, String> typeResultMap = new HashMap<>();
                    BaseTypeRelation typeRelation = relationIdListMap.get(relationId).get(0);
                    typeResultMap.put("type", String.valueOf(typeRelation.getType()));
                    typeResultMap.put("unitName", typeRelation.getUnitName());
                    List<Map<String, String>> energyList = new ArrayList<>();
                    //单元内容
                    List<String> monitorIdList = relationIdListMap.get(relationId).stream().map(BaseTypeRelation::getMonitorId).collect(Collectors.toList());
                    map.put("monitorIdList",monitorIdList);
                    map.put("timeSub", type.equals("hour") ? 13: type.equals("day") ? 10 : type.equals("month") ? 7 : 4);
                    if (energyType == 2L){
                        //查询电实时数据
                        energyList = reportPointDnbMapper.energyConsumptionReportByTime(map);
                    }else if (energyType == 3L){
                        energyList = reportPointWaterMapper.energyConsumptionReportByTime(map);
                    }
                    if (energyList.size() > 0){
                        BigDecimal expendSum = new BigDecimal(0);
                        for (Map<String, String> energyMap : energyList) {
                            typeResultMap.put("expend" + String.valueOf(energyMap.get("pointTime")), String.valueOf(energyMap.get("expend")));
                            expendSum = expendSum.add(new BigDecimal(String.valueOf(energyMap.get("expend"))));
                        }
                        typeResultMap.put("expendSum", expendSum.toPlainString());
                    }
                    resultList.add(typeResultMap);
                }
            }
//         resultList = resultList.stream()
//                    .sorted(Comparator.comparing(e -> e.get("expend")))
//                    .collect(Collectors.toList());
        } catch (Exception e) {
            System.out.println("电能源预览返回数据异常11111：" + e.getMessage());
        }
        return resultList;
    }

    /**
     * 首页能耗曲线图
     * 请求参数energyType：2、3
     * 请求参数type：hour、day
     *
     * @param paramMap
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public Map<String, Object> indexBarChart(Map paramMap) {
        HashMap<String, Object> result = new HashMap<>();
        List<Map<String, String>> energyList = new ArrayList<>();
        List<String> dateList = new ArrayList<>();
        List<Float> valueList = new ArrayList<>();
        if (String.valueOf(paramMap.get("energyType")).equals("") || String.valueOf(paramMap.get("type")).equals("")) {
            return result;
        }
        String energyType = String.valueOf(paramMap.get("energyType"));
        String type = String.valueOf(paramMap.get("type"));
        Map<String, String> startAndEndTime = DateUtils.getStartAndEndTime();
        if (type.equals("hour")) {
            paramMap.put("timeSub", 13);
            paramMap.put("startTime", startAndEndTime.get("todayStart"));
            paramMap.put("endTime", startAndEndTime.get("todayEnd"));
            dateList = DateUtils.getHourlyIntervals(startAndEndTime.get("todayStart"), startAndEndTime.get("todayEnd"));
        } else if (type.equals("day")) {
            paramMap.put("timeSub", 10);
            paramMap.put("startDay", startAndEndTime.get("monthStart").substring(0, 10));
            paramMap.put("endDay", startAndEndTime.get("monthEnd").substring(0, 10));
            dateList = DateUtils.getDatesBetween(startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
        }
        ArrayList<String> monitorIdList = new ArrayList<>();
        BaseTypeRelation relation = new BaseTypeRelation();
        relation.setMonitorType(Long.parseLong(energyType));
        relation.setType(0L);
        relation.setRelationId(1L);
        List<BaseTypeRelation> baseTypeRelations = baseTypeRelationMapper.selectBaseTypeRelationList(relation);
        for (BaseTypeRelation baseTypeRelation : baseTypeRelations) {
            monitorIdList.add(baseTypeRelation.getMonitorId());
        }
        if (energyType.equals("2")) {
            paramMap.put("monitorIdList", monitorIdList);
            energyList = reportPointDnbMapper.energyConsumptionReportByTime(paramMap);
        } else if (energyType.equals("3")) {
            energyList = reportPointWaterMapper.energyConsumptionReportByTime(paramMap);
        }
        List<Map<String, String>> finalEnergyList = energyList;
        List<String> resDateList = new ArrayList<>();
        dateList.forEach(date -> {
            boolean flag = true;
            if (type.equals("hour")) {
                resDateList.add(date.substring(11, 13) + "时");
                date = date.substring(0, 13);
            } else if (type.equals("day")) {
                date = date.substring(0, 10);
                resDateList.add(date);
            }
            for (Map<String, String> map : finalEnergyList) {
                if (date.equals(String.valueOf(map.get("pointTime")))) {
                    flag = false;
                    valueList.add(Float.parseFloat(String.valueOf(map.get("expend"))));
                    break;
                }
            }
            if (flag) {
                valueList.add(0.00f);
            }
        });
        result.put("dateList", resDateList);
        result.put("valueList", valueList);
        return result;
    }


    /**
     * 首页今日、本周、当月、当年耗量
     *
     * @param paramMap
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public Map<String, Object> fourEnergy(Map paramMap) {
        HashMap<String, Object> result = new HashMap<>();
        List<Map<String, String>> energyList = new ArrayList<>();
        if (String.valueOf(paramMap.get("energyType")).equals("")) {
            return result;
        }

        ArrayList<String> monitorIdList = new ArrayList<>();
        BaseTypeRelation relation = new BaseTypeRelation();
        relation.setMonitorType(Long.parseLong(String.valueOf(paramMap.get("energyType"))));
        relation.setType(0L);
        relation.setRelationId(1L);
        List<BaseTypeRelation> baseTypeRelations = baseTypeRelationMapper.selectBaseTypeRelationList(relation);
        for (BaseTypeRelation baseTypeRelation : baseTypeRelations) {
            monitorIdList.add(baseTypeRelation.getMonitorId());
        }
        paramMap.put("monitorIdList", monitorIdList);
        paramMap.put("timeSub", 0);
        Map<String, String> startAndEndTime = DateUtils.getStartAndEndTime();
        paramMap.put("startTime", startAndEndTime.get("todayStart"));
        paramMap.put("endTime", startAndEndTime.get("todayEnd"));
        energyList = energyConsumptionByTime(paramMap);
        if (energyList.size() > 0) {
            result.put("todayEnergy", energyList.get(0).get("expend"));
        } else {
            result.put("todayEnergy", 0.00);
        }
        paramMap.put("startTime", startAndEndTime.get("weekStart"));
        paramMap.put("endTime", startAndEndTime.get("weekEnd"));
        energyList = energyConsumptionByTime(paramMap);
        if (energyList.size() > 0) {
            result.put("weekEnergy", energyList.get(0).get("expend"));
        } else {
            result.put("weekEnergy", 0.00);
        }
        paramMap.put("startTime", startAndEndTime.get("monthStart"));
        paramMap.put("endTime", startAndEndTime.get("monthEnd"));
        energyList = energyConsumptionByTime(paramMap);
        if (energyList.size() > 0) {
            result.put("monthEnergy", energyList.get(0).get("expend"));
        } else {
            result.put("monthEnergy", 0.00);
        }
        paramMap.put("startTime", startAndEndTime.get("yearStart"));
        paramMap.put("endTime", startAndEndTime.get("yearEnd"));
        energyList = energyConsumptionByTime(paramMap);
        if (energyList.size() > 0) {
            result.put("yearEnergy", energyList.get(0).get("expend"));
        } else {
            result.put("monthEnergy", 0.00);
        }
        return result;
    }


    /**
     * 根据统计名获取monitorIdList
     *
     * @param type
     * @param energyType
     * @return
     */
    public HashMap<String, List<String>> monitorIdListByUnitName(Long type, Long energyType) {
        List<String> monitorIdList = new ArrayList<>();
        HashMap<String, List<String>> result = new HashMap<>();
        BaseTypeRelation relation = new BaseTypeRelation();
        //0-建筑  1-业态  2-分项
        relation.setMonitorType(energyType);
        relation.setType(type);
        try {
            List<BaseTypeRelation> baseTypeRelations = baseTypeRelationMapper.selectFirstOrderTypeRelationList(relation);
            Map<Long, List<BaseTypeRelation>> relationIdMap =
                    baseTypeRelations.stream().collect(Collectors.groupingBy(BaseTypeRelation::getRelationId));
            for (Long relationId : relationIdMap.keySet()) {
                monitorIdList = relationIdMap.get(relationId).stream().map(BaseTypeRelation::getMonitorId).collect(Collectors.toList());
                result.put(relationIdMap.get(relationId).get(0).getUnitName(), monitorIdList);
            }
        } catch (Exception e) {
            System.out.println("根据统计名获取monitorIdList异常：" + e.getMessage());
        }
        return result;
    }

//    /**
//     * 能耗排名
//     *
//     * @param paramMap
//     * @return
//     */
//    @Override
//    //@DS("#header.poolName")
//    public Map<String, Object> energyRanking(Map paramMap) {
//        HashMap<String, Object> result = new HashMap<>();
//        ArrayList<String> nameList = new ArrayList<>();
//        ArrayList<Float> valueList = new ArrayList<>();
//        if (String.valueOf(paramMap.get("energyType")).equals("")) {
//            return result;
//        }
//        Long energyType = Long.valueOf(String.valueOf(paramMap.get("energyType")));
//        Long type;
//        if (String.valueOf(paramMap.get("type")).equals("")){
//            type = null;
//        }else {
//            type = Long.valueOf(String.valueOf(paramMap.get("type")));
//        }
//        String beginCollectTime = String.valueOf(paramMap.get("beginCollectTime"));
//        String endCollectTime = String.valueOf(paramMap.get("endCollectTime"));
//        HashMap<String, String> unitMap = monitorValueByMonitorIdList(type, energyType, beginCollectTime, endCollectTime);
//        for (String unitIdName : unitMap.keySet()) {
//            nameList.add(unitIdName);
//            valueList.add(Float.valueOf(unitMap.get(unitIdName)));
//        }
//        sortReportUitls.sortArrayList(nameList,valueList);
//        result.put("nameList", nameList);
//        result.put("valueList", valueList);
//        return result;
//    }

    /**
     * 首页monitorValueByMonitorIdList
     *
     * @param type
     * @param energyType
     * @return
     */
    public HashMap<String, String> monitorValueByMonitorIdList(Long type, Long energyType, String beginCollectTime, String endCollectTime) {
        HashMap<String, String> result = new HashMap<>();
        List<Map<String, String>> energyList = new ArrayList<>();
        Map<String, String> startAndEndTime = DateUtils.getStartAndEndTime();
        HashMap<String, List<String>> unitNameMap = monitorIdListByUnitName(type, energyType);
        for (String unitName : unitNameMap.keySet()) {
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("timeSub", 0);
            hashMap.put("energyType", energyType);
            hashMap.put("startTime", beginCollectTime);
            hashMap.put("endTime", endCollectTime);
            hashMap.put("monitorIdList", unitNameMap.get(unitName));
            energyList = energyConsumptionByTime(hashMap);
            if (energyList.size() > 0) {
                result.put(unitName, String.valueOf(energyList.get(0).get("expend")));
            } else {
                result.put(unitName, "0.00");
            }
        }
        return result;
    }


    /**
     * 首页建筑、业态、分项饼图
     *
     * @param paramMap
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public Map<String, Object> threePieChart(Map paramMap) {
        HashMap<String, Object> result = new HashMap<>();
        if (String.valueOf(paramMap.get("energyType")).equals("")) {
            return result;
        }
        String energyType = String.valueOf(paramMap.get("energyType"));
        ArrayList<HashMap<String, Object>> build = new ArrayList<>();
        ArrayList<HashMap<String, Object>> business = new ArrayList<>();
        ArrayList<HashMap<String, Object>> subentry = new ArrayList<>();
        Map<String, String> startAndEndTime = DateUtils.getStartAndEndTime();
        try {
            HashMap<String, String> buildMap = monitorValueByMonitorIdList(0L, Long.valueOf(energyType), startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
            for (String unitIdName : buildMap.keySet()) {
                HashMap<String, Object> buildNewMap = new HashMap<>();
                buildNewMap.put("name", unitIdName);
                buildNewMap.put("value", Float.valueOf(buildMap.get(unitIdName)));
                build.add(buildNewMap);
            }
            HashMap<String, String> businessMap = monitorValueByMonitorIdList(1L, Long.valueOf(energyType), startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
            for (String unitIdName : businessMap.keySet()) {
                HashMap<String, Object> businessNewMap = new HashMap<>();
                businessNewMap.put("name", unitIdName);
                businessNewMap.put("value", Float.valueOf(businessMap.get(unitIdName)));
                business.add(businessNewMap);
            }
            HashMap<String, String> subentryMap = monitorValueByMonitorIdList(2L, Long.valueOf(energyType), startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
            for (String unitIdName : subentryMap.keySet()) {
                HashMap<String, Object> subentryNewMap = new HashMap<>();
                subentryNewMap.put("name", unitIdName);
                subentryNewMap.put("value", Float.valueOf(subentryMap.get(unitIdName)));
                subentry.add(subentryNewMap);
            }
        } catch (Exception e) {
            System.out.println("首页建筑、业态、分项饼图:" + e.getMessage());
        }

        result.put("build", build);
        result.put("business", business);
        result.put("subentry", subentry);
        return result;
    }

    /**
     * 首页建筑、业态、分项柱图
     *
     * @param paramMap
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public Map<String, Object> columnarChart(Map paramMap) {
        HashMap<String, Object> result = new HashMap<>();
        if (String.valueOf(paramMap.get("energyType")).equals("")) {
            return result;
        }
        String energyType = String.valueOf(paramMap.get("energyType"));
        ArrayList<String> buildName = new ArrayList<>();
        ArrayList<Float> buildValue = new ArrayList<>();
        ArrayList<String> businessName = new ArrayList<>();
        ArrayList<Float> businessValue = new ArrayList<>();
        ArrayList<String> subentryName = new ArrayList<>();
        ArrayList<Float> subentryValue = new ArrayList<>();
        Map<String, String> startAndEndTime = DateUtils.getStartAndEndTime();
        HashMap<String, String> buildMap = monitorValueByMonitorIdList(0L, Long.valueOf(energyType), startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
        for (String unitIdName : buildMap.keySet()) {
            buildName.add(unitIdName);
            buildValue.add(Float.valueOf(buildMap.get(unitIdName)));
        }
        HashMap<String, String> businessMap = monitorValueByMonitorIdList(1L, Long.valueOf(energyType), startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
        for (String unitIdName : businessMap.keySet()) {
            businessName.add(unitIdName);
            businessValue.add(Float.valueOf(businessMap.get(unitIdName)));
        }
        HashMap<String, String> subentryMap = monitorValueByMonitorIdList(2L, Long.valueOf(energyType), startAndEndTime.get("monthStart"), startAndEndTime.get("monthEnd"));
        for (String unitIdName : subentryMap.keySet()) {
            subentryName.add(unitIdName);
            subentryValue.add(Float.valueOf(subentryMap.get(unitIdName)));
        }
        sortReportUitls.sortArrayList(buildName, buildValue);
        sortReportUitls.sortArrayList(businessName, businessValue);
        sortReportUitls.sortArrayList(subentryName, subentryValue);
        result.put("buildName", buildName);
        result.put("buildValue", buildValue);
        result.put("businessName", businessName);
        result.put("businessValue", businessValue);
        result.put("subentryName", subentryName);
        result.put("subentryValue", subentryValue);
        return result;
    }


    /**
     * 点抄数据柱状图
     *
     * @param paramMap
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public Map<String, Object> dnbCountingData(Map paramMap) {
        HashMap<String, Object> result = new HashMap<>();
        List<Map<String, String>> energyList = new ArrayList<>();
        List<String> dateList = new ArrayList<>();
        List<Float> valueList = new ArrayList<>();
        if (String.valueOf(paramMap.get("energyType")).equals("")) {
            return result;
        }
        String energyType = String.valueOf(paramMap.get("energyType"));
        String type = String.valueOf(paramMap.get("type"));
        String beginCollectTime = String.valueOf(paramMap.get("beginCollectTime"));
        String endCollectTime = String.valueOf(paramMap.get("endCollectTime"));
        Map<String, String> startAndEndTime = DateUtils.getStartAndEndTime();
        paramMap.put("startDay", beginCollectTime.substring(0, 10));
        paramMap.put("endDay", endCollectTime.substring(0, 10));
        if (!String.valueOf(paramMap.get("monitorSubset")).equals("")) {
            List<BaseMonitorInfo> baseMonitorInfos = baseMonitorInfoService.selectChildrenMonitorById(String.valueOf(paramMap.get("monitorSubset")));
            List<String> monitorIdList = baseMonitorInfos.stream().map(BaseMonitorInfo::getMonitorId).collect(Collectors.toList());
            paramMap.put("monitorIdList", monitorIdList);
        }
        if (type.equals("day")) {
            paramMap.put("timeSub", 10);
            paramMap.put("startTime", startAndEndTime.get("startDay"));
            paramMap.put("endTime", startAndEndTime.get("todayEnd"));
            dateList = DateUtils.getDatesBetween(beginCollectTime, endCollectTime);
        } else if (type.equals("month")) {
            paramMap.put("timeSub", 7);
            dateList = DateUtils.getDatesBetween(beginCollectTime, endCollectTime);
            dateList = DateUtils.getSortedMonthList(dateList, "month");
        } else if (type.equals("year")) {
            paramMap.put("timeSub", 4);
            dateList = DateUtils.getDatesBetween(beginCollectTime, endCollectTime);
            dateList = DateUtils.getSortedMonthList(dateList, "year");
        } else if (type.equals("hour")) {
            paramMap.put("timeSub", 13);
            dateList = DateUtils.getTimeList(beginCollectTime, endCollectTime, "hour");
        }
        if (energyType.equals("2")) {
            energyList = reportPointDnbMapper.energyConsumptionReportByTime(paramMap);
        } else if (energyType.equals("3")) {
            energyList = reportPointWaterMapper.energyConsumptionReportByTime(paramMap);
        }
        List<Map<String, String>> finalEnergyList = energyList;
        List<String> resDateList = new ArrayList<>();
        dateList.forEach(date -> {
            boolean flag = true;
            if (type.equals("day")) {
                date = date.substring(0, 10);
                resDateList.add(date);
            } else if (type.equals("month")) {
                date = date.substring(0, 7);
                resDateList.add(date);
            } else if (type.equals("year")) {
                date = date.substring(0, 4);
                resDateList.add(date);
            } else if (type.equals("hour")) {
                date = date.substring(0, 13);
                resDateList.add(date + "时");
            }
            for (Map<String, String> map : finalEnergyList) {
                if (date.equals(String.valueOf(map.get("pointTime")))) {
                    flag = false;
                    valueList.add(Float.parseFloat(String.valueOf(map.get("expend"))));
                    break;
                }
            }
            if (flag) {
                valueList.add(0.00f);
            }
        });
        result.put("dateList", resDateList);
        result.put("valueList", valueList);
        return result;
    }


    /**
     * 查询能源耗量
     *
     * @param paramMap
     * @return
     */
    public List<Map<String, String>> energyConsumptionByTime(Map paramMap) {
//        paramMap.put("startTime",  paramMap.get("todayStart"));
//        paramMap.put("endTime",  paramMap.get("todayEnd"));
//        paramMap.put("timeSub", 0);
        List<Map<String, String>> energyList = new ArrayList<>();
        String energyType = String.valueOf(paramMap.get("energyType"));
        if (energyType.equals("2")) {
            energyList = reportPointDnbMapper.energyConsumptionReportByTime(paramMap);
        } else if (energyType.equals("3")) {
            energyList = reportPointWaterMapper.energyConsumptionReportByTime(paramMap);
        }
        return energyList;
    }

    /**
     * 能耗排名
     *
     * @param paramMap
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public Map<String, Object> energyRanking(Map paramMap) {
        HashMap<String, Object> result = new HashMap<>();
        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<Float> valueList = new ArrayList<>();
        if (String.valueOf(paramMap.get("energyType")).equals("")) {
            return result;
        }
        Long energyType = Long.valueOf(String.valueOf(paramMap.get("energyType")));
        Long type;
        if (String.valueOf(paramMap.get("type")).equals("")) {
            type = null;
        } else {
            type = Long.valueOf(String.valueOf(paramMap.get("type")));
        }
        String beginCollectTime = String.valueOf(paramMap.get("beginCollectTime"));
        String endCollectTime = String.valueOf(paramMap.get("endCollectTime"));
        HashMap<String, String> unitMap = monitorValueByMonitorIdList(type, energyType, beginCollectTime, endCollectTime);
        for (String unitIdName : unitMap.keySet()) {
            nameList.add(unitIdName);
            valueList.add(Float.valueOf(unitMap.get(unitIdName)));
        }
        sortReportUitls.sortArrayList(nameList, valueList);
        result.put("nameList", nameList);
        result.put("valueList", valueList);
        return result;
    }
}
