...
|
...
|
@@ -364,12 +364,11 @@ func (service UsersService) GetUserData(userId int64, companyId int64) (map[stri |
|
|
}
|
|
|
}
|
|
|
transactionContext.CommitTransaction()
|
|
|
result := service.buildGetUserData(&usersData, pertnerList)
|
|
|
return result, nil
|
|
|
return service.buildGetUserData(&usersData, pertnerList)
|
|
|
}
|
|
|
|
|
|
//buildGetUserData 构建前端需要的数据
|
|
|
func (service UsersService) buildGetUserData(userData *domain.Users, partnerList []domain.PartnerInfo) map[string]interface{} {
|
|
|
func (service UsersService) buildGetUserData(userData *domain.Users, partnerList []domain.PartnerInfo) (map[string]interface{}, error) {
|
|
|
result := map[string]interface{}{
|
|
|
"id": userData.Id,
|
|
|
"permissionType": []int64{},
|
...
|
...
|
@@ -389,6 +388,26 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList |
|
|
for _, v := range userData.Permission {
|
|
|
permissionIds = append(permissionIds, v.Id)
|
|
|
}
|
|
|
|
|
|
if userData.IsSuperAdmin() {
|
|
|
transactionContext, _ := factory.CreateTransactionContext(nil)
|
|
|
var permissionRepository domain.AdminPermissionRepository
|
|
|
var err error
|
|
|
if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
permissionList, err := permissionRepository.Find(domain.PermissionFindOption{})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取权限列表数据失败:%s", err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
permissionIds = make([]int64, 0)
|
|
|
for _, v := range permissionList {
|
|
|
permissionIds = append(permissionIds, v.Id)
|
|
|
}
|
|
|
}
|
|
|
result["permissionType"] = permissionIds
|
|
|
checkedPartner := make([]map[string]interface{}, 0, len(partnerList))
|
|
|
for i := range partnerList {
|
...
|
...
|
@@ -399,7 +418,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList |
|
|
checkedPartner = append(checkedPartner, m)
|
|
|
}
|
|
|
result["checkedPartner"] = checkedPartner
|
|
|
return result
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
//EditUserPermission 编辑用户的权限
|
...
|
...
|
@@ -437,10 +456,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom |
|
|
if !usersData.InCompany(cmd.CompanyId) {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "提交的数据异常")
|
|
|
}
|
|
|
if usersData.IsSuperAdmin() {
|
|
|
//超级管理员无需编辑权限
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
...
|
...
|
@@ -479,7 +495,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom |
|
|
partners = append(partners, p)
|
|
|
}
|
|
|
for i := range permissionList {
|
|
|
if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER {
|
|
|
if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
|
|
|
}
|
|
|
p := domain.AdminPermissionBase{
|
...
|
...
|
@@ -488,11 +504,13 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom |
|
|
}
|
|
|
permissionsBase = append(permissionsBase, p)
|
|
|
}
|
|
|
|
|
|
_ = usersData.Update(map[string]interface{}{
|
|
|
updateMap := map[string]interface{}{
|
|
|
"AccessPartners": partners,
|
|
|
"Permission": permissionsBase,
|
|
|
})
|
|
|
}
|
|
|
if !usersData.IsSuperAdmin() {
|
|
|
updateMap["Permission"] = permissionsBase
|
|
|
}
|
|
|
_ = usersData.Update(updateMap)
|
|
|
err = userRespository.Edit(&usersData)
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("更新用户(id=%d)数据失败:%s", usersData.Id, err)
|
...
|
...
|
|