From 7ca521e4267b987270f6ccbb9a6c076aeb467d96 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Wed, 04 Jul 2018 17:11:33 +0800 Subject: [PATCH] 设备,监控站 管理功能增强 --- src/app/business/services/util/example.service.ts | 13 + src/app/routes/devices/basic-info/basic-info.component.ts | 64 ++++++++ src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html | 2 src/app/business/services/http/organization.service.ts | 1 src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts | 16 + src/app/routes/devices/version/version-edit/version-edit.component.ts | 58 +++++++ src/app/routes/map/coordinates-picker/coordinates-picker.component.ts | 11 + src/app/routes/devices/basic-info/device-edit/device-edit.component.ts | 64 ++++++++- src/app/business/services/util/tools.service.ts | 3 src/app/routes/devices/monitor-point/monitor-point.component.ts | 36 ++++ src/app/routes/devices/basic-info/basic-info.component.html | 44 ++++- src/app/business/services/http/device.service.ts | 30 +++ src/app/routes/devices/monitor-point/monitor-point.component.html | 20 ++ src/app/routes/devices/basic-info/device-edit/device-edit.component.html | 12 + 14 files changed, 321 insertions(+), 53 deletions(-) diff --git a/src/app/business/services/http/device.service.ts b/src/app/business/services/http/device.service.ts index 8bf7bfd..83c70d2 100644 --- a/src/app/business/services/http/device.service.ts +++ b/src/app/business/services/http/device.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { ResultBean, PageBean } from '@business/entity/grid'; import { Observable } from 'rxjs/Observable'; -import { ExampleService } from '@business/services/util/example.service'; +import { ExampleService, Criteria } from '@business/services/util/example.service'; import { Device } from '@business/entity/data'; @Injectable() @@ -17,11 +17,31 @@ public getListUrl () { return this.urls.list; } - public getSqlParams(queryText: string) { + public getSqlParams(queryMap: {[key: string]: number|string}) { const example = new ExampleService(); - if (queryText != null && queryText !== '') { - example.or().andLike({name: 'name', value: '%' + queryText + '%'}); - example.or().andLike({name: 'mac', value: '%' + queryText + '%'}); + const orgId = !!queryMap.orgId ? queryMap.orgId : null; + const mpointId = !!queryMap.mpointId ? queryMap.mpointId : null; + const devMacOrName = !!queryMap.devMacOrName && !!(<string>queryMap.devMacOrName).trim() ? queryMap.devMacOrName : null; + let criWithMac: Criteria = null; + let criWithName: Criteria = null; + if (!!devMacOrName) { + criWithName = example.or().andLike({name: 'name', value: '%' + devMacOrName + '%'}); + criWithMac = example.or().andLike({name: 'mac', value: '%' + devMacOrName + '%'}); + } + if (!!mpointId) { + if (!!devMacOrName) { + criWithName.andEqualTo({name: 'monitorPointId', value: mpointId}); + criWithMac.andEqualTo({name: 'monitorPointId', value: mpointId}); + }else { + example.or().andEqualTo({name: 'monitorPointId', value: mpointId}); + } + } else if (!!orgId) { + if (!!devMacOrName) { + criWithName.andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); + criWithMac.andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); + }else { + example.or().andCondition(`monitor_point_id in (select id from monitor_point where organization_id = ${orgId})`); + } } return example.getSqlParam(); } diff --git a/src/app/business/services/http/organization.service.ts b/src/app/business/services/http/organization.service.ts index 20fb068..ba9f9c1 100644 --- a/src/app/business/services/http/organization.service.ts +++ b/src/app/business/services/http/organization.service.ts @@ -22,6 +22,7 @@ }; constructor(private http: _HttpClient) { } public getPagingList(page: PageBean, queryText: string): Observable<PageBean> { + queryText = !!queryText && !!queryText.trim() ? queryText : null; const example = new ExampleService(); if (queryText != null && queryText !== '') { example.or().andLike({name: 'name', value: '%' + queryText + '%'}); diff --git a/src/app/business/services/util/example.service.ts b/src/app/business/services/util/example.service.ts index 082c31f..fdcb472 100644 --- a/src/app/business/services/util/example.service.ts +++ b/src/app/business/services/util/example.service.ts @@ -8,9 +8,16 @@ return this.conditions; } - public addCondition(condition: string, colName: string, ...values: any[]) { + private addCondition(condition: string, colName: string, ...values: any[]) { const split = Criteria.CONDITION_SPLIT; // '||' - this.conditions.push(condition + split + colName + split + values.join(split)); + let conditionStr = condition + split + colName; + if (!!values && values.length > 0) { + conditionStr += split + values.join(split); + } + this.conditions.push(conditionStr); + } + public andCondition(condition: string) { + this.addCondition('andCondition', condition); } public andLike(col: { name: string, value: any}): Criteria { this.addCondition('andLike', col.name, col.value); @@ -47,7 +54,7 @@ return encodeURI(whereSql); } constructor() { } - public or() { + public or(): Criteria { const cri = new Criteria(); this.criterion.push(cri); return cri; diff --git a/src/app/business/services/util/tools.service.ts b/src/app/business/services/util/tools.service.ts index 3478144..3841b8f 100644 --- a/src/app/business/services/util/tools.service.ts +++ b/src/app/business/services/util/tools.service.ts @@ -44,4 +44,7 @@ if (num) { result = num + result; } return result; } + public static getObjById<T>(id: number, list: T[]): T { + return list.find(item => item['id'] === id); + } } diff --git a/src/app/routes/devices/basic-info/basic-info.component.html b/src/app/routes/devices/basic-info/basic-info.component.html index bf288eb..3c5a796 100644 --- a/src/app/routes/devices/basic-info/basic-info.component.html +++ b/src/app/routes/devices/basic-info/basic-info.component.html @@ -5,23 +5,47 @@ </h1> </div> <nz-card [nzBordered]="false"> - <div class="mb-md"> + <div nz-row class="mb-sm"> + <div nz-col [nzSpan]="4"> <button nz-button (click)="addOrModify($event)" [nzType]="'primary'" [nzSize]="'large'"> <i class="anticon anticon-plus"></i><span>������</span> </button> - <ng-container *ngIf="selectedRows.length > 0"> + <ng-container *ngIf="selectedRows.length > 0"> <button nz-button [nzSize]="'large'" (click)="deleteSelected()">������������</button> </ng-container> - <nz-input [ngStyle]="{'width': '280px','float':'right'}" [(ngModel)]="queryText" name="" [nzPlaceHolder]="'������������������mac'" + </div> + <div nz-col [nzSpan]="7"> + <span style="padding: 5px 10px;"> + ������: + </span> + <nz-select style="width: 79%;" [(ngModel)]="queryMap.orgId" (ngModelChange)="setOrgId($event)" [nzPlaceHolder]="'������ ������(������������������)'" + nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="orgSelectChange($event)" [nzNotFoundContent]="'������������'" > + <nz-option *ngFor="let option of orgOptions" [nzLabel]="option.name" [nzValue]="option.id" [nzDisabled]="option.disabled"> + </nz-option> + </nz-select> + </div> + <div nz-col [nzSpan]="7"> + <span style="padding: 5px 10px;"> + ���������: + </span> + <nz-select style="width: 75%;" [(ngModel)]="queryMap.mpointId" (ngModelChange)="setMpointId($event)" [nzPlaceHolder]="'������ ���������������(������������������)'" + nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="monitorPointChange($event)" [nzNotFoundContent]="'������������'" > + <nz-option *ngFor="let option of monitorPoints" [nzLabel]="option.name" [nzValue]="option.id" [nzDisabled]="option.disabled"> + </nz-option> + </nz-select> + </div> + <div nz-col [nzSpan]="6"> + <nz-input [ngStyle]="{'width': '240px','float':'right'}" [(ngModel)]="queryText" name="" [nzPlaceHolder]="'������������������������������mac'" (keyup)="queryTextChanged($event)" (change)="queryTextChanged($event)" ></nz-input> </div> - <div class="mb-md"> - <nz-alert *ngIf="selectedRows.length > 0" [nzType]="'info'" [nzShowIcon]="true"> - <span alert-body> - ���������<strong class="text-primary">{{selectedRows.length}}</strong>��� - </span> - </nz-alert> - </div> + </div> + <div class="mb-md"> + <nz-alert *ngIf="selectedRows.length > 0" [nzType]="'info'" [nzShowIcon]="true"> + <span alert-body> + ���������<strong class="text-primary">{{selectedRows.length}}</strong>��� + </span> + </nz-alert> + </div> <simple-table #simpleTable [data]="listUrl" [extraParams]="extraParams" [columns]="columns" [showTotal]="true" [reqReName]="{pi: 'pageIndex',ps: 'pageSize'}" (checkboxChange)="checkboxChange($event)" [ps]="10" [resReName]="{list: 'data',total: 'total'}"></simple-table> </nz-card> diff --git a/src/app/routes/devices/basic-info/basic-info.component.ts b/src/app/routes/devices/basic-info/basic-info.component.ts index 3dfa853..3494c41 100644 --- a/src/app/routes/devices/basic-info/basic-info.component.ts +++ b/src/app/routes/devices/basic-info/basic-info.component.ts @@ -11,6 +11,8 @@ import { Subject } from 'rxjs/Subject'; import { CoordinatesPickerComponent } from 'app/routes/map/coordinates-picker/coordinates-picker.component'; import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service'; +import { OrganizationService } from '@business/services/http/organization.service'; +import { ExampleService } from '@business/services/util/example.service'; @Component({ selector: 'app-basic-info', @@ -61,13 +63,19 @@ } ]; queryTextStream: Subject<string> = new Subject<string>(); + private queryMap: {orgId?: number, mpointId?: number, devMacOrName?: string} + = {orgId: null, mpointId: null, devMacOrName: ''}; + extraParams = { queryParams: null }; + public orgOptions = []; + public monitorPoints = []; constructor( private monitorPointService: MonitorPointService, private deviceService: DeviceService, private confirmServ: NzModalService, public msgSrv: NzMessageService, private modalHelper: ModalHelper, - private coorPickerService: CoorPickerService + private coorPickerService: CoorPickerService, + private organizationService: OrganizationService ) { } ngOnInit() { @@ -75,14 +83,14 @@ .debounceTime(900) .distinctUntilChanged() .subscribe(value => { - this.extraParams.queryParams = this.deviceService.getSqlParams(value); + this.queryMap.devMacOrName = value; this.load(); }); + this.orgSelectChange(); } get listUrl() { return this.deviceService.getListUrl(); } - extraParams = { queryParams: null }; queryText: string; selectedRows: any[] = []; checkboxChange(list: any[]) { @@ -107,6 +115,7 @@ }); } load() { + this.extraParams.queryParams = this.deviceService.getSqlParams(this.queryMap); this.selectedRows = []; this.simpleTable.load(); } @@ -129,7 +138,12 @@ if (d != null) { Object.assign(data, d); } - this.modalHelper.static(DeviceEditComponent, { data }).subscribe( + const configMap = this.queryMap; + // Object.assign(configMap, this.queryMap); + if (!!configMap['mpointId'] && !d['monitorPoint']) { + data['monitorPoint'] = this.getMonitorPoint(configMap['mpointId']); + } + this.modalHelper.static(DeviceEditComponent, { data, configMap }).subscribe( (ret: { data: any, close: Function }) => { // ������������ if (ret.data['id'] != null) { @@ -156,6 +170,11 @@ } ); }); + } + private getMonitorPoint(mpointId: number) { + return this.monitorPoints.find( + mpoint => mpoint.id === mpointId + ); } configCoord(record: Device): void { // ������������������������������������������adress������������ @@ -207,4 +226,41 @@ } ); } + public setOrgId(orgId) { + this.queryMap.orgId = orgId; + this.queryMap.mpointId = null; + // this.queryMap.devMacOrName = null; + this.monitorPointChange(); + this.load(); + } + public setMpointId(mpointId) { + this.queryMap.mpointId = mpointId; + this.load(); + } + orgSelectChange(text?: string) { + const pageBean: PageBean = {pageIndex: 0, pageSize: 20}; + this.organizationService.getPagingList(pageBean, text).subscribe( + (res: PageBean) => { + if (res != null && res.data != null) { + this.orgOptions = res.data; + } + } + ); + } + monitorPointChange(text?: string) { + const pageBean: PageBean = {pageIndex: 0, pageSize: 20}; + const example = new ExampleService(); + const organizationId = !!this.queryMap.orgId ? this.queryMap.orgId : null; + const mpointName = !!text ? '%' + text + '%' : null; + example.or() + .andEqualTo({name: 'organizationId', value: organizationId }) + .andLike({name: 'name', value: mpointName }); + this.monitorPointService.getPageByExample(pageBean, example).subscribe( + (res: PageBean) => { + if (res != null && res.data != null) { + this.monitorPoints = res.data; + } + } + ); + } } diff --git a/src/app/routes/devices/basic-info/device-edit/device-edit.component.html b/src/app/routes/devices/basic-info/device-edit/device-edit.component.html index b3b6f4b..9816dc7 100644 --- a/src/app/routes/devices/basic-info/device-edit/device-edit.component.html +++ b/src/app/routes/devices/basic-info/device-edit/device-edit.component.html @@ -105,7 +105,17 @@ </nz-input> </div> </div> + </form> <div class="modal-footer"> + <span style="padding: 5px 10px;"> + ������: + </span> + <nz-select style="width: 240px;" [(ngModel)]="configMap.orgId" (ngModelChange)="setOrgId($event)" [nzPlaceHolder]="'������ ������(������������������)'" + nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="orgSelectChange($event)" [nzNotFoundContent]="'������������'" > + <nz-option *ngFor="let option of orgOptions" [nzLabel]="option.name" [nzValue]="option.id" [nzDisabled]="option.disabled"> + </nz-option> + </nz-select> + <button nz-button type="button" (click)="close()">������</button> <button nz-button [nzType]="'primary'" [nzLoading]="isSaving"> <span> @@ -114,4 +124,4 @@ </span> </button> </div> - </form> + diff --git a/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts b/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts index 47ec2f0..26d687b 100644 --- a/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts +++ b/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts @@ -6,13 +6,14 @@ import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { DeviceService } from '@business/services/http/device.service'; import { Component, OnInit } from '@angular/core'; -import { Device} from '@business/entity/data'; +import { Device, MonitorPoint} from '@business/entity/data'; import { _Validators } from '@delon/abc'; import { PageBean, ResultBean } from '@business/entity/grid'; import { _HttpClient } from '@delon/theme'; import { environment } from '@env/environment'; import { ExampleService } from '@business/services/util/example.service'; import { Observable } from 'rxjs/Observable'; +import { OrganizationService } from '@business/services/http/organization.service'; @Component({ selector: 'app-device-edit', @@ -25,6 +26,8 @@ public deviceVersions: any [] = []; public operateUsers: any [] = []; public isSaving = false; + public configMap: {orgId?: number, mpointId?: number, mpoint?: MonitorPoint} = {orgId: null}; + public orgOptions = []; constructor( private subject: NzModalSubject, private formBuilder: FormBuilder, @@ -32,13 +35,16 @@ private versionService: VersionService, private operateUserService: OperateUserService, private deviceService: DeviceService, - private http: _HttpClient + private http: _HttpClient, + private organizationService: OrganizationService ) { } data: Device; - //������������������ + // ������������������ originalData: Device = {}; + orgId: number = null; validateForm: FormGroup; ngOnInit() { + console.log(this.configMap); if (!!this.data) { Object.assign(this.originalData, this.data); } @@ -50,6 +56,14 @@ if (this.data.createTime == null) { this.data.createTime = new Date().getTime(); } + if (!!this.configMap.mpointId + && !!this.data.monitorPoint + && !data.longitude + && !data.latitude) { + data.longitude = this.data.monitorPoint.longitude; + data.latitude = this.data.monitorPoint.latitude; + } + data.monitorPointId = !!data.monitorPointId ? data.monitorPointId : this.configMap.mpointId; const validates: Device = { name: [data.name, [Validators.required]], mac: [data.mac, [Validators.required], [this.macAsyncValidator]], @@ -67,6 +81,12 @@ this.validateForm = this.formBuilder.group( validates ); + this.orgSelectChange(); + const control = this.validateForm.controls['monitorPointId']; + control.valueChanges.subscribe(value => { + const mpoint = ToolsService.getObjById<MonitorPoint>(value, this.monitorPoints); + this.resetCoor(mpoint); + }); } macAsyncValidator = (control: FormControl): any => { return Observable.create(observer => { @@ -79,7 +99,6 @@ exampleService.or().andEqualTo({name: 'mac', value: control.value}); this.deviceService.countByExample(exampleService).subscribe( res => { - debugger; if (!!res.code && !!res.data) { observer.next({ error: true, duplicated: true }); } else { @@ -114,9 +133,15 @@ } ); } - monitorPointChange(text) { - const pageBean: PageBean = {pageIndex: 0, pageSize: 20}; - this.monitorPointService.getPagingList(pageBean, text).subscribe( + monitorPointChange(text?: string) { + const pageBean: PageBean = {pageIndex: 0, pageSize: 100}; + const orgId = this.configMap.orgId; + const example = new ExampleService(); + text = !!text && !!text.trim() ? text : null; + example.or() + .andEqualTo({name: 'organizationId', value: this.configMap.orgId}) + .andEqualTo({name: 'name', value: text}); + this.monitorPointService.getPageByExample(pageBean, example).subscribe( (res: PageBean) => { if (res != null && res.data != null) { this.monitorPoints = res.data; @@ -177,4 +202,29 @@ } ); } + orgSelectChange(text?: string) { + const pageBean: PageBean = {pageIndex: 0, pageSize: 20}; + this.organizationService.getPagingList(pageBean, text).subscribe( + (res: PageBean) => { + if (res != null && res.data != null) { + this.orgOptions = res.data; + } + } + ); + } + setOrgId(orgId: number) { + this.configMap.mpointId = null; + this.monitorPointChange(); + this.clearMpoint(); + } + clearMpoint() { + ToolsService.setValueToControl(this.validateForm, 'monitorPointId', null); + this.resetCoor(); + } + resetCoor(mpoint?: MonitorPoint) { + const longitude = !!mpoint ? mpoint.longitude : null; + const latitude = !!mpoint ? mpoint.latitude : null; + ToolsService.setValueToControl(this.validateForm, 'longitude', longitude); + ToolsService.setValueToControl(this.validateForm, 'latitude', latitude); + } } diff --git a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html index c120cc2..e8b6eff 100644 --- a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html +++ b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.html @@ -15,7 +15,7 @@ </div> <div nz-form-control nz-col [nzSpan]="6" nzHasFeedback> <nz-select formControlName="organizationId" [nzPlaceHolder]="'������ ������(������������������)'" - nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="OrgSelectChange($event)" [nzNotFoundContent]="'������������'" > + nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="orgSelectChange($event)" [nzNotFoundContent]="'������������'" > <nz-option *ngFor="let option of orgOptions" [nzLabel]="option.name" [nzValue]="option.id" [nzDisabled]="option.disabled"> </nz-option> </nz-select> diff --git a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts index 826af7e..2e75da8 100644 --- a/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts +++ b/src/app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component.ts @@ -14,8 +14,8 @@ }) export class MonitorPointEditComponent implements OnInit { - orgOptions = []; - + orgOptions = []; + configMap: {organizationId: number}; data: MonitorPoint; isSaving = false; validateForm: FormGroup; @@ -36,7 +36,10 @@ value: data.areaCode }; } - this.OrgSelectChange(null); + this.orgSelectChange(null); + if (!!this.configMap.organizationId && !data.organizationId) { + data.organizationId = this.configMap.organizationId; + } const validates: MonitorPoint|object = { name: [data.name, [Validators.required] ], organizationId: [data.organizationId, [Validators.required]], @@ -48,6 +51,11 @@ }; this.validateForm = this.formBuilder.group( validates + ); + this.validateForm.controls['organizationId'].valueChanges.subscribe( + value => { + this.configMap.organizationId = value; + } ); } close() { @@ -121,7 +129,7 @@ this.data.townCode = codes[3]; this.data.villageCode = codes[4]; } - OrgSelectChange(text) { + orgSelectChange(text) { const pageBean: PageBean = {pageIndex: 0, pageSize: 20}; this.organizationService.getPagingList(pageBean, text).subscribe( (res: PageBean) => { diff --git a/src/app/routes/devices/monitor-point/monitor-point.component.html b/src/app/routes/devices/monitor-point/monitor-point.component.html index b676ceb..bf46e24 100644 --- a/src/app/routes/devices/monitor-point/monitor-point.component.html +++ b/src/app/routes/devices/monitor-point/monitor-point.component.html @@ -1,14 +1,28 @@ <pro-header [title]="grid.title"></pro-header> <nz-card [nzBordered]="false"> - <div class="mb-md"> + <div nz-row class="mb-sm"> + <div nz-col [nzSpan]="6"> <button nz-button (click)="addOrModify($event)" [nzType]="'primary'" [nzSize]="'large'"> <i class="anticon anticon-plus"></i><span>������</span> </button> <ng-container *ngIf="grid.selectedIndexs.length > 0"> <button nz-button [nzSize]="'large'" (click)="deleteSelected()">������������</button> </ng-container> - <nz-input [ngStyle]="{'width': '280px','float':'right'}" [(ngModel)]="queryMap.value" name="" [nzPlaceHolder]="queryMap.text" - (keyup)="queryTextChanged($event)" (change)="queryTextChanged($event)" ></nz-input> + </div> + <div nz-col style="text-align:right;padding: 5px 10px;" [nzSm]="6" [nzXs]="24"> + <label>���������</label> + </div> + <div nz-col [nzSpan]="6"> + <nz-select style="width: 90%;" [(ngModel)]="queryMap.organizationId" (ngModelChange)="setOrganizationId($event)" [nzPlaceHolder]="'������ ������(������������������)'" + nzAllowClear [nzFilter]="false" nzShowSearch (nzSearchChange)="orgSelectChange($event)" [nzNotFoundContent]="'������������'" > + <nz-option *ngFor="let option of orgOptions" [nzLabel]="option.name" [nzValue]="option.id" [nzDisabled]="option.disabled"> + </nz-option> + </nz-select> + </div> + <div nz-col [nzSpan]="6"> + <nz-input [(ngModel)]="queryMap.mpointName" name="" [nzPlaceHolder]="'������������������������'" + (keyup)="queryTextChanged($event)" (change)="queryTextChanged($event)" ></nz-input> + </div> </div> <div class="mb-md"> <nz-alert *ngIf="grid.selectedIndexs.length > 0" [nzType]="'info'" [nzShowIcon]="true"> diff --git a/src/app/routes/devices/monitor-point/monitor-point.component.ts b/src/app/routes/devices/monitor-point/monitor-point.component.ts index 67e290b..6892d0e 100644 --- a/src/app/routes/devices/monitor-point/monitor-point.component.ts +++ b/src/app/routes/devices/monitor-point/monitor-point.component.ts @@ -14,6 +14,8 @@ import { MonitorPointEditComponent } from 'app/routes/devices/monitor-point/monitor-point-edit/monitor-point-edit.component'; import { MonitorPointService } from '@business/services/http/monitor-point.service'; import { CoordinatesPickerComponent } from 'app/routes/map/coordinates-picker/coordinates-picker.component'; +import { OrganizationService } from '@business/services/http/organization.service'; +import { ExampleService } from '@business/services/util/example.service'; @Component({ @@ -23,10 +25,10 @@ }) export class MonitorPointComponent implements OnInit { - + public orgOptions = []; private monitorPoint: MonitorPoint; grid: Grid<MonitorPoint> = new Grid(null); - queryMap = { text: '���������������', value: '' }; + queryMap: { mpointName?: string, organizationId?: number } = { mpointName: null, organizationId: null }; queryTextStream: Subject<string> = new Subject<string>(); private initPage() { this.monitorPoint = { @@ -64,10 +66,10 @@ constructor( private coorPickerService: CoorPickerService, private monitorPointService: MonitorPointService, - private confirmServ: NzModalService, public msgSrv: NzMessageService, private modalHelper: ModalHelper, + private organizationService: OrganizationService ) { } ngOnInit() { @@ -78,9 +80,14 @@ .subscribe(queryText => { this.load(); }); + this.orgSelectChange(); + } + public setOrganizationId(orgId) { + this.queryMap.organizationId = orgId; + this.load(); } queryTextChanged($event) { - this.queryTextStream.next(this.queryMap.value); + this.queryTextStream.next(this.queryMap.mpointName); } load(reload: boolean = false) { if (reload) { @@ -90,7 +97,13 @@ setTimeout(() => { this.grid.loading = true; }, 1); - this.monitorPointService.getPagingList(this.grid, this.queryMap.value).subscribe( + const example = new ExampleService(); + const organizationId = !!this.queryMap.organizationId ? this.queryMap.organizationId : null; + const mpointName = !!this.queryMap.mpointName ? '%' + this.queryMap.mpointName + '%' : null; + example.or() + .andEqualTo({name: 'organizationId', value: organizationId }) + .andLike({name: 'name', value: mpointName }); + this.monitorPointService.getPageByExample(this.grid, example).subscribe( (res: PageBean) => { this.grid.loading = true; if (res != null && res.data != null) { @@ -110,7 +123,8 @@ if (d != null) { Object.assign(data, d); } - this.modalHelper.static(MonitorPointEditComponent, { data }).subscribe( + const configMap = this.queryMap; + this.modalHelper.static(MonitorPointEditComponent, { data, configMap }).subscribe( (ret: { data: any, close: Function }) => { // ������������ if (ret.data['index'] != null) { @@ -217,4 +231,14 @@ } ); } + orgSelectChange(text?: string) { + const pageBean: PageBean = {pageIndex: 0, pageSize: 20}; + this.organizationService.getPagingList(pageBean, text).subscribe( + (res: PageBean) => { + if (res != null && res.data != null) { + this.orgOptions = res.data; + } + } + ); + } } diff --git a/src/app/routes/devices/version/version-edit/version-edit.component.ts b/src/app/routes/devices/version/version-edit/version-edit.component.ts index b6d02dd..273b62f 100644 --- a/src/app/routes/devices/version/version-edit/version-edit.component.ts +++ b/src/app/routes/devices/version/version-edit/version-edit.component.ts @@ -1,8 +1,11 @@ import { DeviceVersion } from '@business/entity/data'; import { Component, OnInit } from '@angular/core'; import { NzMessageService, NzModalSubject } from 'ng-zorro-antd'; -import { FormGroup, FormBuilder, Validators } from '@angular/forms'; - +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; +import { _HttpClient } from '@delon/theme'; +import { ResultBean } from '@business/entity/grid'; +import { Observable } from 'rxjs/Observable'; +import { ToolsService } from '@business/services/util/tools.service'; @Component({ selector: 'app-version-edit', templateUrl: './version-edit.component.html', @@ -10,29 +13,47 @@ }) export class VersionEditComponent implements OnInit { + private originalData: DeviceVersion = {}; cols: DeviceVersion; - data: DeviceVersion; isSaving = false; validateForm: FormGroup; constructor( private subject: NzModalSubject, - private formBuilder: FormBuilder + private formBuilder: FormBuilder, + private http: _HttpClient ) { } ngOnInit() { if (this.data.createTime == null) { this.data.createTime = new Date().getTime(); } + if (!this.data.version) { + this.setMaxVersionNo(); + } const validates: DeviceVersion = { name: [this.data.name, [Validators.required] ], - version: [this.data.version == null ? 1 : this.data.version, [Validators.required] ], + version: [this.data.version, [Validators.required], [this.versionAsyncValidator] ], createTime: [this.data.createTime, [Validators.required] ], description: [this.data.description] }; + Object.assign(this.originalData, this.data); this.validateForm = this.formBuilder.group( validates ); + } + private setMaxVersionNo() { + this.isSaving = true; + this.http.get('device-version/get-maxverno').subscribe( + (res: ResultBean<number>) => { + if (!!res.code && res.data) { + ToolsService.setValueToControl(this.validateForm, 'version', res.data + 1); + }else { + this.data.version = 1; + } + this.isSaving = false; + } + ); } close() { this.subject.destroy(); @@ -64,6 +85,33 @@ this.validate(); } } + versionAsyncValidator = (control: FormControl): any => { + return Observable.create(observer => { + if (!!control && !!control.value) { + // ���������������version��������� + if (!!this.originalData && this.originalData.version === control.value) { + observer.next(null); + observer.complete(); + } else { + this.isSaving = true; + this.http.get('device-version/get-byversion', {version: control.value} ).subscribe( + (res: ResultBean<any>) => { + if (!!res.code && !!res.data) { + observer.next({ error: true, duplicated: true }); + } else { + observer.next(null); + } + observer.complete(); + this.isSaving = false; + } + ); + } + }else { + observer.next(null); + observer.complete(); + } + }); + } validate() { for (const i in this.validateForm.controls) { this.validateForm.controls[ i ].markAsDirty(); diff --git a/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts b/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts index 470d625..726a069 100644 --- a/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts +++ b/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts @@ -1,6 +1,6 @@ import { NzModalSubject } from 'ng-zorro-antd'; import { ReactiveFormsModule } from '@angular/forms'; -import { ViewEncapsulation, Component, ViewChild, ElementRef, NgZone } from '@angular/core'; +import { ViewEncapsulation, Component, ViewChild, ElementRef, NgZone, OnInit } from '@angular/core'; import { MapOptions, Point, MarkerOptions, ControlAnchor, NavigationControlOptions, NavigationControlType, BMapInstance } from 'angular2-baidu-map'; import { CoorPicker } from '@business/entity/data'; import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service'; @@ -13,7 +13,7 @@ templateUrl: './coordinates-picker.component.html', styleUrls: [ './coordinates-picker.component.css' ], }) -export class CoordinatesPickerComponent { +export class CoordinatesPickerComponent implements OnInit { Default_LNG = 121; Default_LAT = 31.4; isSaving = false; @@ -30,6 +30,9 @@ _BMap: any = null; constructor(private subject: NzModalSubject, private coorPickerService: CoorPickerService) { + + } + ngOnInit(): void { this.data = this.coorPickerService.data; let lng = this.data.longitude; lng = lng === 0 || lng == null ? this.Default_LNG : lng; @@ -69,7 +72,7 @@ width: -15 } }; - } + } private _marker: any = null; loadMarker(marker) { if (this._marker == null) { @@ -84,7 +87,7 @@ this._map.addEventListener( 'tilesloaded', (type, fn) => { - this._map.clearOverlays(); + // this._map.clearOverlays(); this._map.addOverlay(this._marker); } ); -- Gitblit v1.8.0