package data_stat import ( "eta_gn/eta_index_lib/global" "github.com/beego/beego/v2/client/orm" "time" ) // EdbSourceStat 数据源统计表 type EdbSourceStat struct { Id int `gorm:"primaryKey;autoIncrement;column:id" description:"ID"` SourceName string `gorm:"column:source_name" description:"来源名称"` Source int `gorm:"column:source" description:"来源id"` TerminalCode string `gorm:"column:terminal_code" description:"终端编码,用于配置在机器上"` EdbNum int `gorm:"column:edb_num" description:"指标总数"` EdbNewNum int `gorm:"column:edb_new_num" description:"今日新增指标数"` EdbDelNum int `gorm:"column:edb_del_num" description:"今日删除指标数"` NeedRefreshNum int `gorm:"column:need_refresh_num" description:"今日需刷新指标"` HasRefreshNum int `gorm:"column:has_refresh_num" description:"今日发起刷新任务指标数"` UpdateSuccessNum int `gorm:"column:update_success_num" description:"今日已更新成功指标数"` UpdateFailedNum int `gorm:"column:update_failed_num" description:"今日已更新失败指标数"` RefreshSuccessNum int `gorm:"column:refresh_success_num" description:"今日已刷新成功指标数"` RefreshFailedNum int `gorm:"column:refresh_failed_num" description:"今日已刷新失败指标数"` CreateTime time.Time `gorm:"column:create_time" description:"创建时间"` ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"` } func GetEdbSourceStatByCondition(condition string, pars []interface{}) (item []*EdbSourceStat, err error) { sql := ` SELECT * FROM edb_source_stat WHERE 1=1 ` if condition != "" { sql += condition } err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&item).Error return } // Add 新增 func (r *EdbSourceStat) Add(list []*EdbSourceStat) (err error) { o := orm.NewOrm() _, err = o.InsertMulti(len(list), list) return } // UpdateEdbSourceStatMulti 批量更新 func UpdateEdbSourceStatMulti(list []*EdbSourceStat) (err error) { o := orm.NewOrm() sql := `UPDATE edb_source_stat SET edb_num=?, edb_new_num=?, edb_del_num=?, need_refresh_num=?, has_refresh_num=?, update_success_num=?, update_failed_num=?, refresh_success_num=?, refresh_failed_num=?, modify_time=? WHERE id = ?` p, err := o.Raw(sql).Prepare() if err != nil { return } defer func() { _ = p.Close() // 别忘记关闭 statement }() for _, v := range list { _, err = p.Exec(v.EdbNum, v.EdbNewNum, v.EdbDelNum, v.NeedRefreshNum, v.HasRefreshNum, v.UpdateSuccessNum, v.UpdateFailedNum, v.RefreshSuccessNum, v.RefreshFailedNum, v.ModifyTime, v.Id) if err != nil { return } } return }