package data_stat import "github.com/beego/beego/v2/client/orm" // EdbInfoStatColumn 数据源统计表自定义列 type EdbInfoStatColumn struct { Id int `orm:"column(id);pk" description:"自增id"` ColumnName string `description:"字段名称"` ColumnKey string `description:"字段"` CreateTime string `description:" 创建时间"` ModifyTime string `description:"修改时间"` Type int `description:"列表类型:1数据源明细表,2数据源统计表,3删除指标列表,4指标信息变更表"` Sort int `description:"列排序"` IsMust int `description:"是否必选列: 0非必选 1必须"` IsSort int `description:"是否是允许排序的列,0否,1是"` IsShow int `description:"是否展示:1展示,0不展示"` ColumnNameEn string `description:"英文字段名称"` } type EdbInfoStatColumnListItem struct { Id int `description:"自增id"` ColumnName string `description:"字段名称"` ColumnKey string `description:"字段"` Type int `description:"列表类型:1数据源明细表,2数据源统计表,3删除指标列表,4指标信息变更表"` IsMust int `description:"是否必选列: 0非必选 1必须"` IsSort int `description:"是否是允许排序的列,0否,1是"` IsShow int `description:"是否展示:1展示,0不展示"` ColumnNameEn string `description:"英文字段名称"` } type StatColumnList struct { List []*EdbInfoStatColumnListItem } type EditStatColumnReq struct { List []*EdbInfoStatColumnListReq } type EdbInfoStatColumnListReq struct { Id int `description:"自增id"` IsShow int `description:"是否展示:1展示,0不展示"` } // GetStatColumn 获取自定义列 func GetStatColumn(columnType int) (list []EdbInfoStatColumn, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM edb_info_stat_column WHERE type=? ORDER BY sort asc, id asc ` _, err = o.Raw(sql, columnType).QueryRows(&list) return } // GetAllStatColumn 获取所有自定义列 func GetAllStatColumn() (list []EdbInfoStatColumn, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM edb_info_stat_column ORDER BY sort asc, id asc ` _, err = o.Raw(sql).QueryRows(&list) return } // UpdateStatColumn 批量更新自定义列 func UpdateStatColumn(list []*EdbInfoStatColumn) (err error) { o := orm.NewOrmUsingDB("data") p, err := o.Raw("UPDATE edb_info_stat_column SET is_show = ?, sort=? WHERE id = ?").Prepare() if err != nil { return } defer func() { _ = p.Close() // 别忘记关闭 statement }() for _, v := range list { _, err = p.Exec(v.IsShow, v.Sort, v.Id) if err != nil { return } } return }