package com.gyee.alarm.util.statisticcs;

import com.gyee.common.contant.Contant;
import com.gyee.common.model.PointData;
import com.gyee.alarm.model.auto.ProBasicEquipment;
import com.gyee.alarm.model.auto.ProBasicPowerstationPoint;
import com.gyee.alarm.model.vo.StatusItemVo;

import java.util.*;

public abstract class StatusStatistics {
    private static Map<Integer, String> statusToUniformCode = new HashMap<Integer, String>();

    static  {
        statusToUniformCode.put(0, Contant.DJTS);
        statusToUniformCode.put(1, Contant.YXTS);
        statusToUniformCode.put(2, Contant.GZTJ);
        statusToUniformCode.put(3, Contant.TXZD);
        statusToUniformCode.put(4, Contant.WHTJ);

         //   #region 新增限电台数
        statusToUniformCode.put(5, Contant.XDTS);
        statusToUniformCode.put(6, Contant.XDTS);

    }

    protected Map<String, Map<String, StatusItemVo>> dic = new HashMap<String, Map<String, StatusItemVo>>();
    protected Map<String, ProBasicEquipment> windTurbines;
    protected Date date;

    public StatusStatistics(Map<String, ProBasicEquipment> windTurbines, Date date) {
        this.windTurbines = windTurbines;
        this.date = date;
    }

    public void addInitData(ProBasicPowerstationPoint wpstp) {
        Map<String, StatusItemVo> items = null;
        if (dic.containsKey(wpstp.getWindpowerstationId())) {
            items = dic.get(wpstp.getWindpowerstationId());
        } else {
            items = new HashMap<String, StatusItemVo>();
            dic.put(wpstp.getWindpowerstationId(), items);
        }
            //#region EDNA转EDOS
        //StatusItemVo item = new StatusItemVo { UniformCode = wpstp.UNIFORMCODE, EdnaPoint = wpstp.SHORTID, EdnaValue = 0, size = 0 };
        StatusItemVo item = new StatusItemVo();
        item.setUniformCode(wpstp.getUniformCode());
        item.setEdnaValue(0.0);
        item.setEdnaPoint(wpstp.getNemCode());
        item.setCount(0.0);


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

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

        if (!statusToUniformCode.containsKey(value.intValue())){
            return;
        }


        if (dic.containsKey(wt.getWindpowerstationId()) && dic.get(wt.getWindpowerstationId()).containsKey(statusToUniformCode.get(value.intValue()))) {

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

        }
        if (dic.containsKey(wt.getLineId()) && dic.get(wt.getLineId()).containsKey(statusToUniformCode.get(value.intValue()))) {

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

        }
        if (dic.containsKey(wt.getProjectId()) && dic.get(wt.getProjectId()).containsKey(statusToUniformCode.get(value.intValue()))) {

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

        }
        if (dic.containsKey("0") && dic.get("0").containsKey(statusToUniformCode.get(value.intValue()))) {

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

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

                Map<String, StatusItemVo> tempmap=dic.get("-1");
                Double tempvalue= tempmap.get(statusToUniformCode.get(value.intValue())).getEdnaValue();
                tempvalue++;
                tempmap.get(statusToUniformCode.get(value.intValue())).setEdnaValue(tempvalue);
            }
        } else {
            if (dic.containsKey("-2") && dic.get("-2").containsKey(statusToUniformCode.get(value.intValue()))) {

                Map<String, StatusItemVo> tempmap=dic.get("-2");
                Double tempvalue= tempmap.get(statusToUniformCode.get(value.intValue())).getEdnaValue();
                tempvalue++;
                tempmap.get(statusToUniformCode.get(value.intValue())).setEdnaValue(tempvalue);
            }
        }


    }

    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);
                PointData p = new PointData();
                p.setPointValueInDouble(item.getEdnaValue());
                p.setEdnaId(item.getEdnaPoint());
                p.setPointTime(date.getTime()/1000);
                retValue.add(p);
            }
        }
        return retValue;
    }

    public abstract void addPointValue(String windTurbineId, double value);
}