package data_manage import ( "fmt" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "strings" "time" ) // BaseFromBusinessIndex // @Description: 外部指标(商家系统)表 type BaseFromBusinessIndex struct { BaseFromBusinessIndexId int64 `orm:"column(base_from_business_index_id);pk"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` Source int `description:"数据来源"` SourceName string `description:"数据来源名称"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` Remark string `description:"备注字段"` BaseModifyTime time.Time `description:"基础信息(名称,单位,频度)变更时间"` DataUpdateTime time.Time `description:"最近一次数据发生变化的时间"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } // BaseFromBusinessIndexItem // @Description: 外部指标结构 type BaseFromBusinessIndexItem struct { IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` SourceName string `description:"数据来源名称"` } // BaseFromBusinessIndexResp 联合国商品贸易列表数据返回 type BaseFromBusinessIndexResp struct { Paging *paging.PagingItem List []*BaseFromBusinessIndexItem LastUpdateTime string } func (m *BaseFromBusinessIndex) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (total int, items []*BaseFromBusinessIndexItem, err error) { o := orm.NewOrmUsingDB("data") fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } // 获取总数 sql := fmt.Sprintf(`SELECT count(1) FROM base_from_business_index WHERE 1=1 %s `, cond) err = o.Raw(sql, pars).QueryRow(&total) if err != nil { return } // 排序字段 order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql = fmt.Sprintf(`SELECT %s FROM base_from_business_index WHERE 1=1 %s %s limit ?,?`, fields, cond, order) _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return }