sandbox_version.go 6.5 KB

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