ref: 重构网元状态,提升加载网元列表带状态速度

Refactor network element state management

- Removed the NE state endpoint and related service logic from the network_data module.
- Introduced a new NEStateController to handle network element state records.
- Implemented NEState service and repository for managing state records in the database.
- Updated NEInfo and NeLicense controllers to utilize the new NEState service for fetching and saving state information.
- Enhanced state handling in the websocket processor to reflect the latest state of network elements.
- Added caching logic for network element states using Redis.
- Improved error handling and response formatting for state queries.
This commit is contained in:
TsMask
2025-10-27 15:15:27 +08:00
parent 667d0fdad8
commit e7ae390f6e
18 changed files with 428 additions and 343 deletions

View File

@@ -6,11 +6,12 @@ import (
"github.com/gin-gonic/gin"
"be.ems/src/framework/constants"
"be.ems/src/framework/database/redis"
"be.ems/src/framework/i18n"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/parse"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
"be.ems/src/modules/network_element/model"
neService "be.ems/src/modules/network_element/service"
)
@@ -19,6 +20,7 @@ import (
var NewNeLicense = &NeLicenseController{
neLicenseService: neService.NewNeLicense,
neInfoService: neService.NewNeInfo,
neStateService: neService.NewNEState,
}
// 网元授权激活请求
@@ -27,6 +29,7 @@ var NewNeLicense = &NeLicenseController{
type NeLicenseController struct {
neLicenseService *neService.NeLicense // 网元授权激活服务
neInfoService *neService.NeInfo // 网元信息服务
neStateService *neService.NEState // 网元状态服务
}
// 网元授权激活列表
@@ -260,15 +263,21 @@ func (s *NeLicenseController) State(c *gin.Context) {
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
if neState, err := neFetchlink.NeState(neInfo); err == nil && neState["sn"] != nil {
neLicense.Status = "1"
neLicense.SerialNum = fmt.Sprint(neState["sn"])
neLicense.ExpiryDate = fmt.Sprint(neState["expire"])
neLicense.UeNumber = parse.Number(neState["ueNumber"])
neLicense.NbNumber = parse.Number(neState["nbNumber"])
} else {
// 没状态标记,视为离线
key := fmt.Sprintf("%s:%s:%s_status", constants.CACHE_NE_INFO, neInfo.NeType, neInfo.NeId)
keyNum, err := redis.Has("", key)
if keyNum == 0 || err != nil {
neLicense.Status = "0"
} else {
state := s.neStateService.Last(neInfo.NeType, neInfo.NeId)
neLicense.Status = "1"
neLicense.SerialNum = state.SerialNum
neLicense.ExpiryDate = state.ExpiryDate
neLicense.UeNumber = state.UENumber
neLicense.NbNumber = state.NbNumber
}
// 更新授权码
if neLicense.ActivationRequestCode == "" || strings.HasPrefix(neLicense.ActivationRequestCode, "SN") || neLicense.Status == "0" {
code, licensePath := s.neLicenseService.ReadLicenseInfo(neLicense)