1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var cabinetSmaple = {
cabinetKey: '',
cabinetName: '',
cabinetType: '',
locationKey: '',
height: '',
depth: '',
width: '',
frameCount: -1,
voltage: '',
delFlag: -1,
modifyTime: ''
}
class CabinetMgrImplement {
// 根据key值查找机架
findCabinetByKey (CabinetCollection, cabinetKey) {
return CabinetCollection[cabinetKey]
}
// 查找机房内的机架
findLocationCabinet (locationKey, CabinetCollection) {
let cabinetList = {}
for (var cabinetKey in CabinetCollection) {
if (CabinetCollection[cabinetKey].locationKey === locationKey) {
let cabinet = this.findCabinetByKey(CabinetCollection, cabinetKey)
cabinetList[cabinetKey] = cabinet
}
}
return cabinetList
}
// 结构体转数组
cabinetAsArray (CabinetCollection) {
return Object.values(CabinetCollection)
}
}
let implementMethods = new CabinetMgrImplement()
var staticMethods = {
createDeviceSample: function () {
return Object.freeze(Object.assign({}, cabinetSmaple))
}
}
function CabinetManager (CabinetCollection) {
// 根据key值获取机架
function findCabinetByKey (cabinetKey) {
return implementMethods.findCabinetByKey(CabinetCollection, cabinetKey)
}
// 查找机房内的机架
function findLocationCabinet (locationKey) {
return implementMethods.findLocationCabinet(locationKey, CabinetCollection)
}
function asArray() {
return implementMethods.cabinetAsArray(CabinetCollection)
}
return Object.freeze(Object.assign(
{
findCabinetByKey,
findLocationCabinet,
asArray
},
staticMethods
))
}
export default CabinetManager