sand_box_classify.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package sandbox
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type SandboxClassify struct {
  8. SandboxClassifyId int `orm:"column(sandbox_classify_id);pk"`
  9. SandboxClassifyName string `description:"分类名称"`
  10. ParentId int `description:"父级id"`
  11. HasData int `description:"是否含有指标数据"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. SysUserId int `description:"创建人id"`
  15. SysUserRealName string `description:"创建人姓名"`
  16. Level int `description:"层级"`
  17. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  18. }
  19. func AddSandboxClassify(item *SandboxClassify) (lastId int64, err error) {
  20. o := orm.NewOrmUsingDB("data")
  21. lastId, err = o.Insert(item)
  22. return
  23. }
  24. // GetSandboxClassifyByParentId
  25. func GetSandboxClassifyByParentId(parentId int) (items []*SandboxClassifyItems, err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. sql := ` SELECT * FROM sandbox_classify WHERE parent_id=? order by sort asc,sandbox_classify_id asc`
  28. _, err = o.Raw(sql, parentId).QueryRows(&items)
  29. return
  30. }
  31. // GetSandboxClassifyAll
  32. func GetSandboxClassifyAll() (items []*SandboxClassifyItems, err error) {
  33. o := orm.NewOrmUsingDB("data")
  34. sql := ` SELECT * FROM sandbox_classify WHERE parent_id<>0 order by sort asc,sandbox_classify_id asc`
  35. _, err = o.Raw(sql).QueryRows(&items)
  36. return
  37. }
  38. type SandboxClassifyItems struct {
  39. SandboxClassifyId int `orm:"column(sandbox_classify_id);pk"`
  40. SandboxClassifyName string `description:"分类名称"`
  41. ParentId int `description:"父级id"`
  42. HasData int `description:"是否含有指标数据"`
  43. CreateTime time.Time `description:"创建时间"`
  44. ModifyTime time.Time `description:"修改时间"`
  45. SysUserId int `description:"创建人id"`
  46. SysUserRealName string `description:"创建人姓名"`
  47. Level int `description:"层级"`
  48. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  49. SandboxId int `description:"沙盘id"`
  50. Children []*SandboxClassifyItems
  51. }
  52. type SandboxClassifyListResp struct {
  53. AllNodes []*SandboxClassifyItems
  54. }
  55. type AddSandboxClassifyReq struct {
  56. SandboxClassifyName string `description:"分类名称"`
  57. ParentId int `description:"父级id,第一级传0"`
  58. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  59. }
  60. func GetSandboxClassifyCount(sandboxClassifyName string, parentId int) (count int, err error) {
  61. o := orm.NewOrmUsingDB("data")
  62. sql := `SELECT COUNT(1) AS count FROM sandbox_classify WHERE parent_id=? AND sandbox_classify_name=? `
  63. err = o.Raw(sql, parentId, sandboxClassifyName).QueryRow(&count)
  64. return
  65. }
  66. // GetSandboxClassifyMaxSort 获取沙盘分类下最大的排序数
  67. func GetSandboxClassifyMaxSort(parentId int) (sort int, err error) {
  68. o := orm.NewOrmUsingDB("data")
  69. sql := `SELECT Max(sort) AS sort FROM sandbox_classify WHERE parent_id=? `
  70. err = o.Raw(sql, parentId).QueryRow(&sort)
  71. return
  72. }
  73. type EditSandboxClassifyReq struct {
  74. SandboxClassifyName string `description:"分类名称"`
  75. SandboxClassifyId int `description:"分类id"`
  76. }
  77. func GetSandboxClassifyById(classifyId int) (item *SandboxClassify, err error) {
  78. o := orm.NewOrmUsingDB("data")
  79. sql := `SELECT * FROM sandbox_classify WHERE sandbox_classify_id=? `
  80. err = o.Raw(sql, classifyId).QueryRow(&item)
  81. return
  82. }
  83. func EditSandboxClassify(classifyId int, sandboxClassifyName string) (err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := `UPDATE sandbox_classify SET sandbox_classify_name=?,modify_time=NOW() WHERE sandbox_classify_id=? `
  86. _, err = o.Raw(sql, sandboxClassifyName, classifyId).Exec()
  87. return
  88. }
  89. type SandboxClassifyDeleteCheckReq struct {
  90. SandboxClassifyId int `description:"分类id"`
  91. SandboxInfoId int `description:"指标id"`
  92. }
  93. func GetSandboxInfoCountByClassifyId(classifyId int) (count int, err error) {
  94. o := orm.NewOrmUsingDB("data")
  95. sql := ` SELECT COUNT(1) AS count FROM sandbox AS a
  96. WHERE a.sandbox_classify_id IN(
  97. SELECT t.sandbox_classify_id FROM
  98. (
  99. SELECT rd.*
  100. FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
  101. (SELECT @pid := ?) pd
  102. WHERE FIND_IN_SET(parent_id, @pid) > 0
  103. AND @pid := CONCAT(@pid, ',', sandbox_classify_id)
  104. UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
  105. )AS t
  106. ) `
  107. err = o.Raw(sql, classifyId).QueryRow(&count)
  108. return
  109. }
  110. type SandboxClassifyDeleteCheckResp struct {
  111. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  112. TipsMsg string `description:"提示信息"`
  113. }
  114. type DeleteSandboxClassifyReq struct {
  115. SandboxClassifyId int `description:"分类id"`
  116. SandboxId int `description:"指标id"`
  117. }
  118. func DeleteSandboxClassify(classifyId int) (err error) {
  119. o := orm.NewOrmUsingDB("data")
  120. sql := ` DELETE FROM sandbox_classify
  121. WHERE sandbox_classify_id IN(
  122. SELECT t.sandbox_classify_id FROM
  123. (
  124. SELECT rd.*
  125. FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
  126. (SELECT @pid := ?) pd
  127. WHERE FIND_IN_SET(parent_id, @pid) > 0
  128. AND @pid := CONCAT(@pid, ',', sandbox_classify_id)
  129. UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
  130. )AS t
  131. ) `
  132. _, err = o.Raw(sql, classifyId).Exec()
  133. return
  134. }
  135. // MoveSandboxClassifyReq 移动沙盘分类请求参数
  136. type MoveSandboxClassifyReq struct {
  137. ClassifyId int `description:"分类id"`
  138. ParentClassifyId int `description:"父级分类id"`
  139. PrevClassifyId int `description:"上一个兄弟节点分类id"`
  140. NextClassifyId int `description:"下一个兄弟节点分类id"`
  141. }
  142. // UpdateSandboxClassifySortByParentId 根据沙盘父类id更新排序
  143. func UpdateSandboxClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  144. o := orm.NewOrmUsingDB("data")
  145. sql := ` update sandbox_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  146. if classifyId > 0 {
  147. sql += ` or ( sandbox_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  148. }
  149. _, err = o.Raw(sql, parentId, nowSort).Exec()
  150. return
  151. }
  152. // GetFirstSandboxClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
  153. func GetFirstSandboxClassifyByParentId(parentId int) (item *SandboxClassify, err error) {
  154. o := orm.NewOrmUsingDB("data")
  155. sql := ` SELECT * FROM sandbox_classify WHERE parent_id=? order by sort asc,sandbox_classify_id asc limit 1`
  156. err = o.Raw(sql, parentId).QueryRow(&item)
  157. return
  158. }
  159. // Update 更新沙盘分类基础信息
  160. func (sandboxClassify *SandboxClassify) Update(cols []string) (err error) {
  161. o := orm.NewOrmUsingDB("data")
  162. _, err = o.Update(sandboxClassify, cols...)
  163. return
  164. }