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.*;
import com.gyee.frame.model.custom.*;
import com.gyee.frame.service.*;
import com.gyee.frame.util.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class HealthSubService {

    @Resource
    private WindTurbineTestingPointAiService windTurbineTestingPointAiService;
    @Resource
    private FailurestatisticsmainService failurestatisticsmainService;
    @Resource
    private EarlywarningmainService earlywarningmainService;
    @Resource
    private PartstatisticsmainService partstatisticsmainService;
    @Resource
    private Daylygradeassessmentmain2Service daylygradeassessmentmain2Service;
    @Resource
    private Monthlygradeassessmentmain2Service monthlygradeassessmentmain2Service;
    @Resource
    private ShutdowneventService shutdowneventService;
    @Resource
    private StatejudgmentrecordService statejudgmentrecordService;
    @Resource
    private CurvefittingsubService curvefittingsubService;
    @Resource
    private ParttemperaturesubService parttemperaturesubService;
    @Resource
    private Statejudgmentrecord2Service statejudgmentrecord2Service;
    @Resource
    private DailyratingmainService dailyratingmainService;


    private final int digit = 2;
    private final double NUM = 3.6;
    private final double XZNUM = 1.25;
    IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();
    /*********************************************风机明细页面******************************************************/

    /**
     * 获取故障类型和风机健康得分
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public Map<String, String> findWtInfo(String wtId) throws Exception {

        Map<String, String> map = new HashMap<String, String>();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);

        Date endDate = cal.getTime();
        cal.add(Calendar.MONTH, -6);
        Date beginDate = cal.getTime();


        if (StringUtils.notEmp(wtId)) {

            List<Statejudgmentrecord2> sdls = statejudgmentrecord2Service.findStatejudgmentrecord2(wtId);

            if (!sdls.isEmpty()) {
                Statejudgmentrecord2 stpo = sdls.get(0);

                map.put("top1type", stpo.getPart1());
                map.put("top2type", stpo.getPart2());
                map.put("top3type", stpo.getPart3());
            } else {
                map.put("top1type", "");
                map.put("top2type", "");
                map.put("top3type", "");
            }


            double score = getWtScore(wtId);
            map.put("wtscore", String.valueOf(StringUtils.round(score, 2)));

        }


        return map;
    }


    private double getWtScore(String wtId) throws Exception {

        double score = 0.0;
        if (StringUtils.notEmp(wtId)) {
            String pointid = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FJJKZZ).getId();
            PointData po = realApiUtil.getRealData(pointid);
            score = po.getPointValueInDouble();

        }
        return score;
    }

    /**
     * 获取健康管理风机部件基础信息
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public Map<String, Map<String, Object>> findPartHealthInfo(String wtId) throws Exception {

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

        Map<String, Object> clxmap = new HashMap<>();
        Map<String, Object> fdjmap = new HashMap<>();
        Map<String, Object> bjmap = new HashMap<>();
        Map<String, Object> zkmap = new HashMap<>();
        Map<String, Object> zzmap = new HashMap<>();
        Map<String, Object> phmap = new HashMap<>();
        Map<String, Object> jcmap = new HashMap<>();
        Map<String, Object> bpqmap = new HashMap<>();
        Map<String, Object> fjmap = new HashMap<>();

        int totalscore = 0;

        // 获得风机健康状态结果数组
        String[] jkpoints = new String[5];

        WindTurbineTestingPointAi ai = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.CLXJKZT);
        jkpoints[0] = ai.getId();
        ai = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FDJJKZT);
        jkpoints[1] = ai.getId();
        ai = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.BJJKZT);
        jkpoints[2] = ai.getId();
        ai = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.ZKJKZT);
        jkpoints[3] = ai.getId();
        ai = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FJJKZT);
        jkpoints[4] = ai.getId();

        DNAVal[] ssjkvalues = realApiUtil.getRealtimeTagValues(jkpoints);


        clxmap.put("jkzt", String.valueOf(ssjkvalues[0].DValue));
        fdjmap.put("jkzt", String.valueOf(ssjkvalues[1].DValue));
        bjmap.put("jkzt", String.valueOf(ssjkvalues[2].DValue));
        zkmap.put("jkzt", String.valueOf(ssjkvalues[3].DValue));
        fjmap.put("jkzt", String.valueOf(ssjkvalues[4].DValue));


        totalscore = calScore(totalscore, ssjkvalues[0].DValue);
        totalscore = calScore(totalscore, ssjkvalues[1].DValue);
        totalscore = calScore(totalscore, ssjkvalues[2].DValue);
        totalscore = calScore(totalscore, ssjkvalues[3].DValue);


        zzmap.put("jkzt", "1.0");
        phmap.put("jkzt", "1.0");
        jcmap.put("jkzt", "1.0");
        bpqmap.put("jkzt", "1.0");


        Windturbine wt = InitialRunner.wtmap.get(wtId);

        int smlv = 0;

        if (StringUtils.notEmp(wt.getFirstintegratedtime())) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(wt.getFirstintegratedtime());
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);

            Date beginDate = cal.getTime();
            cal.add(Calendar.YEAR, 9);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            Date endDate = cal.getTime();
            // 获得开始使用到设备报废的小时
            double smsj = DateUtils.hoursDiff(beginDate, endDate);
            cal = Calendar.getInstance();
            cal.setTime(wt.getFirstintegratedtime());
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);

            beginDate = cal.getTime();
            cal = Calendar.getInstance();
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            endDate = cal.getTime();
            // 当前使用时间小时
            double syxs = DateUtils.daysDiff(beginDate, endDate);

            // 寿命使用率
            smlv = 100 - new BigDecimal(syxs).divide(new BigDecimal(smsj), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).intValue();
        } else {
            smlv = 100;
        }

        clxmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.98)));
        fdjmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.95)));
        bjmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.96)));
        zkmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.97)));
        zzmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.91)));
        phmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.94)));
        jcmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.93)));
        bpqmap.put("smsyl", String.valueOf(MathUtil.twoBit(smlv * 0.92)));

        int fjsmlv = new BigDecimal(totalscore).divide(new BigDecimal(32), 0, RoundingMode.HALF_EVEN).intValue();

        fjmap.put("smsyl", String.valueOf(fjsmlv));


        map.put("clx", clxmap);
        map.put("fdj", fdjmap);
        map.put("bj", bjmap);
        map.put("zk", zkmap);
        map.put("zz", zzmap);
        map.put("ph", phmap);
        map.put("jc", jcmap);
        map.put("bpq", bpqmap);

        map.put("fj", fjmap);


        return map;
    }

    private int calScore(int total, double score) {
        if (score == 1) {
            total = total + 4;
        } else if (score == 2) {
            total = total + 3;
        } else if (score == 3) {
            total = total + 2;
        } else if (score == 4) {
            total = total + 1;
        }

        return total;
    }

    /**
     * 故障数据统计
     *
     * @param wtId
     * @param recodedate
     * @return
     */
    public List<GzfxVo> initalGzjfx(String wtId, Date recodedate) {
        List<Failurestatisticsmain> ewls = failurestatisticsmainService.getFailurestatisticsmainListBywtId(wtId, recodedate);
        List<GzfxVo> ls = new ArrayList<GzfxVo>();
        if (!ewls.isEmpty()) {
            Failurestatisticsmain po = ewls.get(0);
            GzfxVo vo1 = new GzfxVo();
            vo1.setName("1天故障数据分析");
            vo1.setTop1gzname(po.getDay1top1name());
            vo1.setTop1gznum(po.getDay1top1());
            vo1.setTop2gzname(po.getDay1top2name());
            vo1.setTop2gznum(po.getDay1top2());
            vo1.setTop3gzname(po.getDay1top3name());
            vo1.setTop3gznum(po.getDay1top3());
            ls.add(vo1);

            GzfxVo vo2 = new GzfxVo();
            vo2.setName("3天故障数据分析");
            vo2.setTop1gzname(po.getDay3top1name());
            vo2.setTop1gznum(po.getDay3top1());
            vo2.setTop2gzname(po.getDay3top2name());
            vo2.setTop2gznum(po.getDay3top2());
            vo2.setTop3gzname(po.getDay3top3name());
            vo2.setTop3gznum(po.getDay3top3());
            ls.add(vo2);
        }
        return ls;
    }

    /**
     * 预警数据统计
     *
     * @param wtId
     * @param recodedate
     * @return
     */
    public List<YjfxVo> initalYjfx(String wtId, Date recodedate) {
        List<Earlywarningmain> ewls = earlywarningmainService.getEarlywarningmainListBywtId(wtId, recodedate);
        List<YjfxVo> ls = new ArrayList<YjfxVo>();
        if (!ewls.isEmpty()) {
            Earlywarningmain po = ewls.get(0);
            YjfxVo vo1 = new YjfxVo();
            vo1.setName("1天预警数据分析");
            vo1.setTop1gzname(po.getDay1top1name());
            vo1.setTop1gznum(po.getDay1top1());
            vo1.setTop2gzname(po.getDay1top2name());
            vo1.setTop2gznum(po.getDay1top2());
            vo1.setTop3gzname(po.getDay1top3name());
            vo1.setTop3gznum(po.getDay1top3());
            ls.add(vo1);

            YjfxVo vo2 = new YjfxVo();
            vo2.setName("3天预警数据分析");
            vo2.setTop1gzname(po.getDay3top1name());
            vo2.setTop1gznum(po.getDay3top1());
            vo2.setTop2gzname(po.getDay3top2name());
            vo2.setTop2gznum(po.getDay3top2());
            vo2.setTop3gzname(po.getDay3top3name());
            vo2.setTop3gznum(po.getDay3top3());
            ls.add(vo2);
        }
        return ls;
    }

    /**
     * 部件运行数据
     *
     * @param wtId
     * @param recodedate
     * @return
     */
    public List<YxfxVo> initalYxfx(String wtId, Date recodedate) {
        List<Partstatisticsmain> psls = partstatisticsmainService.getPartstatisticsmainListBywtId(wtId, recodedate);
        List<YxfxVo> ls = new ArrayList<YxfxVo>();
        if (!psls.isEmpty()) {

            Partstatisticsmain po = psls.get(0);
            int day1fdj = po.getDay1fdj();
            int day1clx = po.getDay1clx();
            int day1zz = po.getDay1zz();
            int day1bj = po.getDay1bj();
            int day1ph = po.getDay1ph();
            int day1jc = po.getDay1jc();
            int day1bpq = po.getDay1bpq();
            int day1zk = po.getDay1zk();

            int day3fdj = po.getDay3fdj();
            int day3clx = po.getDay3clx();
            int day3zz = po.getDay3zz();
            int day3bj = po.getDay3bj();
            int day3ph = po.getDay3ph();
            int day3jc = po.getDay3jc();
            int day3bpq = po.getDay3bpq();
            int day3zk = po.getDay3zk();

            YxfxVo vo1 = new YxfxVo();
            vo1.setName("1天运行数据分析");
            vo1.setNumbj(day1bj);
            vo1.setNumbpq(day1bpq);
            vo1.setNumclx(day1clx);
            vo1.setNumfdj(day1fdj);
            vo1.setNumjc(day1jc);
            vo1.setNumph(day1ph);
            vo1.setNumzk(day1zk);
            vo1.setNumzz(day1zz);

            ls.add(vo1);

            YxfxVo vo2 = new YxfxVo();
            vo2.setName("3天运行数据分析");
            vo2.setNumbj(day3bj);
            vo2.setNumbpq(day3bpq);
            vo2.setNumclx(day3clx);
            vo2.setNumfdj(day3fdj);
            vo2.setNumjc(day3jc);
            vo2.setNumph(day3ph);
            vo2.setNumzk(day3zk);
            vo2.setNumzz(day3zz);

            ls.add(vo2);
        }
        return ls;
    }

    /**
     * 获得日、月等级评估
     *
     * @param cal
     * @param wtId
     * @return
     */
    public List<XnfxVo> initalXnfx(String wtId, Calendar cal) {

        List<XnfxVo> ls = new ArrayList<XnfxVo>();


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

        List<Dailyratingmain> day1ls = dailyratingmainService.getDaylygradeassessmentmain2ListBywtId(wtId, DateUtils.truncate(cal.getTime()));
        if (!day1ls.isEmpty()) {
            Dailyratingmain top = day1ls.get(0);
            XnfxVo vo = new XnfxVo();
            vo.setName("日等级评估数据分析");
            vo.setLevelname(top.getGrade());
            vo.setTopnum(top.getScore().intValue());
            ls.add(vo);
        }


        String year = String.valueOf(cal.get(Calendar.YEAR));
        int m = cal.get(Calendar.MONTH);
        String month = null;
        if ((m + 1) < 10) {
            StringBuilder sb = new StringBuilder();
            sb.append("0").append(m + 1);
            month = String.valueOf(sb);
        } else {
            month = String.valueOf(m + 1);
        }


        List<Monthlygradeassessmentmain2> day3ls = monthlygradeassessmentmain2Service.getMonthlygradeassessmentmain2ListBywtId(wtId, year, month);
        if (!day3ls.isEmpty()) {
            Monthlygradeassessmentmain2 top = day3ls.get(0);
            XnfxVo vo = new XnfxVo();
            vo.setName("月等级评估数据分析");
            vo.setLevelname(top.getModlevel());
            vo.setTopnum(top.getModscore().intValue());
            ls.add(vo);
        }
        return ls;
    }

    /**
     * 获得当日停机事件
     *
     * @param wtId
     * @return
     */
    public List<ShutdowneventVo> initalShutdown(String wtId) {

        List<ShutdowneventVo> vos = new ArrayList<>();

        if (StringUtils.notEmp(wtId)) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);

            Date beginDate = cal.getTime();
            cal.add(Calendar.DAY_OF_MONTH, 1);
            Date endDate = cal.getTime();

            vos = shutdowneventService.queryEvents(null, wtId, beginDate, endDate, null);
        }

        return vos;
    }

    /**
     * 获得健康评价列表
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public List<ValueVo> findJudgmentList(String wtId) throws Exception {

        List<ValueVo> vols = new ArrayList<ValueVo>();

        if (StringUtils.notEmp(wtId)) {


            List<Statejudgmentrecord> ls = statejudgmentrecordService.getStatejudgmentrecordListBywtId(wtId);


            if (!ls.isEmpty()) {
                String[] str = ls.get(0).getStatejudgment().split("-");
                if (str.length == 4) {
                    ValueVo vo1 = new ValueVo();
                    ValueVo vo2 = new ValueVo();
                    ValueVo vo3 = new ValueVo();
                    ValueVo vo4 = new ValueVo();


                    vo1.setName("运行状态为故障！");
                    vo2.setName("风机部件温度超出合理值范围！");
                    vo3.setName("性能损失率连续三天大于基准值");
                    vo4.setName("曲线偏差率率连续三天大于基准值");


                    setScoreValue(str[0], vo1);
                    setScoreValue(str[1], vo2);
                    setScoreValue(str[2], vo3);
                    setScoreValue(str[3], vo4);


                    vols.add(vo1);
                    vols.add(vo2);
                    vols.add(vo3);
                    vols.add(vo4);

                }
            }

        }
        return vols;

    }

    private void setScoreValue(String str, ValueVo vo1) {
        if (str.equals("1")) {
            vo1.setValue("进行扣分处理！");
        } else {
            vo1.setValue("未扣分！");
        }
    }

    /**
     * 各个区间曲线偏差率
     *
     * @param wtId
     * @return
     */
    public List<QxpcVo> findQxpcList(String wtId) {

        List<QxpcVo> ls = new ArrayList<QxpcVo>();
        Map<String, List<Curvefittingsub>> cfmap = new HashMap<>();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, -1);
        if (StringUtils.notEmp(wtId)) {

            Windturbine wt = InitialRunner.wtmap.get(wtId);
            QxpcVo vo = new QxpcVo();
            cfmap = curvefittingsubService.findCurvefittingmapByDate(cal.getTime(), wtId, 3.0, 5.0);
            double qxpc1 = curvefittingsubService.getNuberValue(cfmap, wt);
            cfmap = curvefittingsubService.findCurvefittingmapByDate(cal.getTime(), wtId, 5.0, 11.0);
            double qxpc2 = curvefittingsubService.getNuberValue(cfmap, wt);
            cfmap = curvefittingsubService.findCurvefittingmapByDate(cal.getTime(), wtId, 11.0, 25.0);
            double qxpc3 = curvefittingsubService.getNuberValue(cfmap, wt);
            vo.setQxpc1(qxpc1);
            vo.setQxpc2(qxpc2);
            vo.setQxpc3(qxpc3);
            ls.add(vo);
        }


        return ls;
    }

    /**
     * 温度范围
     *
     * @param wtId
     * @return
     */
    public List<YxfxVo> findWdList(String wtId) {

        List<Parttemperaturesub> ls = new ArrayList<Parttemperaturesub>();
        List<YxfxVo> vos = new ArrayList<>();
        Calendar cal = Calendar.getInstance();
        Date recodedate = DateUtils.truncate(cal.getTime());
        if (StringUtils.notEmp(wtId)) {

            ls = parttemperaturesubService.getParttemperaturesubListBywtId(wtId, recodedate);
            vos = parttemperaturesubService.getListValue(ls);
        }


        return vos;
    }
    /**********************************************风机明细页面*****************************************************/
    /**********************************************风机明细页面*****************************************************/
    /**
     * 获得等级评估前5数据
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public Map<String, Object> gadaytop5(String wtId) throws Exception {


        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        Date endDate = cal.getTime();
        cal.add(Calendar.MONTH, -1);
        Date beginDate = cal.getTime();


        List<Dailyratingmain> ls = dailyratingmainService.getDaylygradeassessmentmain2ListBywtId(wtId, beginDate, endDate);
        Map<String, Object> map = new HashMap<String, Object>();
        int num = 1;
        for (Dailyratingmain top : ls) {
            if (num <= 5) {
                String[] str = new String[5];
                str[0] = String.valueOf(top.getId());
                str[1] = DateUtils.format(top.getRecorddate());
                str[2] = String.valueOf(top.getGrade());
                str[3] = String.valueOf(top.getWpid());
                str[4] = String.valueOf(top.getWtid());
                map.put(String.valueOf(num), str);
                num++;
            } else {
                break;
            }
        }


        return map;
    }

    /**
     * 获取最新的十次停机事件
     *
     * @param wtId
     * @return
     */
    public List<ShutdowneventVo> queryStopTop10(String wtId) {

        List<ShutdowneventVo> vos = shutdowneventService.queryStopTop10(wtId);


        return vos;
    }

    /**
     * 获得实际功率和理论功率曲线
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public Map<String, Object[]> findPowerChar(String wtId) throws Exception {

        Map<String, Object[]> resultmap = new HashMap<String, Object[]>();

        Integer[] begin = new Integer[3];
        Integer[] end = new Integer[3];

        Calendar cal = Calendar.getInstance();

        //        cal.set(Calendar.HOUR_OF_DAY, 0);


        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND,0);
        Date beginDate = cal.getTime();

        begin[0] = cal.get(Calendar.YEAR);
        begin[1] = cal.get(Calendar.MONTH);
        begin[2] = cal.get(Calendar.DAY_OF_MONTH);

        cal.add(Calendar.DAY_OF_MONTH,1);

        end[0] = cal.get(Calendar.YEAR);
        end[1] = cal.get(Calendar.MONTH);
        end[2] = cal.get(Calendar.DAY_OF_MONTH);
        Date endDate = cal.getTime();

        int length = DateUtils.minutesDiff(beginDate,endDate)/3;
        Double[] sjglarr = new Double[length];
        Double[] llglarr = new Double[length];
        Double[] sjfsarr = new Double[length];
        Long[] timearr = new Long[length];

        cal = Calendar.getInstance();
        cal.setTime(beginDate);
        for(int i=0;i<length;i++)
        {
            timearr[i]=cal.getTime().getTime();
            cal.add(Calendar.MINUTE,3);
        }
        WindTurbineTestingPointAi sjgl = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.TPOINT_WT_FJGL);

        List<PointData> sjglls = realApiUtil.getHistoryDatasSnap(sjgl, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 180L);

        if (!sjglls.isEmpty()) {
            for (int i = 0; i < sjglls.size() ; i++) {
               // timearr[i]=sjglls.get(i).getPointTime()*1000;
                sjglarr[i] = MathUtil.twoBit(sjglls.get(i).getPointValueInDouble());
            }
        }
        WindTurbineTestingPointAi llgl = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.TPOINT_WT_LLGL);

        List<PointData> llglls = realApiUtil.getHistoryDatasSnap(llgl, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 180L);

        if (!llglls.isEmpty()) {
            for (int i = 0; i < llglls.size() ; i++) {
                llglarr[i] = MathUtil.twoBit(llglls.get(i).getPointValueInDouble());
            }
        }

        WindTurbineTestingPointAi ssfs = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.TPOINT_WT_FJSSFS);

        List<PointData> ssfsls = realApiUtil.getHistoryDatasSnap(ssfs, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 180L);

        if (!ssfsls.isEmpty()) {
            for (int i = 0; i < ssfsls.size() ; i++) {
                sjfsarr[i] = MathUtil.twoBit(ssfsls.get(i).getPointValueInDouble());
            }
        }

        resultmap.put("sjgl", sjglarr);
        resultmap.put("llgl", llglarr);
        resultmap.put("ssfs", sjfsarr);
        resultmap.put("timearr", timearr);

        resultmap.put("begin", begin);
        resultmap.put("end", end);

        return resultmap;
    }

    private String selectCol(String value)
    {
        String col="#05bb4c";

        switch (value) {
            case "1.0":
                col="#05bb4c";
                break;
            case "2.0":
                col="#4b55ae";
                break;
            case "3.0":
                col="#edbf03";
                break;
            case "4.0":
                col="#e17e23";
                break;

            default:
                break;
        }

        return col;
    }
    /**
     * 数组 0健康状态、1部件名称 2 7天健康状态 3 故障进度 4 mtbf 5 mttr 6损失电量
     * @param wtId
     * @return获取风机部件MTTR和MTBF
     * @throws Exception
     */
    public Map<String, Object> getWtMttrandMtbfByBj(String wtId) throws Exception {

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

        String[] clxstrs = new String[8];
        String[] fdjstrs = new String[8];
        String[] bjstrs = new String[8];
        String[] zkstrs = new String[8];

        String[] zzstrs = new String[8];
        String[] phstrs = new String[8];
        String[] jcstrs = new String[8];
        String[] bpqstrs = new String[8];

        // 获得风机健康状态结果数组
        String[] jkpoints = new String[4];

        WindTurbineTestingPointAi clx = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.CLXJKZT);
        WindTurbineTestingPointAi fdj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FDJJKZT);
        WindTurbineTestingPointAi bj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.BJJKZT);
        WindTurbineTestingPointAi zk = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.ZKJKZT);

        jkpoints[0] = clx.getId();
        jkpoints[1] = fdj.getId();
        jkpoints[2] = bj.getId();
        jkpoints[3] = zk.getId();

        DNAVal[] ssjkvalues = realApiUtil.getRealtimeTagValues(jkpoints);


        clxstrs[0] = selectCol(String.valueOf(ssjkvalues[0].DValue));
        fdjstrs[0] = selectCol(String.valueOf(ssjkvalues[1].DValue));
        bjstrs[0] = selectCol(String.valueOf(ssjkvalues[2].DValue));
        zkstrs[0] = selectCol(String.valueOf(ssjkvalues[3].DValue));

        zzstrs[0] = selectCol(String.valueOf(1.0));;
        phstrs[0] = selectCol(String.valueOf(1.0));;
        jcstrs[0] = selectCol(String.valueOf(1.0));;
        bpqstrs[0] =selectCol(String.valueOf(1.0));;

        StringBuilder clxsb = new StringBuilder();
        StringBuilder fdjsb = new StringBuilder();
        StringBuilder bjsb = new StringBuilder();
        StringBuilder zksb = new StringBuilder();
        Calendar cal = Calendar.getInstance();

        cal.add(Calendar.DAY_OF_MONTH, -7);
        for (int i = 0; i < 7; i++) {
            int recodeDate = new BigDecimal(cal.getTime().getTime()).divide(new BigDecimal(1000), 0, RoundingMode.HALF_EVEN).intValue();
            DNAVal[] jkvalues = realApiUtil.getHistMatrix(jkpoints, recodeDate);
            clxsb.append(jkvalues[0].DValue).append(",");
            fdjsb.append(jkvalues[1].DValue).append(",");
            bjsb.append(jkvalues[2].DValue).append(",");
            zksb.append(jkvalues[3].DValue).append(",");
            cal.add(Calendar.DAY_OF_MONTH, 1);
        }
        String clxchart = clxsb.substring(0, clxsb.length() - 1);
        String fdjchart = fdjsb.substring(0, fdjsb.length() - 1);
        String bjchart = bjsb.substring(0, bjsb.length() - 1);
        String zkchart = zksb.substring(0, zksb.length() - 1);

        clxstrs[2] = String.valueOf(clxchart);
        fdjstrs[2] = String.valueOf(fdjchart);
        bjstrs[2] = String.valueOf(bjchart);
        zkstrs[2] = String.valueOf(zkchart);

        zzstrs[2] = "4,4,4,4,4,4,4";
        phstrs[2] = "4,4,4,4,4,4,4";
        jcstrs[2] = "4,4,4,4,4,4,4";
        bpqstrs[2] = "4,4,4,4,4,4,4";



        clxstrs[1] = "齿轮箱";
        fdjstrs[1] = "发电机";
        bjstrs[1] = "变桨";
        zkstrs[1] = "主控";

        zzstrs[1] = "液压";
        phstrs[1] = "偏航";
        jcstrs[1] = "机舱";
        bpqstrs[1] ="变频器";


        if (StringUtils.notEmp(wtId)) {
            List<Shutdownevent> selist = shutdowneventService.queryStopWtByPart(wtId);
            Map<String, List<Shutdownevent>> semap = new HashMap<>();

            if (!selist.isEmpty()) {
                for (Shutdownevent se : selist) {
                    if (semap.containsKey(se.getStoptypeid())) {
                        List<Shutdownevent> sels = semap.get(se.getStoptypeid());
                        sels.add(se);
                        semap.put(se.getStoptypeid(), sels);
                    } else {
                        List<Shutdownevent> sels = new ArrayList<>();
                        sels.add(se);
                        semap.put(se.getStoptypeid(), sels);
                    }
                }

                clxstrs =getPartInfo(semap,  "clx", clxstrs);
                fdjstrs = getPartInfo(semap, "fdj",  fdjstrs);
                bjstrs = getPartInfo(semap, "bj",  bjstrs);
                zkstrs = getPartInfo(semap, "zz",  zkstrs);

                zzstrs = getPartInfo(semap, "yy",  zzstrs);
                phstrs = getPartInfo(semap, "ph",  phstrs);
                jcstrs = getPartInfo(semap, "jc",  jcstrs);
                bpqstrs = getPartInfo(semap, "bpq", bpqstrs);

            }
        }


        map.put("clx", clxstrs);
        map.put("fdj", fdjstrs);
        map.put("bj", bjstrs);
        map.put("zk", zkstrs);
        map.put("zz", zzstrs);
        map.put("ph", phstrs);
        map.put("jc", jcstrs);
        map.put("bpq", bpqstrs);
        return map;
    }

    private String[] getPartInfo(Map<String, List<Shutdownevent>> semap, String type, String[] strs) {

        Calendar c = Calendar.getInstance();
        int days=c.get(Calendar.DAY_OF_YEAR);
        double yearhours=24*days;

        if(semap.containsKey(type))
        {

            List<Shutdownevent> sels =semap.get(type);
            int num=sels.size();

            double stophours=0.0;
            double losspowers=0.0;
            Date fristStopTime=null;
            for(Shutdownevent se:sels)
            {
                fristStopTime=se.getStoptime();
                stophours=stophours+se.getStophours();
                losspowers=losspowers+se.getLosspower();
            }
            double runhours=yearhours-stophours;
            double mtbf = new BigDecimal(runhours).divide(new BigDecimal(num), 2, RoundingMode.HALF_EVEN).doubleValue();
            double mttr = new BigDecimal(stophours).divide(new BigDecimal(num), 2, RoundingMode.HALF_EVEN).doubleValue();
            double loss = new BigDecimal(losspowers).divide(new BigDecimal(num), 2, RoundingMode.HALF_EVEN).doubleValue();

            if(mtbf<0)
            {
                mtbf=0;
                strs[3]=String.valueOf(0.0);
            }

            if(null!=fristStopTime && mtbf!=0)
            {
                //最近一次故障距离当前时间
                double jldqsj = DateUtils.hoursDiff(fristStopTime, new Date());//剩余时间

                double gzjd = new BigDecimal(jldqsj).divide(new BigDecimal(mtbf), 2, RoundingMode.HALF_EVEN).doubleValue();
                strs[3]=String.valueOf(gzjd);
            }

            strs[4]=String.valueOf(mtbf);
            strs[5]=String.valueOf(mttr);
            strs[6]=String.valueOf(loss);
        }else
        {
            strs[3]=String.valueOf(0.0);
            strs[4]=String.valueOf(yearhours);
            strs[5]=String.valueOf(0.0);
            strs[6]=String.valueOf(0.0);
        }
        return strs;
    }

    /**********************************************风机明细页面*****************************************************/


    /**********************************************风机健康曲线*****************************************************/
    /**
     * 获取风机、部件健康状态图表
     *
     * @param wtId
     * @param beginDate
     * @param endDate
     * @return
     * @throws Exception
     */
    public ActivityVo hsFjValueIndex(String wtId, Date beginDate, Date endDate) throws Exception {

        ActivityVo vo = null;
        long num = 96;
        long step = 900;

        int length = DateUtils.daysDiff(beginDate, endDate);

        if (length > 30) {
            num = length;
            step = 3600 * 24;
        } else if (length >= 15 && length < 30) {
            num = length * 2;
            step = 3600 * 12;
        } else if (length >= 7 && length < 15) {
            num = length * 4;
            step = 3600 * 6;
        } else if (length >= 3 && length < 7) {
            num = length * 8;
            step = 3600 * 3;
        }
        vo = getWTChart(wtId, beginDate, endDate, num, step);


        return vo;
    }


    private ActivityVo getWTChart(String wtId, Date beginDate, Date endDate, long num, long step) throws Exception {
        ActivityVo vo = new ActivityVo();
        List<DatasetsVo> datasets = new ArrayList<DatasetsVo>();


        WindTurbineTestingPointAi fj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FJJKZZ);
        WindTurbineTestingPointAi clx = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.CLXJKJL);
        WindTurbineTestingPointAi fdj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FDJJKJL);
        WindTurbineTestingPointAi kzys = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.BJJKJL);
        WindTurbineTestingPointAi jcxt = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.ZKJKJL);


        if (null != fj) {
            List<PointData> fjls = realApiUtil.getHistoryDatasSnap(fj, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, num, step);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();

            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("风机");
            dvo.setType("line");
            dvo.setValueDecimals(2);

            for (int i = 0; i < fjls.size(); i++) {

                xData.add(fjls.get(i).getPointTime() * 1000);

                double temp = fjls.get(i).getPointValueInDouble();
                temp = new BigDecimal(temp).divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN).doubleValue();
                data.add(temp);

            }
            dvo.setData(data);
            datasets.add(dvo);
            vo.setxData(xData);
        }
        if (null != fdj) {
            List<PointData> fdjls = realApiUtil.getHistoryDatasSnap(fdj, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();

            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("发电机");
            dvo.setType("line");
            dvo.setValueDecimals(2);

            for (int i = 0; i < fdjls.size(); i++) {

                xData.add(fdjls.get(i).getPointTime() * 1000);

                // System.out.println(DateUtils.toDate1(new
                // Date(fdjls.get(i).getPointTime() * 1000)));
                data.add(StringUtils.round(fdjls.get(i).getPointValueInDouble(), 2));

            }
            dvo.setData(data);
            datasets.add(dvo);
            vo.setxData(xData);
        }

        if (null != kzys) {
            List<PointData> kzysls = realApiUtil.getHistoryDatasSnap(kzys, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();

            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("变桨系统");
            dvo.setType("line");
            dvo.setValueDecimals(2);
            datasets.add(dvo);
            for (int i = 0; i < kzysls.size(); i++) {

                xData.add(kzysls.get(i).getPointTime() * 1000);
                // data.add(kzysls.get(i).getPointValueInDouble());
                data.add(StringUtils.round(kzysls.get(i).getPointValueInDouble(), 2));
            }
            dvo.setData(data);
            vo.setxData(xData);
        }

        if (null != jcxt) {
            List<PointData> jcxtls = realApiUtil.getHistoryDatasSnap(jcxt, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();
            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("主控系统");
            dvo.setType("line");
            dvo.setValueDecimals(2);
            datasets.add(dvo);
            for (int i = 0; i < jcxtls.size(); i++) {

                xData.add(jcxtls.get(i).getPointTime() * 1000);
                // data.add(jcxtls.get(i).getPointValueInDouble());
                if (jcxtls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                    data.add(StringUtils.round(jcxtls.get(i).getPointValueInDouble(), 2));
                    // data.add(jcxtls.get(i).getPointValueInDouble());
                }
            }
            dvo.setData(data);
            vo.setxData(xData);
        }
        if (null != clx) {
            List<PointData> clxls = realApiUtil.getHistoryDatasSnap(clx, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            List<Long> xData = new ArrayList<Long>();
            List<Double> data1 = new ArrayList<Double>();
            // List<Double> data2 = new ArrayList<Double>();
            // List<Double> data3 = new ArrayList<Double>();
            // List<Double> data4 = new ArrayList<Double>();
            // List<Double> data5 = new ArrayList<Double>();
            DatasetsVo dvo1 = new DatasetsVo();
            dvo1.setUnit("");
            dvo1.setName("齿轮箱");
            dvo1.setType("line");
            dvo1.setValueDecimals(2);

            // DatasetsVo dvo2 = new DatasetsVo();
            // dvo2.setUnit("");
            // dvo2.setName("偏航");
            // dvo2.setType("line");
            // dvo2.setValueDecimals(2);
            //
            // DatasetsVo dvo3 = new DatasetsVo();
            // dvo3.setUnit("");
            // dvo3.setName("机舱");
            // dvo3.setType("line");
            // dvo3.setValueDecimals(2);
            //
            // DatasetsVo dvo4 = new DatasetsVo();
            // dvo4.setUnit("");
            // dvo4.setName("主控");
            // dvo4.setType("line");
            // dvo4.setValueDecimals(2);
            //
            // DatasetsVo dvo5 = new DatasetsVo();
            // dvo5.setUnit("");
            // dvo5.setName("变频器");
            // dvo5.setType("line");
            // dvo5.setValueDecimals(2);

            for (int i = 0; i < clxls.size(); i++) {

                xData.add(clxls.get(i).getPointTime() * 1000);
                // data.add(clxls.get(i).getPointValueInDouble());

                if (clxls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                    data1.add(StringUtils.round(clxls.get(i).getPointValueInDouble(), 2));
                    // data2.add(1.0);
                    // data3.add(1.0);
                    // data4.add(1.0);
                    // data5.add(1.0);

                }
            }
            dvo1.setData(data1);
            // dvo2.setData(data2);
            // dvo3.setData(data3);
            // dvo4.setData(data4);
            // dvo5.setData(data5);

            datasets.add(dvo1);
            // datasets.add(dvo2);
            // datasets.add(dvo3);
            // datasets.add(dvo4);
            // datasets.add(dvo5);
            vo.setxData(xData);
        }

        vo.setDatasets(datasets);
        return vo;
    }
    /*************************************************风机健康曲线**************************************************/


    /**
     * 获取风机以及部件的健康历史
     *
     * @param wtId
     * @return
     */
    public Map<String, Object> findWtHisValueForBj(String wtId) {
        Map<String, Object> mapstatus = new HashMap();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Map<String, Windturbine> wtmap = InitialRunner.wtmap;
        //String wtName = wtmap.get(wtId).getName();

        WindTurbineTestingPointAi fj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FJJKZT);
        WindTurbineTestingPointAi clx = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.CLXJKZT);
        WindTurbineTestingPointAi fdj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FDJJKZT);
        WindTurbineTestingPointAi bj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.BJJKZT);
        WindTurbineTestingPointAi zk = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.ZKJKZT);

        // 时间 目前当天0点开始
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.SECOND, 0);
        Long start = cl.getTimeInMillis();
        Long end = new Date().getTime();
        List<PointData> jkValueList = new ArrayList<PointData>();
        List<String> tList = new ArrayList<String>();

        List<List<Double>> datals = new ArrayList<List<Double>>();
        List<Double> fjls = new ArrayList<Double>();
        List<Double> clxls = new ArrayList<Double>();
        List<Double> fdjls = new ArrayList<Double>();
        List<Double> bjls = new ArrayList<Double>();
        List<Double> zkls = new ArrayList<Double>();

        List<String> namels = new ArrayList<String>();
        namels.add("风机健康状态");
        namels.add("齿轮箱健康状态");
        namels.add("发电机健康状态");
        namels.add("变桨健康状态");
        namels.add("主控健康状态");
        try {
            jkValueList = realApiUtil.getHistoryDatasSnap(fj, start / 1000, end / 1000, 0L, 15 * 60L);
            for (int i = 0; i < jkValueList.size(); i++) {
                double hisData = (Double) jkValueList.get(i).getPointValueInDouble();
                String time = sdf.format(new Date(jkValueList.get(i).getPointTime() * 1000));
                time = time.substring(time.length() - 5);
                tList.add(time);
                fjls.add(hisData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            jkValueList = realApiUtil.getHistoryDatasSnap(clx, start / 1000, end / 1000, 0L, 15 * 60L);
            for (int i = 0; i < jkValueList.size(); i++) {
                double hisData = (Double) jkValueList.get(i).getPointValueInDouble();
                String time = sdf.format(new Date(jkValueList.get(i).getPointTime() * 1000));
                time = time.substring(time.length() - 5);
                tList.add(time);
                clxls.add(hisData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            jkValueList = realApiUtil.getHistoryDatasSnap(fdj, start / 1000, end / 1000, 0L, 15 * 60L);
            for (int i = 0; i < jkValueList.size(); i++) {
                double hisData = (Double) jkValueList.get(i).getPointValueInDouble();
                String time = sdf.format(new Date(jkValueList.get(i).getPointTime() * 1000));
                time = time.substring(time.length() - 5);
                tList.add(time);
                fdjls.add(hisData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            jkValueList = realApiUtil.getHistoryDatasSnap(bj, start / 1000, end / 1000, 0L, 15 * 60L);
            for (int i = 0; i < jkValueList.size(); i++) {
                double hisData = (Double) jkValueList.get(i).getPointValueInDouble();
                String time = sdf.format(new Date(jkValueList.get(i).getPointTime() * 1000));
                time = time.substring(time.length() - 5);
                tList.add(time);
                bjls.add(hisData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            jkValueList = realApiUtil.getHistoryDatasSnap(zk, start / 1000, end / 1000, 0L, 15 * 60L);
            for (int i = 0; i < jkValueList.size(); i++) {
                double hisData = (Double) jkValueList.get(i).getPointValueInDouble();
                String time = sdf.format(new Date(jkValueList.get(i).getPointTime() * 1000));
                time = time.substring(time.length() - 5);
                tList.add(time);
                zkls.add(hisData);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        datals.add(fjls);
        datals.add(clxls);
        datals.add(fdjls);
        datals.add(bjls);
        datals.add(zkls);

        mapstatus.put("data", datals);
//        mapstatus.put("clxls", clxls);
//        mapstatus.put("fdjls", fdjls);
//        mapstatus.put("bjls", bjls);
//        mapstatus.put("zkls", zkls);
        mapstatus.put("name", namels);
        mapstatus.put("time", tList);

        return mapstatus;
    }




    /************************************************************风机健康状态列表***********************************************************************/
    public ActivityVo getWTChart(String wtId) throws Exception {
        ActivityVo vo = new ActivityVo();
        List<DatasetsVo> datasets = new ArrayList<DatasetsVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = DateUtils.now();
        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(currentDate, 1)) + " 00:00:00");
        Date beginDate = sdfs.parse(sdf.format(currentDate) + " 00:00:00");





        WindTurbineTestingPointAi clx = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.CLXJKZT);
        WindTurbineTestingPointAi fdj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.FDJJKZT);
        WindTurbineTestingPointAi bj = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.BJJKZT);
        WindTurbineTestingPointAi zk = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.ZKJKZT);


        if (null != clx) {
            List<PointData> clxls = realApiUtil.getHistoryDatasSnap(clx, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();
            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("齿轮箱");
            dvo.setType("line");
            dvo.setValueDecimals(2);
            datasets.add(dvo);
            for (int i = 0; i < clxls.size(); i++) {

                xData.add(clxls.get(i).getPointTime() * 1000);
                // data.add(clxls.get(i).getPointValueInDouble());

                if (clxls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                    data.add(StringUtils.round(clxls.get(i).getPointValueInDouble(), 2));
                    // data.add(clxls.get(i).getPointValueInDouble());
                }
            }
            dvo.setData(data);
            vo.setxData(xData);
        }
        if (null != fdj) {
            List<PointData> fdjls = realApiUtil.getHistoryDatasSnap(fdj, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();

            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("发电机");
            dvo.setType("line");
            dvo.setValueDecimals(2);
            datasets.add(dvo);
            for (int i = 0; i < fdjls.size(); i++) {

                xData.add(fdjls.get(i).getPointTime() * 1000);

                System.out.println(DateUtils.format(new Date(fdjls.get(i).getPointTime() * 1000)));
                if (fdjls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                    data.add(StringUtils.round(fdjls.get(i).getPointValueInDouble(), 2));
                    // data.add(fdjls.get(i).getPointValueInDouble());
                }

            }
            dvo.setData(data);
            vo.setxData(xData);
        }

        if (null != bj) {
            List<PointData> kzysls = realApiUtil.getHistoryDatasSnap(bj, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();

            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("变桨系统");
            dvo.setType("line");
            dvo.setValueDecimals(2);
            datasets.add(dvo);
            for (int i = 0; i < kzysls.size(); i++) {

                xData.add(kzysls.get(i).getPointTime() * 1000);
                // data.add(kzysls.get(i).getPointValueInDouble());
                if (kzysls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                    data.add(StringUtils.round(kzysls.get(i).getPointValueInDouble(), 2));
                }
            }
            dvo.setData(data);
            vo.setxData(xData);
        }

        if (null != zk) {
            List<PointData> jcxtls = realApiUtil.getHistoryDatasSnap(zk, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            List<Long> xData = new ArrayList<Long>();
            List<Double> data = new ArrayList<Double>();
            DatasetsVo dvo = new DatasetsVo();
            dvo.setUnit("");
            dvo.setName("主控系统");
            dvo.setType("line");
            dvo.setValueDecimals(2);
            datasets.add(dvo);
            for (int i = 0; i < jcxtls.size(); i++) {

                xData.add(jcxtls.get(i).getPointTime() * 1000);
                // data.add(jcxtls.get(i).getPointValueInDouble());
                if (jcxtls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                    data.add(StringUtils.round(jcxtls.get(i).getPointValueInDouble(), 2));
                    // data.add(jcxtls.get(i).getPointValueInDouble());
                }
            }
            dvo.setData(data);
            vo.setxData(xData);
        }
        vo.setDatasets(datasets);
        return vo;
    }

/************************************************************齿轮箱健康状态列表***********************************************************************/
    /**
     * 齿轮箱系统图表
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public ActivityVo getClxChart(String wtId) throws Exception {
        ActivityVo vo = new ActivityVo();
        List<DatasetsVo> datasets = new ArrayList<DatasetsVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = DateUtils.now();
        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(currentDate, 1)) + " 00:00:00");
        Date beginDate = sdfs.parse(sdf.format(currentDate) + " 00:00:00");

        WindTurbineTestingPointAi clxsrzc = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI038");
        WindTurbineTestingPointAi clxsczc = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI039");
        WindTurbineTestingPointAi clxrkyw = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI040");
        WindTurbineTestingPointAi clxyw = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI041");


        if (null != clxsrzc && StringUtils.notEmp(clxsrzc.getId())) {
            List<PointData> clxsrzcls = realApiUtil.getHistoryDatasSnap(clxsrzc, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!clxsrzcls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("齿轮箱输入轴油温(最大值95,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < clxsrzcls.size(); i++) {

                    xData.add(clxsrzcls.get(i).getPointTime() * 1000);
                    // data.add(clxls.get(i).getPointValueInDouble());

                    if (clxsrzcls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(clxsrzcls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        if (null != clxsczc  && StringUtils.notEmp(clxsczc.getId())) {
            List<PointData> clxsczcls = realApiUtil.getHistoryDatasSnap(clxsczc, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!clxsczcls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("齿轮箱输出轴油温(最大值95,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < clxsczcls.size(); i++) {

                    xData.add(clxsczcls.get(i).getPointTime() * 1000);

                    // System.out.println(DateUtils.toDate1(new
                    // Date(fdjls.get(i).getPointTime() * 1000)));
                    if (clxsczcls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(clxsczcls.get(i).getPointValueInDouble()));
                    }

                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != clxrkyw  && StringUtils.notEmp(clxrkyw.getId())) {
            List<PointData> clxrkywls = realApiUtil.getHistoryDatasSnap(clxrkyw, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);

            if (!clxrkywls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("齿轮箱入口油温(最大值80,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < clxrkywls.size(); i++) {

                    xData.add(clxrkywls.get(i).getPointTime() * 1000);
                    // data.add(kzysls.get(i).getPointValueInDouble());
                    if (clxrkywls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(clxrkywls.get(i).getPointValueInDouble()));
                    }
                }

                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != clxyw  && StringUtils.notEmp(clxyw.getId())) {
            List<PointData> clxywls = realApiUtil.getHistoryDatasSnap(clxyw, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!clxywls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("齿轮箱油温(最大值80,最佳范围最大值76,最佳范围最小值14,最小值10)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < clxywls.size(); i++) {

                    xData.add(clxywls.get(i).getPointTime() * 1000);
                    // data.add(kzysls.get(i).getPointValueInDouble());
                    if (clxywls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(clxywls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        vo.setDatasets(datasets);
        return vo;
    }
/************************************************************发电机健康状态列表***********************************************************************/
    /**
     * 发电机系统图表
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public ActivityVo getFdjChart(String wtId) throws Exception {
        ActivityVo vo = new ActivityVo();
        List<DatasetsVo> datasets = new ArrayList<DatasetsVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = DateUtils.now();
        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(currentDate, 1)) + " 00:00:00");
        Date beginDate = sdfs.parse(sdf.format(currentDate) + " 00:00:00");


        WindTurbineTestingPointAi fdjzca = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI052");
        WindTurbineTestingPointAi fdjzcb = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI053");
        WindTurbineTestingPointAi fdjrzu = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI045");
        WindTurbineTestingPointAi fdjrzv = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI047");
        WindTurbineTestingPointAi fdjrzw = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI049");
        WindTurbineTestingPointAi fdjlqf = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI054");


        if (null != fdjzca  && StringUtils.notEmp(fdjzca.getId())) {
            List<PointData> fdjzcals = realApiUtil.getHistoryDatasSnap(fdjzca, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!fdjzcals.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("发电机轴承a温度(最大值95,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < fdjzcals.size(); i++) {

                    xData.add(fdjzcals.get(i).getPointTime() * 1000);
                    // data.add(clxls.get(i).getPointValueInDouble());

                    if (fdjzcals.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(fdjzcals.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        if (null != fdjzcb  && StringUtils.notEmp(fdjzcb.getId())) {
            List<PointData> fdjzcbls = realApiUtil.getHistoryDatasSnap(fdjzcb, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!fdjzcbls.isEmpty()) {

                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("发电机轴承b温度(最大值95,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < fdjzcbls.size(); i++) {

                    xData.add(fdjzcbls.get(i).getPointTime() * 1000);

                    // System.out.println(DateUtils.toDate1(new
                    // Date(fdjls.get(i).getPointTime() * 1000)));
                    if (fdjzcbls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(fdjzcbls.get(i).getPointValueInDouble()));
                    }

                }
                dvo.setData(data);
                vo.setxData(xData);
            }
        }

        if (null != fdjrzu  && StringUtils.notEmp(fdjrzu.getId())) {
            List<PointData> fdjrzuls = realApiUtil.getHistoryDatasSnap(fdjrzu, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!fdjrzuls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("发电机u项绕组温度(最大值150,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < fdjrzuls.size(); i++) {

                    xData.add(fdjrzuls.get(i).getPointTime() * 1000);
                    // data.add(kzysls.get(i).getPointValueInDouble());
                    if (fdjrzuls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(fdjrzuls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != fdjrzv  && StringUtils.notEmp(fdjrzv.getId())) {
            List<PointData> fdjrzvls = realApiUtil.getHistoryDatasSnap(fdjrzv, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!fdjrzvls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("发电机v项绕组温度(最大值150,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < fdjrzvls.size(); i++) {

                    xData.add(fdjrzvls.get(i).getPointTime() * 1000);
                    // data.add(jcxtls.get(i).getPointValueInDouble());
                    if (fdjrzvls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(fdjrzvls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != fdjrzw  && StringUtils.notEmp(fdjrzw.getId())) {
            List<PointData> fdjrzwls = realApiUtil.getHistoryDatasSnap(fdjrzw, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!fdjrzwls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("发电机w项绕组温度(最大值150,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < fdjrzwls.size(); i++) {

                    xData.add(fdjrzwls.get(i).getPointTime() * 1000);
                    // data.add(kzysls.get(i).getPointValueInDouble());
                    if (fdjrzwls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(fdjrzwls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != fdjlqf  && StringUtils.notEmp(fdjlqf.getId())) {
            List<PointData> fdjlqfls = realApiUtil.getHistoryDatasSnap(fdjlqf, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!fdjlqfls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("发电机冷却风温度(最大值70,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < fdjlqfls.size(); i++) {

                    xData.add(fdjlqfls.get(i).getPointTime() * 1000);
                    // data.add(jcxtls.get(i).getPointValueInDouble());
                    if (fdjlqfls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(fdjlqfls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        vo.setDatasets(datasets);
        return vo;
    }


/************************************************************变桨健康状态列表***********************************************************************/
    /**
     * 变桨系统图表
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public ActivityVo getKzysChart(String wtId) throws Exception {
        ActivityVo vo = new ActivityVo();
        List<DatasetsVo> datasets = new ArrayList<DatasetsVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = DateUtils.now();
        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(currentDate, 1)) + " 00:00:00");
        Date beginDate = sdfs.parse(sdf.format(currentDate) + " 00:00:00");

        WindTurbineTestingPointAi bjdrqwd = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI113");
        WindTurbineTestingPointAi bjdrqdy = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI236");
        WindTurbineTestingPointAi bjblwd = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI239");
        WindTurbineTestingPointAi bjdjwd = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI103");
        WindTurbineTestingPointAi bjkzgwd = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI233");


        if (null != bjdrqwd  && StringUtils.notEmp(bjdrqwd.getId())) {
            List<PointData> bjdrqwdls = realApiUtil.getHistoryDatasSnap(bjdrqwd, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!bjdrqwdls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("变桨电容器温度(最大值65,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < bjdrqwdls.size(); i++) {

                    xData.add(bjdrqwdls.get(i).getPointTime() * 1000);
                    // data.add(clxls.get(i).getPointValueInDouble());

                    if (bjdrqwdls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(bjdrqwdls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        if (null != bjdrqdy  && StringUtils.notEmp(bjdrqdy.getId())) {
            List<PointData> bjdrqdyls = realApiUtil.getHistoryDatasSnap(bjdrqdy, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!bjdrqdyls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("变桨电容电压(最大值63,最佳范围最大值60,最佳范围最小值56,最小值53)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < bjdrqdyls.size(); i++) {

                    xData.add(bjdrqdyls.get(i).getPointTime() * 1000);

                    // System.out.println(DateUtils.toDate1(new
                    // Date(fdjls.get(i).getPointTime() * 1000)));
                    if (bjdrqdyls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(bjdrqdyls.get(i).getPointValueInDouble()));
                    }

                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != bjblwd  && StringUtils.notEmp(bjblwd.getId())) {
            List<PointData> bjblwdls = realApiUtil.getHistoryDatasSnap(bjblwd, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!bjblwdls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("变桨变流器温度(最大值75,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < bjblwdls.size(); i++) {

                    xData.add(bjblwdls.get(i).getPointTime() * 1000);
                    // data.add(kzysls.get(i).getPointValueInDouble());
                    if (bjblwdls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(bjblwdls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        if (null != bjdjwd  && StringUtils.notEmp(bjdjwd.getId())) {
            List<PointData> bjdjwdls = realApiUtil.getHistoryDatasSnap(bjdjwd, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!bjdjwdls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("变桨电机温度(最大值135,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < bjdjwdls.size(); i++) {

                    xData.add(bjdjwdls.get(i).getPointTime() * 1000);
                    // data.add(jcxtls.get(i).getPointValueInDouble());
                    if (bjdjwdls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(bjdjwdls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        if (null != bjkzgwd  && StringUtils.notEmp(bjkzgwd.getId())) {
            List<PointData> bjkzgwdls = realApiUtil.getHistoryDatasSnap(bjkzgwd, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!bjkzgwdls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("变桨控制柜温度(最大值65,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < bjkzgwdls.size(); i++) {

                    xData.add(bjkzgwdls.get(i).getPointTime() * 1000);
                    // data.add(jcxtls.get(i).getPointValueInDouble());
                    if (bjkzgwdls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(bjkzgwdls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        vo.setDatasets(datasets);
        return vo;
    }
/************************************************************主控健康状态列表***********************************************************************/
    /**
     * 主控系统图表
     *
     * @param wtId
     * @return
     * @throws Exception
     */
    public ActivityVo getJcxtChart(String wtId) throws Exception {
        ActivityVo vo = new ActivityVo();
        List<DatasetsVo> datasets = new ArrayList<DatasetsVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = DateUtils.now();
        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(currentDate, 1)) + " 00:00:00");
        Date beginDate = sdfs.parse(sdf.format(currentDate) + " 00:00:00");


        WindTurbineTestingPointAi tdgwd = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI069");
        WindTurbineTestingPointAi tdkzgwd = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "AI070");


        if (null != tdgwd   && StringUtils.notEmp(tdgwd.getId())) {
            List<PointData> tdgwdls = realApiUtil.getHistoryDatasSnap(tdgwd, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!tdgwdls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();
                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("塔底柜温度(最大值50,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < tdgwdls.size(); i++) {

                    xData.add(tdgwdls.get(i).getPointTime() * 1000);
                    // data.add(clxls.get(i).getPointValueInDouble());

                    if (tdgwdls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(tdgwdls.get(i).getPointValueInDouble()));
                    }
                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }
        if (null != tdkzgwd  && StringUtils.notEmp(tdkzgwd.getId())) {
            List<PointData> tdkzgwdls = realApiUtil.getHistoryDatasSnap(tdkzgwd, beginDate.getTime() / 1000,
                    endDate.getTime() / 1000, (long) 96, 900L);
            if (!tdkzgwdls.isEmpty()) {
                List<Long> xData = new ArrayList<Long>();
                List<Double> data = new ArrayList<Double>();

                DatasetsVo dvo = new DatasetsVo();
                dvo.setUnit("");
                dvo.setName("塔顶机舱柜温度(最大值75,最小值0)");
                dvo.setType("line");
                dvo.setValueDecimals(2);
                datasets.add(dvo);
                for (int i = 0; i < tdkzgwdls.size(); i++) {

                    xData.add(tdkzgwdls.get(i).getPointTime() * 1000);

                    // System.out.println(DateUtils.toDate1(new
                    // Date(fdjls.get(i).getPointTime() * 1000)));
                    if (tdkzgwdls.get(i).getPointTime() * 1000 <= DateUtils.now().getTime()) {
                        data.add(MathUtil.twoBit(tdkzgwdls.get(i).getPointValueInDouble()));
                    }

                }
                dvo.setData(data);
                vo.setxData(xData);
            }

        }

        vo.setDatasets(datasets);
        return vo;
    }


    public Double getrealValue(String wtId, String type) {


        String pointid = null;
        if (type.equals("1")) {
            WindTurbineTestingPointAi pointAi2 = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "JKZT001");
            pointid = pointAi2.getId();
        } else if (type.equals("2")) {
            WindTurbineTestingPointAi pointAi2 = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "JKZT002");
            pointid = pointAi2.getId();
        } else if (type.equals("3")) {
            WindTurbineTestingPointAi pointAi2 = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "JKZT003");
            pointid = pointAi2.getId();
        } else if (type.equals("4")) {
            WindTurbineTestingPointAi pointAi2 = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "JKZT004");
            pointid = pointAi2.getId();
        } else if (type.equals("5")) {
            WindTurbineTestingPointAi pointAi2 = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, "JKZT005");
            pointid =pointAi2.getId();
        }

        try {

            PointData vo = realApiUtil.getRealData(pointid);

            return vo.getPointValueInDouble();

        } catch (Exception e) {

        }
        return 0.0;
    }
}
