package com.gyee.frame.service.websocket;


import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.model.auto.WindPowerStationTestingPoint;
import com.gyee.frame.model.custom.DataVo;
import com.gyee.frame.model.custom.PointData;
import com.gyee.frame.service.ProjectPlanService;
import com.gyee.frame.service.WindPowerstationTestingPoint2Service;
import com.gyee.frame.service.WindpowerinfodayService;
import com.gyee.frame.service.WindpowerstationthewindinfoService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.RealTimeDataBaseFactory;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class CftInfoPushService {


    @Resource
    private WindPowerstationTestingPoint2Service windPowerstationTestingPoint2Service;
    @Resource
    private WindpowerinfodayService windpowerinfodayService;
    @Resource
    private ProjectPlanService projectPlanService;
    @Resource
    private WindpowerstationthewindinfoService windpowerstationthewindinfoService;
    @Resource
    private RealPowerPushService realPowerPushService;
    IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();



    public Map<String, Object> genreSetMap() throws Exception {

        Map<String, Object> map = new HashMap<>();

        map.put("MHS_FDC",findCftInfo("MHS_FDC"));
        map.put("NSS_FDC",findCftInfo("NSS_FDC"));
        map.put("QS_FDC",findCftInfo("QS_FDC"));
        map.put("SBQ_FDC",findCftInfo("SBQ_FDC"));
        map.put("XS_FDC",findCftInfo("XS_FDC"));

       return map;

    }

    public Map<String, Object> findCftInfo(String id) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        if (StringUtils.notEmp(id)) {




/*************************************************测风塔*************************************************************/

            Map<String, Double> cftmap = new HashMap<>();
            String[] cftstrs=Constant.TPOINT_WP_CFT;

            for(int i=0;i<cftstrs.length;i++)
            {
                WindPowerStationTestingPoint point2 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(id, cftstrs[i]);

                if(StringUtils.notEmp(point2.getCode()))
                {
                    PointData value = realApiUtil.getRealData(point2);
                    cftmap.put(cftstrs[i],StringUtils.round(value.getPointValueInDouble(),2));
                }
            }

            map.put("cftmap", cftmap);
/*************************************************测风塔*************************************************************/


            List<DataVo> glvos =realPowerPushService.findRealPower(id);
            map.put("glvos", glvos);

/*************************************************关系库指标**************************************************************/

            Calendar cal = Calendar.getInstance();


            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);

            cal.add(Calendar.HOUR_OF_DAY, -1);

            Date date = cal.getTime();

            Map<String, Object> rmgtmap = new HashMap<>();

            rmgtmap=windpowerstationthewindinfoService.wprfxpl(id,DateUtils.format(date));
            
            map.put("rmgtmap", rmgtmap);


            Map<String, Object> ymgtmap = new HashMap<>();

            ymgtmap=windpowerstationthewindinfoService.wpyfxpl(id,DateUtils.format(date));

            map.put("ymgtmap", ymgtmap);
        }
/*************************************************关系库指标**************************************************************/

        return map;
    }






}


