From 4c75d3f7678238a61f7c644f2a673896b454525a Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Fri, 20 Jul 2018 13:47:59 +0800
Subject: [PATCH] 添加两个页面

---
 src/app/routes/operation/device-status/device-status.component.ts |  286 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 275 insertions(+), 11 deletions(-)

diff --git a/src/app/routes/operation/device-status/device-status.component.ts b/src/app/routes/operation/device-status/device-status.component.ts
index 2e709f1..dbd700b 100644
--- a/src/app/routes/operation/device-status/device-status.component.ts
+++ b/src/app/routes/operation/device-status/device-status.component.ts
@@ -1,17 +1,281 @@
-import { Component, OnInit } from '@angular/core';
-import { _HttpClient } from '@delon/theme';
+import { MonitorPointService } from '@business/services/http/monitor-point.service';
+import { CoorPicker, Device } from '@business/entity/data';
+import { ModalHelper, _HttpClient } from '@delon/theme';
+import { NzModalService, NzMessageService } from 'ng-zorro-antd';
+import { PageBean, ResultBean } from '@business/entity/grid';
+import { DeviceService } from '@business/services/http/device.service';
+import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';
+import { SimpleTableColumn, SimpleTableComponent } from '@delon/abc';
+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, Criteria } from '@business/services/util/example.service';
+import { AdjustConfigComponent } from '../../devices/basic-info/adjust-config/adjust-config.component';
+import { DeviceEditComponent } from '../../devices/basic-info/device-edit/device-edit.component';
 
 @Component({
   selector: 'app-device-status',
   templateUrl: './device-status.component.html',
 })
 export class DeviceStatusComponent implements OnInit {
-
-    constructor(
-        private http: _HttpClient
-    ) { }
-
-    ngOnInit() {
-    }
-
-}
+         private getBadge(id): string  {
+             return `<div>${id}</div>`;
+         }
+        columns: SimpleTableColumn[] = [
+          { title: '������', index: 'id', type: 'checkbox' },
+          { title: '������', index: 'name' },
+          { title: 'mac', index: 'mac' },
+          {
+            title: '������',
+            render: 'state-badge'
+          },
+          { title: '������', index: 'deviceVersion.name' },
+          { title: '������������', index: 'monitorPoint.name' },
+          { title: '���������', index: 'operateUser.name' },
+          { title: '������������', width: '100px', type: 'date', index: 'createTime' },
+          { title: '������������', width: '100px', type: 'date', index: 'installTime' },
+        ];
+        queryTextStream: Subject<string> = new Subject<string>();
+        public 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 organizationService: OrganizationService,
+          private http: _HttpClient
+        ) { }
+      
+        ngOnInit() {
+          this.queryTextStream
+            .debounceTime(900)
+            .distinctUntilChanged()
+            .subscribe(value => {
+              this.queryMap.devMacOrName = value;
+              this.load();
+            });
+            this.orgSelectChange();
+        }
+        get listUrl() {
+          return this.deviceService.getListUrl();
+        }
+        queryText: string;
+        selectedRows: any[] = [];
+        checkboxChange(list: any[]) {
+          this.selectedRows = list;
+        }
+        deleteSelected() {
+          this.confirmServ.confirm({
+            title: '������������',
+            content: '������������������������������������������������',
+            okText: '������',
+            cancelText: '������'
+          }).on('onOk', () => {
+            if (this.selectedRows != null && this.selectedRows.length > 0) {
+              const ids = this.selectedRows.map(
+                (row: any) => {
+      
+                  return Number.parseInt(row.id);
+                }
+              );
+              this.delete(...ids);
+            }
+          });
+        }
+        load() {
+          const example  = this.initQueryExample();
+          this.extraParams.queryParams = example.getSqlParam();
+          this.selectedRows = [];
+          this.deviceService.countByExample(example).subscribe(
+            res => {
+                 if (!!res && !!res.code) {
+                      const count = res.data;
+                      const pages = Math.ceil(count / this.simpleTable.ps);
+                      const pi = this.simpleTable.pi > pages ? pages : this.simpleTable.pi;
+                      this.simpleTable.load(pi);
+                 }
+            }
+          );
+          
+        }
+        private initQueryExample() {
+          const example = new ExampleService();
+          const orgId = !!this.queryMap.orgId ? this.queryMap.orgId : null;
+          const mpointId = !!this.queryMap.mpointId ? this.queryMap.mpointId : null;
+          const devMacOrName = !!this.queryMap.devMacOrName && !!(<string>this.queryMap.devMacOrName).trim() ? this.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;
+        }
+        delete(...id: number[]) {
+          this.deviceService.delete(...id).subscribe(
+            (res: any) => {
+              if (res.code === 1) {
+                this.load();
+                this.msgSrv.success('���������������');
+              }
+            }
+          );
+        }
+        @ViewChild('simpleTable') simpleTable: SimpleTableComponent;
+        queryTextChanged(event) {
+          this.queryTextStream.next(this.queryText);
+        }
+        addOrModify(d) {
+          const data = {};
+          if (d != null) {  
+            Object.assign(data, d);
+          }
+          let configMap = {};
+          configMap = Object.assign(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) {
+                const origData = d;
+                const isModified = Object.keys(ret.data).some(
+                  (key: string) => {
+                    return ret.data[key] !== origData[key];
+                  }
+                );
+                // ������������
+                if (!isModified) {
+                  ret.close();
+                  this.msgSrv.success('���������������������������');
+                  return;
+                }
+              }
+              this.deviceService.save(ret.data).subscribe(
+                (res: any) => {
+                  if (res.code === 1) {
+                    this.load();
+                    ret.close();
+                    this.msgSrv.success('���������������������');
+                  }
+                }
+              );
+            });
+        }
+        private getMonitorPoint(mpointId: number) {
+           return this.monitorPoints.find(
+              mpoint => mpoint.id === mpointId
+           );
+        }
+        configCoord(record: Device): void {
+           // ������������������������������������������adress������������
+           Object.assign(this.coorPickerService.data, record);
+           this.coorPickerService.data['describe'] = '������������';
+            // ������ ��������������� ������������������
+            if ((!record.latitude || !record.longitude) && !!record.monitorPointId) {
+                  this.monitorPointService.getEntity(record.monitorPointId).subscribe(
+                    res => {
+                      if (res != null && res.code === 1 && res.data != null) {
+                          const areaNames = res.data.areaNames;
+                          let adress = '';
+                          if (areaNames != null) {
+                            adress += !!areaNames.provinceName ? areaNames.provinceName : '';
+                            adress += ' ';
+                            adress += !!areaNames.cityName ? areaNames.cityName : '';
+                            adress += ' ';
+                            adress += !!areaNames.areaName ? areaNames.areaName : '';
+                            adress += ' ';
+                            adress += !!res.data.address ? res.data.address : '';                  
+                          }
+                          this.coorPickerService.data.address = adress;
+                          this.openMap(record);              
+                      }
+                    }
+              );
+            } else {
+              this.openMap(record);
+            }
+        }
+        private openMap(record: Device) {
+          const _data = this.coorPickerService.data;    
+          this.modalHelper.static(CoordinatesPickerComponent).subscribe(
+            (staticComp) => {
+                   const data: Device = {
+                      id: record.id,
+                      mac: record.mac,
+                      longitude: _data.longitude,
+                      latitude: _data.latitude,
+                   };
+                   this.deviceService.save(data).subscribe(
+                    (resp: any) => {
+                      if (resp.code === 1) {
+                        this.load();
+                        this.msgSrv.success('���������������������');
+                      }
+                    }
+                   );                     
+            }
+         );
+        }
+        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;
+                  }
+              }
+          );
+          }
+      }
\ No newline at end of file

--
Gitblit v1.8.0