sandbox.go 5.7 KB

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