切换导航条
此项目
正在载入...
登录
allied-creation
/
performance
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
郑周
2 years ago
提交
8c53a46ca10c29c377e303c99faa7f13c4a66403
1 个父辈
9774b9e9
1. 编辑通讯录的上级
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
173 行增加
和
1 行删除
pkg/application/role/role_user_service.go
pkg/application/user/adapter/user_adapter.go
pkg/application/user/command/edit_parent.go
pkg/application/user/user.go
pkg/port/beego/controllers/user_controller.go
pkg/port/beego/routers/user_router.go
pkg/application/role/role_user_service.go
查看文件 @
8c53a46
...
...
@@ -113,3 +113,31 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
}
return
tool_funs
.
SimpleWrapGridMap
(
total
,
tempList
),
nil
}
// GetHRBP 当前操作人是否拥有HRBP权限
func
GetHRBP
(
transactionContext
application
.
TransactionContext
,
companyId
int
,
operatorId
int
)
(
int
,
error
)
{
roleRepo
:=
factory
.
CreateRoleRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
roleUserRepo
:=
factory
.
CreateRoleUserRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
_
,
roleList
,
err
:=
roleRepo
.
Find
(
map
[
string
]
interface
{}{
"type"
:
domain
.
RoleTypeSystem
,
"companyId"
:
companyId
})
if
err
!=
nil
{
return
-
1
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"获取角色信息列表"
+
err
.
Error
())
}
_
,
userRoleList
,
err
:=
roleUserRepo
.
Find
(
map
[
string
]
interface
{}{
"companyId"
:
companyId
,
"userId"
:
operatorId
})
if
err
!=
nil
{
return
-
1
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
"获取用户的角色信息列表"
+
err
.
Error
())
}
// 拥有HRBP权限
hrbp
:=
-
1
for
_
,
v
:=
range
userRoleList
{
for
_
,
v2
:=
range
roleList
{
if
v
.
RoleId
==
v2
.
Id
{
hrbp
=
1
break
}
}
if
hrbp
==
1
{
break
}
}
return
hrbp
,
nil
}
...
...
pkg/application/user/adapter/user_adapter.go
0 → 100644
查看文件 @
8c53a46
package
adapter
import
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
type
UserResp
struct
{
*
domain
.
User
ParentName
string
`json:"parentName"`
// 上级名称
PositionNames
[]
string
`json:"positionNames"`
// 职位名称
}
...
...
pkg/application/user/command/edit_parent.go
0 → 100644
查看文件 @
8c53a46
package
command
import
(
"github.com/beego/beego/v2/core/validation"
)
type
EditParentCommand
struct
{
Id
int64
`cname:"用户ID" json:"id,string" valid:"Required"`
ParentId
int64
`cname:"上级ID" json:"parentId,string" valid:"Required"`
CompanyId
int
`cname:"公司ID" json:"companyId"`
OperatorId
int
`cname:"操作人ID" json:"operatorId"`
}
func
(
in
*
EditParentCommand
)
Valid
(
*
validation
.
Validation
)
{
}
...
...
pkg/application/user/user.go
查看文件 @
8c53a46
...
...
@@ -4,6 +4,9 @@ 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"
service
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
...
...
@@ -46,6 +49,8 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf
}()
userRepo
:=
factory
.
CreateUserRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
positionRepo
:=
factory
.
CreatePositionRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
inMap
:=
tool_funs
.
SimpleStructToMap
(
in
)
if
in
.
DepartmentId
==
0
{
delete
(
inMap
,
"departmentId"
)
// 删除部门ID字段
...
...
@@ -54,8 +59,108 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
parentIds
:=
make
([]
int64
,
0
)
// 上级ID
positionIds
:=
make
([]
int
,
0
)
// 职位ID
for
i
:=
range
list
{
if
list
[
i
]
.
ParentId
>
0
{
parentIds
=
append
(
parentIds
,
list
[
i
]
.
ParentId
)
}
pList
:=
list
[
i
]
.
PositionId
for
i2
:=
range
pList
{
if
pList
[
i2
]
>
0
{
positionIds
=
append
(
positionIds
,
pList
[
i2
])
}
}
}
// 获取上级
parentMap
:=
map
[
int64
]
*
domain
.
User
{}
if
len
(
parentIds
)
>
0
{
_
,
parentList
,
err
:=
userRepo
.
Find
(
map
[
string
]
interface
{}{
"ids"
:
parentIds
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
for
i
:=
range
parentList
{
parentMap
[
parentList
[
i
]
.
Id
]
=
parentList
[
i
]
}
}
// 获取职位
positionMap
:=
map
[
int64
]
*
domain
.
Position
{}
if
len
(
positionIds
)
>
0
{
_
,
positionList
,
err
:=
positionRepo
.
Find
(
map
[
string
]
interface
{}{
"ids"
:
positionIds
})
if
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
for
i
:=
range
positionList
{
positionMap
[
positionList
[
i
]
.
Id
]
=
positionList
[
i
]
}
}
adapters
:=
make
([]
*
adapter
.
UserResp
,
0
)
for
i
:=
range
list
{
adp
:=
&
adapter
.
UserResp
{
User
:
list
[
i
],
}
// 上级名称
if
v
,
ok
:=
parentMap
[
list
[
i
]
.
ParentId
];
ok
{
adp
.
ParentName
=
v
.
Name
}
// 职位名称数组
adp
.
PositionNames
=
make
([]
string
,
0
)
pList
:=
list
[
i
]
.
PositionId
for
i2
:=
range
pList
{
if
v2
,
ok
:=
positionMap
[
int64
(
pList
[
i2
])];
ok
{
adp
.
PositionNames
=
append
(
adp
.
PositionNames
,
v2
.
Name
)
}
}
adapters
=
append
(
adapters
,
adp
)
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
}
return
tool_funs
.
SimpleWrapGridMap
(
int64
(
count
),
list
),
nil
return
tool_funs
.
SimpleWrapGridMap
(
int64
(
count
),
adapters
),
nil
}
// EditParentUser 保存上级
func
(
us
*
UserService
)
EditParentUser
(
in
*
command
.
EditParentCommand
)
error
{
transactionContext
,
err
:=
factory
.
ValidateStartTransaction
(
in
)
if
err
!=
nil
{
return
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
hrbp
,
err
:=
service
.
GetHRBP
(
transactionContext
,
in
.
CompanyId
,
in
.
OperatorId
)
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
hrbp
!=
1
{
return
application
.
ThrowError
(
application
.
BUSINESS_ERROR
,
"拥有HRBP权限才能编辑"
)
}
userRepo
:=
factory
.
CreateUserRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
user
,
err
:=
userRepo
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
in
.
Id
})
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
// 上级ID是否存在
_
,
err
=
userRepo
.
FindOne
(
map
[
string
]
interface
{}{
"id"
:
in
.
ParentId
})
if
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
user
.
ParentId
=
in
.
ParentId
if
_
,
err
=
userRepo
.
Update
(
user
);
err
!=
nil
{
return
application
.
ThrowError
(
application
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
err
:=
transactionContext
.
CommitTransaction
();
err
!=
nil
{
return
application
.
ThrowError
(
application
.
TRANSACTION_ERROR
,
err
.
Error
())
}
return
nil
}
...
...
pkg/port/beego/controllers/user_controller.go
查看文件 @
8c53a46
...
...
@@ -4,6 +4,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
...
...
@@ -33,3 +34,15 @@ func (controller *UserController) ListByDepartment() {
controller
.
Response
((
&
user
.
UserService
{})
.
ListByDepartment
(
in
))
}
}
func
(
controller
*
UserController
)
EditParentUser
()
{
in
:=
&
command
.
EditParentCommand
{}
if
err
:=
controller
.
Unmarshal
(
in
);
err
!=
nil
{
controller
.
Response
(
nil
,
application
.
ThrowError
(
application
.
ARG_ERROR
,
err
.
Error
()))
}
else
{
ua
:=
middlewares
.
GetUser
(
controller
.
Ctx
)
in
.
CompanyId
=
int
(
ua
.
CompanyId
)
in
.
OperatorId
=
int
(
ua
.
UserId
)
controller
.
Response
(
nil
,
(
&
user
.
UserService
{})
.
EditParentUser
(
in
))
}
}
...
...
pkg/port/beego/routers/user_router.go
查看文件 @
8c53a46
...
...
@@ -12,6 +12,7 @@ func init() {
web
.
NSBefore
(
filters
.
AllowCors
(),
middlewares
.
CheckAdminToken
()),
web
.
NSRouter
(
"/search"
,
&
controllers
.
UserController
{},
"Post:ListUsers"
),
web
.
NSRouter
(
"/list-dep"
,
&
controllers
.
UserController
{},
"Post:ListByDepartment"
),
web
.
NSRouter
(
"/edit-parent"
,
&
controllers
.
UserController
{},
"Put:EditParentUser"
),
)
web
.
AddNamespace
(
ns
)
}
...
...
请
注册
或
登录
后发表评论