蛋蛋星球 后台端
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

164 linhas
4.6 KiB

  1. package comm
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/enum"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. "applet/app/utils/cache"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  12. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  13. "github.com/gin-gonic/gin"
  14. )
  15. func MenuList(c *gin.Context) {
  16. engine := db.Db
  17. admin := svc.GetUser(c)
  18. qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
  19. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
  20. if err != nil {
  21. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  22. return
  23. }
  24. // 1、查询出当前用户所有角色
  25. adminRoleDb := implement.NewAdminRoleDb(engine)
  26. roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
  27. if err != nil {
  28. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  29. return
  30. }
  31. roleDb := implement.NewRoleDb(engine, 0)
  32. var adminHasPermissionGroupIds []string
  33. for _, v := range *roles {
  34. list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
  35. if err1 != nil {
  36. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  37. return
  38. }
  39. for _, v1 := range list {
  40. adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
  41. }
  42. }
  43. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  44. var tempRespMapKeys []string
  45. for _, v := range *groupList {
  46. var isCheck bool
  47. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  48. isCheck = true
  49. } else {
  50. isCheck = false
  51. }
  52. if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
  53. isCheck = true
  54. }
  55. if v.State == enum.PermissionGroupStateForDiscard {
  56. isCheck = false
  57. }
  58. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  59. Id: v.Id,
  60. Name: v.Name,
  61. Key: v.Key,
  62. State: v.State,
  63. ParentId: v.ParentId,
  64. CreateAt: v.CreateAt,
  65. UpdateAt: v.UpdateAt,
  66. IsCheck: isCheck,
  67. }
  68. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  69. }
  70. for _, v := range tempRespMap {
  71. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  72. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  73. }
  74. }
  75. for _, v := range tempRespMap {
  76. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  77. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  78. }
  79. }
  80. var resp []*md.PermissionGroupListResp
  81. for _, v := range tempRespMapKeys {
  82. if tempRespMap[v].ParentId == 0 {
  83. resp = append(resp, tempRespMap[v])
  84. }
  85. }
  86. e.OutSuc(c, map[string]interface{}{
  87. "list": resp,
  88. "state": []map[string]interface{}{
  89. {
  90. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  91. "value": enum.PermissionGroupStateForNormal,
  92. },
  93. {
  94. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  95. "value": enum.PermissionGroupStateForDiscard,
  96. },
  97. },
  98. }, nil)
  99. return
  100. }
  101. // GetOssUrl
  102. // @Summary 通用请求-对象存储-上传许可链接(获取)
  103. // @Tags 对象存储
  104. // @Description 上传许可链接(获取)
  105. // @Accept json
  106. // @Produce json
  107. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  108. // @Success 200 {string} "许可链接"
  109. // @Failure 400 {object} md.Response "具体错误"
  110. // @Router /api/comm/getOssUrl [get]
  111. func GetOssUrl(c *gin.Context) {
  112. redisConn := cache.GetPool().Get()
  113. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  114. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  115. if err != nil {
  116. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  117. return
  118. }
  119. if sysCfgs == nil {
  120. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  121. return
  122. }
  123. cfgMap := make(map[string]string, len(*sysCfgs))
  124. for _, cfg := range *sysCfgs {
  125. cfgMap[cfg.Key] = cfg.Val
  126. }
  127. endpoint := cfgMap[enum2.AliyunOss(enum2.AliyunOssEndpoint).String()]
  128. bucketName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketName).String()]
  129. objectName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()]
  130. accessKeyID := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()]
  131. accessKeySecret := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()]
  132. client, err := oss.New(endpoint, accessKeyID, accessKeySecret)
  133. if err != nil {
  134. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  135. return
  136. }
  137. bucket, err := client.Bucket(bucketName)
  138. if err != nil {
  139. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  140. return
  141. }
  142. signedURL, err := bucket.SignURL(objectName, oss.HTTPPut, 60*5)
  143. if err != nil {
  144. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  145. return
  146. }
  147. e.OutSuc(c, signedURL, nil)
  148. }