import {environment} from '../../../../environments/environment';
|
import {DateService} from '../../../business/services/util/date.service';
|
import {NzMessageService} from 'ng-zorro-antd';
|
import {Component, OnInit} from '@angular/core';
|
import {HttpClient} from '@angular/common/http';
|
import {CascaderOption} from 'ng-zorro-antd/src/cascader/nz-cascader.component';
|
import {Organization} from '@business/entity/data';
|
import {ResultCode} from '@business/enum/types.enum';
|
import {ResultBean} from '@business/entity/grid';
|
import {AreacodeService} from '@business/services/http/areacode.service';
|
|
@Component({
|
selector: 'app-demo',
|
templateUrl: './demo.component.html',
|
styles: []
|
})
|
|
export class DemoComponent implements OnInit {
|
[x: string]: any;
|
public query: any = {};
|
public sensorOptions = [];
|
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'}
|
];
|
public reportOptions = [
|
{value: 'bar', label: '柱状图'},
|
{value: 'line', label: '折线图'}
|
];
|
|
public items = [{
|
id: 0,
|
monitorPoint: null,
|
device: null,
|
time: null,
|
monitorPointOptions: [],
|
deviceOptions: [],
|
_areas: []
|
}];
|
|
constructor(
|
public http: HttpClient,
|
public dateSrv: DateService,
|
private areacodeService: AreacodeService,
|
public msgSrv: NzMessageService
|
) {
|
this.timeType = this.typeOptions[1];
|
this.query.reportType = this.reportOptions[1].value;
|
}
|
|
ngOnInit() {
|
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;
|
}
|
});
|
}
|
|
addItem() {
|
const id = (this.items.length > 0) ? this.items[this.items.length - 1].id + 1 : 0;
|
const index = this.items.push({
|
id: id,
|
monitorPoint: null,
|
device: null,
|
time: null,
|
monitorPointOptions: [],
|
deviceOptions: [],
|
_areas: []
|
});
|
}
|
|
public areaLazyLoad(event: {option: CascaderOption, index: number, resolve: (children: CascaderOption[]) => void, reject: () => void}) {
|
const index = event['index'];
|
const option = event.option;
|
switch (index) {
|
case -1:
|
this.areacodeService.getProvinces().subscribe(
|
(res: {label: string, value: string}[]) => {
|
event.resolve(res);
|
}
|
); break;
|
case 0:
|
this.areacodeService.getCities(option.value).subscribe(
|
(res: {label: string, value: string}[]) => {
|
event.resolve(res);
|
}
|
); break;
|
case 1:
|
this.areacodeService.getAreas(option.value).subscribe(
|
(res: {label: string, value: string}[]) => {
|
event.resolve(res);
|
}
|
); break;
|
}
|
}
|
|
public setAreasData(areas: {label: string, value: string}[], i) {
|
let isChanged = false;
|
const _areas = this.items[i]._areas
|
isChanged = areas.some((item, index: number) => {
|
// this._areas[index] 为null 改变 监控点选项
|
return _areas.length < areas.length
|
|| !_areas[index]
|
|| _areas[index].value !== item.value;
|
});
|
if (isChanged) {
|
this.items[i]._areas = areas;
|
this.items[i].monitorPoint = null;
|
this.regionChange(i);
|
}
|
}
|
|
regionChange(i) {
|
let areaName = '';
|
switch (this.items[i]._areas.length) {
|
case 1:
|
areaName = 'provinceCode'; break;
|
case 2:
|
areaName = 'cityCode'; break;
|
case 3:
|
areaName = 'areaCode'; break;
|
}
|
this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: areaName, value: this.items[i]._areas.slice(-1).pop().value}}).subscribe((res: any) => {
|
if (res.code === 0) {
|
this.msgSrv.error(res.message);
|
} else {
|
this.items[i].monitorPointOptions = res.data;
|
}
|
});
|
}
|
|
monitorPointChange(value, i) {
|
this.items[i].deviceOptions = [];
|
this.items[i].device = null;
|
if (value) {
|
this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value.id}}).subscribe((res: any) => {
|
if (res.code === 0) {
|
this.msgSrv.error(res.message);
|
} else {
|
this.items[i].deviceOptions = res.data;
|
}
|
});
|
}
|
}
|
|
_disabledDate(current: Date): boolean {
|
return current && current.getTime() > Date.now();
|
}
|
|
reportQuery() {
|
const query = this.query;
|
let validate = true;
|
const queryItems = [];
|
for (let i = 0; i < this.items.length; i++) {
|
let item = this.items[i];
|
let queryItem: any = {};
|
if ((!!item.time) && (item.monitorPointOptions.length > 0)) {
|
for (var key in item) {
|
if (item[key]) {
|
queryItem[key] = item[key];
|
}
|
}
|
for (let i = 0; i < queryItem._areas.length; i++) {
|
let region = queryItem._areas[i];
|
if (i == 0) {
|
queryItem.provinceCode = region.value;
|
}
|
if (i == 1) {
|
queryItem.cityCode = region.value;
|
}
|
if (i == 2) {
|
queryItem.areaCode = region.value;
|
}
|
}
|
delete queryItem._areas;
|
if (queryItem.monitorPoint) {
|
queryItem.monitorPointId = queryItem.monitorPoint.id;
|
queryItem.monitorPointName = queryItem.monitorPoint.name;
|
queryItem.monitorPointAddress = queryItem.monitorPoint.address;
|
delete queryItem.monitorPoint;
|
}
|
delete queryItem.monitorPointOptions;
|
if (queryItem.device) {
|
queryItem.mac = queryItem.device.mac;
|
queryItem.deviceName = queryItem.device.name;
|
delete queryItem.device;
|
}
|
queryItem.deviceCount = queryItem.deviceOptions.length;
|
delete queryItem.deviceOptions;
|
queryItem.formatTime = this.dateSrv.date_format(queryItem.time, this.timeType.format);
|
delete queryItem.time;
|
queryItems.push(queryItem);
|
} else {
|
validate = false;
|
break;
|
}
|
}
|
if (validate && this.timeType && query.reportType) {
|
if (query.sensorKeys && query.sensorKeys.length > 0) {
|
query.sensors = JSON.stringify(query.sensorKeys);
|
}
|
query.items = JSON.stringify(queryItems);
|
query.type = this.timeType.value;
|
sessionStorage.setItem("queryParams", JSON.stringify(query));
|
} else {
|
this.msgSrv.error('请完善搜索项或删除查询条目');
|
return false;
|
}
|
}
|
}
|