...
|
...
|
@@ -2,6 +2,7 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/emirpasic/gods/sets/hashset"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
|
...
|
...
|
@@ -9,6 +10,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -16,7 +18,7 @@ import ( |
|
|
type UserService struct {
|
|
|
}
|
|
|
|
|
|
// 批量添加
|
|
|
// TODO:批量添加
|
|
|
func (userService *UserService) BatchAdd(batchAddCommand *command.BatchAddCommand) (interface{}, error) {
|
|
|
if err := batchAddCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -342,13 +344,67 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 1.用户角色包含的菜单Set
|
|
|
_, user, err := factory.FastPgUser(transactionContext, getUserAccessMenusQuery.UserId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
menuIdSet := hashset.New()
|
|
|
for i := range user.UserRole {
|
|
|
var role *domain.Role
|
|
|
if _, role, err = factory.FastPgRole(transactionContext, user.UserRole[i].RoleId); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 只要当前登录组织的有权限菜单
|
|
|
if getUserAccessMenusQuery.OrgId > 0 && getUserAccessMenusQuery.OrgId != role.OrgId {
|
|
|
continue
|
|
|
}
|
|
|
for i := 0; i < len(role.AccessMenus); i++ {
|
|
|
menuIdSet.Add(role.AccessMenus[i])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 2.所有的菜单
|
|
|
menuRepository, _, err := factory.FastPgMenu(transactionContext, 0)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
queryOptions := make(map[string]interface{})
|
|
|
queryOptions["isPublish"] = domain.MenuPublic
|
|
|
if len(getUserAccessMenusQuery.MenuCategory) > 0 {
|
|
|
queryOptions["code"] = ""
|
|
|
if m, e := menuRepository.FindOne(map[string]interface{}{"code": getUserAccessMenusQuery.MenuCategory}); e == nil && m != nil {
|
|
|
queryOptions["category"] = strconv.Itoa(int(m.MenuId))
|
|
|
}
|
|
|
}
|
|
|
_, menus, err := menuRepository.Find(queryOptions)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 3.自定义菜单
|
|
|
customizeMenuRepository, _, err := factory.FastPgCustomizeMenu(transactionContext, 0)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
_, customizeMenus, err := customizeMenuRepository.Find(map[string]interface{}{"companyId": user.CompanyId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 4.适配
|
|
|
accessMenuDto := dto.NewUserAccessMenuDto()
|
|
|
accessMenuDto.LoadDto(menus, customizeMenus, menuIdSet.Values(), getUserAccessMenusQuery.ALLDisableMenu)
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
return map[string]interface{}{
|
|
|
"menus": accessMenuDto,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 获取用户概要数据
|
|
|
// TODO:获取用户概要数据
|
|
|
func (userService *UserService) GetUserProfile(getUserProfileQuery *query.GetUserProfileQuery) (interface{}, error) {
|
|
|
if err := getUserProfileQuery.ValidateQuery(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
|