sandbox.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // Update 沙盘字段变更
  23. func (sandbox *Sandbox) Update(cols []string) (err error) {
  24. o := orm.NewOrm()
  25. _, err = o.Update(sandbox, cols...)
  26. return
  27. }
  28. // SandboxListItem 沙盘推演列表数据
  29. type SandboxListItem struct {
  30. SandboxId int `description:"沙盘id"`
  31. Name string `description:"沙盘名称"`
  32. ChartPermissionId int `description:"品种id"`
  33. ChartPermissionName string `description:"品种名称"`
  34. CurrVersion int `description:"当前版本"`
  35. Code string `description:"沙盘code"`
  36. VersionCode string `description:"沙盘版本code"`
  37. //Content string `description:"沙盘数据"`
  38. PicUrl string `description:"沙盘图片地址"`
  39. OpUserId int `description:"最近一次编辑操作的用户id"`
  40. OpUserName string `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
  41. IsDelete int8 `description:"是否删除,0:未删除,1:已删除" json:"is_delete"`
  42. CanEdit bool `description:"是否可编辑"`
  43. Editor string `description:"编辑人"`
  44. VersionTotal int `description:"历史版本数量"`
  45. ModifyTime time.Time `description:"修改时间"`
  46. CreateTime time.Time `description:"创建时间"`
  47. }
  48. // GetList 获取沙盘列表页
  49. func GetList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*SandboxListItem, err error) {
  50. o := orm.NewOrm()
  51. sql := "select a.sandbox_id,a.name,a.chart_permission_id,a.chart_permission_name,a.curr_version,a.code,a.pic_url,a.op_user_id,a.op_user_name,a.modify_time,a.create_time,b.version_code from sandbox as a join sandbox_version b on a.sandbox_id=b.sandbox_id and a.curr_version=b.curr_version where 1=1 AND a.is_delete = 0 "
  52. sql += condition
  53. sql += ` order by a.modify_time desc,a.sandbox_id desc`
  54. totalSql := `select count(1) total from (` + sql + `) z `
  55. err = o.Raw(totalSql, pars).QueryRow(&total)
  56. if err != nil {
  57. return
  58. }
  59. sql += ` LIMIT ?,? `
  60. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  61. return
  62. }