Ver Fonte

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

- 在编辑网关 IP 时,如果 IP 地址或节点区域发生变化,会先删除旧的 IP,再添加新的 IP
- 确保网关 IP 的更新能够正确同步到相关设备
fusu há 2 semanas atrás
pai
commit
fe186c5632
1 ficheiros alterados com 17 adições e 0 exclusões
  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)
 }