import { injectable , inject } from "inversify" ; import TYPES from "../../common/types" ; import { SystemInfoInstance , SystemInfoAttribute } from "./system-info.model" ; import { SystemInfoDto , SystemInfoMapDto , SystemInfoDetailMapDto } from "./system-info.dto" ; import { SystemInfoDao } from "./system-info.dao" ; interface SystemInfoService { getSystemList ( ) : Promise < Array < string > > ; getAllSystemInfo ( begin ) : Promise < Array < SystemInfoDto > > ; getSystemInfo ( system , begin , end , count ) : Promise < SystemInfoMapDto > ; getSystemInfoDetail ( system , begin , end , count ) : Promise < SystemInfoDetailMapDto > ; saveSystemInfo ( systemInfos ) : Promise < void > ; } @ injectable ( ) class SystemInfoServiceImpl implements SystemInfoService { constructor ( @ inject ( TYPES . SystemInfoDao ) private systemInfoDao ) { } public getSystemList ( ) { return this . systemInfoDao . getSystemList ( ) ; } public getAllSystemInfo ( begin ) { return this . systemInfoDao . getAllSystemInfo ( begin ) . then ( ( systemInfos ) => { return systemInfos . map ( ( systemInfo ) => { return { id : systemInfo . id , time : systemInfo . time , name : systemInfo . name , node : systemInfo . node , source : systemInfo . source , rpm : systemInfo . rpm , fpm : systemInfo . fpm } ; } ) ; } ) ; } public getSystemInfo ( system , begin , end , count ) { return this . systemInfoDao . getSystemInfo ( system , begin , end , count ) . then ( ( systemInfos ) => { let result = { } ; systemInfos . forEach ( ( item ) => { let time = item . time ; if ( result [ time ] === undefined ) result [ time ] = [ 0 , 0 ] ; result [ time ] [ 0 ] += item . rpm ; result [ time ] [ 1 ] += item . fpm ; } ) ; return result ; } ) ; } public getSystemInfoDetail ( system , begin , end , count ) { return this . systemInfoDao . getSystemInfo ( system , begin , end , count ) . then ( ( systemInfos ) => { let result = { } ; systemInfos . forEach ( ( item ) => { let time = item . time ; if ( result [ time ] === undefined ) result [ time ] = [ ] ; result [ time ] . push ( [ item . node , item . rpm , item . fpm ] ) ; } ) ; return result ; } ) ; } public saveSystemInfo ( systemInfos ) { return this . systemInfoDao . saveSystemInfo ( systemInfos ) . then ( ( result ) => { return ; } ) ; } } export { SystemInfoService , SystemInfoServiceImpl } ;