import { Component, OnInit } from '@angular/core';
import {AnalysisService} from '../analysis.service';
import {NzMessageService} from 'ng-zorro-antd';
import {DatePipe} from '@angular/common';
import {pageSize} from '../../app.constants';
import {OverAllService} from '../../overAll/overAll.service';

@Component({
  selector: 'smart-resource-alarm',
  templateUrl: './resource-alarm.component.html',
  styles: []
})
export class ResourceAlarmComponent implements OnInit {

  timeType;
    startTime;
    endTime;
    groupList;

    obj = {
        priority:"",
        groupid:"",
        startTime:"",
        endTime:"",
    };

    pageCount = pageSize;
    pageNum = 1;

    inList = [];
    outList = [];

  constructor(private analysisSer:AnalysisService,private message:NzMessageService,
              private datePipe:DatePipe,private overAllSer:OverAllService) { }

  ngOnInit() {
    this.getGroup();
  }

  getData(){
    this.getAlarmTopEchart();
    this.getAlarmTrend();
    this.getCommonTop();
    this.getAnalysis();
  }

    //获取分组
    getGroup() {
        this.overAllSer.getgroups({}).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.groupList = res.data;
                }
            }
        );
    }

  //告警总数TOP10
  getAlarmTopEchart(){
      const data = {
          groupid:this.obj.groupid,
          startTime:this.obj.startTime,
          endTime:this.obj.endTime,
          priority:this.obj.priority,
      };
    this.analysisSer.waringCountTop(data).subscribe(
        (res)=>{

        }
    )
  }

  //告警总数趋势
  getAlarmTrend(){
      const data = {
          groupid:this.obj.groupid,
          startTime:this.obj.startTime,
          endTime:this.obj.endTime,
          priority:this.obj.priority,
      };
      this.analysisSer.waringTrend(data).subscribe(
          (res)=>{

          }
      )
  }

  //常发问题TOP10
  getCommonTop(){
      const data = {
          groupid:this.obj.groupid,
          startTime:this.obj.startTime,
          endTime:this.obj.endTime,
          priorityName:this.obj.priority,
      };
      this.analysisSer.commonProblemTop(data).subscribe(
          (res)=>{

          }
      )
  }

  //统计报告
  getAnalysis(){
      const data = {
          pageCount:this.pageCount,
          pageNum:this.pageNum,
          obj:{
              startTime:this.obj.startTime,
              endTime:this.obj.endTime,
              priorityName:this.obj.priority,
          }
      };
      this.analysisSer.statisticalReport(data).subscribe(
          (res)=>{

          }
      )
  }

    //时间改变
    changeType(){
        const nowDate = new Date().getTime();
        let day1,day2;
        switch (this.timeType){
            case'1':{
                this.obj.startTime = this.datePipe.transform(nowDate,'yyyy-MM-dd') +' 00:00:00';
                this.obj.endTime = this.datePipe.transform(nowDate,'yyyy-MM-dd') +' 23:59:59';
                break;
            }
            case'2':{
                day1 = nowDate - 1*24*60*60*1000;
                this.obj.startTime = this.datePipe.transform(day1,'yyyy-MM-dd') + ' 00:00:00';
                this.obj.endTime = this.datePipe.transform(day1,'yyyy-MM-dd') + ' 23:59:59';
                break;
            }
            case'3':{
                day1 = nowDate - 3*24*60*60*1000;
                day2 = nowDate - 1*24*60*60*1000;
                this.obj.startTime = this.datePipe.transform(day1,'yyyy-MM-dd') + ' 00:00:00';
                this.obj.endTime = this.datePipe.transform(day2,'yyyy-MM-dd') + ' 23:59:59';
                break;
            }
            case'4':{
                day1 = nowDate - 7*24*60*60*1000;
                day2 = nowDate - 1*24*60*60*1000;
                this.obj.startTime = this.datePipe.transform(day1,'yyyy-MM-dd') + ' 00:00:00';
                this.obj.endTime = this.datePipe.transform(day2,'yyyy-MM-dd') + ' 23:59:59';
                break;
            }
            case'5':{
                break;
            }
        }
    }

    //搜索
    search(){
        if(this.timeType == '5'){
            this.obj.startTime = this.datePipe.transform(this.startTime,'yyyy-MM-dd HH:mm:ss');
            this.obj.endTime = this.datePipe.transform(this.endTime,'yyyy-MM-dd HH:mm:ss');
        }
        this.getData();
    }

}
