xufenglei
2018-03-26 ba15aacf079d1a3fd13e4594f5a94cf25dacb036
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {environment} from '../../../../environments/environment';
import {DateService} from '../../../business/services/util/date.service';
import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {Component, OnInit, Inject} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import { ITokenService, DA_SERVICE_TOKEN } from '@delon/auth';
 
@Component({
  selector: 'app-excel',
  templateUrl: './excel.component.html',
  styles: []
})
export class ExcelComponent implements OnInit {
  [x: string]: any;
 
  query: any = {
  };
 
  time: any = {
    format: 'YYYY',
    mode: 'month'
  };
 
  public sensorOptions = [];
  public monitorPointOptions = [];
  public deviceOptions = [];
 
  constructor(
    public http: HttpClient,
    public dateSrv: DateService,
    public msgSrv: NzMessageService,
    @Inject(DA_SERVICE_TOKEN)public tokenService: ITokenService
  ) {}
 
  ngOnInit() {
    this.query.time = null;
    this.query.timeb = null;
    this.http.get(environment.SERVER_BASH_URL + 'sensor/all').subscribe((res: any) => {
      if (res.code === 0) {
        this.msgSrv.error(res.message);
      } else {
        this.sensorOptions = res.data;
      }
    });
  }
 
  sensorChange(value) {
    this.sensorOptions.forEach(sensor => {
      if (sensor.sensorKey === value) {
        this.sensor = sensor;
      }
    });
  }
 
  searchChange(searchText) {
    if (searchText) {
      const query = encodeURI(searchText);
      if (query) {
        this.http.get(environment.SERVER_BASH_URL + '/monitor-point/list/' + query).subscribe((res: any) => {
          if (res.code === 0) {
            this.msgSrv.error(res.message);
          } else {
            this.monitorPointOptions = res.data;
          }
        });
      }
    }
  }
 
  monitorPointChange(value) {
    this.query.mac = null;
    this.deviceOptions = [];
    if (value) {
      this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value}}).subscribe((res: any) => {
        if (res.code === 0) {
          this.msgSrv.error(res.message);
        } else {
          this.deviceOptions = res.data;
        }
      });
    } else {
      this.monitorPointa = null;
    }
  }
 
 
  public typeOptions = [
    {value: 'year', label: '年', mode: 'month', xAxisName: '月', format: 'yyyy', typeFormat: '%Y-%m'},
    {value: 'month', label: '月', mode: 'month', xAxisName: '日', format: 'yyyy-MM', typeFormat: '%Y-%m-%d'},
    {value: 'day', label: '日', mode: 'day', xAxisName: '时', format: 'yyyy-MM-dd', typeFormat: '%Y-%m-%d %H'},
    {value: 'hour', label: '时', mode: 'day', xAxisName: '分', format: 'yyyy-MM-dd HH', typeFormat: '%Y-%m-%d %H:%i'}
  ];
 
 
  typeChange(searchText) {
    this.typeOptions.forEach(types => {
      if (types.value === searchText) {
        this.timeType = types;
        this.time.format = types.format.toUpperCase();
        this.time.mode = types.mode;
      }
    });
  }
 
  reportQuery() {
    const query = this.query;
    if (query.type && query.monitorPointId && query.time) {
      if (query.time) {
        query.time = this.dateSrv.date_format(query.time, this.time.format);
      }
      if (query.timeb) {
        query.timeb = this.dateSrv.date_format(query.timeb, this.time.format);
      }
      if (query.sensorKey) {
        query.sensorName = this.sensor.name;
      }
      query.format = this.timeType.format;
      query.typeFormat = this.timeType.typeFormat;
      let url = environment.SERVER_BASH_URL + 'report/excel?';
      for (const a in query) {
        if (query[a]) {
          url += encodeURI(a) + '=' + encodeURI(query[a]) + '&';
        }
      }
 
      window.location.href = url + '_token=' + this.tokenService.get().token;
    } else {
      this.msgSrv.error('请完善搜索项');
    }
 
  }
 
}