|
@@ -2,6 +2,7 @@ package handler
|
|
|
|
|
|
import (
|
|
|
"GtDataStore/app/cmd/organization/internal/logic/job"
|
|
|
+ "GtDataStore/app/model"
|
|
|
"context"
|
|
|
"time"
|
|
|
)
|
|
@@ -16,6 +17,15 @@ const (
|
|
|
DEVICE_CHEST = "chest"
|
|
|
)
|
|
|
|
|
|
+type (
|
|
|
+ DeviceBindCache struct {
|
|
|
+ Expire time.Time
|
|
|
+ Data []model.DcDeviceBind
|
|
|
+ }
|
|
|
+
|
|
|
+ DeviceBindCacheMap map[string]DeviceBindCache
|
|
|
+)
|
|
|
+
|
|
|
var (
|
|
|
DeviceIntervalTable = map[string]time.Duration{
|
|
|
DEVICE_UF: 1 * time.Second,
|
|
@@ -36,4 +46,33 @@ var (
|
|
|
DEVICE_PUMP: DevicePump,
|
|
|
DEVICE_CHEST: DeviceChest,
|
|
|
}
|
|
|
+
|
|
|
+ deviceBindCacheTable = DeviceBindCacheMap{
|
|
|
+ DEVICE_UF: DeviceBindCache{},
|
|
|
+ DEVICE_MF: DeviceBindCache{},
|
|
|
+ DEVICE_NF: DeviceBindCache{},
|
|
|
+ DEVICE_RO: DeviceBindCache{},
|
|
|
+ DEVICE_VALVE: DeviceBindCache{},
|
|
|
+ DEVICE_PUMP: DeviceBindCache{},
|
|
|
+ DEVICE_CHEST: DeviceBindCache{},
|
|
|
+ }
|
|
|
)
|
|
|
+
|
|
|
+func (t DeviceBindCacheMap) GetCache(technologyName string) []model.DcDeviceBind {
|
|
|
+ if cache, ok := t[technologyName]; ok {
|
|
|
+ if time.Now().After(cache.Expire) {
|
|
|
+ t[technologyName] = DeviceBindCache{}
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return cache.Data
|
|
|
+ } else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (t DeviceBindCacheMap) SetCache(technologyName string, data []model.DcDeviceBind, expire time.Time) {
|
|
|
+ t[technologyName] = DeviceBindCache{
|
|
|
+ Expire: expire,
|
|
|
+ Data: data,
|
|
|
+ }
|
|
|
+}
|