package com.gyee.frame.service.health;

import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.auto.WindTurbineTestingPointAi2;
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.WindTurbineTestingPointAiService;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.golden.EdosUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
@Service
public class HealthMainService {

    @Resource
    private WindTurbineTestingPointAiService windTurbineTestingPointAiService;

    IRealTimeDataBaseUtil realApiUtil = new EdosUtil();
    private final int digit = 2;
    public Map<String, Object> findHealthMatrix() throws Exception {


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

        for (Windpowerstation wp:InitialRunner.wpls) {



                int ysl = 0;// 优数量
                int lsl = 0;// 良数量
                int csl = 0;// 差数量

                List<String[]> wtIdls = new ArrayList<String[]>();// 风机编号集合

                List<Windturbine> wtls = InitialRunner.wp_wtmap.get(wp.getId());


                String[] jkpoints = new String[wtls.size()];
                String[] ztpoints = new String[wtls.size()];

                // 获得训练参数对象
                for (int x = 0; x < wtls.size(); x++) {

                    Windturbine wt=wtls.get(x);

                    WindTurbineTestingPointAi2 jkztpoint =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wt.getId(),Constant.FJJKZZ);
                    jkpoints[x] = jkztpoint.getId();
                    WindTurbineTestingPointAi2 fjztpoint =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wt.getId(),Constant.FJZT);
                    ztpoints[x] = fjztpoint.getId();

                }

                // 获得风机健康状态结果数组
                List<PointData> jkvalues = realApiUtil.getRealData(jkpoints);
                // 获得风机实时状态结果数组
                List<PointData> ztvalues = realApiUtil.getRealData(ztpoints);


                Calendar cal2 = Calendar.getInstance();
                Date end = cal2.getTime();
                cal2.add(Calendar.DAY_OF_MONTH, -1);
                Date begin = cal2.getTime();
                for (int x = 0; x < wtls.size(); x++) {
                    String wtId = wtls.get(x).getId();
                    double jk = jkvalues.get(x).getPointValueInDouble();
                    double zt = ztvalues.get(x).getPointValueInDouble();


                    if (zt == 2.0) {

                        String[] str = new String[2];
                        str[0] = wtId;
                        str[1] = "3";
                        wtIdls.add(str);
                        csl++;
                    } else {
                        String[] str = new String[2];
                        if (jk >= 60) {
                            str[0] = wtId;
                            str[1] = "1";
                            wtIdls.add(str);
                            ysl++;
                        } else if (jk < 60  && jk >= 30) {
                            str[0] = wtId;
                            str[1] = "2";
                            wtIdls.add(str);
                            lsl++;
                        } else {
                            str[0] = wtId;
                            str[1] = "3";
                            wtIdls.add(str);
                            csl++;
                        }

                    }

                }

                map.put(wp.getId() + "_csl", csl);
                map.put(wp.getId() + "_lsl", lsl);
                map.put(wp.getId() + "_ysl", ysl);
                map.put(wp.getId() + "_wtIdls", wtIdls);

        }

        return map;
    }
}
