蛋蛋星球 后台端
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.

hdl_comm.go 5.2 KiB

2 週之前
2 週之前
2 週之前
2 週之前
2 週之前
2 週之前
1 天之前
2 週之前
2 週之前
1 天之前
2 週之前
2 週之前
1 天之前
2 週之前
1 天之前
1 天之前
2 週之前
1 天之前
2 週之前
1 天之前
2 週之前
1 天之前
2 週之前
1 天之前
2 週之前
1 天之前
1 天之前
2 週之前
2 週之前
2 週之前
2 週之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. "strings"
  15. )
  16. func MenuList(c *gin.Context) {
  17. engine := db.Db
  18. admin := svc.GetUser(c)
  19. qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
  20. groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
  21. if err != nil {
  22. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  23. return
  24. }
  25. // 1、查询出当前用户所有角色
  26. adminRoleDb := implement.NewAdminRoleDb(engine)
  27. roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
  28. if err != nil {
  29. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  30. return
  31. }
  32. roleDb := implement.NewRoleDb(engine, 0)
  33. var adminHasPermissionGroupIds []string
  34. for _, v := range *roles {
  35. list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
  36. if err1 != nil {
  37. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  38. return
  39. }
  40. for _, v1 := range list {
  41. adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
  42. }
  43. }
  44. var tempRespMap = map[string]*md.PermissionGroupListResp{}
  45. var tempRespMapKeys []string
  46. for _, v := range *groupList {
  47. var isCheck bool
  48. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  49. isCheck = true
  50. } else {
  51. isCheck = false
  52. }
  53. if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
  54. isCheck = true
  55. }
  56. if v.State == enum.PermissionGroupStateForDiscard {
  57. isCheck = false
  58. }
  59. tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
  60. Id: v.Id,
  61. Name: v.Name,
  62. Key: v.Key,
  63. State: v.State,
  64. ParentId: v.ParentId,
  65. CreateAt: v.CreateAt,
  66. UpdateAt: v.UpdateAt,
  67. IsCheck: isCheck,
  68. }
  69. tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
  70. }
  71. for _, v := range tempRespMap {
  72. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
  73. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  74. }
  75. }
  76. for _, v := range tempRespMap {
  77. if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
  78. tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
  79. }
  80. }
  81. var resp []*md.PermissionGroupListResp
  82. for _, v := range tempRespMapKeys {
  83. if tempRespMap[v].ParentId == 0 {
  84. resp = append(resp, tempRespMap[v])
  85. }
  86. }
  87. e.OutSuc(c, map[string]interface{}{
  88. "list": resp,
  89. "state": []map[string]interface{}{
  90. {
  91. "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
  92. "value": enum.PermissionGroupStateForNormal,
  93. },
  94. {
  95. "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
  96. "value": enum.PermissionGroupStateForDiscard,
  97. },
  98. },
  99. }, nil)
  100. return
  101. }
  102. type ImgReqUploadReq struct {
  103. FileName string `json:"file_name" binding:"required" example:"文件名"`
  104. }
  105. type ImgReqUploadResp struct {
  106. SignUrl string `json:"sign_url" example:"签名上传url"`
  107. }
  108. // GetOssUrl
  109. // @Summary 通用请求-对象存储-上传许可链接(获取)
  110. // @Tags 对象存储
  111. // @Description 上传许可链接(获取)
  112. // @Accept json
  113. // @Produce json
  114. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  115. // @Success 200 {string} "许可链接"
  116. // @Failure 400 {object} md.Response "具体错误"
  117. // @Router /api/comm/getOssUrl [get]
  118. func GetOssUrl(c *gin.Context) {
  119. var args ImgReqUploadReq
  120. err := c.ShouldBindJSON(&args)
  121. if err != nil {
  122. err = svc.HandleValidateErr(err)
  123. err1 := err.(e.E)
  124. e.OutErr(c, err1.Code, err1.Error())
  125. return
  126. }
  127. redisConn := cache.GetPool().Get()
  128. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  129. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  130. if err != nil {
  131. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  132. return
  133. }
  134. if sysCfgs == nil {
  135. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  136. return
  137. }
  138. cfgMap := make(map[string]string, len(*sysCfgs))
  139. for _, cfg := range *sysCfgs {
  140. cfgMap[cfg.Key] = cfg.Val
  141. }
  142. endpoint := cfgMap[enum2.AliyunOssEndpoint]
  143. bucketName := cfgMap[enum2.AliyunOssBucketName]
  144. ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
  145. accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
  146. accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
  147. aliyunOptions := cfgMap[enum2.AliyunOptions]
  148. // 创建OSSClient实例。
  149. client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
  150. if err != nil {
  151. e.OutErr(c, e.ERR, err.Error())
  152. return
  153. }
  154. // 获取存储空间。
  155. bucket, err := client.Bucket(bucketName)
  156. if err != nil {
  157. e.OutErr(c, e.ERR, err.Error())
  158. return
  159. }
  160. optionsList := strings.Split(aliyunOptions, ",")
  161. var options []oss.Option
  162. for _, option := range optionsList {
  163. options = append(options, oss.ContentType(option))
  164. }
  165. signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...)
  166. if err != nil {
  167. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  168. return
  169. }
  170. e.OutSuc(c, signedURL, nil)
  171. }