sandbox_classify.go 10 KB

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