base_from_business.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. StartDate time.Time `description:"开始日期" json:"StartDate,omitempty"`
  36. EndDate time.Time `description:"结束日期" json:"EndDate,omitempty"`
  37. CreateTime time.Time `description:"创建时间" json:"CreateTime,omitempty"`
  38. }
  39. // BaseFromBusinessIndexResp 联合国商品贸易列表数据返回
  40. type BaseFromBusinessIndexResp struct {
  41. Paging *paging.PagingItem
  42. List []*BaseFromBusinessIndexItem
  43. LastUpdateTime string
  44. }
  45. // BaseFromBusinessIndexDataItem
  46. // @Description: 外部指标(商家系统)数据结构
  47. type BaseFromBusinessIndexDataItem struct {
  48. ID string
  49. EdbDataId int `orm:"column(edb_data_id);pk"`
  50. IndexCode string
  51. DataTime string
  52. Value float64
  53. }
  54. func (m *BaseFromBusinessIndex) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (total int, items []*BaseFromBusinessIndexItem, err error) {
  55. o := orm.NewOrmUsingDB("data")
  56. fields := strings.Join(fieldArr, ",")
  57. if len(fieldArr) == 0 {
  58. fields = `*`
  59. }
  60. // 获取总数
  61. sql := fmt.Sprintf(`SELECT count(1) FROM base_from_business_index WHERE 1=1 %s `, cond)
  62. err = o.Raw(sql, pars).QueryRow(&total)
  63. if err != nil {
  64. return
  65. }
  66. // 排序字段
  67. order := `ORDER BY create_time DESC`
  68. if orderRule != "" {
  69. order = ` ORDER BY ` + orderRule
  70. }
  71. sql = fmt.Sprintf(`SELECT %s FROM base_from_business_index WHERE 1=1 %s %s limit ?,?`, fields, cond, order)
  72. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  73. return
  74. }
  75. type BusinessIndexDataListResp struct {
  76. List []*BaseFromBusinessIndexDataItem
  77. Paging *paging.PagingItem `description:"分页数据"`
  78. }