base_from_business.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. // BaseFromBusinessIndex
  10. // @Description: 外部指标(商家系统)表
  11. type BaseFromBusinessIndex struct {
  12. BaseFromBusinessIndexId int64 `orm:"column(base_from_business_index_id);pk"`
  13. IndexCode string `description:"指标编码"`
  14. IndexName string `description:"指标名称"`
  15. Unit string `description:"单位"`
  16. Frequency string `description:"频度"`
  17. Source int `description:"数据来源"`
  18. SourceName string `description:"数据来源名称"`
  19. StartDate time.Time `description:"开始日期"`
  20. EndDate time.Time `description:"结束日期"`
  21. Remark string `description:"备注字段"`
  22. BaseModifyTime time.Time `description:"基础信息(名称,单位,频度)变更时间"`
  23. DataUpdateTime time.Time `description:"最近一次数据发生变化的时间"`
  24. CreateTime time.Time `description:"创建时间"`
  25. ModifyTime time.Time `description:"修改时间"`
  26. }
  27. // BaseFromBusinessIndexItem
  28. // @Description: 外部指标结构
  29. type BaseFromBusinessIndexItem struct {
  30. IndexCode string `description:"指标编码"`
  31. IndexName string `description:"指标名称"`
  32. Unit string `description:"单位"`
  33. Frequency string `description:"频度"`
  34. SourceName string `description:"数据来源名称"`
  35. }
  36. // BaseFromBusinessIndexResp 联合国商品贸易列表数据返回
  37. type BaseFromBusinessIndexResp struct {
  38. Paging *paging.PagingItem
  39. List []*BaseFromBusinessIndexItem
  40. LastUpdateTime string
  41. }
  42. func (m *BaseFromBusinessIndex) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (total int, items []*BaseFromBusinessIndexItem, err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. fields := strings.Join(fieldArr, ",")
  45. if len(fieldArr) == 0 {
  46. fields = `*`
  47. }
  48. // 获取总数
  49. sql := fmt.Sprintf(`SELECT count(1) FROM base_from_business_index WHERE 1=1 %s `, cond)
  50. err = o.Raw(sql, pars).QueryRow(&total)
  51. if err != nil {
  52. return
  53. }
  54. // 排序字段
  55. order := `ORDER BY create_time DESC`
  56. if orderRule != "" {
  57. order = ` ORDER BY ` + orderRule
  58. }
  59. sql = fmt.Sprintf(`SELECT %s FROM base_from_business_index WHERE 1=1 %s %s limit ?,?`, fields, cond, order)
  60. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  61. return
  62. }