package com.gyee.frame.service.comm;


import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.auto.Windpowerstation;
import com.gyee.frame.model.auto.Windturbine;
import com.gyee.frame.model.custom.PointData;
import com.gyee.frame.service.PushMessageService;
import com.gyee.frame.service.WindPowerstationTestingPoint2Service;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.MathUtil;
import com.gyee.frame.util.RealTimeDataBaseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 推送全场重要消息
 */
@Service
public class FullPushMsgService {

    @Autowired
    private PushMessageService pushMessageService;

    @Resource
    private WindPowerstationTestingPoint2Service windPowerstationTestingPoint2Service;

    IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();

    public Map<String, Object> addPushMsg() {


        try {
            Map<String, Object> jczbmap = new HashMap<>();
            for (Windpowerstation wp : InitialRunner.wpls) {
                List<Windturbine> wtls = InitialRunner.wp_wtmap.get(wp.getId());//场站设备数量
                List<String> jczbls = new ArrayList<>();
                //离线台数
                jczbls.add(windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.TPOINT_WT_TXZD).getCode());
                realApiUtil.getRealData(windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.TPOINT_WT_TXZD).getCode());
                List<PointData> jczblist = realApiUtil.getRealData(jczbls);
                //离线台数
                Double lxts = MathUtil.twoBit(jczblist.get(0).getPointValueInDouble());
                if(wtls.size() == lxts.intValue()){
                    jczbmap.put("wp_lx", wp.getName()+"全场离线");
                }


            }

            return jczbmap;
        } catch (Exception e) {
            return null;
        }


    }
}
