作者 郑周

角色逻辑

... ... @@ -80,7 +80,7 @@ func (rs *RoleService) Update(in *command.UpdateRoleCommand) (interface{}, error
}
role.Name = in.Name
role.Name = in.Description
role.Description = in.Description
role, err = roleRepository.Insert(role)
if err != nil {
... ... @@ -171,6 +171,5 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
roleUser.Users = tempList
adapterList = append(adapterList, roleUser)
}
return map[string]interface{}{"list": adapterList}, nil
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
... ... @@ -88,47 +89,25 @@ func (rs *RoleUserService) Remove(in *command.UserRoleDeleteCommand) (interface{
return rus, nil
}
//func (rs *RoleUserService) ListForUser(in *command.UserRoleQueryCommand) (interface{}, error) {
// transactionContext, err := factory.StartTransaction()
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// roleRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
// userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// in.PageNumber = 1
// in.PageSize = 9999999
//
// conditionMap := tool_funs.SimpleStructToMap(in)
// _, roles, err := roleRepository.Find(conditionMap)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if len(roles) == 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "未找到角色数据")
// }
//
// ids := make([]int64, 0)
// for i := range roles {
// ids = append(ids, roles[i].Id)
// }
//
// _, users, err := userRepository.Find(conditionMap)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// //for i := range users {
// // users[i].RoleUserIds
// //}
//
// //if err := transactionContext.CommitTransaction(); err != nil {
// // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// //}
// //groupAdapter := &adapter.RoleUserAdapter{}
// //newList := groupAdapter.TransformTree(groups)
// return map[string]interface{}{"list": users}, nil
//}
func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
in.PageNumber = 1
in.PageSize = 9999999
tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, in.RoleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(tempList)), tempList), nil
}
... ...
... ... @@ -44,3 +44,14 @@ func (controller *RoleController) RemoveRole() {
controller.Response(ruService.Remove(in))
}
}
func (controller *RoleController) ListForUserRole() {
ruService := service.NewRoleService()
in := &command.QueryRoleUserCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListForUser(in))
}
}
... ...
... ... @@ -33,3 +33,14 @@ func (controller *RoleUserController) RemoveRoleUser() {
controller.Response(ruService.Remove(in))
}
}
func (controller *RoleUserController) ListRoleUser() {
ruService := service.NewRoleUserService()
in := &command.UserRoleQueryCommand{}
if err := controller.Unmarshal(in); err != nil {
controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
controller.Response(ruService.ListRole(in))
}
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/role",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
//web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"),
//web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"),
//web.NSRouter("/:Id", &controllers.RoleController{}, "Get:GetRole"),
web.NSRouter("/all", &controllers.RoleController{}, "Post:ListForUserRole"),
)
web.AddNamespace(ns)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)
func init() {
ns := web.NewNamespace("/v1/role-user",
web.NSBefore(filters.AllowCors(), middlewares.CheckToken()),
web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRole"),
web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRole"),
web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"),
)
web.AddNamespace(ns)
}
... ...