sandbox.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package sandbox
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. sandboxLogic "hongze/hongze_yb/logic/sandbox"
  6. sandboxReq "hongze/hongze_yb/models/request/sandbox"
  7. responseModel "hongze/hongze_yb/models/response"
  8. sandboxModel "hongze/hongze_yb/models/tables/sandbox"
  9. "hongze/hongze_yb/services"
  10. "hongze/hongze_yb/services/company"
  11. "hongze/hongze_yb/services/user"
  12. "strconv"
  13. "strings"
  14. )
  15. // List 获取沙盘逻辑图列表
  16. // @Tags 沙盘模块
  17. // @Summary 获取沙盘逻辑图列表
  18. // @Description 获取沙盘逻辑图列表
  19. // @Security ApiKeyAuth
  20. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  21. // @Accept json
  22. // @Product json
  23. // @Param chart_permission query int false "品种权限id"
  24. // @Param keyword query string false "关键字"
  25. // @Param is_high_light query bool false "是否高亮显示"
  26. // @Param curr_page query int false "当前页码"
  27. // @Param page_size query int false "每页返回数据"
  28. // @Success 200 {object} sandbox.SandboxListResp
  29. // @failure 400 {string} string "获取失败"
  30. // @Router /sandbox/list [get]
  31. func List(c *gin.Context) {
  32. var req sandboxReq.ListReq
  33. if err := c.Bind(&req); err != nil {
  34. response.Fail("参数有误", c)
  35. return
  36. }
  37. // 品种id
  38. chartPermissionId := req.ChartPermissionId
  39. // 关键字
  40. keyword := req.Keyword
  41. // 是否高亮
  42. isHighLight := req.IsHighLight
  43. page := services.GetCurrPageByClaims(c)
  44. pageSize := services.GetPageSizeByClaims(c)
  45. userInfo := user.GetInfoByClaims(c)
  46. //权限验证
  47. checkOk, companyPermissionIdList, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), chartPermissionId)
  48. if tempErr != nil {
  49. response.FailMsg("沙盘权限验证失败", "沙盘权限验证失败:"+tempErr.Error(), c)
  50. c.Abort()
  51. return
  52. }
  53. if !checkOk {
  54. response.AuthError(permissionCheckInfo, "暂无权限", c)
  55. c.Abort()
  56. return
  57. }
  58. //获取指标信息
  59. total, list, err, errMsg := sandboxLogic.GetList(chartPermissionId, companyPermissionIdList, keyword, page, pageSize)
  60. if err != nil {
  61. response.FailMsg(errMsg, err.Error(), c)
  62. return
  63. }
  64. // 如果要高亮,且有输入关键字搜索,那么就返回高亮显示字符串
  65. if isHighLight && keyword != `` {
  66. for index, v := range list {
  67. tmpKeyword := `<span style="color:#E3B377">` + keyword + `</span>`
  68. list[index].Name = strings.Replace(v.Name, keyword, tmpKeyword, -1)
  69. }
  70. }
  71. resp := responseModel.SandboxListResp{
  72. List: list,
  73. Paging: responseModel.GetPaging(page, pageSize, int(total)),
  74. }
  75. response.OkData("获取成功", resp, c)
  76. }
  77. // Detail 获取沙盘逻辑图详情
  78. // @Tags 沙盘模块
  79. // @Summary 获取沙盘逻辑图详情
  80. // @Description 获取沙盘逻辑图详情
  81. // @Security ApiKeyAuth
  82. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  83. // @Accept json
  84. // @Product json
  85. // @Param sandbox_id query int false "沙盘逻辑id"
  86. // @Success 200 {object} sandbox.SandboxItem
  87. // @failure 400 {string} string "获取失败"
  88. // @Router /sandbox/detail [get]
  89. func Detail(c *gin.Context) {
  90. // 沙盘id
  91. sandboxIdStr := c.DefaultQuery("sandbox_id", "0")
  92. sandboxId, _ := strconv.Atoi(sandboxIdStr)
  93. userInfo := user.GetInfoByClaims(c)
  94. sandboxInfo, err := sandboxModel.GetBySandboxId(uint32(sandboxId))
  95. if err != nil {
  96. response.FailMsg("获取沙盘失败", "获取沙盘失败:"+err.Error(), c)
  97. c.Abort()
  98. return
  99. }
  100. //权限验证
  101. checkOk, _, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), int(sandboxInfo.ChartPermissionID))
  102. if tempErr != nil {
  103. response.FailMsg("沙盘权限验证失败", "沙盘权限验证失败:"+tempErr.Error(), c)
  104. c.Abort()
  105. return
  106. }
  107. if !checkOk {
  108. response.AuthError(permissionCheckInfo, "暂无权限", c)
  109. c.Abort()
  110. return
  111. }
  112. response.OkData("获取成功", sandboxLogic.SandboxItem{
  113. SandboxID: sandboxInfo.SandboxID,
  114. Name: sandboxInfo.Name,
  115. ChartPermissionID: sandboxInfo.ChartPermissionID,
  116. ChartPermissionName: sandboxInfo.ChartPermissionName,
  117. CurrVersion: sandboxInfo.CurrVersion,
  118. Code: sandboxInfo.Code,
  119. PicURL: sandboxInfo.PicURL,
  120. OpUserName: sandboxInfo.OpUserName,
  121. ModifyTime: sandboxInfo.ModifyTime,
  122. }, c)
  123. }
  124. // PermissionCountList 获取各个品种下的沙盘图数量列表
  125. // @Tags 沙盘模块
  126. // @Summary 获取各个品种下的沙盘图数量列表
  127. // @Description 获取各个品种下的沙盘图数量列表
  128. // @Security ApiKeyAuth
  129. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  130. // @Accept json
  131. // @Product json
  132. // @Param sandbox_id query int false "沙盘逻辑id"
  133. // @Success 200 {object} []sandboxModel.PermissionSandboxCount
  134. // @failure 400 {string} string "获取失败"
  135. // @Router /sandbox/permission_count [get]
  136. func PermissionCountList(c *gin.Context) {
  137. userInfo := user.GetInfoByClaims(c)
  138. //权限验证
  139. checkOk, companyPermissionIdList, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), 0)
  140. if tempErr != nil {
  141. response.FailMsg("沙盘权限验证失败", "沙盘权限验证失败:"+tempErr.Error(), c)
  142. c.Abort()
  143. return
  144. }
  145. if !checkOk {
  146. response.AuthError(permissionCheckInfo, "暂无权限", c)
  147. c.Abort()
  148. return
  149. }
  150. //获取指标信息
  151. list, err, errMsg := sandboxLogic.GetPermissionCountList(companyPermissionIdList)
  152. if err != nil {
  153. response.FailMsg(errMsg, err.Error(), c)
  154. return
  155. }
  156. response.OkData("获取成功", list, c)
  157. }