sandbox_version.go 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package sandbox
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. type SandboxVersion struct {
  7. SandboxVersionId int `gorm:"primaryKey;column:sandbox_version_id;type:int(9) unsigned;not null"` // 沙盘版本记录id
  8. SandboxId int `gorm:"index:idx_sandbox_version_id;column:sandbox_id;type:int(9) unsigned;not null;default:0"` // 沙盘id
  9. Name string `gorm:"index:idx_name;column:name;type:varchar(64);not null;default:''"` // 沙盘名称
  10. ChartPermissionId int `gorm:"column:chart_permission_id;type:int(9) unsigned;not null;default:0"` // 品种id
  11. ChartPermissionName string `gorm:"index:idx_chart_permission_name;column:chart_permission_name;type:varchar(32);not null;default:''"` // 品种名称(冗余字段,避免列表页查询时再去关联表查询)
  12. CurrVersion int `gorm:"index:idx_sandbox_version_id;column:curr_version;type:int(9) unsigned;not null;default:0"` // 当前版本
  13. VersionCode string `gorm:"index:idx_version_code;column:version_code;type:varchar(255);default:''"` // 沙盘版本code,对外开放使用
  14. Content string `gorm:"column:content;type:text"` // 沙盘数据
  15. PicURL string `gorm:"column:pic_url;type:varchar(255);not null;default:''"` // 沙盘图片
  16. SvgData string `gorm:"column:svg_data;type:text;not null"` // svg信息,便于前端构建图片
  17. OpUserId int `gorm:"column:op_user_id;type:int(10) unsigned;not null;default:0"` // 当前版本编辑操作的用户id
  18. OpUserName string `gorm:"index:idx_op_user_name;column:op_user_name;type:varchar(32);not null;default:''"` // 当前版本编辑的用户名称(冗余字段,避免查表)
  19. IsDelete int8 `gorm:"column:is_delete;type:tinyint(9);not null;default:0"` // 是否删除,0:未删除,1:已删除
  20. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP"` // 沙盘创建时间
  21. }
  22. func (item *SandboxVersion) Update(cols []string) (err error) {
  23. err = global.DmSQL["data"].Select(cols).Updates(item).Error
  24. return
  25. }
  26. func GetSandboxVersionBySandboxVersionCode(sandboxVersionCode string) (sandboxVersionInfo *SandboxVersion, err error) {
  27. 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 = ?`
  28. err = global.DmSQL["data"].Raw(sql, sandboxVersionCode).First(&sandboxVersionInfo).Error
  29. return
  30. }
  31. type SandboxVersionListItem struct {
  32. SandboxVersionId int `gorm:"primaryKey;column:sandbox_version_id;type:int(9) unsigned;not null"` // 沙盘版本记录id
  33. SandboxId int `gorm:"index:idx_sandbox_version_id;column:sandbox_id;type:int(9) unsigned;not null;default:0"` // 沙盘id
  34. Name string `gorm:"index:idx_name;column:name;type:varchar(64);not null;default:''"` // 沙盘名称
  35. ChartPermissionId int `gorm:"column:chart_permission_id;type:int(9) unsigned;not null;default:0"` // 品种id
  36. ChartPermissionName string `gorm:"index:idx_chart_permission_name;column:chart_permission_name;type:varchar(32);not null;default:''"` // 品种名称(冗余字段,避免列表页查询时再去关联表查询)
  37. CurrVersion int `gorm:"index:idx_sandbox_version_id;column:curr_version;type:int(9) unsigned;not null;default:0"` // 当前版本
  38. VersionCode string `gorm:"index:idx_version_code;column:version_code;type:varchar(255);default:''"` // 沙盘版本code,对外开放使用
  39. PicURL string `gorm:"column:pic_url;type:varchar(255);not null;default:''"` // 沙盘图片
  40. SvgData string `gorm:"column:svg_data;type:text;not null"` // svg信息,便于前端构建图片
  41. OpUserId int `gorm:"column:op_user_id;type:int(10) unsigned;not null;default:0"` // 当前版本编辑操作的用户id
  42. OpUserName string `gorm:"index:idx_op_user_name;column:op_user_name;type:varchar(32);not null;default:''"` // 当前版本编辑的用户名称(冗余字段,避免查表)
  43. IsDelete int8 `gorm:"column:is_delete;type:tinyint(9);not null;default:0"` // 是否删除,0:未删除,1:已删除
  44. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP"` // 沙盘创建时间
  45. ModifyTime time.Time `gorm:"-" description:"最后一次修改时间"`
  46. CanEdit bool `gorm:"-" description:"是否可编辑"`
  47. }
  48. func GetVersionList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*SandboxVersionListItem, err error) {
  49. 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 "
  50. sql += condition
  51. sql += ` order by b.sandbox_version_id desc`
  52. totalSql := `select count(1) total from (` + sql + `) z `
  53. err = global.DmSQL["data"].Raw(totalSql, pars...).Scan(&total).Error
  54. if err != nil {
  55. return
  56. }
  57. sql += ` LIMIT ?,? `
  58. pars = append(pars, startSize)
  59. pars = append(pars, pageSize)
  60. err = global.DmSQL["data"].Raw(sql, pars...).Find(&list).Error
  61. return
  62. }
  63. type TotalSandboxVersion struct {
  64. SandboxId int `description:"沙盘id"`
  65. Total int `description:"沙盘版本数量"`
  66. }