package com.nantian.cloud.dbcapp.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.dbcapp.mapper.record.DataHomeMapper;
import com.nantian.cloud.dbcapp.service.DataHomeService;
import com.nantian.cloud.dbcapp.vo.DataHomeDataVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 发改决策分析支撑服务实现类
 */
@Service("dataHomeService")
public class DataHomeServiceImpl implements DataHomeService {

    @Autowired
    private DataHomeMapper dataHomeMapper;


    @Override
    public IPage<DataHomeDataVo> getData(Page<Object> page, String regionCode, String startTime, String endTime, String tradeCode, String tradeType, String tradeStr) {
        return dataHomeMapper.getData(page,regionCode,startTime,endTime,tradeCode,tradeType,tradeStr);
    }

    @Override
    public List<Map<String, String>> getElectricityDatas(String regionCode, String startTime, String endTime, String tradeCode, String tradeType, String type, String tradeStr) {
        return dataHomeMapper.getElectricityDatas(regionCode,startTime,endTime,tradeCode,tradeType,type,tradeStr);
    }

    @Override
    public IPage<DataHomeDataVo> getElectricityData(Page<Object> page, String regionCode, String startTime, String endTime, String tradeCode, String tradeType, String tradeStr) {
        return dataHomeMapper.getElectricityData(page,regionCode,startTime,endTime,tradeCode,tradeType,tradeStr);
    }

    @Override
    public List<Map<String, String>> getTradeRanking(String startTime, String endTime, String tradeType, String tradeStr) {
        return dataHomeMapper.getTradeRanking(startTime,endTime,tradeType,tradeStr);
    }

    @Override
    public Map<String, String> getTradeTotal(String startTime, String endTime, String tradeType, String tradeStr) {
        return dataHomeMapper.getTradeTotal(startTime,endTime,tradeType,tradeStr);
    }

    @Override
    public List<Map<String, String>> getTradeTrends(String[] yearArr, String tradeType, String tradeStr) {
        return dataHomeMapper.getTradeTrends(yearArr,tradeType,tradeStr);
    }

    @Override
    public List<Map<String, String>> getRegionTrends(String[] yearArr, String tradeStr) {
        return dataHomeMapper.getRegionTrends(yearArr, tradeStr);
    }

    @Override
    public IPage<DataHomeDataVo> getTrendsDetail(Page page, String regionCode, String[] yearArr, String tradeCode, String tradeType, String tradeStr) {
        return dataHomeMapper.getTrendsDetail(page, regionCode, yearArr, tradeCode, tradeType, tradeStr);
    }

    @Override
    public Map<String, Object> getEnergyConsumption(String startTime, String endTime, String tradeType, String type, String tradeStr, String energyStr) {
        Map<String,Object> result = new HashMap<>();

        String[] energyArr = energyStr.split(",");
        result.put("energyArr",energyArr);
        if("1".equals(type)){ //能源消费结构占比
            //String[] energyArr = (energyStr+",其他").split(",");
            //result.put("energyArr",energyArr);
            List<Map<String, String>> ratio = dataHomeMapper.getEnergyConsumptionRatio(startTime, endTime, tradeStr, energyStr);
            result.put("energyRatio",ratio);
        }else{

            List<Map<String, String>> trends =  dataHomeMapper.getEnergyConsumptionTrends(startTime, endTime, tradeType, type, tradeStr, energyStr, energyArr);
            result.put("trends",trends);
        }
        return result;
    }

    @Override
    public IPage<DataHomeDataVo> getEnergyConsumptionDetail(Page page, String startTime, String endTime, String tradeType, String tradeCode, String energyName, String tradeStr, String energyStr) {
        return dataHomeMapper.getEnergyConsumptionDetail(page,startTime,endTime,tradeType,tradeCode,energyName,tradeStr,energyStr);
    }

    @Override
    public List<Map<String, String>> getOverLimit(String startTime, String endTime) {
        return dataHomeMapper.getOverLimit(startTime,endTime);
    }

    @Override
    public List<Map<String, String>> getOverLimitDetail(String startTime, String endTime, String regionCode, String tradeStr, String type) {
        return dataHomeMapper.getOverLimitDetail(startTime,endTime,regionCode,tradeStr,type);
    }
}



