...
|
...
|
@@ -6,6 +6,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/adapter"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
)
|
|
|
|
|
|
type RoleService struct {
|
...
|
...
|
@@ -150,11 +151,37 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{ |
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if len(roles) == 0 {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, "未找到角色数据")
|
|
|
}
|
|
|
|
|
|
adapterList := make([]*adapter.RoleUserAdapter, 0)
|
|
|
|
|
|
// 如果不存在系统预支hrbp角色时,插入一条数据
|
|
|
var havaSystemType = false
|
|
|
for i := range roles {
|
|
|
if roles[i].Type == domain.RoleTypeSystem {
|
|
|
havaSystemType = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !havaSystemType {
|
|
|
role := &domain.Role{
|
|
|
Id: 0,
|
|
|
Name: "HRBP",
|
|
|
Type: domain.RoleTypeSystem,
|
|
|
Description: "拥有全部权限,预置角色不可删除",
|
|
|
CompanyId: in.CompanyId,
|
|
|
}
|
|
|
role, err = roleRepository.Insert(role)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 创建HRBP角色
|
|
|
roleUser := &adapter.RoleUserAdapter{}
|
|
|
roleUser.Role = role
|
|
|
roleUser.Users = make([]*domain.RoleContainUser, 0)
|
|
|
adapterList = append(adapterList, roleUser)
|
|
|
}
|
|
|
|
|
|
for i := range roles {
|
|
|
v := roles[i]
|
|
|
tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
|
...
|
...
|
@@ -162,13 +189,14 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{ |
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
roleUser := &adapter.RoleUserAdapter{}
|
|
|
roleUser.Id = v.Id
|
|
|
roleUser.Name = v.Name
|
|
|
roleUser.Type = v.Type
|
|
|
roleUser.Description = v.Description
|
|
|
roleUser.CompanyId = v.CompanyId
|
|
|
roleUser.Role = v
|
|
|
roleUser.Users = tempList
|
|
|
adapterList = append(adapterList, roleUser)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
|
|
|
} |
...
|
...
|
|