From 8a745bda24d96e435909373c782bbfcffaed4b03 Mon Sep 17 00:00:00 2001 From: actiontech-zihan Date: Wed, 17 Jun 2026 23:22:48 +0800 Subject: [PATCH 1/2] feat: strengthen environment tag color display (#2983) --- api/dms/service/v1/environment_tag.go | 4 +++- internal/apiserver/service/dms_controller.go | 4 ++-- internal/dms/biz/environment_tag.go | 18 ++++++++++-------- internal/dms/service/environment_tag.go | 13 +++++++------ internal/dms/storage/convert.go | 5 +++-- internal/dms/storage/environment_tag.go | 9 +++++++-- internal/dms/storage/model/model.go | 1 + pkg/dms-common/api/dms/v1/db_service.go | 5 +++-- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/api/dms/service/v1/environment_tag.go b/api/dms/service/v1/environment_tag.go index 3e64e8671..d4782ba51 100644 --- a/api/dms/service/v1/environment_tag.go +++ b/api/dms/service/v1/environment_tag.go @@ -10,6 +10,7 @@ type CreateEnvironmentTagReq struct { // swagger:ignore ProjectUID string `param:"project_uid" json:"project_uid" validate:"required"` Name string `json:"environment_name" validate:"required,min=1,max=50"` + Color string `json:"color" validate:"omitempty,max=32"` } // swagger:model @@ -19,7 +20,8 @@ type UpdateEnvironmentTagReq struct { // swagger:ignore ProjectUID string `param:"project_uid" json:"project_uid" validate:"required"` - Name string `json:"environment_name" validate:"required,min=1,max=50"` + Name string `json:"environment_name" validate:"required,min=1,max=50"` + Color string `json:"color" validate:"omitempty,max=32"` } // swagger:parameters ListEnvironmentTags diff --git a/internal/apiserver/service/dms_controller.go b/internal/apiserver/service/dms_controller.go index d0d775772..95f773fa6 100644 --- a/internal/apiserver/service/dms_controller.go +++ b/internal/apiserver/service/dms_controller.go @@ -109,7 +109,7 @@ func (ctl *DMSController) CreateEnvironmentTag(c echo.Context) error { return NewErrResp(c, err, apiError.DMSServiceErr) } - err = ctl.DMS.CreateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.Name) + err = ctl.DMS.CreateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.Name, req.Color) if nil != err { return NewErrResp(c, err, apiError.DMSServiceErr) } @@ -160,7 +160,7 @@ func (ctl *DMSController) UpdateEnvironmentTag(c echo.Context) error { return NewErrResp(c, err, apiError.DMSServiceErr) } - err = ctl.DMS.UpdateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.EnvironmentTagUID, req.Name) + err = ctl.DMS.UpdateEnvironmentTag(c.Request().Context(), req.ProjectUID, currentUserUid, req.EnvironmentTagUID, req.Name, req.Color) if nil != err { return NewErrResp(c, err, apiError.DMSServiceErr) } diff --git a/internal/dms/biz/environment_tag.go b/internal/dms/biz/environment_tag.go index 3c2f1c197..2f9e1c4c5 100644 --- a/internal/dms/biz/environment_tag.go +++ b/internal/dms/biz/environment_tag.go @@ -10,7 +10,7 @@ import ( type EnvironmentTagRepo interface { CreateEnvironmentTag(ctx context.Context, environmentTag *EnvironmentTag) error - UpdateEnvironmentTag(ctx context.Context, environmentTagName, environmentTagUID string) error + UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName, color string) error DeleteEnvironmentTag(ctx context.Context, environmentTagUID string) error GetEnvironmentTagByName(ctx context.Context, projectUid, name string) (bool, *EnvironmentTag, error) GetEnvironmentTagByUID(ctx context.Context, uid string) (*EnvironmentTag, error) @@ -39,9 +39,10 @@ type EnvironmentTag struct { UID string Name string ProjectUID string + Color string } -func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName string) (*EnvironmentTag, error) { +func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName, color string) (*EnvironmentTag, error) { uid, err := pkgRand.GenStrUid() if err != nil { return nil, err @@ -53,6 +54,7 @@ func (uc *EnvironmentTagUsecase) newEnvironmentTag(projectUid, tagName string) ( UID: uid, Name: tagName, ProjectUID: projectUid, + Color: color, }, nil } @@ -66,7 +68,7 @@ func (uc *EnvironmentTagUsecase) InitDefaultEnvironmentTags(ctx context.Context, } for _, environmentTag := range defaultEnvironmentTags { - err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag) + err = uc.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTag, "") if err != nil { uc.log.Errorf("create environment tag failed: %v", err) return fmt.Errorf("create environment tag failed: %w", err) @@ -75,7 +77,7 @@ func (uc *EnvironmentTagUsecase) InitDefaultEnvironmentTags(ctx context.Context, return nil } -func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, tagName string) error { +func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, tagName, color string) error { // 检查项目是否归档/删除 if err := uc.projectUsecase.isProjectActive(ctx, projectUid); err != nil { return fmt.Errorf("update db service error: %v", err) @@ -96,7 +98,7 @@ func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, proje if exist { return fmt.Errorf("the tag %s already exists in the current project", tagName) } - environmentTag, err := uc.newEnvironmentTag(projectUid, tagName) + environmentTag, err := uc.newEnvironmentTag(projectUid, tagName, color) if err != nil { uc.log.Errorf("new environment tag failed: %v", err) return err @@ -109,7 +111,7 @@ func (uc *EnvironmentTagUsecase) CreateEnvironmentTag(ctx context.Context, proje return nil } -func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagUID, environmentTagName string) error { +func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagUID, environmentTagName, color string) error { // 检查项目是否归档/删除 if err := uc.projectUsecase.isProjectActive(ctx, projectUid); err != nil { return fmt.Errorf("update db service error: %v", err) @@ -130,7 +132,7 @@ func (uc *EnvironmentTagUsecase) UpdateEnvironmentTag(ctx context.Context, proje uc.log.Errorf("get environment tag failed: %v", err) return err } - err = uc.environmentTagRepo.UpdateEnvironmentTag(ctx, environmentTagUID, environmentTagName) + err = uc.environmentTagRepo.UpdateEnvironmentTag(ctx, environmentTagUID, environmentTagName, color) if err != nil { uc.log.Errorf("update environment tag failed: %v", err) return err @@ -206,7 +208,7 @@ func (uc *EnvironmentTagUsecase) GetOrCreateEnvironmentTag(ctx context.Context, if exist { return environmentTag, nil } - newTag, err := uc.newEnvironmentTag(projectUid, tagName) + newTag, err := uc.newEnvironmentTag(projectUid, tagName, "") if err != nil { uc.log.Errorf("new environment tag failed: %v", err) return nil, err diff --git a/internal/dms/service/environment_tag.go b/internal/dms/service/environment_tag.go index c16e4e0e1..9e827f850 100644 --- a/internal/dms/service/environment_tag.go +++ b/internal/dms/service/environment_tag.go @@ -10,26 +10,26 @@ import ( dmsCommonV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" ) -func (d *DMSService) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagName string) (err error) { +func (d *DMSService) CreateEnvironmentTag(ctx context.Context, projectUid, currentUserUid, environmentTagName, color string) (err error) { d.log.Infof("CreateEnvironmentTag.req=%v", environmentTagName) defer func() { d.log.Infof("CreateEnvironmentTag.req=%v;error=%v", environmentTagName, err) }() - if err := d.EnvironmentTagUsecase.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagName); err != nil { + if err := d.EnvironmentTagUsecase.CreateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagName, color); err != nil { return fmt.Errorf("create environment tag failed: %w", err) } return nil } -func (d *DMSService) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid string, environmentTagUID, environmentTagName string) (err error) { +func (d *DMSService) UpdateEnvironmentTag(ctx context.Context, projectUid, currentUserUid string, environmentTagUID, environmentTagName, color string) (err error) { d.log.Infof("UpdateEnvironmentTag.req=%v", environmentTagName) defer func() { d.log.Infof("UpdateEnvironmentTag.req=%v;error=%v", environmentTagName, err) }() - if err := d.EnvironmentTagUsecase.UpdateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagUID, environmentTagName); err != nil { + if err := d.EnvironmentTagUsecase.UpdateEnvironmentTag(ctx, projectUid, currentUserUid, environmentTagUID, environmentTagName, color); err != nil { return fmt.Errorf("update environment tag failed: %w", err) } return nil @@ -82,8 +82,9 @@ func (d *DMSService) ListEnvironmentTags(ctx context.Context, req *v1.ListEnviro environmentTags := make([]*dmsCommonV1.EnvironmentTag, 0, len(bizEnvironmentTags)) for _, bizEnvironmentTag := range bizEnvironmentTags { environmentTags = append(environmentTags, &dmsCommonV1.EnvironmentTag{ - UID: bizEnvironmentTag.UID, - Name: bizEnvironmentTag.Name, + UID: bizEnvironmentTag.UID, + Name: bizEnvironmentTag.Name, + Color: bizEnvironmentTag.Color, }) } return &v1.ListEnvironmentTagsReply{ diff --git a/internal/dms/storage/convert.go b/internal/dms/storage/convert.go index eb48eb1f7..5637fba89 100644 --- a/internal/dms/storage/convert.go +++ b/internal/dms/storage/convert.go @@ -129,8 +129,9 @@ func convertModelDBService(ds *model.DBService) (*biz.DBService, error) { if ds.EnvironmentTag != nil { dbService.EnvironmentTag = &dmsCommonV1.EnvironmentTag{ - UID: ds.EnvironmentTagUID, - Name: ds.EnvironmentTag.EnvironmentName, + UID: ds.EnvironmentTagUID, + Name: ds.EnvironmentTag.EnvironmentName, + Color: ds.EnvironmentTag.Color, } } diff --git a/internal/dms/storage/environment_tag.go b/internal/dms/storage/environment_tag.go index bd1d7f3bb..047a961e0 100644 --- a/internal/dms/storage/environment_tag.go +++ b/internal/dms/storage/environment_tag.go @@ -30,6 +30,7 @@ func (repo *EnvironmentTagRepo) toModel(environmentTag *biz.EnvironmentTag) *mod EnvironmentName: environmentTag.Name, Model: model.Model{UID: environmentTag.UID}, ProjectUID: environmentTag.ProjectUID, + Color: environmentTag.Color, } } @@ -38,6 +39,7 @@ func (repo *EnvironmentTagRepo) toBiz(environmentTag *model.EnvironmentTag) *biz Name: environmentTag.EnvironmentName, UID: environmentTag.UID, ProjectUID: environmentTag.ProjectUID, + Color: environmentTag.Color, } } @@ -50,9 +52,12 @@ func (repo *EnvironmentTagRepo) CreateEnvironmentTag(ctx context.Context, enviro }) } -func (repo *EnvironmentTagRepo) UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName string) error { +func (repo *EnvironmentTagRepo) UpdateEnvironmentTag(ctx context.Context, environmentTagUID, environmentTagName, color string) error { return transaction(repo.log, ctx, repo.db, func(tx *gorm.DB) error { - if err := tx.WithContext(ctx).Model(&model.EnvironmentTag{}).Where("uid = ?", environmentTagUID).Update("environment_name", environmentTagName).Error; err != nil { + if err := tx.WithContext(ctx).Model(&model.EnvironmentTag{}).Where("uid = ?", environmentTagUID).Updates(map[string]interface{}{ + "environment_name": environmentTagName, + "color": color, + }).Error; err != nil { return pkgErr.WrapStorageErr(repo.log, fmt.Errorf("failed to update environment tag: %v", err)) } return nil diff --git a/internal/dms/storage/model/model.go b/internal/dms/storage/model/model.go index 640732ca5..9e877d636 100644 --- a/internal/dms/storage/model/model.go +++ b/internal/dms/storage/model/model.go @@ -95,6 +95,7 @@ type EnvironmentTag struct { Model ProjectUID string `json:"project_uid" gorm:"size:32;column:project_uid;index:project_uid_name"` EnvironmentName string `json:"environment_name" gorm:"not null;index:project_uid_name"` + Color string `json:"color" gorm:"size:32;column:color"` } type ExtraParameters struct { diff --git a/pkg/dms-common/api/dms/v1/db_service.go b/pkg/dms-common/api/dms/v1/db_service.go index e928b60e0..dcabb72ec 100644 --- a/pkg/dms-common/api/dms/v1/db_service.go +++ b/pkg/dms-common/api/dms/v1/db_service.go @@ -170,7 +170,8 @@ type ListDBService struct { type EnvironmentTag struct { UID string `json:"uid,omitempty"` // 环境属性标签最多50个字符 - Name string `json:"name" validate:"max=50"` + Name string `json:"name" validate:"max=50"` + Color string `json:"color,omitempty" validate:"omitempty,max=32"` } type SQLEConfig struct { @@ -206,7 +207,7 @@ type SQLQueryConfig struct { AllowQueryWhenLessThanAuditLevel SQLAllowQueryAuditLevel `json:"allow_query_when_less_than_audit_level" enums:"normal,notice,warn,error" valid:"omitempty,oneof=normal notice warn error " example:"error"` RuleTemplateName string `json:"rule_template_name"` RuleTemplateID string `json:"rule_template_id"` - MaintenanceTimes []*MaintenanceTime `json:"maintenance_times"` // 允许执行非 DQL 的运维时间窗口,与数据源 maintenance_times 结构一致 + MaintenanceTimes []*MaintenanceTime `json:"maintenance_times"` // 允许执行非 DQL 的运维时间窗口,与数据源 maintenance_times 结构一致 } // swagger:model ListDBServiceReply From 86033977efc3142549d4c87881e6a6c7cbf3a9cc Mon Sep 17 00:00:00 2001 From: yangzhongjiao Date: Mon, 22 Jun 2026 08:15:58 +0000 Subject: [PATCH 2/2] feat: return environment_tag in ListDBServiceTips (#2983) Co-authored-by: Cursor --- api/dms/service/v1/db_service.go | 11 ++++++----- internal/dms/service/db_service.go | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/api/dms/service/v1/db_service.go b/api/dms/service/v1/db_service.go index 73bb5d03c..d57deb5db 100644 --- a/api/dms/service/v1/db_service.go +++ b/api/dms/service/v1/db_service.go @@ -264,11 +264,12 @@ type ListDBServiceTipsReq struct { } type ListDBServiceTipItem struct { - Id string `json:"id"` - Name string `json:"name"` - Type string `json:"db_type"` - Host string `json:"host"` - Port string `json:"port"` + Id string `json:"id"` + Name string `json:"name"` + Type string `json:"db_type"` + Host string `json:"host"` + Port string `json:"port"` + EnvironmentTag *dmsCommonV1.EnvironmentTag `json:"environment_tag,omitempty"` } // swagger:model ListDBServiceTipsReply diff --git a/internal/dms/service/db_service.go b/internal/dms/service/db_service.go index 33d29bca8..5987f6b89 100644 --- a/internal/dms/service/db_service.go +++ b/internal/dms/service/db_service.go @@ -715,11 +715,12 @@ func (d *DMSService) ListDBServiceTips(ctx context.Context, req *dmsV1.ListDBSer ret := make([]*dmsV1.ListDBServiceTipItem, 0, len(dbServices)) for _, item := range dbServices { ret = append(ret, &dmsV1.ListDBServiceTipItem{ - Id: item.UID, - Name: item.Name, - Host: item.Host, - Port: item.Port, - Type: item.DBType, + Id: item.UID, + Name: item.Name, + Host: item.Host, + Port: item.Port, + Type: item.DBType, + EnvironmentTag: item.EnvironmentTag, }) }