refactor: 标签资源重构

This commit is contained in:
meilin.huang
2024-04-06 18:19:17 +08:00
parent 582d879a77
commit 408bac09a1
52 changed files with 476 additions and 347 deletions

View File

@@ -2,6 +2,7 @@ package form
type Mongo struct {
Id uint64 `json:"id"`
Code uint64 `json:"code" binding:"required"`
Uri string `binding:"required" json:"uri"`
SshTunnelMachineId int `json:"sshTunnelMachineId"` // ssh隧道机器id
Name string `binding:"required" json:"name"`

View File

@@ -10,7 +10,6 @@ import (
"mayfly-go/pkg/base"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils/stringx"
)
type Mongo interface {
@@ -59,8 +58,10 @@ func (d *mongoAppImpl) Delete(ctx context.Context, id uint64) error {
return d.DeleteById(ctx, id)
},
func(ctx context.Context) error {
var tagIds []uint64
return d.tagApp.RelateResource(ctx, mongoEntity.Code, consts.TagResourceTypeMongo, tagIds)
return d.tagApp.SaveResource(ctx, &tagapp.SaveResourceTagParam{
ResourceType: consts.TagResourceTypeMongo,
ResourceCode: mongoEntity.Code,
})
})
}
@@ -81,14 +82,18 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagIds ..
if err == nil {
return errorx.NewBiz("该名称已存在")
}
resouceCode := stringx.Rand(16)
m.Code = resouceCode
if d.CountByCond(&entity.Mongo{Code: m.Code}) > 0 {
return errorx.NewBiz("该编码已存在")
}
return d.Tx(ctx, func(ctx context.Context) error {
return d.Insert(ctx, m)
}, func(ctx context.Context) error {
return d.tagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeMongo, tagIds)
return d.tagApp.SaveResource(ctx, &tagapp.SaveResourceTagParam{
ResourceType: consts.TagResourceTypeMongo,
ResourceCode: m.Code,
TagIds: tagIds,
})
})
}
@@ -103,10 +108,15 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagIds ..
// 先关闭连接
mgm.CloseConn(m.Id)
m.Code = ""
return d.Tx(ctx, func(ctx context.Context) error {
return d.UpdateById(ctx, m)
}, func(ctx context.Context) error {
return d.tagApp.RelateResource(ctx, oldMongo.Code, consts.TagResourceTypeMongo, tagIds)
return d.tagApp.SaveResource(ctx, &tagapp.SaveResourceTagParam{
ResourceType: consts.TagResourceTypeMongo,
ResourceCode: oldMongo.Code,
TagIds: tagIds,
})
})
}

View File

@@ -5,6 +5,7 @@ import "mayfly-go/pkg/model"
type MongoQuery struct {
model.Model
Code string `json:"code" form:"code"`
Name string
Uri string
SshTunnelMachineId uint64 // ssh隧道机器id

View File

@@ -20,6 +20,7 @@ func newMongoRepo() repository.Mongo {
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
qd := gormx.NewQuery(new(entity.Mongo)).
Like("name", condition.Name).
Eq("code", condition.Code).
In("code", condition.Codes)
return gormx.PageQuery(qd, pageParam, toEntity)
}