123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package handler
- import (
- "GtDataStore/app/cmd/organization/internal/logic/job"
- "GtDataStore/app/model"
- "context"
- "time"
- )
- const (
- DEVICE_UF = "uf"
- DEVICE_MF = "mf"
- DEVICE_NF = "nf"
- DEVICE_RO = "ro"
- DEVICE_VALVE = "valve"
- DEVICE_PUMP = "pump"
- 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,
- DEVICE_MF: 1 * time.Second,
- DEVICE_NF: 1 * time.Second,
- DEVICE_RO: 1 * time.Second,
- DEVICE_VALVE: 1 * time.Second,
- DEVICE_PUMP: 1 * time.Second,
- DEVICE_CHEST: 1 * time.Second,
- }
- DeviceHandlerTable = map[string]func(ctx context.Context, task *job.Task, technologyName string) error{
- DEVICE_UF: DeviceUf,
- DEVICE_MF: DeviceMf,
- DEVICE_NF: DeviceNf,
- DEVICE_RO: DeviceRo,
- DEVICE_VALVE: DeviceValve,
- 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,
- }
- }
|