LocationManager.js 1.7 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
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
import CabinetManager from './CabinetManager'

var LocationSample = {
  locationKey: '',
  locationId: '',
  locationName: '',
  line: '',
  site: '',
  km: '',
  longitude: '',
  latitude: '',
  delFlag: '',
  modifyTime: ''
}

class LocationMgrImplement {
  // 根据key值获取机房
  findLocationByKey (locationCollection, locationKey) {
    return locationCollection[locationKey]
  }

  // 查找机架所在机房
  findCabinetLocation (cabinetKey, CabinetCollection, locationCollection) {
    let cabiinetMgr = CabinetManager(CabinetCollection)
    let cabinet = cabiinetMgr.findCabinetByKey(cabinetKey)
    return this.findLocationByKey(locationCollection, cabinet.locationKey)
  }

  // 结构体转数组
  locationAsArray (locationCollection) {
    return Object.values(locationCollection)
  }
}

let implementMethods = new LocationMgrImplement()

var staticMethods = {
  createSubnetSample: function () {
    return Object.freeze(Object.assign({}, LocationSample))
  }
}

function LocationManager (LocationCollection) {
  // 根据key值获取机房
  function findLocationByKey (LocationKey) {
    return implementMethods.findLocationByKey()
  }

  // 查找机架所在机房
  function findCabinetLocation (cabinetKey, CabinetCollection) {
    return implementMethods.findCabinetLocation(cabinetKey, CabinetCollection, LocationCollection)
  }

  // 结构体转数组
  function asArray() {
    implementMethods.locationAsArray(LocationCollection)
  }

  return Object.freeze(Object.assign(
    {
      // 在此列出模型对象方法
      findLocationByKey,
      findCabinetLocation,
      asArray
    },
    staticMethods // 将静态模型方法注入到模型对象方法中
  ))
}

export default LocationManager