sand_box_classify.go 7.1 KB

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