feat: 网元信息查询带主机信息查询函数
This commit is contained in:
@@ -140,7 +140,7 @@ func (s *NeInfoController) Info(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
neHost := s.neInfoService.SelectById(infoId)
|
neHost := s.neInfoService.SelectById(infoId, true)
|
||||||
if neHost.ID != infoId {
|
if neHost.ID != infoId {
|
||||||
// 没有可访问网元信息数据!
|
// 没有可访问网元信息数据!
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
|
||||||
@@ -193,6 +193,14 @@ func (s *NeInfoController) Add(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 下发网管配置信息给网元
|
||||||
|
_, err = neService.NeConfigOMC(body)
|
||||||
|
if err == nil {
|
||||||
|
body.Status = "1"
|
||||||
|
} else {
|
||||||
|
body.Status = "0"
|
||||||
|
}
|
||||||
|
|
||||||
insertId := s.neInfoService.Insert(body)
|
insertId := s.neInfoService.Insert(body)
|
||||||
if insertId != "" {
|
if insertId != "" {
|
||||||
c.JSON(200, result.Ok(nil))
|
c.JSON(200, result.Ok(nil))
|
||||||
@@ -223,13 +231,21 @@ func (s *NeInfoController) Edit(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否存在
|
// 检查是否存在
|
||||||
neInfo := s.neInfoService.SelectById(body.ID)
|
neInfo := s.neInfoService.SelectById(body.ID, false)
|
||||||
if neInfo.ID != body.ID {
|
if neInfo.ID != body.ID {
|
||||||
// 没有可访问网元信息数据!
|
// 没有可访问网元信息数据!
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neInfo.noData")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 下发网管配置信息给网元
|
||||||
|
_, err = neService.NeConfigOMC(body)
|
||||||
|
if err == nil {
|
||||||
|
body.Status = "1"
|
||||||
|
} else {
|
||||||
|
body.Status = "0"
|
||||||
|
}
|
||||||
|
|
||||||
rows := s.neInfoService.Update(body)
|
rows := s.neInfoService.Update(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
c.JSON(200, result.Ok(nil))
|
c.JSON(200, result.Ok(nil))
|
||||||
|
|||||||
@@ -16,9 +16,13 @@ type NeInfo struct {
|
|||||||
NeAddress string `json:"neAddress"`
|
NeAddress string `json:"neAddress"`
|
||||||
Status string `json:"status"` // 0: 在线 1: 下线 2: 备用 3: 工程
|
Status string `json:"status"` // 0: 在线 1: 下线 2: 备用 3: 工程
|
||||||
UpdateTime string `json:"updateTime"`
|
UpdateTime string `json:"updateTime"`
|
||||||
|
HostIDs string `json:"hostIds"` // 网元主机ID组 数据格式(ssh,telnet,telnet)
|
||||||
|
|
||||||
// ====== 非数据库字段属性 ======
|
// ====== 非数据库字段属性 ======
|
||||||
|
|
||||||
// 服务状态
|
// 服务状态
|
||||||
ServerState map[string]any `json:"serverState,omitempty"`
|
ServerState map[string]any `json:"serverState,omitempty"`
|
||||||
|
|
||||||
|
// 主机对象组
|
||||||
|
Hosts []NeHost `json:"hosts,omitempty" binding:"hosts"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ var neListSort = []string{
|
|||||||
|
|
||||||
// 实例化数据层 NeInfoImpl 结构体
|
// 实例化数据层 NeInfoImpl 结构体
|
||||||
var NewNeInfoImpl = &NeInfoImpl{
|
var NewNeInfoImpl = &NeInfoImpl{
|
||||||
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time from ne_info`,
|
selectSql: `select id, ne_type, ne_id, rm_uid, ne_name, ip, port, pv_flag, province, vendor_name, dn, ne_address, status, update_time, host_ids from ne_info`,
|
||||||
|
|
||||||
resultMap: map[string]string{
|
resultMap: map[string]string{
|
||||||
"id": "ID",
|
"id": "ID",
|
||||||
@@ -50,6 +50,7 @@ var NewNeInfoImpl = &NeInfoImpl{
|
|||||||
"ne_address": "NeAddress",
|
"ne_address": "NeAddress",
|
||||||
"status": "Status",
|
"status": "Status",
|
||||||
"update_time": "UpdateTime",
|
"update_time": "UpdateTime",
|
||||||
|
"host_ids": "HostIDs",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,13 +292,16 @@ func (r *NeInfoImpl) Insert(neInfo model.NeInfo) string {
|
|||||||
params["vendor_name"] = neInfo.VendorName
|
params["vendor_name"] = neInfo.VendorName
|
||||||
}
|
}
|
||||||
if neInfo.Dn != "" {
|
if neInfo.Dn != "" {
|
||||||
params["dn"] = neInfo.VendorName
|
params["dn"] = neInfo.Dn
|
||||||
}
|
}
|
||||||
if neInfo.NeAddress != "" {
|
if neInfo.NeAddress != "" {
|
||||||
params["ne_address"] = neInfo.NeAddress
|
params["ne_address"] = neInfo.NeAddress
|
||||||
}
|
}
|
||||||
params["status"] = neInfo.Status
|
params["status"] = neInfo.Status
|
||||||
params["update_time"] = time.Now()
|
params["update_time"] = time.Now()
|
||||||
|
if neInfo.HostIDs != "" {
|
||||||
|
params["host_ids"] = neInfo.HostIDs
|
||||||
|
}
|
||||||
|
|
||||||
// 构建执行语句
|
// 构建执行语句
|
||||||
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
keys, placeholder, values := repo.KeyPlaceholderValueByInsert(params)
|
||||||
@@ -353,10 +357,13 @@ func (r *NeInfoImpl) Update(neInfo model.NeInfo) int64 {
|
|||||||
}
|
}
|
||||||
params["province"] = neInfo.Province
|
params["province"] = neInfo.Province
|
||||||
params["vendor_name"] = neInfo.VendorName
|
params["vendor_name"] = neInfo.VendorName
|
||||||
params["dn"] = neInfo.VendorName
|
params["dn"] = neInfo.Dn
|
||||||
params["ne_address"] = neInfo.NeAddress
|
params["ne_address"] = neInfo.NeAddress
|
||||||
params["status"] = neInfo.Status
|
params["status"] = neInfo.Status
|
||||||
params["update_time"] = time.Now()
|
params["update_time"] = time.Now()
|
||||||
|
if neInfo.HostIDs != "" {
|
||||||
|
params["host_ids"] = neInfo.HostIDs
|
||||||
|
}
|
||||||
|
|
||||||
// 构建执行语句
|
// 构建执行语句
|
||||||
keys, values := repo.KeyValueByUpdate(params)
|
keys, values := repo.KeyValueByUpdate(params)
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ type INeInfo interface {
|
|||||||
SelectList(ne model.NeInfo, bandStatus bool) []model.NeInfo
|
SelectList(ne model.NeInfo, bandStatus bool) []model.NeInfo
|
||||||
|
|
||||||
// SelectByIds 通过ID查询
|
// SelectByIds 通过ID查询
|
||||||
SelectById(infoId string) model.NeInfo
|
//
|
||||||
|
// bandStatus 带主机信息
|
||||||
|
SelectById(infoId string, bandHost bool) model.NeInfo
|
||||||
|
|
||||||
// Insert 新增信息
|
// Insert 新增信息
|
||||||
Insert(neInfo model.NeInfo) string
|
Insert(neInfo model.NeInfo) string
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"ems.agt/src/framework/constants/cachekey"
|
"ems.agt/src/framework/constants/cachekey"
|
||||||
"ems.agt/src/framework/redis"
|
"ems.agt/src/framework/redis"
|
||||||
@@ -13,12 +14,15 @@ import (
|
|||||||
// 实例化服务层 NeInfoImpl 结构体
|
// 实例化服务层 NeInfoImpl 结构体
|
||||||
var NewNeInfoImpl = &NeInfoImpl{
|
var NewNeInfoImpl = &NeInfoImpl{
|
||||||
neInfoRepository: repository.NewNeInfoImpl,
|
neInfoRepository: repository.NewNeInfoImpl,
|
||||||
|
neHostRepository: repository.NewNeHostImpl,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元信息 服务层处理
|
// 网元信息 服务层处理
|
||||||
type NeInfoImpl struct {
|
type NeInfoImpl struct {
|
||||||
// 网元信息数据信息
|
// 网元信息数据信息
|
||||||
neInfoRepository repository.INeInfo
|
neInfoRepository repository.INeInfo
|
||||||
|
// 网元主机连接表
|
||||||
|
neHostRepository repository.INeHost
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
// SelectNeInfoByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||||
@@ -123,13 +127,20 @@ func (r *NeInfoImpl) SelectList(ne model.NeInfo, bandStatus bool) []model.NeInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SelectByIds 通过ID查询
|
// SelectByIds 通过ID查询
|
||||||
func (r *NeInfoImpl) SelectById(infoId string) model.NeInfo {
|
//
|
||||||
|
// bandStatus 带主机信息
|
||||||
|
func (r *NeInfoImpl) SelectById(infoId string, bandHost bool) model.NeInfo {
|
||||||
if infoId == "" {
|
if infoId == "" {
|
||||||
return model.NeInfo{}
|
return model.NeInfo{}
|
||||||
}
|
}
|
||||||
neInfos := r.neInfoRepository.SelectByIds([]string{infoId})
|
neInfos := r.neInfoRepository.SelectByIds([]string{infoId})
|
||||||
if len(neInfos) > 0 {
|
if len(neInfos) > 0 {
|
||||||
return neInfos[0]
|
neInfo := neInfos[0]
|
||||||
|
// 带主机信息
|
||||||
|
if neInfo.HostIDs != "" && bandHost {
|
||||||
|
neInfo.Hosts = r.neHostRepository.SelectByIds(strings.Split(neInfo.HostIDs, ","))
|
||||||
|
}
|
||||||
|
return neInfo
|
||||||
}
|
}
|
||||||
return model.NeInfo{}
|
return model.NeInfo{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user