sandbox.go 5.9 KB

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