mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
refactor: 标签列表选择调整
This commit is contained in:
@@ -14,7 +14,15 @@ type TagTree struct {
|
||||
}
|
||||
|
||||
func (p *TagTree) GetAccountTags(rc *ctx.ReqCtx) {
|
||||
rc.ResData = p.TagTreeApp.ListTagByAccountId(rc.LoginAccount.Id)
|
||||
tagPaths := p.TagTreeApp.ListTagByAccountId(rc.LoginAccount.Id)
|
||||
allTagPath := make([]string, 0)
|
||||
if len(tagPaths) > 0 {
|
||||
tags := p.TagTreeApp.ListTagByPath(tagPaths...)
|
||||
for _, v := range tags {
|
||||
allTagPath = append(allTagPath, v.CodePath)
|
||||
}
|
||||
}
|
||||
rc.ResData = allTagPath
|
||||
}
|
||||
|
||||
func (p *TagTree) GetTagTree(rc *ctx.ReqCtx) {
|
||||
|
||||
@@ -31,6 +31,9 @@ type TagTree interface {
|
||||
// 获取以指定tagPath数组开头的所有标签id
|
||||
ListTagIdByPath(tagPath ...string) []uint64
|
||||
|
||||
// 根据tagPath获取自身及其所有子标签信息
|
||||
ListTagByPath(tagPath ...string) []entity.TagTree
|
||||
|
||||
// 根据账号id获取其可访问标签信息
|
||||
ListTagByAccountId(accountId uint64) []string
|
||||
|
||||
@@ -109,14 +112,19 @@ func (p *tagTreeAppImpl) ListTagIdByAccountId(accountId uint64) []uint64 {
|
||||
return p.ListTagIdByPath(p.ListTagByAccountId(accountId)...)
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) ListTagByPath(tagPaths ...string) []entity.TagTree {
|
||||
var tags []entity.TagTree
|
||||
p.tagTreeRepo.SelectByCondition(&entity.TagTreeQuery{CodePathLikes: tagPaths}, &tags)
|
||||
return tags
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) ListTagIdByPath(tagPaths ...string) []uint64 {
|
||||
tagIds := make([]uint64, 0)
|
||||
if len(tagPaths) == 0 {
|
||||
return tagIds
|
||||
}
|
||||
|
||||
var tags []entity.TagTree
|
||||
p.tagTreeRepo.SelectByCondition(&entity.TagTreeQuery{CodePathLikes: tagPaths}, &tags)
|
||||
tags := p.ListTagByPath(tagPaths...)
|
||||
for _, v := range tags {
|
||||
tagIds = append(tagIds, v.Id)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func newTagTreeRepo() repository.TagTree {
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEntity interface{}, orderBy ...string) {
|
||||
sql := "SELECT p.* FROM t_tag_tree p WHERE 1 = 1 "
|
||||
sql := "SELECT DISTINCT(p.id), p.pid, p.code, p.code_path, p.name, p.remark, p.create_time, p.creator, p.update_time, p.modifier FROM t_tag_tree p WHERE 1 = 1 "
|
||||
if condition.Name != "" {
|
||||
sql = sql + " AND p.name LIKE '%" + condition.Name + "%'"
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEn
|
||||
}
|
||||
sql = sql + ")"
|
||||
}
|
||||
sql = sql + " ORDER BY p.pid DESC"
|
||||
sql = sql + " ORDER BY p.code_path"
|
||||
model.GetListBySql2Model(sql, toEntity)
|
||||
}
|
||||
|
||||
@@ -56,11 +56,11 @@ func (a *tagTreeRepoImpl) GetBy(condition *entity.TagTree, cols ...string) error
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) Insert(project *entity.TagTree) {
|
||||
biz.ErrIsNil(model.Insert(project), "新增项目失败")
|
||||
biz.ErrIsNil(model.Insert(project), "新增标签失败")
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) UpdateById(project *entity.TagTree) {
|
||||
biz.ErrIsNil(model.UpdateById(project), "更新项目失败")
|
||||
biz.ErrIsNil(model.UpdateById(project), "更新标签失败")
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) Delete(id uint64) {
|
||||
|
||||
Reference in New Issue
Block a user