作者 唐旭辉

bug 修复

@@ -364,12 +364,11 @@ func (service UsersService) GetUserData(userId int64, companyId int64) (map[stri @@ -364,12 +364,11 @@ func (service UsersService) GetUserData(userId int64, companyId int64) (map[stri
364 } 364 }
365 } 365 }
366 transactionContext.CommitTransaction() 366 transactionContext.CommitTransaction()
367 - result := service.buildGetUserData(&usersData, pertnerList)  
368 - return result, nil 367 + return service.buildGetUserData(&usersData, pertnerList)
369 } 368 }
370 369
371 //buildGetUserData 构建前端需要的数据 370 //buildGetUserData 构建前端需要的数据
372 -func (service UsersService) buildGetUserData(userData *domain.Users, partnerList []domain.PartnerInfo) map[string]interface{} { 371 +func (service UsersService) buildGetUserData(userData *domain.Users, partnerList []domain.PartnerInfo) (map[string]interface{}, error) {
373 result := map[string]interface{}{ 372 result := map[string]interface{}{
374 "id": userData.Id, 373 "id": userData.Id,
375 "permissionType": []int64{}, 374 "permissionType": []int64{},
@@ -389,6 +388,26 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList @@ -389,6 +388,26 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList
389 for _, v := range userData.Permission { 388 for _, v := range userData.Permission {
390 permissionIds = append(permissionIds, v.Id) 389 permissionIds = append(permissionIds, v.Id)
391 } 390 }
  391 +
  392 + if userData.IsSuperAdmin() {
  393 + transactionContext, _ := factory.CreateTransactionContext(nil)
  394 + var permissionRepository domain.AdminPermissionRepository
  395 + var err error
  396 + if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
  397 + "transactionContext": transactionContext,
  398 + }); err != nil {
  399 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  400 + }
  401 + permissionList, err := permissionRepository.Find(domain.PermissionFindOption{})
  402 + if err != nil {
  403 + e := fmt.Sprintf("获取权限列表数据失败:%s", err)
  404 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  405 + }
  406 + permissionIds = make([]int64, 0)
  407 + for _, v := range permissionList {
  408 + permissionIds = append(permissionIds, v.Id)
  409 + }
  410 + }
392 result["permissionType"] = permissionIds 411 result["permissionType"] = permissionIds
393 checkedPartner := make([]map[string]interface{}, 0, len(partnerList)) 412 checkedPartner := make([]map[string]interface{}, 0, len(partnerList))
394 for i := range partnerList { 413 for i := range partnerList {
@@ -399,7 +418,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList @@ -399,7 +418,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList
399 checkedPartner = append(checkedPartner, m) 418 checkedPartner = append(checkedPartner, m)
400 } 419 }
401 result["checkedPartner"] = checkedPartner 420 result["checkedPartner"] = checkedPartner
402 - return result 421 + return result, nil
403 } 422 }
404 423
405 //EditUserPermission 编辑用户的权限 424 //EditUserPermission 编辑用户的权限
@@ -437,10 +456,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom @@ -437,10 +456,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
437 if !usersData.InCompany(cmd.CompanyId) { 456 if !usersData.InCompany(cmd.CompanyId) {
438 return lib.ThrowError(lib.BUSINESS_ERROR, "提交的数据异常") 457 return lib.ThrowError(lib.BUSINESS_ERROR, "提交的数据异常")
439 } 458 }
440 - if usersData.IsSuperAdmin() {  
441 - //超级管理员无需编辑权限  
442 - return nil  
443 - } 459 +
444 if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{ 460 if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
445 "transactionContext": transactionContext, 461 "transactionContext": transactionContext,
446 }); err != nil { 462 }); err != nil {
@@ -479,7 +495,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom @@ -479,7 +495,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
479 partners = append(partners, p) 495 partners = append(partners, p)
480 } 496 }
481 for i := range permissionList { 497 for i := range permissionList {
482 - if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER { 498 + if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
483 return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常") 499 return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
484 } 500 }
485 p := domain.AdminPermissionBase{ 501 p := domain.AdminPermissionBase{
@@ -488,11 +504,13 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom @@ -488,11 +504,13 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
488 } 504 }
489 permissionsBase = append(permissionsBase, p) 505 permissionsBase = append(permissionsBase, p)
490 } 506 }
491 -  
492 - _ = usersData.Update(map[string]interface{}{ 507 + updateMap := map[string]interface{}{
493 "AccessPartners": partners, 508 "AccessPartners": partners,
494 - "Permission": permissionsBase,  
495 - }) 509 + }
  510 + if !usersData.IsSuperAdmin() {
  511 + updateMap["Permission"] = permissionsBase
  512 + }
  513 + _ = usersData.Update(updateMap)
496 err = userRespository.Edit(&usersData) 514 err = userRespository.Edit(&usersData)
497 if err != nil { 515 if err != nil {
498 e := fmt.Sprintf("更新用户(id=%d)数据失败:%s", usersData.Id, err) 516 e := fmt.Sprintf("更新用户(id=%d)数据失败:%s", usersData.Id, err)
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 ) 9 )
10 10
11 type PartnerInfo struct { 11 type PartnerInfo struct {
12 - tableName struct{} `pg:"partner_info,alias:partner_info"` 12 + tableName struct{} `pg:"partner_info"`
13 // 合伙人ID 13 // 合伙人ID
14 Id int64 `pg:",pk"` 14 Id int64 `pg:",pk"`
15 // 合伙人姓名 15 // 合伙人姓名
@@ -256,12 +256,14 @@ func (c *PartnerInfoController) ListPartnerInfo() { @@ -256,12 +256,14 @@ func (c *PartnerInfoController) ListPartnerInfo() {
256 if param.PageSize == 0 { 256 if param.PageSize == 0 {
257 param.PageSize = 20 257 param.PageSize = 20
258 } 258 }
  259 + companyId := c.GetUserCompany()
259 query := partnerQuery.ListPartnerInfoQuery{ 260 query := partnerQuery.ListPartnerInfoQuery{
260 Partnertype: param.Partnertype, 261 Partnertype: param.Partnertype,
261 PartnerName: param.PartnerName, 262 PartnerName: param.PartnerName,
262 RegionInfo: param.Area, 263 RegionInfo: param.Area,
263 Limit: param.PageSize, 264 Limit: param.PageSize,
264 Offset: (param.PageNumber - 1) * param.PageSize, 265 Offset: (param.PageNumber - 1) * param.PageSize,
  266 + CompanyId: companyId,
265 } 267 }
266 268
267 newPartnerService := partnerInfoService.NewPartnerInfoService(nil) 269 newPartnerService := partnerInfoService.NewPartnerInfoService(nil)