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