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

@@ -9,7 +9,6 @@ import (
"be.ems/src/framework/ssh"
"be.ems/src/framework/utils/file"
neFetchlink "be.ems/src/modules/network_element/fetch_link"
"be.ems/src/modules/network_element/model"
"be.ems/src/modules/network_element/repository"
)
@@ -18,12 +17,14 @@ import (
var NewNeVersion = &NeVersion{
neVersionRepository: repository.NewNeVersion,
neInfoService: NewNeInfo,
neStateService: NewNEState,
}
// NeVersion 网元版本信息 服务层处理
type NeVersion struct {
neVersionRepository *repository.NeVersion // 网元版本信息表
neInfoService *NeInfo // 网元信息数据信息
neStateService *NEState // 网元状态服务
}
// FindByPage 分页查询列表数据
@@ -54,29 +55,15 @@ func (r NeVersion) Find(neVersion model.NeVersion, checkVersion bool) []model.Ne
func (r NeVersion) checkNeVersion(arr *[]model.NeVersion) {
for i := range *arr {
item := (*arr)[i]
// 查询网元获取IP
neInfo := r.neInfoService.FindByNeTypeAndNeID(item.NeType, item.NeId)
if neInfo.NeId != item.NeId || neInfo.IP == "" {
state := r.neStateService.Last(item.NeType, item.NeId)
if state.RefreshTime <= 0 {
continue
}
result, err := neFetchlink.NeState(neInfo)
if err != nil {
if state.NeVersion == item.Version {
continue
}
if v, ok := result["version"]; ok && v != nil {
ver := fmt.Sprint(v)
if ver == item.Version {
continue
}
// item.Name = "-"
// item.Path = "-"
item.Version = ver
}
if item.NeType != neInfo.NeType || item.NeId != neInfo.NeId {
item.NeType = neInfo.NeType
item.NeId = neInfo.NeId
}
r.Update(item)
item.Version = state.NeVersion
r.neVersionRepository.UpdateVersion(item.ID, item.Version)
(*arr)[i] = item
}
}