蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

183 lines
5.0 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. type ImgReqUploadReq struct {
  102. FileName string `json:"file_name" binding:"required" example:"文件名"`
  103. }
  104. type ImgReqUploadResp struct {
  105. SignUrl string `json:"sign_url" example:"签名上传url"`
  106. }
  107. // GetOssUrl
  108. // @Summary 通用请求-对象存储-上传许可链接(获取)
  109. // @Tags 对象存储
  110. // @Description 上传许可链接(获取)
  111. // @Accept json
  112. // @Produce json
  113. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  114. // @Success 200 {string} "许可链接"
  115. // @Failure 400 {object} md.Response "具体错误"
  116. // @Router /api/comm/getOssUrl [get]
  117. func GetOssUrl(c *gin.Context) {
  118. var args ImgReqUploadReq
  119. err := c.ShouldBindJSON(&args)
  120. if err != nil {
  121. err = svc.HandleValidateErr(err)
  122. err1 := err.(e.E)
  123. e.OutErr(c, err1.Code, err1.Error())
  124. return
  125. }
  126. redisConn := cache.GetPool().Get()
  127. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  128. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  129. if err != nil {
  130. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  131. return
  132. }
  133. if sysCfgs == nil {
  134. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  135. return
  136. }
  137. cfgMap := make(map[string]string, len(*sysCfgs))
  138. for _, cfg := range *sysCfgs {
  139. cfgMap[cfg.Key] = cfg.Val
  140. }
  141. endpoint := cfgMap[enum2.AliyunOssEndpoint]
  142. bucketName := cfgMap[enum2.AliyunOssBucketName]
  143. ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
  144. accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
  145. accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
  146. // 创建OSSClient实例。
  147. client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
  148. if err != nil {
  149. e.OutErr(c, e.ERR, err.Error())
  150. return
  151. }
  152. // 获取存储空间。
  153. bucket, err := client.Bucket(bucketName)
  154. if err != nil {
  155. e.OutErr(c, e.ERR, err.Error())
  156. return
  157. }
  158. signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5)
  159. if err != nil {
  160. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  161. return
  162. }
  163. e.OutSuc(c, signedURL, nil)
  164. }