sandbox.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package sandbox
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // Sandbox 沙盘推演主表
  7. //type Sandbox struct {
  8. // SandboxId int `orm:"column(sandbox_id);pk" description:"沙盘id"`
  9. // Name string `description:"沙盘名称"`
  10. // ChartPermissionId int `description:"品种id"`
  11. // ChartPermissionName string `description:"品种名称"`
  12. // CurrVersion int `description:"当前版本"`
  13. // Code string `description:"沙盘code"`
  14. // Content string `description:"沙盘数据"`
  15. // PicUrl string `description:"沙盘图片地址"`
  16. // OpUserId int `description:"最近一次编辑操作的用户id"`
  17. // OpUserName string `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
  18. // IsDelete int8 `description:"是否删除,0:未删除,1:已删除"`
  19. // ModifyTime time.Time `description:"修改时间"`
  20. // CreateTime time.Time `description:"创建时间"`
  21. //}
  22. type Sandbox struct {
  23. SandboxId int `orm:"column(sandbox_id);pk" description:"沙盘id"`
  24. Name string `description:"沙盘名称"`
  25. Code string `description:"沙盘code"`
  26. Content string `description:"沙盘数据"`
  27. MindmapData string `description:"思维导图数据"`
  28. PicUrl string `description:"沙盘图片地址"`
  29. SysUserId int `description:"作者id"`
  30. SysUserName string `description:"作者名称"`
  31. IsDelete int8 `description:"是否删除,0:未删除,1:已删除"`
  32. ModifyTime time.Time `description:"修改时间"`
  33. CreateTime time.Time `description:"创建时间"`
  34. SandboxClassifyId int `description:"分类id"`
  35. Sort int `description:"排序"`
  36. }
  37. // Update 沙盘字段变更
  38. func (sandbox *Sandbox) Update(cols []string) (err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. _, err = o.Update(sandbox, cols...)
  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 time.Time `description:"修改时间"`
  61. CreateTime time.Time `description:"创建时间"`
  62. }
  63. // GetList 获取沙盘列表页
  64. func GetList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*Sandbox, err error) {
  65. o := orm.NewOrmUsingDB("data")
  66. sql := "select a.sandbox_id,a.name,a.code,a.pic_url,a.sys_user_id,a.sys_user_name,a.modify_time,a.create_time from sandbox as a where 1=1 AND a.is_delete = 0 "
  67. sql += condition
  68. sql += ` order by a.modify_time desc,a.sandbox_id desc`
  69. totalSql := `select count(1) total from (` + sql + `) z `
  70. err = o.Raw(totalSql, pars).QueryRow(&total)
  71. if err != nil {
  72. return
  73. }
  74. sql += ` LIMIT ?,? `
  75. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  76. return
  77. }