sandbox_classify.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. ChartPermissionId int `description:"品种id"`
  53. ChartPermissionName string `description:"品种名称"`
  54. Children []*SandboxClassifyItems
  55. }
  56. type SandboxClassifyListResp struct {
  57. AllNodes []*SandboxClassifyItems
  58. }
  59. type AddSandboxClassifyReq struct {
  60. SandboxClassifyName string `description:"分类名称"`
  61. ParentId int `description:"父级id,第一级传0"`
  62. Level int `description:"层级,第一级传0,其余传上一级的层级"`
  63. ChartPermissionId int `description:"品种id"`
  64. ChartPermissionName string `description:"品种名称"`
  65. }
  66. func GetSandboxClassifyCount(sandboxClassifyName string, parentId int) (count int, err error) {
  67. o := orm.NewOrmUsingDB("data")
  68. sql := `SELECT COUNT(1) AS count FROM sandbox_classify WHERE parent_id=? AND sandbox_classify_name=? `
  69. err = o.Raw(sql, parentId, sandboxClassifyName).QueryRow(&count)
  70. return
  71. }
  72. // GetSandboxClassifyMaxSort 获取沙盘分类下最大的排序数
  73. func GetSandboxClassifyMaxSort(parentId int) (sort int, err error) {
  74. o := orm.NewOrmUsingDB("data")
  75. sql := `SELECT Max(sort) AS sort FROM sandbox_classify WHERE parent_id=? `
  76. err = o.Raw(sql, parentId).QueryRow(&sort)
  77. return
  78. }
  79. type EditSandboxClassifyReq struct {
  80. SandboxClassifyName string `description:"分类名称"`
  81. SandboxClassifyId int `description:"分类id"`
  82. ChartPermissionId int `description:"品种id"`
  83. ChartPermissionName string `description:"品种名称"`
  84. }
  85. func GetSandboxClassifyById(classifyId int) (item *SandboxClassify, err error) {
  86. o := orm.NewOrmUsingDB("data")
  87. sql := `SELECT * FROM sandbox_classify WHERE sandbox_classify_id=? `
  88. err = o.Raw(sql, classifyId).QueryRow(&item)
  89. return
  90. }
  91. func EditSandboxClassify(classifyId, ChartPermissionId int, sandboxClassifyName, ChartPermissionName string) (err error) {
  92. o := orm.NewOrmUsingDB("data")
  93. sql := `UPDATE sandbox_classify SET sandbox_classify_name=?,chart_permission_id = ?, chart_permission_name = ?, modify_time=NOW() WHERE sandbox_classify_id=? `
  94. _, err = o.Raw(sql, sandboxClassifyName, ChartPermissionId, ChartPermissionName, classifyId).Exec()
  95. return
  96. }
  97. type SandboxClassifyDeleteCheckReq struct {
  98. SandboxClassifyId int `description:"分类id"`
  99. }
  100. func GetSandboxInfoCountByClassifyId(classifyId int) (count int, err error) {
  101. o := orm.NewOrmUsingDB("data")
  102. sql := ` SELECT COUNT(1) AS count FROM sandbox AS a
  103. WHERE a.sandbox_classify_id IN(
  104. SELECT t.sandbox_classify_id FROM
  105. (
  106. SELECT rd.*
  107. FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
  108. (SELECT @pid := ?) pd
  109. WHERE FIND_IN_SET(parent_id, @pid) > 0
  110. AND @pid := CONCAT(@pid, ',', sandbox_classify_id)
  111. UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
  112. )AS t
  113. ) AND a.is_delete = 0 `
  114. err = o.Raw(sql, classifyId).QueryRow(&count)
  115. return
  116. }
  117. type SandboxClassifyDeleteCheckResp struct {
  118. DeleteStatus int `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:该分类下关联图表不可删除,2:确认删除当前目录及包含的子目录吗"`
  119. TipsMsg string `description:"提示信息"`
  120. }
  121. type DeleteSandboxClassifyReq struct {
  122. SandboxClassifyId int `description:"分类id"`
  123. SandboxId int `description:"指标id"`
  124. }
  125. func DeleteSandboxClassify(classifyId int) (err error) {
  126. o := orm.NewOrmUsingDB("data")
  127. sql := ` DELETE FROM sandbox_classify
  128. WHERE sandbox_classify_id IN(
  129. SELECT t.sandbox_classify_id FROM
  130. (
  131. SELECT rd.*
  132. FROM (SELECT * FROM sandbox_classify WHERE parent_id IS NOT NULL) rd,
  133. (SELECT @pid := ?) pd
  134. WHERE FIND_IN_SET(parent_id, @pid) > 0
  135. AND @pid := CONCAT(@pid, ',', sandbox_classify_id)
  136. UNION SELECT * FROM sandbox_classify WHERE sandbox_classify_id = @pid
  137. )AS t
  138. ) `
  139. _, err = o.Raw(sql, classifyId).Exec()
  140. return
  141. }
  142. // MoveSandboxClassifyReq 移动沙盘分类请求参数
  143. type MoveSandboxClassifyReq struct {
  144. ClassifyId int `description:"分类id"`
  145. SandboxId int `description:"沙盘ID"`
  146. ParentClassifyId int `description:"父级分类id 移动沙盘时为目标分类id"`
  147. PrevId int `description:"上一个兄弟节点分类id"`
  148. NextId int `description:"下一个兄弟节点分类id"`
  149. PrevType int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
  150. NextType int `description:"上一个兄弟节点类型 1分类 2沙盘 "`
  151. }
  152. // UpdateSandboxClassifySortByParentId 根据沙盘父类id更新排序
  153. func UpdateSandboxClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
  154. o := orm.NewOrmUsingDB("data")
  155. sql := ` update sandbox_classify set sort = ` + updateSort + ` WHERE parent_id=? and sort > ? `
  156. if classifyId > 0 {
  157. sql += ` or ( sandbox_classify_id > ` + fmt.Sprint(classifyId) + ` and sort= ` + fmt.Sprint(nowSort) + `)`
  158. }
  159. _, err = o.Raw(sql, parentId, nowSort).Exec()
  160. return
  161. }
  162. // GetFirstSandboxClassifyByParentId 获取当前父级沙盘分类下的排序第一条的数据
  163. func GetFirstSandboxClassifyByParentId(parentId int) (item *SandboxClassify, err error) {
  164. o := orm.NewOrmUsingDB("data")
  165. sql := ` SELECT * FROM sandbox_classify WHERE parent_id=? order by sort asc,sandbox_classify_id asc limit 1`
  166. err = o.Raw(sql, parentId).QueryRow(&item)
  167. return
  168. }
  169. // Update 更新沙盘分类基础信息
  170. func (sandboxClassify *SandboxClassify) Update(cols []string) (err error) {
  171. o := orm.NewOrmUsingDB("data")
  172. _, err = o.Update(sandboxClassify, cols...)
  173. return
  174. }
  175. // GetSandboxClassifyAndInfoByParentId
  176. func GetSandboxClassifyAndInfoByParentId(parentId int) (items []*SandboxClassifyItems, err error) {
  177. o := orm.NewOrmUsingDB("data")
  178. sql := ` SELECT
  179. 0 AS sandbox_id,
  180. sandbox_classify_id,
  181. sandbox_classify_name,
  182. parent_id,
  183. create_time,
  184. modify_time,
  185. sys_user_id,
  186. sys_user_real_name AS sys_user_name,
  187. sort,
  188. level,
  189. chart_permission_id,
  190. chart_permission_name,
  191. 0 AS is_delete
  192. FROM
  193. sandbox_classify
  194. WHERE
  195. parent_id = ? UNION ALL
  196. SELECT
  197. sandbox_id,
  198. sandbox_classify_id,
  199. name AS sandbox_classify_name,
  200. 0 AS parent_id,
  201. create_time,
  202. modify_time,
  203. sys_user_id,
  204. sys_user_name,
  205. sort,
  206. 0 AS level,
  207. chart_permission_id,
  208. chart_permission_name,
  209. is_delete
  210. FROM
  211. sandbox
  212. WHERE
  213. sandbox_classify_id = ? AND is_delete = 0
  214. ORDER BY
  215. sort ASC,
  216. sandbox_classify_id ASC`
  217. _, err = o.Raw(sql, parentId, parentId).QueryRows(&items)
  218. return
  219. }
  220. type SandboxLinkCheckReq struct {
  221. EdbInfoIdList []int `description:"指标id列表"`
  222. ChartInfoIdList []int `description:"图库id列表"`
  223. ReportIdList []int `description:"报告id列表"`
  224. }
  225. type SandboxLinkCheckItem struct {
  226. Id int `description:"id"`
  227. Name string `description:"名称"`
  228. UniqueCode string `description:"唯一编码"`
  229. ClassifyId int `description:"分类id"`
  230. }
  231. type SandboxLinkCheckResp struct {
  232. EdbInfoIdList []*SandboxLinkCheckItem `description:"指标id列表"`
  233. ChartInfoIdList []*SandboxLinkCheckItem `description:"图库id列表"`
  234. ReportIdList []*SandboxLinkCheckItem `description:"报告id列表"`
  235. }
  236. // 获取所有子级分类id
  237. func GetSandboxClassifySubcategories(classifyId int) (Ids string, err error) {
  238. o := orm.NewOrmUsingDB("data")
  239. sql := `SELECT GROUP_CONCAT(sandbox_classify_id) AS ids
  240. FROM (
  241. SELECT @pv := ? AS sandbox_classify_id
  242. UNION ALL
  243. SELECT sc.sandbox_classify_id
  244. FROM sandbox_classify sc
  245. JOIN (SELECT @pv := ?) initial
  246. WHERE sc.parent_id = @pv
  247. ) subcategories; `
  248. err = o.Raw(sql, classifyId, classifyId).QueryRow(&Ids)
  249. return
  250. }
  251. // UpdateSandboxClassifyChartPermissionById 根据沙盘id更新品种
  252. func UpdateSandboxClassifyChartPermissionById(ChartPermissionId int, ChartPermissionName, Ids string) (err error) {
  253. o := orm.NewOrmUsingDB("data")
  254. sql := ` UPDATE sandbox_classify SET chart_permission_id = ?, chart_permission_name = ? WHERE sandbox_classify_id IN ( ` + Ids + ` ) `
  255. _, err = o.Raw(sql, ChartPermissionId, ChartPermissionName).Exec()
  256. return
  257. }