sandbox.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package sandbox
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type Sandbox struct {
  8. SandboxId int `orm:"column(sandbox_id);pk" description:"沙盘id"`
  9. Name string `description:"沙盘名称"`
  10. Code string `description:"沙盘code"`
  11. Content string `description:"沙盘数据"`
  12. MindmapData string `description:"思维导图数据"`
  13. PicUrl string `description:"沙盘图片地址"`
  14. SysUserId int `description:"作者id"`
  15. SysUserName string `description:"作者名称"`
  16. IsDelete int8 `description:"是否删除,0:未删除,1:已删除"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. CreateTime time.Time `description:"创建时间"`
  19. SandboxClassifyId int `description:"分类id"`
  20. Sort int `description:"排序"`
  21. Style int `description:"风格"`
  22. }
  23. // Update 沙盘字段变更
  24. func (sandbox *Sandbox) Update(cols []string) (err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. _, err = o.Update(sandbox, cols...)
  27. return
  28. }
  29. // GetSandboxById 根据沙盘id获取沙盘详情
  30. func GetSandboxById(sandboxId int) (sandboxInfo *Sandbox, err error) {
  31. o := orm.NewOrmUsingDB("data")
  32. sql := `select * from sandbox where sandbox_id = ? and is_delete = 0`
  33. err = o.Raw(sql, sandboxId).QueryRow(&sandboxInfo)
  34. return
  35. }
  36. // SandboxListItem 沙盘推演列表数据
  37. type SandboxListItem struct {
  38. SandboxId int `description:"沙盘id"`
  39. Name string `description:"沙盘名称"`
  40. //ChartPermissionId int `description:"品种id"`
  41. //ChartPermissionName string `description:"品种名称"`
  42. //CurrVersion int `description:"当前版本"`
  43. Code string `description:"沙盘code"`
  44. //VersionCode string `description:"沙盘版本code"`
  45. //Content string `description:"沙盘数据"`
  46. PicUrl string `description:"沙盘图片地址"`
  47. //OpUserId int `description:"最近一次编辑操作的用户id"`
  48. //OpUserName string `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
  49. IsDelete int8 `description:"是否删除,0:未删除,1:已删除" json:"is_delete"`
  50. // CanEdit bool `description:"是否可编辑"`
  51. // Editor string `description:"编辑人"`
  52. // VersionTotal int `description:"历史版本数量"`
  53. ModifyTime time.Time `description:"修改时间"`
  54. CreateTime time.Time `description:"创建时间"`
  55. SysUserId int `description:"作者id"`
  56. SysUserName string `description:"作者名称"`
  57. SandboxClassifyId int `description:"分类id"`
  58. Sort int `description:"排序"`
  59. Style int `description:"风格"`
  60. }
  61. func GetSandboxClassify(sandboxClassifyId int) (sandbox_classify_id string, err error) {
  62. o := orm.NewOrmUsingDB("data")
  63. sql := `SELECT GROUP_CONCAT(t.sandbox_classify_id) AS sandbox_classify_id FROM (
  64. SELECT a.sandbox_classify_id FROM sandbox_classify AS a
  65. WHERE a.sandbox_classify_id=?
  66. UNION ALL
  67. SELECT a.sandbox_classify_id FROM sandbox_classify AS a
  68. WHERE a.parent_id=? UNION ALL
  69. SELECT
  70. sandbox_classify_id
  71. FROM
  72. sandbox_classify
  73. WHERE
  74. parent_id IN ( SELECT sandbox_classify_id FROM sandbox_classify WHERE parent_id = ? )
  75. )AS t`
  76. err = o.Raw(sql, sandboxClassifyId, sandboxClassifyId, sandboxClassifyId).QueryRow(&sandbox_classify_id)
  77. return
  78. }
  79. type SandboxListItems struct {
  80. SandboxListItem
  81. ParentIds string
  82. }
  83. func GetSandboxListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*SandboxListItems, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT * FROM sandbox WHERE 1=1 `
  86. if condition != "" {
  87. sql += condition
  88. }
  89. sql += " ORDER BY create_time DESC LIMIT ?,? "
  90. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  91. return
  92. }
  93. func GetSandboxListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  94. o := orm.NewOrmUsingDB("data")
  95. sql := ` SELECT COUNT(1) AS count FROM sandbox WHERE 1=1 `
  96. if condition != "" {
  97. sql += condition
  98. }
  99. err = o.Raw(sql, pars).QueryRow(&count)
  100. return
  101. }
  102. type SandboxListResp struct {
  103. Paging *paging.PagingItem
  104. List []*SandboxListItems
  105. }
  106. func GetSandboxAllParentByClassifyId(sandboxClassifyId int) (ids string, err error) {
  107. o := orm.NewOrmUsingDB("data")
  108. sql := `SELECT
  109. GROUP_CONCAT(DISTINCT m.sandbox_classify_id ORDER BY m.level) AS ids
  110. FROM
  111. (
  112. SELECT
  113. @id AS _id,(
  114. SELECT
  115. @id := parent_id
  116. FROM
  117. sandbox_classify
  118. WHERE
  119. sandbox_classify_id = _id
  120. )
  121. FROM
  122. (
  123. SELECT
  124. @id :=(
  125. SELECT
  126. parent_id
  127. FROM
  128. sandbox_classify
  129. WHERE
  130. sandbox_classify_id = ?
  131. )) vm,
  132. sandbox_classify m
  133. WHERE
  134. @id IS NOT NULL
  135. ) vm
  136. INNER JOIN sandbox_classify m
  137. WHERE
  138. sandbox_classify_id = vm._id `
  139. err = o.Raw(sql, sandboxClassifyId).QueryRow(&ids)
  140. return
  141. }
  142. // ContentDataStruct 沙盘内容结构体
  143. type ContentDataStruct struct {
  144. Cells []struct {
  145. Data *NodeData `json:"data,omitempty"`
  146. } `json:"cells"`
  147. }
  148. type NodeData struct {
  149. LinkData []*LinkData `json:"linkData"`
  150. LinkFold bool `json:"linkFold"`
  151. }
  152. type LinkData struct {
  153. RId string `json:"RId"`
  154. Id int `json:"Id"`
  155. Name string `json:"Name"`
  156. Type int `json:"Type"`
  157. Editing bool `json:"editing"`
  158. DatabaseType int `json:"databaseType"`
  159. DetailParams DetailParams `json:"detailParams"`
  160. }
  161. type DetailParams struct {
  162. Code string `json:"code"`
  163. Id int `json:"id"`
  164. ClassifyId int `json:"classifyId"`
  165. }