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.DateUtils;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.StringUtils;
import com.gyee.frame.util.golden.EdosUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
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;

    private final int digit = 2;
    private final double NUM = 3.6;
    private final double XZNUM = 1.25;
    IRealTimeDataBaseUtil realApiUtil = new EdosUtil();
    /*********************************************风机明细页面******************************************************/
    /**
     * 获取健康管理风机部件基础信息
     *
     * @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];

        WindTurbineTestingPointAi2 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(smlv));
        fdjmap.put("smsyl", String.valueOf(smlv));
        bjmap.put("smsyl", String.valueOf(smlv));
        zkmap.put("smsyl", String.valueOf(smlv));
        zzmap.put("smsyl", String.valueOf(smlv));
        phmap.put("smsyl", String.valueOf(smlv));
        jcmap.put("smsyl", String.valueOf(smlv));
        bpqmap.put("smsyl", String.valueOf(smlv));

        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<Daylygradeassessmentmain2> day1ls = daylygradeassessmentmain2Service.getDaylygradeassessmentmain2ListBywtId(wtId, DateUtils.truncate(cal.getTime()));
        if (!day1ls.isEmpty()) {
            Daylygradeassessmentmain2 top = day1ls.get(0);
            XnfxVo vo = new XnfxVo();
            vo.setName("日等级评估数据分析");
            vo.setLevelname(top.getModlevel());
            vo.setTopnum(top.getModscore().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<Daylygradeassessmentmain2> ls = daylygradeassessmentmain2Service.getDaylygradeassessmentmain2ListBywtId(wtId, beginDate,endDate);
        Map<String, Object> map = new HashMap<String, Object>();
        int num=1;
        for(Daylygradeassessmentmain2 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.getModlevel());
                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.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);

        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 = 30;
        cal.add(Calendar.DAY_OF_MONTH, -30);
        Date beginDate = cal.getTime();

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

        Double[] sjglarr = new Double[length];
        Double[] llglarr = new Double[length];
        Double[] sjfsarr = new Double[length];

        WindTurbineTestingPointAi2 sjgl = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.TPOINT_WT_FJGL);

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

        if (!sjglls.isEmpty()) {
            for (int i = 0; i < sjglls.size() - 1; i++) {
                sjglarr[i] = sjglls.get(i).getPointValueInDouble();
            }
        }
        WindTurbineTestingPointAi2 llgl = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId, Constant.TPOINT_WT_LLGL);

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

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

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

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

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

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

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

        return resultmap;
    }

    /**********************************************风机明细页面*****************************************************/
    /**********************************************风机健康曲线*****************************************************/
    /**
     * 获取风机、部件健康状态图表
     * @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>();


        WindTurbineTestingPointAi2 fj =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.FJJKZZ);
        WindTurbineTestingPointAi2 clx =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.CLXJKJL);
        WindTurbineTestingPointAi2 fdj =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.FDJJKJL);
        WindTurbineTestingPointAi2 kzys =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.BJJKJL);
        WindTurbineTestingPointAi2 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;
    }
    /*************************************************风机健康曲线**************************************************/

}
