瀏覽代碼

fix(admin): 优化网关 IP 编辑功能

- 在编辑网关 IP 时,如果 IP 地址或节点区域发生变化,会先删除旧的 IP,再添加新的 IP
- 确保网关 IP 的更新能够正确同步到相关设备
fusu 2 周之前
父節點
當前提交
fe186c5632
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      internal/service/admin/gatewayipadmin.go

+ 17 - 0
internal/service/admin/gatewayipadmin.go

@@ -94,6 +94,23 @@ func (s *gatewayIpAdminService) AddGatewayIp(ctx context.Context,req model.Gatew
 }
 
 func (s *gatewayIpAdminService) EditGatewayIp(ctx context.Context,req model.Gatewayip) error {
+	oldData, err := s.GetGatewayIpAdmin(ctx, int64(req.Id))
+	if err != nil {
+		return err
+	}
+	if oldData.Ip != req.Ip  || oldData.NodeArea != "" || req.NodeArea != "" {
+		// 启动网关组IP
+		err := s.sendIp(ctx,oldData.Ip,"deleteIp",oldData.NodeArea)
+		if err != nil {
+			return err
+		}
+
+		err = s.sendIp(ctx,req.Ip,"addIp",req.NodeArea)
+		if err != nil {
+			return err
+		}
+	}
+
 	return s.gatewayIpAdminRepository.EditGatewayIp(ctx,req)
 }