package com.ho.business.util;

import com.ho.business.entity.EarningsCalculate;
import com.ho.business.entity.ModelDeviceColComp;
import com.ho.business.entity.OneKeyProgress;
import com.ho.business.entity.Station;
import com.ho.business.vo.CalculateVo;
import com.ho.business.vo.OneKeyComputationVo;
import lombok.extern.slf4j.Slf4j;

import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author catkins
 * @date 2023/9/25 0025 15:11
 */
@Slf4j
public class QueuesUtil {

    /** start */
    /** todo: 尖峰平谷电表常量 */
    // 尖
    public static final Integer E1 = 1;
    // 峰
    public static final Integer E2 = 2;
    // 平
    public static final Integer E3 = 3;
    // 谷
    public static final Integer E4 = 4;
    /** end */

    /** todo: 电站总充查询参数队列 */
    /** start */
    private static final ConcurrentHashMap<Integer, List<List<ModelDeviceColComp>>> STATION_CHARGE_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationChargeLocker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getChargeStationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_CHARGE_MAP != null ) {
            keys = STATION_CHARGE_MAP.keys();
        }
        return keys;
    }

    public static void setChargeMap( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_CHARGE_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getChargeMap(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationChargeLocker.lock();
        try {
            list = STATION_CHARGE_MAP.get(stationId);
        } finally {
            stationChargeLocker.unlock();
        }
        return list;
    }

    public static void removeChargeMap( Integer stationId ){
        stationChargeLocker.lock();
        try {
            STATION_CHARGE_MAP.remove(stationId);
        } finally {
            stationChargeLocker.unlock();
        }
    }
    /** end */


    /** todo: 电站总放查询参数队列 */
    /** start */
    private static final ConcurrentHashMap<Integer,List< List<ModelDeviceColComp>>> STATION_DISCHARGE_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationDischargeLocker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getDischargeStationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_DISCHARGE_MAP != null ) {
            keys = STATION_DISCHARGE_MAP.keys();
        }
        return keys;
    }

    public static void setDischargeMap( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_DISCHARGE_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getDischargeMap(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationDischargeLocker.lock();
        try {
            list = STATION_DISCHARGE_MAP.get(stationId);
        } finally {
            stationDischargeLocker.unlock();
        }
        return list;
    }

    public static void removeDischargeMap( Integer stationId ){
        stationDischargeLocker.lock();
        try {
            STATION_DISCHARGE_MAP.remove(stationId);
        } finally {
            stationDischargeLocker.unlock();
        }
    }
    /** end */


    /** todo: 存放电站信息 */
    /** start */
    private static final ConcurrentHashMap<Integer, Station> CHARGE_STATION_MAP = new ConcurrentHashMap<Integer, Station>();

    private static final ReentrantLock stationLocker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getStationIds(){
        Enumeration<Integer> keys = null;
        if ( CHARGE_STATION_MAP != null ) {
            keys = CHARGE_STATION_MAP.keys();
        }
        return keys;
    }

    public static void setStationMap( Station station ){
        stationLocker.lock();
        try {
            CHARGE_STATION_MAP.put(station.getId(),station);
        } finally {
            stationLocker.unlock();
        }
    }

    /** todo: 根据stationId取队列里的数据 */
    public static Station getStationMap(Integer stationId){
        Station station = null;
        stationLocker.lock();
        try {
            station = CHARGE_STATION_MAP.get(stationId);
        } finally {
            stationLocker.unlock();
        }
        return station;
    }

    public static void removeStationMap( Integer stationId ){
        stationLocker.lock();
        try {
            CHARGE_STATION_MAP.remove(stationId);
        } finally {
            stationLocker.unlock();
        }
    }
    /** end */

/** todo: 存放电站信息 */
    /** start */
    private static final ConcurrentHashMap<Integer, Station> DISCHARGE_STATION_MAP = new ConcurrentHashMap<Integer, Station>();

    private static final ReentrantLock dischargeStationLocker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getDischargeStations(){
        Enumeration<Integer> keys = null;
        if ( DISCHARGE_STATION_MAP != null ) {
            keys = DISCHARGE_STATION_MAP.keys();
        }
        return keys;
    }

    public static void setDischargeStationMap( Station station ){
        dischargeStationLocker.lock();
        try {
            DISCHARGE_STATION_MAP.put(station.getId(),station);
        } finally {
            dischargeStationLocker.unlock();
        }
    }

    /** todo: 根据stationId取队列里的数据 */
    public static Station getDischargeStationMap(Integer stationId){
        Station station = null;
        dischargeStationLocker.lock();
        try {
            station = DISCHARGE_STATION_MAP.get(stationId);
        } finally {
            dischargeStationLocker.unlock();
        }
        return station;
    }

    public static void removeDischargeStationMap( Integer stationId ){
        dischargeStationLocker.lock();
        try {
            DISCHARGE_STATION_MAP.remove(stationId);
        } finally {
            dischargeStationLocker.unlock();
        }
    }
    /** end */



    /** todo: 充电数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> CHARGE_QUEUE = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock queueLock = new ReentrantLock();

    public static int getChargeQueueSize(){
        return CHARGE_QUEUE.size();
    }

    public static void setChargeData(CalculateVo datas){
        queueLock.lock();
        try {
            CHARGE_QUEUE.add(datas);
        } finally {
            queueLock.unlock();
        }
    }

    public static CalculateVo getChargeData(){
        CalculateVo data = null;
        queueLock.lock();
        try {
            if ( CHARGE_QUEUE != null && CHARGE_QUEUE.size() > 0 ) {
                data = CHARGE_QUEUE.poll();
            }
        } finally {
            queueLock.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 放电数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> DISCHARGE_QUEUE = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock disQueueLock = new ReentrantLock();

    public static int getDisChargeQueueSize(){
        return DISCHARGE_QUEUE.size();
    }

    public static void setDisChargeData(CalculateVo datas){
        disQueueLock.lock();
        try {
            DISCHARGE_QUEUE.add(datas);
        } finally {
            disQueueLock.unlock();
        }
    }

    public static CalculateVo getDisChargeData(){
        CalculateVo data = null;
        disQueueLock.lock();
        try {
            if ( DISCHARGE_QUEUE != null && DISCHARGE_QUEUE.size() > 0 ) {
                data = DISCHARGE_QUEUE.poll();
            }
        } finally {
            disQueueLock.unlock();
        }
        return data;
    }
    /** end */

    /**
     * 获取充放电数据队列长度
     * @return
     */
    public static Integer getQueueLength(){
        return CHARGE_QUEUE.size() + DISCHARGE_QUEUE.size();
    }


    /** todo: 入库队列模块 */
    /** start */
    /** 入库队列 */
    private static volatile ConcurrentLinkedQueue<List<EarningsCalculate>> PUSH_QUEUE = new ConcurrentLinkedQueue<List<EarningsCalculate>>();

    /** 入库队列锁 */
    private static final ReentrantLock pushLock = new ReentrantLock();


    public static Integer getQueueCount(){
        return PUSH_QUEUE.size();
    }


    public static void setPushQueue(List<EarningsCalculate> datas){
        pushLock.lock();
        try {
            PUSH_QUEUE.add(datas);
        } finally {
            pushLock.unlock();
        }
    }

    public static List<EarningsCalculate> getPushQueue(){
        List<EarningsCalculate> datas = null;
        pushLock.lock();
        try {
            if( PUSH_QUEUE != null && PUSH_QUEUE.size() > 0 ){
                datas = PUSH_QUEUE.poll();
            }
//            System.err.println("PUSH_QUEUE.size() -> "+PUSH_QUEUE.size());
        } finally {
            pushLock.unlock();
        }
        return datas;
    }
    /** end */

    public static String date ;



    /**
     * 补算队列
     */
    private static final ConcurrentHashMap<Integer, OneKeyComputationVo> ONE_KEY_COMPUTATION_MAP = new ConcurrentHashMap<Integer, OneKeyComputationVo>();

    private static final ReentrantLock oneKeyComputationLock = new ReentrantLock();

    /**
     * 存放数据
     * @param stationId
     */
    public static void setOneKeyComputationMap( Integer stationId,OneKeyComputationVo vo ){
        oneKeyComputationLock.lock();
        try {
            ONE_KEY_COMPUTATION_MAP.put(stationId,vo);
        } finally {
            oneKeyComputationLock.unlock();
        }
    }

    /**
     * 获取后删除当前key
     * @return
     */
    public static OneKeyComputationVo getOneKeyComputationMap(){
        OneKeyComputationVo vo = null;
        oneKeyComputationLock.lock();
        try {
            if ( !ONE_KEY_COMPUTATION_MAP.isEmpty() ) {
                Set<Map.Entry<Integer, OneKeyComputationVo>> entries = ONE_KEY_COMPUTATION_MAP.entrySet();
                for (Map.Entry<Integer, OneKeyComputationVo> entry : entries) {
                    vo = entry.getValue();
                    ONE_KEY_COMPUTATION_MAP.remove(entry.getKey());
                    break;
                }
            }
        } finally {
            oneKeyComputationLock.unlock();
        }
        return vo;
    }

    /**
     * 根据电站id判断是否已经存在等待计算的数据
     * @param stationId
     * @return
     */
    public static boolean checkOneKeyComputationHasData(Integer stationId){
        boolean flag = false;
        if( ONE_KEY_COMPUTATION_MAP.get(stationId) != null ){
            flag = true;
        }
        return flag;
    }

    /**
     * 根据电站id保存当前计算进度数据
     */
    private static final ConcurrentHashMap<Integer, OneKeyProgress> ONE_KEY_PROGRESS = new ConcurrentHashMap<Integer, OneKeyProgress>();

    private static final ReentrantLock oneKeyProgressLock = new ReentrantLock();

    /**
     * 存放进度数据
     * @param stationId
     * @param progress
     */
    public static void setOneKeyProgress( Integer stationId,OneKeyProgress progress ){
        oneKeyProgressLock.lock();
        try {
            ONE_KEY_PROGRESS.put(stationId,progress);
        } finally {
            oneKeyProgressLock.unlock();
        }
    }

    /**
     * 获取进度数据
     * @param stationId
     * @return
     */
    public static OneKeyProgress getOneKeyProgress( Integer stationId ){
        OneKeyProgress progress = null;
        if ( !ONE_KEY_PROGRESS.isEmpty() ) {
            progress = ONE_KEY_PROGRESS.get(stationId);
        }
        return progress;
    }

    /**
     * 移除进度数据
     * @param stationId
     */
    public static void removeOneKeyProgress( Integer stationId ){
        oneKeyProgressLock.lock();
        try {
            ONE_KEY_PROGRESS.remove(stationId);
        } finally {
            oneKeyProgressLock.unlock();
        }
    }


    /** todo: 电站总充查询参数队列 */
    /** start */
    private static final ConcurrentHashMap<Integer, String> STATION_DATE_MAPE = new ConcurrentHashMap<>();

    private static final ReentrantLock stationDateLocker = new ReentrantLock();

//    public static void setDateMap( Integer stationId, String date ){
//        STATION_DATE_MAPE.put(stationId,date);
//    }

    /** todo: 根据stationId取队列里的数据 */
//    public static String getDateMap(Integer stationId){
//        String date = null;
//        stationDateLocker.lock();
//        try {
//            date = STATION_DATE_MAPE.get(stationId);
////            removeDateMap(stationId);
//        } finally {
//            stationDateLocker.unlock();
//        }
//        return date;
//    }

//    public static void removeDateMap( Integer stationId ){
//        stationDateLocker.lock();
//        try {
//            STATION_DATE_MAPE.remove(stationId);
//        } finally {
//            stationDateLocker.unlock();
//        }
//    }
    /** end */


    public static final String PROGRESS_REDIS_KEY = "oneKeyProgress";


    /** start */
    /** todo: 尖峰平谷电表队列 */
    //// 尖
    private static final ConcurrentHashMap<Integer, List<List<ModelDeviceColComp>>> STATION_CHARGE_E1_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationChargeE1Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getChargeE1StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_CHARGE_E1_MAP != null ) {
            keys = STATION_CHARGE_E1_MAP.keys();
        }
        return keys;
    }

    public static void setChargeE1Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_CHARGE_E1_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getChargeE1Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationChargeE1Locker.lock();
        try {
            list = STATION_CHARGE_E1_MAP.get(stationId);
        } finally {
            stationChargeE1Locker.unlock();
        }
        return list;
    }

    public static void removeChargeE1Map( Integer stationId ){
        stationChargeE1Locker.lock();
        try {
            STATION_CHARGE_E1_MAP.remove(stationId);
        } finally {
            stationChargeE1Locker.unlock();
        }
    }

    private static final ConcurrentHashMap<Integer,List< List<ModelDeviceColComp>>> STATION_DISCHARGE_E1_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationDischargeE1Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getDischargeE1StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_DISCHARGE_E1_MAP != null ) {
            keys = STATION_DISCHARGE_E1_MAP.keys();
        }
        return keys;
    }

    public static void setDischargeE1Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_DISCHARGE_E1_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getDischargeE1Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationDischargeE1Locker.lock();
        try {
            list = STATION_DISCHARGE_E1_MAP.get(stationId);
        } finally {
            stationDischargeE1Locker.unlock();
        }
        return list;
    }

    public static void removeDischargeE1Map( Integer stationId ){
        stationDischargeE1Locker.lock();
        try {
            STATION_DISCHARGE_E1_MAP.remove(stationId);
        } finally {
            stationDischargeE1Locker.unlock();
        }
    }

    //// 峰
    private static final ConcurrentHashMap<Integer, List<List<ModelDeviceColComp>>> STATION_CHARGE_E2_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationChargeE2Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getChargeE2StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_CHARGE_E2_MAP != null ) {
            keys = STATION_CHARGE_E2_MAP.keys();
        }
        return keys;
    }

    public static void setChargeE2Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_CHARGE_E2_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getChargeE2Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationChargeE2Locker.lock();
        try {
            list = STATION_CHARGE_E2_MAP.get(stationId);
        } finally {
            stationChargeE2Locker.unlock();
        }
        return list;
    }

    public static void removeChargeE2Map( Integer stationId ){
        stationChargeE2Locker.lock();
        try {
            STATION_CHARGE_E2_MAP.remove(stationId);
        } finally {
            stationChargeE2Locker.unlock();
        }
    }

    private static final ConcurrentHashMap<Integer,List< List<ModelDeviceColComp>>> STATION_DISCHARGE_E2_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationDischargeE2Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getDischargeE2StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_DISCHARGE_E2_MAP != null ) {
            keys = STATION_DISCHARGE_E2_MAP.keys();
        }
        return keys;
    }

    public static void setDischargeE2Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_DISCHARGE_E2_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getDischargeE2Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationDischargeE2Locker.lock();
        try {
            list = STATION_DISCHARGE_E2_MAP.get(stationId);
        } finally {
            stationDischargeE2Locker.unlock();
        }
        return list;
    }

    public static void removeDischargeE2Map( Integer stationId ){
        stationDischargeE2Locker.lock();
        try {
            STATION_DISCHARGE_E2_MAP.remove(stationId);
        } finally {
            stationDischargeE2Locker.unlock();
        }
    }

    //// 平
    private static final ConcurrentHashMap<Integer, List<List<ModelDeviceColComp>>> STATION_CHARGE_E3_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationChargeE3Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getChargeE3StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_CHARGE_E3_MAP != null ) {
            keys = STATION_CHARGE_E3_MAP.keys();
        }
        return keys;
    }

    public static void setChargeE3Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_CHARGE_E3_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getChargeE3Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationChargeE3Locker.lock();
        try {
            list = STATION_CHARGE_E3_MAP.get(stationId);
        } finally {
            stationChargeE3Locker.unlock();
        }
        return list;
    }

    public static void removeChargeE3Map( Integer stationId ){
        stationChargeE3Locker.lock();
        try {
            STATION_CHARGE_E3_MAP.remove(stationId);
        } finally {
            stationChargeE3Locker.unlock();
        }
    }

    private static final ConcurrentHashMap<Integer,List< List<ModelDeviceColComp>>> STATION_DISCHARGE_E3_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationDischargeE3Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getDischargeE3StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_DISCHARGE_E3_MAP != null ) {
            keys = STATION_DISCHARGE_E3_MAP.keys();
        }
        return keys;
    }

    public static void setDischargeE3Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_DISCHARGE_E3_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getDischargeE3Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationDischargeE3Locker.lock();
        try {
            list = STATION_DISCHARGE_E3_MAP.get(stationId);
        } finally {
            stationDischargeE3Locker.unlock();
        }
        return list;
    }

    public static void removeDischargeE3Map( Integer stationId ){
        stationDischargeE3Locker.lock();
        try {
            STATION_DISCHARGE_E3_MAP.remove(stationId);
        } finally {
            stationDischargeE3Locker.unlock();
        }
    }

    //// 谷
    private static final ConcurrentHashMap<Integer, List<List<ModelDeviceColComp>>> STATION_CHARGE_E4_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationChargeE4Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getChargeE4StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_CHARGE_E4_MAP != null ) {
            keys = STATION_CHARGE_E4_MAP.keys();
        }
        return keys;
    }

    public static void setChargeE4Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_CHARGE_E4_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getChargeE4Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationChargeE4Locker.lock();
        try {
            list = STATION_CHARGE_E4_MAP.get(stationId);
        } finally {
            stationChargeE4Locker.unlock();
        }
        return list;
    }

    public static void removeChargeE4Map( Integer stationId ){
        stationChargeE4Locker.lock();
        try {
            STATION_CHARGE_E4_MAP.remove(stationId);
        } finally {
            stationChargeE4Locker.unlock();
        }
    }

    private static final ConcurrentHashMap<Integer,List< List<ModelDeviceColComp>>> STATION_DISCHARGE_E4_MAP = new ConcurrentHashMap<>();

    private static final ReentrantLock stationDischargeE4Locker = new ReentrantLock();

    /** todo: 如果队列不为空，那就取出所有的key */
    public static Enumeration<Integer> getDischargeE4StationIds(){
        Enumeration<Integer> keys = null;
        if ( STATION_DISCHARGE_E4_MAP != null ) {
            keys = STATION_DISCHARGE_E4_MAP.keys();
        }
        return keys;
    }

    public static void setDischargeE4Map( Map<Integer,List<List<ModelDeviceColComp>>> map ){
        STATION_DISCHARGE_E4_MAP.putAll(map);
    }

    /** todo: 根据stationId取队列里的数据 */
    public static List<List<ModelDeviceColComp>> getDischargeE4Map(Integer stationId){
        List<List<ModelDeviceColComp>> list = null;
        stationDischargeE4Locker.lock();
        try {
            list = STATION_DISCHARGE_E4_MAP.get(stationId);
        } finally {
            stationDischargeE4Locker.unlock();
        }
        return list;
    }

    public static void removeDischargeE4Map( Integer stationId ){
        stationDischargeE4Locker.lock();
        try {
            STATION_DISCHARGE_E4_MAP.remove(stationId);
        } finally {
            stationDischargeE4Locker.unlock();
        }
    }

    /** end */




    /** todo: 充电尖数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> CHARGE_QUEUE_E1 = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock queueLockE1 = new ReentrantLock();

    public static int getChargeE1QueueSize(){
        return CHARGE_QUEUE_E1.size();
    }

    public static void setChargeE1Data(CalculateVo datas){
        queueLockE1.lock();
        try {
            CHARGE_QUEUE_E1.add(datas);
        } finally {
            queueLockE1.unlock();
        }
    }

    public static CalculateVo getChargeE1Data(){
        CalculateVo data = null;
        queueLockE1.lock();
        try {
            if ( CHARGE_QUEUE_E1 != null && CHARGE_QUEUE_E1.size() > 0 ) {
                data = CHARGE_QUEUE_E1.poll();
            }
        } finally {
            queueLockE1.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 充电峰数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> CHARGE_QUEUE_E2 = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock queueLockE2 = new ReentrantLock();

    public static int getChargeE2QueueSize(){
        return CHARGE_QUEUE_E2.size();
    }

    public static void setChargeE2Data(CalculateVo datas){
        queueLockE2.lock();
        try {
            CHARGE_QUEUE_E2.add(datas);
        } finally {
            queueLockE2.unlock();
        }
    }

    public static CalculateVo getChargeE2Data(){
        CalculateVo data = null;
        queueLockE2.lock();
        try {
            if ( CHARGE_QUEUE_E2 != null && CHARGE_QUEUE_E2.size() > 0 ) {
                data = CHARGE_QUEUE_E2.poll();
            }
        } finally {
            queueLockE2.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 充电平数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> CHARGE_QUEUE_E3 = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock queueLockE3 = new ReentrantLock();

    public static int getChargeE3QueueSize(){
        return CHARGE_QUEUE_E3.size();
    }

    public static void setChargeE3Data(CalculateVo datas){
        queueLockE3.lock();
        try {
            CHARGE_QUEUE_E3.add(datas);
        } finally {
            queueLockE3.unlock();
        }
    }

    public static CalculateVo getChargeE3Data(){
        CalculateVo data = null;
        queueLockE3.lock();
        try {
            if ( CHARGE_QUEUE_E3 != null && CHARGE_QUEUE_E3.size() > 0 ) {
                data = CHARGE_QUEUE_E3.poll();
            }
        } finally {
            queueLockE3.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 充电谷数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> CHARGE_QUEUE_E4 = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock queueLockE4 = new ReentrantLock();

    public static int getChargeE4QueueSize(){
        return CHARGE_QUEUE_E4.size();
    }

    public static void setChargeE4Data(CalculateVo datas){
        queueLockE4.lock();
        try {
            CHARGE_QUEUE_E4.add(datas);
        } finally {
            queueLockE4.unlock();
        }
    }

    public static CalculateVo getChargeE4Data(){
        CalculateVo data = null;
        queueLockE4.lock();
        try {
            if ( CHARGE_QUEUE_E4 != null && CHARGE_QUEUE_E4.size() > 0 ) {
                data = CHARGE_QUEUE_E4.poll();
            }
        } finally {
            queueLockE4.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 放电尖数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> DISCHARGE_E1_QUEUE = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock disQueueLockE1 = new ReentrantLock();

    public static int getDisChargeE1QueueSize(){
        return DISCHARGE_E1_QUEUE.size();
    }

    public static void setDisChargeE1Data(CalculateVo datas){
        disQueueLockE1.lock();
        try {
            DISCHARGE_E1_QUEUE.add(datas);
        } finally {
            disQueueLockE1.unlock();
        }
    }

    public static CalculateVo getDisChargeE1Data(){
        CalculateVo data = null;
        disQueueLockE1.lock();
        try {
            if ( DISCHARGE_E1_QUEUE != null && DISCHARGE_E1_QUEUE.size() > 0 ) {
                data = DISCHARGE_E1_QUEUE.poll();
            }
        } finally {
            disQueueLockE1.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 放电峰数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> DISCHARGE_E2_QUEUE = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock disQueueLockE2 = new ReentrantLock();

    public static int getDisChargeE2QueueSize(){
        return DISCHARGE_E2_QUEUE.size();
    }

    public static void setDisChargeE2Data(CalculateVo datas){
        disQueueLockE2.lock();
        try {
            DISCHARGE_E2_QUEUE.add(datas);
        } finally {
            disQueueLockE2.unlock();
        }
    }

    public static CalculateVo getDisChargeE2Data(){
        CalculateVo data = null;
        disQueueLockE2.lock();
        try {
            if ( DISCHARGE_E2_QUEUE != null && DISCHARGE_E2_QUEUE.size() > 0 ) {
                data = DISCHARGE_E2_QUEUE.poll();
            }
        } finally {
            disQueueLockE2.unlock();
        }
        return data;
    }
    /** end */


    /** todo: 放电平数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> DISCHARGE_E3_QUEUE = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock disQueueLockE3 = new ReentrantLock();

    public static int getDisChargeE3QueueSize(){
        return DISCHARGE_E3_QUEUE.size();
    }

    public static void setDisChargeE3Data(CalculateVo datas){
        disQueueLockE3.lock();
        try {
            DISCHARGE_E3_QUEUE.add(datas);
        } finally {
            disQueueLockE3.unlock();
        }
    }

    public static CalculateVo getDisChargeE3Data(){
        CalculateVo data = null;
        disQueueLockE3.lock();
        try {
            if ( DISCHARGE_E3_QUEUE != null && DISCHARGE_E3_QUEUE.size() > 0 ) {
                data = DISCHARGE_E3_QUEUE.poll();
            }
        } finally {
            disQueueLockE3.unlock();
        }
        return data;
    }
    /** end */

    /** todo: 放电谷数据队列 */
    /** start */
    private static volatile ConcurrentLinkedQueue<CalculateVo> DISCHARGE_E4_QUEUE = new ConcurrentLinkedQueue<CalculateVo>();

    private static final ReentrantLock disQueueLockE4 = new ReentrantLock();

    public static int getDisChargeE4QueueSize(){
        return DISCHARGE_E4_QUEUE.size();
    }

    public static void setDisChargeE4Data(CalculateVo datas){
        disQueueLockE4.lock();
        try {
            DISCHARGE_E4_QUEUE.add(datas);
        } finally {
            disQueueLockE4.unlock();
        }
    }

    public static CalculateVo getDisChargeE4Data(){
        CalculateVo data = null;
        disQueueLockE4.lock();
        try {
            if ( DISCHARGE_E4_QUEUE != null && DISCHARGE_E4_QUEUE.size() > 0 ) {
                data = DISCHARGE_E4_QUEUE.poll();
            }
        } finally {
            disQueueLockE4.unlock();
        }
        return data;
    }
    /** end */

    /// todo: 尖峰平谷电表存放电站信息
    /** todo: 存放电站信息 */
    /** start */
