sandbox.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/sandbox"
  5. sandboxService "eta/eta_hub/services/sandbox"
  6. "eta/eta_hub/utils"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. // SandboxController 逻辑导图
  10. type SandboxController struct {
  11. BaseAuthController
  12. }
  13. // SandboxClassifyItems
  14. // @Title 获取所有沙盘分类接口-包含沙盘
  15. // @Description 获取所有沙盘分类接口-包含沙盘
  16. // @Param IsShowMe query bool true "是否只看我的,true、false"
  17. // @Success 200 {object} data_manage.ChartClassifyListResp
  18. // @router /classify/list [get]
  19. func (this *SandboxController) SandboxClassifyItems() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. resp := new(sandbox.SandboxClassifyListResp)
  26. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  27. rootList, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  28. if err != nil && err.Error() != utils.ErrNoRow() {
  29. br.Msg = "获取失败"
  30. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  31. return
  32. }
  33. classifyAll, err := sandbox.GetSandboxClassifyAndInfoByParentId(sandboxClassifyId)
  34. if err != nil && err.Error() != utils.ErrNoRow() {
  35. br.Msg = "获取失败"
  36. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  37. return
  38. }
  39. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  40. for k := range rootList {
  41. rootNode := rootList[k]
  42. sandboxService.SandboxClassifyItemsMakeTreeV2(classifyAll, rootNode)
  43. nodeAll = append(nodeAll, rootNode)
  44. }
  45. resp.AllNodes = nodeAll
  46. br.Ret = 200
  47. br.Msg = "获取成功"
  48. br.Data = resp
  49. }
  50. // @Title ETA图表列表接口
  51. // @Description ETA图表列表接口
  52. // @Param PageSize query int true "每页数据条数"
  53. // @Param CurrentIndex query int true "当前页页码,从1开始"
  54. // @Param ChartClassifyId query int true "分类id"
  55. // @Param KeyWord query string true "搜索关键词"
  56. // @Param IsShowMe query bool true "是否只看我的,true、false"
  57. // @Success 200 {object} data_manage.ChartListResp
  58. // @router /list [get]
  59. func (this *SandboxController) List() {
  60. br := new(models.BaseResponse).Init()
  61. defer func() {
  62. this.Data["json"] = br
  63. this.ServeJSON()
  64. }()
  65. sandboxClassifyId, _ := this.GetInt("SandboxClassifyId")
  66. pageSize, _ := this.GetInt("PageSize")
  67. currentIndex, _ := this.GetInt("CurrentIndex")
  68. keyWord := this.GetString("KeyWord")
  69. var total int
  70. page := paging.GetPaging(currentIndex, pageSize, total)
  71. var startSize int
  72. if pageSize <= 0 {
  73. pageSize = utils.PageSize20
  74. }
  75. if currentIndex <= 0 {
  76. currentIndex = 1
  77. }
  78. startSize = paging.StartIndex(currentIndex, pageSize)
  79. var condition string
  80. var pars []interface{}
  81. if sandboxClassifyId > 0 {
  82. sandboxClassifyId, err := sandbox.GetSandboxClassify(sandboxClassifyId)
  83. if err != nil && err.Error() != utils.ErrNoRow() {
  84. br.Msg = "获取图表信息失败"
  85. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  86. return
  87. }
  88. condition += " AND sandbox_classify_id IN(" + sandboxClassifyId + ") "
  89. //pars = append(pars, chartClassifyId)
  90. }
  91. if keyWord != "" {
  92. condition += ` AND ( name LIKE '%` + keyWord + `%' )`
  93. }
  94. //获取图表信息
  95. condition += ` AND is_delete = 0 `
  96. list, err := sandbox.GetSandboxListByCondition(condition, pars, startSize, pageSize)
  97. if err != nil && err.Error() != utils.ErrNoRow() {
  98. br.Msg = "获取沙盘信息失败"
  99. br.ErrMsg = "获取沙盘信息失败,Err:" + err.Error()
  100. return
  101. }
  102. for i, v := range list {
  103. ids, err := sandbox.GetSandboxAllParentByClassifyId(v.SandboxClassifyId)
  104. if err != nil {
  105. br.Msg = "获取父级信息错误!"
  106. br.ErrMsg = "获取父级信息错误,Err:" + err.Error()
  107. return
  108. }
  109. list[i].ParentIds = ids
  110. }
  111. resp := new(sandbox.SandboxListResp)
  112. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  113. items := make([]*sandbox.SandboxListItems, 0)
  114. resp.Paging = page
  115. resp.List = items
  116. br.Ret = 200
  117. br.Msg = "获取成功"
  118. return
  119. }
  120. dataCount, err := sandbox.GetSandboxListCountByCondition(condition, pars)
  121. if err != nil && err.Error() != utils.ErrNoRow() {
  122. br.Msg = "获取指标信息失败"
  123. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  124. return
  125. }
  126. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  127. resp.Paging = page
  128. resp.List = list
  129. br.Ret = 200
  130. br.Msg = "获取成功"
  131. br.Data = resp
  132. }
  133. // GetSandboxVersionDetail
  134. // @Title 获取沙盘版本数据详情(已保存的)
  135. // @Description 获取沙盘版本数据详情接口(已保存的)
  136. // @Param SandboxVersionCode query string true "沙盘版本code"
  137. // @Success 200 {object} sandbox.SandboxVersion
  138. // @router /detail [get]
  139. func (this *SandboxController) GetSandboxDetail() {
  140. br := new(models.BaseResponse).Init()
  141. defer func() {
  142. this.Data["json"] = br
  143. this.ServeJSON()
  144. }()
  145. sandboxId, _ := this.GetInt("SandboxId")
  146. if sandboxId == 0 {
  147. br.Msg = "缺少沙盘Id"
  148. return
  149. }
  150. //获取沙盘数据详情(已保存的)
  151. sandboxInfo, err := sandbox.GetSandboxById(sandboxId)
  152. if err != nil {
  153. br.Msg = "获取失败"
  154. br.ErrMsg = "获取失败,Err:" + err.Error()
  155. return
  156. }
  157. msg := "获取成功"
  158. br.Ret = 200
  159. br.Msg = msg
  160. br.Data = sandboxInfo
  161. }
  162. // SandboxClassifyItems
  163. // @Title 获取所有沙盘分类接口-不包含沙盘
  164. // @Description 获取所有沙盘分类接口-不包含沙盘
  165. // @Param IsShowMe query bool true "是否只看我的,true、false"
  166. // @Success 200 {object} data_manage.ChartClassifyListResp
  167. // @router /classifyList [get]
  168. func (this *SandboxController) SandboxClassifyList() {
  169. br := new(models.BaseResponse).Init()
  170. defer func() {
  171. this.Data["json"] = br
  172. this.ServeJSON()
  173. }()
  174. resp := new(sandbox.SandboxClassifyListResp)
  175. rootList, err := sandbox.GetSandboxClassifyByParentId(0)
  176. if err != nil && err.Error() != utils.ErrNoRow() {
  177. br.Msg = "获取失败"
  178. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  179. return
  180. }
  181. classifyAll, err := sandbox.GetSandboxClassifyAll()
  182. if err != nil && err.Error() != utils.ErrNoRow() {
  183. br.Msg = "获取失败"
  184. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  185. return
  186. }
  187. nodeAll := make([]*sandbox.SandboxClassifyItems, 0)
  188. for k := range rootList {
  189. rootNode := rootList[k]
  190. sandboxService.SandboxClassifyItemsMakeTree(classifyAll, rootNode)
  191. nodeAll = append(nodeAll, rootNode)
  192. }
  193. resp.AllNodes = nodeAll
  194. br.Ret = 200
  195. br.Msg = "获取成功"
  196. br.Data = resp
  197. }