广告平台(站长使用)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

hdl_comm.go 2.9 KiB

il y a 1 mois
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/enum"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. db "code.fnuoos.com/zhimeng/model.git/src"
  9. "code.fnuoos.com/zhimeng/model.git/src/implement"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func MenuList(c *gin.Context) {
  13. masterId := svc.GetMasterId(c)
  14. engine := db.DBs[masterId]
  15. admin := svc.GetUser(c)
  16. qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
  17. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
  18. if err != nil {
  19. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  20. return
  21. }
  22. // 1、查询出当前用户所有角色
  23. adminRoleDb := implement.NewAdminRoleDb(engine)
  24. roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
  25. if err != nil {
  26. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  27. return
  28. }
  29. roleDb := implement.NewRoleDb(engine, 0)
  30. var adminHasPermissionGroupIds []string
  31. for _, v := range *roles {
  32. list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
  33. if err1 != nil {
  34. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  35. return
  36. }
  37. for _, v1 := range list {
  38. adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
  39. }
  40. }
  41. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  42. var tempRespMapKeys []string
  43. for _, v := range *groupList {
  44. var isCheck bool
  45. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  46. isCheck = true
  47. } else {
  48. isCheck = false
  49. }
  50. if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
  51. isCheck = true
  52. }
  53. if v.State == enum.PermissionGroupStateForDiscard {
  54. isCheck = false
  55. }
  56. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  57. Id: v.Id,
  58. Name: v.Name,
  59. Key: v.Key,
  60. State: v.State,
  61. ParentId: v.ParentId,
  62. CreateAt: v.CreateAt,
  63. UpdateAt: v.UpdateAt,
  64. IsCheck: isCheck,
  65. }
  66. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  67. }
  68. for _, v := range tempRespMap {
  69. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  70. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  71. }
  72. }
  73. for _, v := range tempRespMap {
  74. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  75. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  76. }
  77. }
  78. var resp []*md.PermissionGroupListResp
  79. for _, v := range tempRespMapKeys {
  80. if tempRespMap[v].ParentId == 0 {
  81. resp = append(resp, tempRespMap[v])
  82. }
  83. }
  84. e.OutSuc(c, map[string]interface{}{
  85. "list": resp,
  86. "state": []map[string]interface{}{
  87. {
  88. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  89. "value": enum.PermissionGroupStateForNormal,
  90. },
  91. {
  92. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  93. "value": enum.PermissionGroupStateForDiscard,
  94. },
  95. },
  96. }, nil)
  97. return
  98. }