//    private static final ConcurrentHashMap<Integer, Station> CHARGE_E1_STATION_MAP = new ConcurrentHashMap<Integer, Station>();
//
//    private static final ReentrantLock stationE1Locker = new ReentrantLock();
//
//    /** todo: 如果队列不为空，那就取出所有的key */
//    public static Enumeration<Integer> getE1StationIds(){
//        Enumeration<Integer> keys = null;
//        if ( CHARGE_E1_STATION_MAP != null ) {
//            keys = CHARGE_E1_STATION_MAP.keys();
//        }
//        return keys;
//    }
//
//    public static void setE1StationMap( Station station ){
//        stationE1Locker.lock();
//        try {
//            CHARGE_E1_STATION_MAP.put(station.getId(),station);
//        } finally {
//            stationE1Locker.unlock();
//        }
//    }
//
//    /** todo: 根据stationId取队列里的数据 */
//    public static Station getE1StationMap(Integer stationId){
//        Station station = null;
//        stationE1Locker.lock();
//        try {
//            station = CHARGE_E1_STATION_MAP.get(stationId);
//        } finally {
//            stationE1Locker.unlock();
//        }
//        return station;
//    }
//
//    public static void removeE1StationMap( Integer stationId ){
//        stationE1Locker.lock();
//        try {
//            CHARGE_E1_STATION_MAP.remove(stationId);
//        } finally {
//            stationE1Locker.unlock();
//        }
//    }
    /** end */








}
