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;
|
public query: any = {};
|
public sensorOptions = [];
|
public monitorPointOptions = [];
|
public deviceOptions = [];
|
public typeOptions = [
|
{value: 'year', label: '年', format: 'YYYY'},
|
{value: 'month', label: '月', format: 'YYYY-MM'},
|
{value: 'day', label: '日', format: 'YYYY-MM-DD'},
|
{value: 'hour', label: '时', format: 'YYYY-MM-DD HH'}
|
];
|
|
constructor(
|
public http: HttpClient,
|
public dateSrv: DateService,
|
public msgSrv: NzMessageService,
|
@Inject(DA_SERVICE_TOKEN) public tokenService: ITokenService
|
) {
|
this.timeType = this.typeOptions[1];
|
}
|
|
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;
|
}
|
});
|
}
|
|
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;
|
}
|
});
|
}
|
}
|
|
reportQuery() {
|
const query = this.query;
|
if (this.timeType && query.monitorPointId && query.time) {
|
query.time = this.dateSrv.date_format(query.time, this.timeType.format);
|
if (query.timeb) {
|
query.timeb = this.dateSrv.date_format(query.timeb, this.timeType.format);
|
}
|
if (query.sensorKey && query.sensorKey.length > 0) {
|
query.sensors = JSON.stringify(query.sensorKey);
|
}
|
query.type = this.timeType.value;
|
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('请完善搜索项');
|
}
|
}
|
}
|