sandbox_version.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package sandbox
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. // SandboxVersion 沙盘推演版本表
  8. type SandboxVersion struct {
  9. SandboxVersionId int `orm:"column(sandbox_version_id);pk" description:"沙盘版本记录id"`
  10. SandboxId int `description:"沙盘id"`
  11. Name string `description:"沙盘名称"`
  12. ChartPermissionId int `description:"品种id"`
  13. ChartPermissionName string `description:"品种名称"`
  14. CurrVersion int `description:"当前版本"`
  15. Content string `description:"沙盘数据"`
  16. SvgData string `description:"沙盘svg图片数据"`
  17. PicUrl string `description:"沙盘图片地址"`
  18. OpUserId int `description:"最近一次编辑操作的用户id"`
  19. OpUserName string `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
  20. VersionCode string `description:"沙盘版本code,对外开放使用"`
  21. IsDelete int8 `description:"是否删除,0:未删除,1:已删除"`
  22. CreateTime time.Time `description:"创建时间"`
  23. }
  24. // Update 沙盘版本字段变更
  25. func (item *SandboxVersion) Update(cols []string) (err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. _, err = o.Update(item, cols...)
  28. return
  29. }
  30. // GetSandboxVersionBySandbox2VersionId 根据沙盘id和版本id获取沙盘版本详情
  31. func GetSandboxVersionBySandbox2VersionId(sandboxId, sandboxVersion int) (sandboxVersionInfo *SandboxVersion, err error) {
  32. o := orm.NewOrmUsingDB("data")
  33. sql := `select b.* from sandbox a join sandbox_version b on a.sandbox_id=b.sandbox_id where a.sandbox_id = ? and a.is_delete = 0 and b.is_delete = 0 and b.curr_version = ?`
  34. err = o.Raw(sql, sandboxId, sandboxVersion).QueryRow(&sandboxVersionInfo)
  35. return
  36. }
  37. // GetSandboxVersionBySandboxVersionCode 根据沙盘版本code获取沙盘版本详情
  38. func GetSandboxVersionBySandboxVersionCode(sandboxVersionCode string) (sandboxVersionInfo *SandboxVersion, err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. sql := `select b.* from sandbox a join sandbox_version b on a.sandbox_id=b.sandbox_id where a.is_delete = 0 and b.is_delete = 0 and b.version_code = ?`
  41. err = o.Raw(sql, sandboxVersionCode).QueryRow(&sandboxVersionInfo)
  42. return
  43. }
  44. // GetLastSandboxVersionBySandbox2VersionId 根据沙盘id和版本id获取距离最新的沙盘版本详情
  45. func GetLastSandboxVersionBySandbox2VersionId(sandboxId, sandboxVersion int) (sandboxVersionInfo *SandboxVersion, err error) {
  46. o := orm.NewOrmUsingDB("data")
  47. sql := `select b.* from sandbox a join sandbox_version b on a.sandbox_id=b.sandbox_id where a.sandbox_id = ? and a.is_delete = 0 and b.is_delete = 0 and b.curr_version < ? order by b.curr_version desc`
  48. err = o.Raw(sql, sandboxId, sandboxVersion).QueryRow(&sandboxVersionInfo)
  49. return
  50. }
  51. // SandboxVersionListItem 沙盘推演版本列表数据
  52. type SandboxVersionListItem struct {
  53. SandboxVersionId int `orm:"column(sandbox_version_id);pk" description:"沙盘版本记录id"`
  54. SandboxId int `description:"沙盘id"`
  55. Name string `description:"沙盘名称"`
  56. ChartPermissionId int `description:"品种id"`
  57. ChartPermissionName string `description:"品种名称"`
  58. CurrVersion int `description:"当前版本"`
  59. //Content string `description:"沙盘数据"`
  60. PicUrl string `description:"沙盘图片地址"`
  61. OpUserId int `description:"最近一次编辑操作的用户id"`
  62. OpUserName string `description:"最近一次编辑的用户名称(冗余字段,避免查表)"`
  63. VersionCode string `description:"沙盘版本code,对外开放使用"`
  64. IsDelete int8 `description:"是否删除,0:未删除,1:已删除" json:"-"`
  65. CanEdit bool `description:"是否可编辑"`
  66. ModifyTime time.Time `description:"最后一次修改时间"`
  67. CreateTime time.Time `description:"创建时间"`
  68. }
  69. // GetVersionList 获取沙盘版本列表页
  70. func GetVersionList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*SandboxVersionListItem, err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. sql := "select b.sandbox_version_id,b.sandbox_id,b.name,b.chart_permission_id,b.chart_permission_name,b.curr_version,b.version_code,b.pic_url,b.op_user_id,b.op_user_name,b.create_time from sandbox as a join sandbox_version b on a.sandbox_id=b.sandbox_id where 1=1 AND a.is_delete = 0 AND b.is_delete = 0 "
  73. sql += condition
  74. sql += ` order by b.sandbox_version_id desc`
  75. totalSql := `select count(1) total from (` + sql + `) z `
  76. err = o.Raw(totalSql, pars).QueryRow(&total)
  77. if err != nil {
  78. return
  79. }
  80. sql += ` LIMIT ?,? `
  81. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  82. return
  83. }
  84. // GetTotalSandboxVersionBySandboxId 根据沙盘id获取沙盘版本数量
  85. func GetTotalSandboxVersionBySandboxId(sandboxId int) (sandboxVersionInfo *SandboxVersion, err error) {
  86. o := orm.NewOrmUsingDB("data")
  87. sql := `select count(1) total from sandbox_version b where b.sandbox_id = ? and b.is_delete = 0 `
  88. err = o.Raw(sql, sandboxId).QueryRow(&sandboxVersionInfo)
  89. return
  90. }
  91. type TotalSandboxVersion struct {
  92. SandboxId int `description:"沙盘id"`
  93. Total int `description:"沙盘版本数量"`
  94. }
  95. // GetTotalSandboxVersionBySandboxIdList 根据沙盘id获取沙盘版本数量
  96. func GetTotalSandboxVersionBySandboxIdList(sandboxIdList []int) (items []*TotalSandboxVersion, err error) {
  97. num := len(sandboxIdList)
  98. if num <= 0 {
  99. return
  100. }
  101. o := orm.NewOrmUsingDB("data")
  102. sql := `select sandbox_id,count(1) AS total from sandbox_version b where b.sandbox_id in (` + utils.GetOrmInReplace(num) + `) and b.is_delete = 0 GROUP BY sandbox_id`
  103. _, err = o.Raw(sql, sandboxIdList).QueryRows(&items)
  104. return
  105. }