fix: 网元信息操作同步更新主机

This commit is contained in:
TsMask
2024-03-06 10:05:52 +08:00
parent 734b11bce0
commit 357a30d62a
2 changed files with 24 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ import "encoding/json"
type NeHost struct {
HostID string `json:"hostId" gorm:"column:host_id"` // 主机主键
HostType string `json:"hostType" gorm:"column:host_type" binding:"oneof=ssh telnet"` // 主机类型 ssh telnet
GroupID string `json:"groupId" gorm:"column:group_id"` // 分组0默认
GroupID string `json:"groupId" gorm:"column:group_id"` // 分组0默认 1网元 2系统
Title string `json:"title" gorm:"column:title"` // 标题名称
Addr string `json:"addr" gorm:"column:addr" binding:"required"` // 主机地址
Port int64 `json:"port" gorm:"column:port" binding:"required,number,max=65535,min=1"` // SSH端口

View File

@@ -175,11 +175,34 @@ func (r *NeInfoImpl) SelectById(infoId string, bandHost bool) model.NeInfo {
// Insert 新增信息
func (r *NeInfoImpl) Insert(neInfo model.NeInfo) string {
// 主机信息新增
if neInfo.Hosts != nil {
var hostIDs []string
for _, host := range neInfo.Hosts {
host.Title = fmt.Sprintf("%s_%s_%d", strings.ToUpper(neInfo.NeType), neInfo.NeId, host.Port)
host.GroupID = "1"
hostId := r.neHostRepository.Insert(host)
if hostId != "" {
hostIDs = append(hostIDs, hostId)
}
}
neInfo.HostIDs = strings.Join(hostIDs, ",")
}
return r.neInfoRepository.Insert(neInfo)
}
// Update 修改信息
func (r *NeInfoImpl) Update(neInfo model.NeInfo) int64 {
// 主机信息更新
if neInfo.Hosts != nil {
for _, host := range neInfo.Hosts {
if host.HostID != "" {
host.Title = fmt.Sprintf("%s_%s_%d", strings.ToUpper(neInfo.NeType), neInfo.NeId, host.Port)
host.GroupID = "1"
r.neHostRepository.Update(host)
}
}
}
return r.neInfoRepository.Update(neInfo)
}