mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-05-04 10:05:18 +08:00
refactor: 数据库管理迁移至数据库实例-库管理、机器管理-文件支持用户和组信息查看
This commit is contained in:
@@ -57,10 +57,20 @@ func (d *Db) Dbs(rc *req.Ctx) {
|
||||
res, err := d.DbApp.GetPageList(queryCond, page, &dbvos)
|
||||
biz.ErrIsNil(err)
|
||||
|
||||
// 填充标签信息
|
||||
d.TagApp.FillTagInfo(tagentity.TagTypeDbName, collx.ArrayMap(dbvos, func(dbvo *vo.DbListVO) tagentity.ITagResource {
|
||||
return dbvo
|
||||
})...)
|
||||
instances, _ := d.InstanceApp.GetByIds(collx.ArrayMap(dbvos, func(i *vo.DbListVO) uint64 {
|
||||
return i.InstanceId
|
||||
}))
|
||||
instancesMap := collx.ArrayToMap(instances, func(i *entity.DbInstance) uint64 {
|
||||
return i.Id
|
||||
})
|
||||
for _, dbvo := range dbvos {
|
||||
di := instancesMap[dbvo.InstanceId]
|
||||
if di != nil {
|
||||
dbvo.InstanceType = di.Type
|
||||
dbvo.Host = di.Host
|
||||
dbvo.Port = di.Port
|
||||
}
|
||||
}
|
||||
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
@@ -2,26 +2,22 @@ package vo
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DbListVO struct {
|
||||
tagentity.ResourceTags
|
||||
|
||||
Id *int64 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name *string `json:"name"`
|
||||
GetDatabaseMode entity.DbGetDatabaseMode `json:"getDatabaseMode"` // 获取数据库方式
|
||||
Database *string `json:"database"`
|
||||
Remark *string `json:"remark"`
|
||||
InstanceId uint64 `json:"instanceId"`
|
||||
AuthCertName string `json:"authCertName"`
|
||||
|
||||
InstanceId *int64 `json:"instanceId"`
|
||||
AuthCertName string `json:"authCertName"`
|
||||
InstanceName *string `json:"instanceName"`
|
||||
InstanceType *string `json:"type"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
InstanceType string `json:"type" gorm:"-"`
|
||||
Host string `json:"host" gorm:"-"`
|
||||
Port int `json:"port" gorm:"-"`
|
||||
|
||||
CreateTime *time.Time `json:"createTime"`
|
||||
Creator *string `json:"creator"`
|
||||
@@ -30,7 +26,3 @@ type DbListVO struct {
|
||||
Modifier *string `json:"modifier"`
|
||||
ModifierId *int64 `json:"modifierId"`
|
||||
}
|
||||
|
||||
func (d DbListVO) GetCode() string {
|
||||
return d.Code
|
||||
}
|
||||
|
||||
@@ -87,16 +87,20 @@ func (app *dbTransferAppImpl) CreateLog(ctx context.Context, taskId uint64) (uin
|
||||
}
|
||||
|
||||
func (app *dbTransferAppImpl) Run(ctx context.Context, taskId uint64, logId uint64) {
|
||||
defer app.logApp.Flush(logId, true)
|
||||
|
||||
task, err := app.GetById(taskId)
|
||||
if err != nil {
|
||||
logx.Errorf("创建DBMS-执行数据迁移日志失败:%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if app.IsRunning(taskId) {
|
||||
logx.Warnf("[%d]该任务正在运行中...", taskId)
|
||||
return
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
defer app.logApp.Flush(logId, true)
|
||||
|
||||
// 修改状态与关联日志id
|
||||
task.LogId = logId
|
||||
task.RunningState = entity.DbTransferTaskRunStateRunning
|
||||
|
||||
@@ -27,16 +27,10 @@ type DbTransferLogQuery struct {
|
||||
|
||||
// 数据库查询实体,不与数据库表字段一一对应
|
||||
type DbQuery struct {
|
||||
Id uint64 `form:"id"`
|
||||
Code string `json:"code" form:"code"`
|
||||
Name string `orm:"column(name)" json:"name"`
|
||||
Database string `orm:"column(database)" json:"database"`
|
||||
Remark string `json:"remark"`
|
||||
|
||||
Codes []string
|
||||
TagIds []uint64 `orm:"column(tag_id)"`
|
||||
TagPath string `form:"tagPath"`
|
||||
|
||||
Id uint64 `form:"id"`
|
||||
TagPath string `form:"tagPath"`
|
||||
Code string `json:"code" form:"code"`
|
||||
Codes []string
|
||||
InstanceId uint64 `form:"instanceId"`
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -18,16 +17,6 @@ func newDbRepo() repository.Db {
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
qd := gormx.NewQueryWithTableName("t_db db").Joins("JOIN t_db_instance inst ON db.instance_id = inst.id").
|
||||
WithCond(model.NewCond().Columns("db.*, inst.name instance_name, inst.type instance_type, inst.host, inst.port ").
|
||||
Eq("db.instance_id", condition.InstanceId).
|
||||
Eq("db.id", condition.Id).
|
||||
Like("db.database", condition.Database).
|
||||
Eq("db.code", condition.Code).
|
||||
In("db.code", condition.Codes).
|
||||
Eq0("db."+model.DeletedColumn, model.ModelUndeleted).
|
||||
Eq0("inst."+model.DeletedColumn, model.ModelUndeleted),
|
||||
)
|
||||
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
pd := model.NewCond().Eq("instance_id", condition.InstanceId).In("code", condition.Codes)
|
||||
return d.PageByCondToAny(pd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user