1
0

marge: 合并代码

This commit is contained in:
TsMask
2024-02-07 12:31:25 +08:00
parent 6d9123314c
commit d5f7a2077e
65 changed files with 2445 additions and 99 deletions

View File

@@ -2,6 +2,7 @@ package controller
import (
"fmt"
"sync"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
@@ -26,7 +27,8 @@ type NeInfoController struct {
}
// neStateCacheMap 网元状态缓存最后一次成功的信息
var neStateCacheMap map[string]map[string]any = make(map[string]map[string]any)
var neStateCacheMap sync.Map
var mutex sync.Mutex
// 网元状态
//
@@ -52,12 +54,13 @@ func (s *NeInfoController) NeState(c *gin.Context) {
// 网元直连
resData, err := neService.NeState(neInfo)
if err != nil {
mutex.Lock()
// 异常取上次缓存
if v, ok := neStateCacheMap[neKey]; ok && v != nil {
v["online"] = false
neStateCacheMap[neKey] = v
resDataCache, ok := neStateCacheMap.Load(neKey)
if ok && resDataCache != nil {
resDataCache.(map[string]any)["online"] = false
} else {
neStateCacheMap[neKey] = map[string]any{
resDataCache = map[string]any{
"online": false,
"neId": neInfo.NeId,
"neName": neInfo.NeName,
@@ -65,13 +68,17 @@ func (s *NeInfoController) NeState(c *gin.Context) {
"neIP": neInfo.IP,
}
}
c.JSON(200, result.OkData(neStateCacheMap[neKey]))
neStateCacheMap.Store(neKey, resDataCache)
mutex.Unlock()
c.JSON(200, result.OkData(resDataCache))
return
}
// 存入缓存
resData["online"] = true
neStateCacheMap[neKey] = resData
mutex.Lock()
neStateCacheMap.Store(neKey, resData)
mutex.Unlock()
c.JSON(200, result.OkData(resData))
}