[fix]首页面板数据缓存未更新

This commit is contained in:
PandaX
2023-11-21 08:46:35 +08:00
parent 1e2ee5bc6e
commit ec0457d7d3
3 changed files with 8 additions and 21 deletions

View File

@@ -11,7 +11,6 @@ import (
"github.com/PandaXGO/PandaKit/model"
"github.com/PandaXGO/PandaKit/restfulx"
"pandax/apps/device/util"
"pandax/pkg/cache"
"pandax/pkg/global"
model2 "pandax/pkg/global/model"
"pandax/pkg/shadow"
@@ -30,17 +29,13 @@ type DeviceApi struct {
}
func (p *DeviceApi) GetDevicePanel(rc *restfulx.ReqCtx) {
get, err := cache.PanelCache.ComputeIfAbsent("panel", func(k any) (any, error) {
var data entity.DeviceTotalOutput
data.DeviceInfo = p.DeviceApp.FindDeviceCount()
data.DeviceLinkStatusInfo = p.DeviceApp.FindDeviceCountGroupByLinkStatus()
data.DeviceCountType = p.DeviceApp.FindDeviceCountGroupByType()
data.AlarmInfo = p.DeviceAlarmApp.FindAlarmCount()
data.ProductInfo = p.ProductApp.FindProductCount()
return data, nil
})
biz.ErrIsNil(err, "获取面板数据失败")
rc.ResData = get
var data entity.DeviceTotalOutput
data.DeviceInfo = p.DeviceApp.FindDeviceCount()
data.DeviceLinkStatusInfo = p.DeviceApp.FindDeviceCountGroupByLinkStatus()
data.DeviceCountType = p.DeviceApp.FindDeviceCountGroupByType()
data.AlarmInfo = p.DeviceAlarmApp.FindAlarmCount()
data.ProductInfo = p.ProductApp.FindProductCount()
rc.ResData = data
}
// GetDeviceList Device列表数据

View File

@@ -17,7 +17,7 @@ server:
rate:
enable: true
rate-num: 100
db-type: postgresql
db-type: mysql
# 是否开启数据库表初始化
isInitTable: false
excel-dir: ./resource/excel/

8
pkg/cache/panel.go vendored
View File

@@ -1,8 +0,0 @@
package cache
import (
"github.com/PandaXGO/PandaKit/cache"
"time"
)
var PanelCache = cache.NewTimedCache(cache.NoExpiration, 600*time.Second)