| | |
| | | import { NzMessageService } from 'ng-zorro-antd'; |
| | | import { getTimeDistance, yuan, fixedZero } from '@delon/abc'; |
| | | import { _HttpClient } from '@delon/theme'; |
| | | import {HttpClient} from '@angular/common/http'; |
| | | import { HttpClient } from '@angular/common/http'; |
| | | import * as moment from 'moment'; |
| | | import { DeviceService } from '@business/services/http/device.service'; |
| | | import { ExampleService } from '@business/services/util/example.service'; |
| | | import { ResultBean } from '@business/entity/grid'; |
| | | import { TimeUnits } from '@business/enum/types.enum'; |
| | | import { ToolsService } from '@business/services/util/tools.service'; |
| | | |
| | | @Component({ |
| | | selector: 'app-dashboard-workplace', |
| | | templateUrl: './workplace.component.html', |
| | | styleUrls: ['./workplace.component.less'] |
| | | styleUrls: ['./workplace.component.less'], |
| | | providers: [DeviceService] |
| | | }) |
| | | export class DashboardWorkplaceComponent implements OnInit, OnDestroy { |
| | | |
| | | totalDeviceCountList: any[] = []; |
| | | totalDeviceCount = 0; |
| | | avgDeviceCount: string; |
| | | |
| | | totalDeviceCount = ''; |
| | | avgDeviceCount = ''; |
| | | deviceCountLoading = true; |
| | | // 报警统计 |
| | | alarmCountList:{x: string,y: number}[] = null; |
| | | alarmCountCurrMonth = ''; |
| | | alarmCountCurrDay = '';// 单月报警次数 |
| | | alarmCountLoading = true; |
| | | operationLoading = true; |
| | | operNormalPercent = 0; |
| | | activities: any[] = []; |
| | | radarData: any[] = []; |
| | | loading = true; |
| | | |
| | | members = [ |
| | | { |
| | | id: 'members-1', |
| | | title: '七星官网', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', |
| | | link: '', |
| | | id: 'members-1', |
| | | title: '七星官网', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', |
| | | link: '', |
| | | }, |
| | | { |
| | | id: 'members-2', |
| | | title: '七星商城', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', |
| | | link: '', |
| | | id: 'members-2', |
| | | title: '七星商城', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', |
| | | link: '', |
| | | }, |
| | | { |
| | | id: 'members-3', |
| | | title: '外链三', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', |
| | | link: '', |
| | | id: 'members-3', |
| | | title: '外链三', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', |
| | | link: '', |
| | | }, |
| | | { |
| | | id: 'members-4', |
| | | title: '外链四', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', |
| | | link: '', |
| | | id: 'members-4', |
| | | title: '外链四', |
| | | logo: 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', |
| | | link: '', |
| | | } |
| | | ]; |
| | | ]; |
| | | |
| | | data: any = {}; |
| | | |
| | |
| | | }; |
| | | |
| | | rankingListData: any[] = [ |
| | | {title: `PM 2.5`, total: 230}, |
| | | {title: `PM 10`, total: 175}, |
| | | {title: `二氧化硫`, total: 123}, |
| | | {title: `二氧化氮`, total: 92}, |
| | | {title: `甲醛`, total: 39}, |
| | | {title: `氯气`, total: 24}, |
| | | {title: `一氧化碳`, total: 8} |
| | | { title: `PM 2.5`, total: 230 }, |
| | | { title: `PM 10`, total: 175 }, |
| | | { title: `二氧化硫`, total: 123 }, |
| | | { title: `二氧化氮`, total: 92 }, |
| | | { title: `甲醛`, total: 39 }, |
| | | { title: `氯气`, total: 24 }, |
| | | { title: `一氧化碳`, total: 8 } |
| | | ]; |
| | | |
| | | constructor( |
| | | private deviceService: DeviceService, |
| | | private http: _HttpClient, |
| | | public msg: NzMessageService, |
| | | private http2: HttpClient) { |
| | | } |
| | | |
| | | ngOnInit() { |
| | | const today = new Date().getTime(); |
| | | const fakeDC = [60, 135, 70, 112, 80, 170, 200, 140, 52, 119, 164, 230]; |
| | | for (let i = 0; i < 12; i += 1) { |
| | | this.totalDeviceCountList.push({ |
| | | x: moment(today).subtract(-1 * i, 'months').format( |
| | | 'YYYY-MM' |
| | | ), |
| | | y: fakeDC[i] |
| | | }); |
| | | this.totalDeviceCount += fakeDC[i]; |
| | | } |
| | | this.avgDeviceCount = (this.totalDeviceCount / 12).toFixed(0); |
| | | // const today = new Date().getTime(); |
| | | // const fakeDC = [60, 135, 70, 112, 80, 170, 200, 140, 52, 119, 164, 230]; |
| | | // for (let i = 0; i < 12; i += 1) { |
| | | // this.totalDeviceCountList.push({ |
| | | // x: moment(today).subtract(-1 * i, 'months').format( |
| | | // "YYYY-MM" |
| | | // ), |
| | | // y: fakeDC[i] |
| | | // }); |
| | | // this.totalDeviceCount += fakeDC[i]; |
| | | // } |
| | | let example1 = new ExampleService(); |
| | | let mo = moment(); |
| | | example1.or().andGreaterThanOrEqualTo({ name: "createTime", value: mo.format('YYYY-MM-01 00:00:00') }); |
| | | let example2 = new ExampleService(); |
| | | let example3 = new ExampleService(); |
| | | example3.or().andNotEqualTo({name:'state',value:4}); |
| | | zip(this.deviceService.countByExample(example1), |
| | | this.deviceService.countByExample(example2), |
| | | this.http.get<ResultBean<{time: string,count: number}[]>>('device/count-by-times',{start:mo.format('YYYY-01-01 00:00:00'),end:mo.format('YYYY-12-31 23:59:59')}), |
| | | this.deviceService.countByExample(example3)).subscribe( |
| | | ([rWtihAvg, rWithToltal,rWithList,rWithNormal]) => { |
| | | if (!!rWtihAvg.code && !!rWithToltal&&!!rWithList.code) { |
| | | this.avgDeviceCount = ToolsService.toThousands(rWtihAvg.data.toString()); |
| | | this.totalDeviceCount = ToolsService.toThousands(rWithToltal.data.toString()); |
| | | rWithList.data.forEach( item =>{ |
| | | this.totalDeviceCountList.push( |
| | | { |
| | | x:item.time, |
| | | y:item.count |
| | | } |
| | | ); |
| | | }); |
| | | this.operNormalPercent = Math.round(rWithNormal.data/rWithToltal.data*100); |
| | | this.deviceCountLoading = false; |
| | | this.operationLoading = false; |
| | | } |
| | | } |
| | | ); |
| | | zip( |
| | | this.http.get<ResultBean<{time: string,count: number}[]>>("alarm/count-by-times",{start: mo.format('YYYY-MM-01 00:00:00'),end: null,timeUnits: TimeUnits.DAY}), |
| | | this.http.get<ResultBean<{time: string,count: number}[]>>("alarm/count-by-times",{start: mo.format('YYYY-MM-01 00:00:00'),end: null}), |
| | | this.http.get<ResultBean<{time: string,count: number}[]>>("alarm/count-by-times",{start: mo.format('YYYY-MM-DD 00:00:00'),end: null}) |
| | | ).subscribe( |
| | | ([rWithList,rWithMonth,rWithDay]) => { |
| | | if(!!rWithList.code&&!!rWithMonth.code&&!!rWithDay.code){ |
| | | this.alarmCountList = rWithList.data.map( |
| | | item => { |
| | | return {x:item.time,y:item.count}; |
| | | } |
| | | ); |
| | | if(!!rWithMonth.data&&rWithMonth.data.length>0){ |
| | | this.alarmCountCurrMonth = ToolsService.toThousands(rWithMonth.data[0].count.toString()); |
| | | } |
| | | if(!!rWithDay.data&&rWithDay.data.length>0) { |
| | | this.alarmCountCurrDay = ToolsService.toThousands(rWithDay.data[0].count.toString()); |
| | | } |
| | | this.alarmCountLoading = false; |
| | | } |
| | | } |
| | | ); |
| | | // this.avgDeviceCount = (this.totalDeviceCount / 12).toFixed(0); |
| | | |
| | | const alarmData = []; |
| | | const alarmData_1 = []; |
| | |
| | | sort(sortName, sortValue) { |
| | | this.data.searchData = [ |
| | | ...(<any[]>this.data.searchData).sort((a, b) => { |
| | | if (a[ sortName ] > b[ sortName ]) { |
| | | if (a[sortName] > b[sortName]) { |
| | | return (sortValue === 'ascend') ? 1 : -1; |
| | | } else if (a[ sortName ] < b[ sortName ]) { |
| | | } else if (a[sortName] < b[sortName]) { |
| | | return (sortValue === 'ascend') ? -1 : 1; |
| | | } else { |
| | | return 0; |