|  |  |  | 
|---|
|  |  |  | import { DataType } from './../../../core/entity/grid'; | 
|---|
|  |  |  | import { VersionSensorConfigComponent } from './version-sensor-config/version-sensor-config.component'; | 
|---|
|  |  |  | import { DataType } from '@business/entity/grid'; | 
|---|
|  |  |  | import { DeviceVersion, Sensor } from '@business/entity/data'; | 
|---|
|  |  |  | import { Version } from '@angular/compiler/src/util'; | 
|---|
|  |  |  | import { Subject } from 'rxjs/Subject'; | 
|---|
|  |  |  | import { ToolsService } from '@core/services/tools.service'; | 
|---|
|  |  |  | import { ToolsService } from '@business/services/util/tools.service'; | 
|---|
|  |  |  | import { Component, OnInit } from '@angular/core'; | 
|---|
|  |  |  | import { NzMessageService, NzModalService } from 'ng-zorro-antd'; | 
|---|
|  |  |  | import { ModalHelper } from '@delon/theme'; | 
|---|
|  |  |  | import { HttpClient } from '@angular/common/http'; | 
|---|
|  |  |  | import { environment } from '../../../../environments/environment'; | 
|---|
|  |  |  | import { DateService } from '@core/services/date.service'; | 
|---|
|  |  |  | import { VersionService } from 'app/routes/devices/version/version.service'; | 
|---|
|  |  |  | import { Types } from '@core/enum/types.enum'; | 
|---|
|  |  |  | import { Column, Grid, PageBean } from '@core/entity/grid'; | 
|---|
|  |  |  | import { filter } from 'rxjs/operators/filter'; | 
|---|
|  |  |  | import { DateService } from '@business/services/util/date.service'; | 
|---|
|  |  |  | import { VersionService } from '@business/services/http/version.service'; | 
|---|
|  |  |  | import { Types } from '@business/enum/types.enum'; | 
|---|
|  |  |  | import { Column, Grid, PageBean } from '@business/entity/grid'; | 
|---|
|  |  |  | import { VersionEditComponent } from 'app/routes/devices/version/version-edit/version-edit.component'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export interface DeviceVersion { | 
|---|
|  |  |  | createTime?: Column|any; | 
|---|
|  |  |  | description?: Column|any; | 
|---|
|  |  |  | id?: Column|any; | 
|---|
|  |  |  | name?: Column|any; | 
|---|
|  |  |  | version?: Column|any; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component({ | 
|---|
|  |  |  | selector: 'app-version', | 
|---|
|  |  |  | templateUrl: './version.component.html', | 
|---|
|  |  |  | 
|---|
|  |  |  | if (res.code === 1) { | 
|---|
|  |  |  | this.load(); | 
|---|
|  |  |  | ret.close(); | 
|---|
|  |  |  | this.msgSrv.success('设备型号保存成功!'); | 
|---|
|  |  |  | this.msgSrv.success(this.grid.title + '保存成功!'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | 
|---|
|  |  |  | ( res: any) => { | 
|---|
|  |  |  | if (res.code === 1) { | 
|---|
|  |  |  | this.load(); | 
|---|
|  |  |  | this.msgSrv.success('设备型号删除成功!'); | 
|---|
|  |  |  | this.msgSrv.success(this.grid.title + '删除成功!'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.load(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | configSensor(data) { | 
|---|
|  |  |  | const deviceVersionId = data.id; | 
|---|
|  |  |  | this.versionService.getSensorIds(deviceVersionId).subscribe( | 
|---|
|  |  |  | (selectedSensorIds: number[]) => { | 
|---|
|  |  |  | this.modalHelper.static(VersionSensorConfigComponent, { deviceVersionId, selectedSensorIds }).subscribe( | 
|---|
|  |  |  | ( ret: { grid: Grid<Sensor>, close: Function} ) => { | 
|---|
|  |  |  | // 获取选中id | 
|---|
|  |  |  | const selectedIds = ret.grid.data.filter( | 
|---|
|  |  |  | (r: any) => { | 
|---|
|  |  |  | return r['checked'] === true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ).map( | 
|---|
|  |  |  | (r: any) => { | 
|---|
|  |  |  | return r['id']; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | // 长度不一样,已经修改 | 
|---|
|  |  |  | let isModified = selectedIds.length !== selectedSensorIds.length; | 
|---|
|  |  |  | // 长度一样再比较内容 | 
|---|
|  |  |  | if (!isModified) { | 
|---|
|  |  |  | isModified = !selectedIds.every( | 
|---|
|  |  |  | (id: number) => { | 
|---|
|  |  |  | // console.log('id:' + id); | 
|---|
|  |  |  | const result = selectedSensorIds.some( | 
|---|
|  |  |  | (sid: number) => { | 
|---|
|  |  |  | return id === sid ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | // console.log('result:' + result); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if ( !isModified ) { | 
|---|
|  |  |  | this.msgSrv.success(this.grid.title + '配置未修改!'); | 
|---|
|  |  |  | ret.close(); | 
|---|
|  |  |  | return ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.versionService.versionSensorConfig(deviceVersionId, selectedIds).subscribe( | 
|---|
|  |  |  | ( res: any) => { | 
|---|
|  |  |  | if (res.code === 1) { | 
|---|
|  |  |  | ret.close(); | 
|---|
|  |  |  | this.msgSrv.success(this.grid.title + '配置成功!'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | reset(ls: any[]) { | 
|---|
|  |  |  | for (const item of ls) item.value = false; | 
|---|
|  |  |  | this.load(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|