12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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: 60 * time.Second,
- DEVICE_MF: 60 * time.Second,
- DEVICE_NF: 60 * time.Second,
- DEVICE_RO: 60 * time.Second,
- DEVICE_VALVE: 60 * time.Second,
- DEVICE_PUMP: 60 * time.Second,
- DEVICE_CHEST: 60 * 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
- }
- if len(cache.Data) > 0 {
- for _, datum := range cache.Data {
- datum.Items.ClearValues()
- }
- }
- 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,
- }
- }
|