package com.gyee.generation.util.statisticcs;

import com.gyee.common.contant.Contant;
import com.gyee.common.model.PointData;
import com.gyee.generation.model.auto.ProBasicEquipment;
import com.gyee.generation.model.auto.ProBasicEquipmentPoint;
import com.gyee.generation.model.vo.StatusItemVo;

import java.util.*;

public class TheoryPowerStatistics extends StatusStatistics {

    public TheoryPowerStatistics(Map<String, ProBasicEquipment> windTurbines, Date date) {
        super(windTurbines, date);
    }

    protected Map<String, Map<String, StatusItemVo>> dicWindturbine = new HashMap<String, Map<String, StatusItemVo>>();

    public void addPointValue(String windTurbineId, double value, String powerKey) {
        ProBasicEquipment wt = windTurbines.get(windTurbineId);


        if (dic.containsKey(wt.getWindpowerstationId()) && dic.get(wt.getWindpowerstationId()).containsKey(Contant.SSZGL)) {

            Map<String, StatusItemVo> tempmap = dic.get(wt.getWindpowerstationId());
            Double tempvalue = tempmap.get(Contant.SSZGL).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSZGL).setEdnaValue(tempvalue);


        }
        if (dic.containsKey(wt.getLineId()) && dic.get(wt.getLineId()).containsKey(Contant.SSZGL)) {

            Map<String, StatusItemVo> tempmap = dic.get(wt.getLineId());
            Double tempvalue = tempmap.get(Contant.SSZGL).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSZGL).setEdnaValue(tempvalue);


        }
        if (dic.containsKey(wt.getProjectId()) && dic.get(wt.getProjectId()).containsKey(Contant.SSZGL)) {

            Map<String, StatusItemVo> tempmap = dic.get(wt.getProjectId());
            Double tempvalue = tempmap.get(Contant.SSZGL).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSZGL).setEdnaValue(tempvalue);


        }
        if (dic.containsKey("0") && dic.get("0").containsKey(Contant.SSZGL)) {

            Map<String, StatusItemVo> tempmap = dic.get("0");
            Double tempvalue = tempmap.get(Contant.SSZGL).getEdnaValue();
            tempvalue++;
            tempmap.get(Contant.SSZGL).setEdnaValue(tempvalue);


        }
        if (wt.getWindpowerstationId().indexOf("FDC") >= 0) {
            if (dic.containsKey("-1") && dic.get("-1").containsKey(Contant.SSZGL)) {

                Map<String, StatusItemVo> tempmap = dic.get("-1");
                Double tempvalue = tempmap.get(Contant.SSZGL).getEdnaValue();
                tempvalue++;
                tempmap.get(Contant.SSZGL).setEdnaValue(tempvalue);

            }
        } else {
            if (dic.containsKey("-2") && dic.get("-2").containsKey(Contant.SSZGL)) {

                Map<String, StatusItemVo> tempmap = dic.get("-2");
                Double tempvalue = tempmap.get(Contant.SSZGL).getEdnaValue();
                tempvalue++;
                tempmap.get(Contant.SSZGL).setEdnaValue(tempvalue);

            }
        }

    }


    public void addInitWindTrubineData(ProBasicEquipmentPoint ais) {
        Map<String, StatusItemVo> items = null;
        if (dicWindturbine.containsKey(ais.getWindturbineId())) {
            items = dicWindturbine.get(ais.getWindturbineId());
        } else {
            items = new HashMap<String, StatusItemVo>();
            dicWindturbine.put(ais.getWindturbineId(), items);
        }

        StatusItemVo item = new StatusItemVo();
        item.setUniformCode(ais.getUniformCode());
        item.setEdnaValue(0.0);
        item.setEdnaPoint(ais.getNemCode());
        item.setCount(0.0);


        items.put(item.getUniformCode(), item);
    }

    public void addWindturbinePointValue(String windTurbineId, double value, String powerKey) {
        if (dicWindturbine.containsKey(windTurbineId)) {
            dicWindturbine.get(windTurbineId).get(powerKey).setEdnaValue(value);
        }
    }

    @Override
    public List<PointData> getRealParameter() {
        java.util.List<PointData> retValue = new ArrayList<PointData>();
        for (String mkey : dic.keySet()) {
            for (String skey : dic.get(mkey).keySet()) {
                StatusItemVo item = dic.get(mkey).get(skey);

                if (item.getCount() != 0) {
                    PointData p = new PointData();

                    p.setPointValueInDouble(item.getEdnaValue());
                    p.setEdnaId(item.getEdnaPoint());
                    p.setPointTime(date.getTime() / 1000);
                    retValue.add(p);
                }
            }
        }


        for (String mkey : dic.keySet()) {
            for (String skey : dic.get(mkey).keySet()) {
                StatusItemVo item = dic.get(mkey).get(skey);
                PointData p = new PointData();

                p.setPointValueInDouble(item.getEdnaValue());
                p.setEdnaId(item.getEdnaPoint());
                p.setPointTime(date.getTime() / 1000);
                retValue.add(p);
            }
        }
        for (String mkey : dicWindturbine.keySet()) {
            for (String skey : dicWindturbine.get(mkey).keySet()) {
                StatusItemVo item = dicWindturbine.get(mkey).get(skey);
                PointData p = new PointData();

                p.setPointValueInDouble(item.getEdnaValue());
                p.setEdnaId(item.getEdnaPoint());
                p.setPointTime(date.getTime() / 1000);
                retValue.add(p);
            }
        }
        return retValue;
    }

    @Override
    public void addPointValue(String windTurbineId, double value) {

    }

}
