From 357a30d62accba8d30f91837eec86029c14822e8 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 6 Mar 2024 10:05:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BD=91=E5=85=83=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=E4=B8=BB?= =?UTF-8?q?=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/network_element/model/ne_host.go | 2 +- .../network_element/service/ne_info.impl.go | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/modules/network_element/model/ne_host.go b/src/modules/network_element/model/ne_host.go index 40620338..a479635b 100644 --- a/src/modules/network_element/model/ne_host.go +++ b/src/modules/network_element/model/ne_host.go @@ -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端口 diff --git a/src/modules/network_element/service/ne_info.impl.go b/src/modules/network_element/service/ne_info.impl.go index 95cea2e5..f450d019 100644 --- a/src/modules/network_element/service/ne_info.impl.go +++ b/src/modules/network_element/service/ne_info.impl.go @@ -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) }