广告平台(总站长使用)
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

164 Zeilen
4.5 KiB

  1. package hdl
  2. import (
  3. implement2 "applet/app/db/implement"
  4. "applet/app/e"
  5. "applet/app/enum"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. db "code.fnuoos.com/zhimeng/model.git/src"
  10. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  11. "github.com/gin-gonic/gin"
  12. )
  13. func MenuList(c *gin.Context) {
  14. engine := db.Db
  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. }
  99. // GetBaseInfo
  100. // @Summary 获取系统信息
  101. // @Tags 公共模块
  102. // @Description 公共模块-获取系统信息
  103. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  104. // @Accept json
  105. // @Produce json
  106. // @Success 200 {string} "success"
  107. // @Failure 400 {object} md.Response "具体错误"
  108. // @Router /api/comm/basicGet [GET]
  109. func GetBaseInfo(c *gin.Context) {
  110. masterId := "0"
  111. engine := db.Db
  112. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  113. res := sysCfgDb.SysCfgFindWithDb(enum.AppLogo, enum.AppName)
  114. e.OutSuc(c, md.BasicSetResp{
  115. AppName: res[enum.AppName],
  116. AppLogo: res[enum.AppLogo],
  117. }, nil)
  118. return
  119. }
  120. // UploadFile
  121. // @Summary 上传文件
  122. // @Tags 公共模块
  123. // @Description 公共模块-上传文件
  124. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  125. // @Accept multipart/form-data
  126. // @Produce multipart/form-data
  127. // @Param file formData file true "上传的文件"
  128. // @Success 200 {string} "success"
  129. // @Failure 400 {object} md.Response "具体错误"
  130. // @Router /api/comm/uploadFile [POST]
  131. func UploadFile(c *gin.Context) {
  132. // 单文件上传
  133. file, err := c.FormFile("file")
  134. if err != nil {
  135. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  136. return
  137. }
  138. dst := "./static/upload/" + file.Filename
  139. if err = c.SaveUploadedFile(file, dst); err != nil {
  140. e.OutErr(c, e.ERR, err.Error())
  141. return
  142. }
  143. e.OutSuc(c, map[string]string{
  144. "url": c.Request.Host + "/api/comm/upload/" + file.Filename,
  145. }, nil)
  146. return
  147. }