...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/domain"
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
|
// 菜单服务
|
...
|
...
|
@@ -48,6 +49,14 @@ func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenu |
|
|
} else {
|
|
|
menuRepository = value
|
|
|
}
|
|
|
if newMenu.ParentId > 0 {
|
|
|
if pMenu, err := menuRepository.FindOne(map[string]interface{}{"menuId": newMenu.ParentId}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
newMenu.ParentPath = pMenu.GetParentPath()
|
|
|
newMenu.Category = pMenu.GetCategory()
|
|
|
}
|
|
|
}
|
|
|
if menu, err := menuRepository.Save(newMenu); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -118,7 +127,14 @@ func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (in |
|
|
} else {
|
|
|
menuRepository = value
|
|
|
}
|
|
|
if count, menus, err := menuRepository.Find(tool_funs.SimpleStructToMap(listMenuQuery)); err != nil {
|
|
|
queryOptions := tool_funs.SimpleStructToMap(listMenuQuery)
|
|
|
if len(listMenuQuery.MenuCategory) > 0 {
|
|
|
queryOptions["code"] = ""
|
|
|
if m, e := menuRepository.FindOne(map[string]interface{}{"code": listMenuQuery.MenuCategory}); e == nil && m != nil {
|
|
|
queryOptions["category"] = strconv.Itoa(int(m.MenuId))
|
|
|
}
|
|
|
}
|
|
|
if count, menus, err := menuRepository.Find(queryOptions); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -201,6 +217,33 @@ func (menuService *MenuService) UpdateMenu(updateMenuCommand *command.UpdateMenu |
|
|
if menu == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateMenuCommand.MenuId)))
|
|
|
}
|
|
|
// 父级节点有发生更新
|
|
|
if updateMenuCommand.ParentId != menu.ParentId && (updateMenuCommand.ParentId != 0 && menu.ParentId != 0) {
|
|
|
var oldParentFullPath, newParentFullPath = menu.GetFullPath(), menu.GetFullPath()
|
|
|
var oldParentPath = menu.ParentPath
|
|
|
if pMenu, err := menuRepository.FindOne(map[string]interface{}{"menuId": updateMenuCommand.ParentId}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
newParentFullPath = pMenu.GetParentPath()
|
|
|
menu.ParentPath = newParentFullPath
|
|
|
}
|
|
|
// 父级目录不一致时,联动更新其他的子节点的父级目录
|
|
|
if oldParentFullPath != newParentFullPath {
|
|
|
if _, menus, err := menuRepository.Find(map[string]interface{}{"parentPath": oldParentFullPath}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
for i := range menus {
|
|
|
if menus[i].ParentPath == oldParentPath {
|
|
|
continue
|
|
|
}
|
|
|
menus[i].UpdateParentPath(oldParentPath, newParentFullPath)
|
|
|
if _, err := menuRepository.Save(menus[i]); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if err := menu.Update(tool_funs.SimpleStructToMap(updateMenuCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
|