sandbox.go 6.2 KB

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