base_from_usda_fas.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type BaseFromUsdaFasIndex struct {
  8. BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"`
  9. ClassifyId int
  10. IndexCode string
  11. IndexName string
  12. Frequency string
  13. Unit string
  14. Sort int
  15. StartDate string `description:"开始日期"`
  16. EndDate string `description:"结束日期"`
  17. EndValue float64
  18. Country string `description:"国家"`
  19. Commodity string `description:"属性"`
  20. CreateTime time.Time
  21. ModifyTime time.Time
  22. }
  23. // BaseFromUsdaFasClassify UsdaFas原始数据分类表
  24. type BaseFromUsdaFasClassify struct {
  25. ClassifyId int `orm:"column(classify_id);pk"`
  26. ClassifyName string `description:"分类名称"`
  27. ParentId int `description:"父级id"`
  28. SysUserId int `description:"创建人id"`
  29. SysUserRealName string `description:"创建人姓名"`
  30. Level int `description:"层级"`
  31. Sort int `description:"排序字段,越小越靠前,默认值:10"`
  32. ModifyTime time.Time `description:"修改时间"`
  33. CreateTime time.Time `description:"创建时间"`
  34. }
  35. func GetBaseFromUsdaFasIndexMaxDate() (max_date time.Time, err error) {
  36. o := orm.NewOrm()
  37. sql := ` SELECT max(a.modify_time)as max_date FROM base_from_usda_fas_data as a `
  38. err = o.Raw(sql).QueryRow(&max_date)
  39. return
  40. }
  41. type UsdaFasIndexResp struct {
  42. Ret int
  43. Msg string
  44. ErrMsg string
  45. ErrCode string
  46. Data []*BaseFromUsdaFasIndex
  47. }
  48. func GetBaseFromUsdaFasIndexAll(dateStr string) (list []*BaseFromUsdaFasIndex, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT * FROM base_from_usda_fas_index WHERE end_date>=?`
  51. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  52. return
  53. }
  54. func (obj *BaseFromUsdaFasIndex) AddBaseFromUsdaFasIndex(item *BaseFromUsdaFasIndex) (lastId int64, err error) {
  55. o := orm.NewOrm()
  56. lastId, err = o.Insert(item)
  57. return
  58. }
  59. func (obj *BaseFromUsdaFasIndex) InsertOrUpdateBaseFromUsdaFasIndex(item *BaseFromUsdaFasIndex) (lastId int64, err error) {
  60. o := orm.NewOrm()
  61. lastId, err = o.InsertOrUpdate(item)
  62. return
  63. }
  64. type UsdaFasClassifyResp struct {
  65. Ret int
  66. Msg string
  67. ErrMsg string
  68. ErrCode string
  69. Data []*BaseFromUsdaFasClassify
  70. }
  71. func GetBaseFromUsdaFasClassifyAll() (list []*BaseFromUsdaFasClassify, err error) {
  72. o := orm.NewOrm()
  73. sql := `SELECT * FROM base_from_usda_fas_classify `
  74. _, err = o.Raw(sql).QueryRows(&list)
  75. return
  76. }
  77. func AddBaseFromUsdaFasClassify(item *BaseFromUsdaFasClassify) (lastId int64, err error) {
  78. o := orm.NewOrm()
  79. lastId, err = o.Insert(item)
  80. return
  81. }
  82. func InsertOrUpdateBaseFromUsdaFasClassify(item *BaseFromUsdaFasClassify) (lastId int64, err error) {
  83. o := orm.NewOrm()
  84. lastId, err = o.InsertOrUpdate(item)
  85. return
  86. }
  87. // GetBaseFromComTradeMaxDate 获取UsdaFas消费者指数最大数据
  88. func GetBaseFromUsdaFasMaxDate() (max_date time.Time, err error) {
  89. o := orm.NewOrm()
  90. sql := ` SELECT max(a.modify_time)as max_date FROM base_from_usda_fas_data as a `
  91. err = o.Raw(sql).QueryRow(&max_date)
  92. return
  93. }
  94. type BaseFromUsdaFasData struct {
  95. BaseFromUsdaFasDataId int `orm:"column(base_from_usda_fas_data_id);pk"`
  96. BaseFromUsdaFasIndexId int `description:"指标id"`
  97. IndexCode string `description:"指标编码"`
  98. DataTime string `description:"日期"`
  99. Value string `description:"值"`
  100. CreateTime time.Time `description:"创建时间"`
  101. ModifyTime time.Time `description:"修改时间"`
  102. }
  103. // GetAllComTradeDataList 获取UsdaFas消费者指数数据
  104. func GetAllBaseFromUsdaFasDataList(startDate string) (list []*BaseFromUsdaFasData, err error) {
  105. o := orm.NewOrm()
  106. sql := `SELECT * FROM base_from_usda_fas_data WHERE modify_time>=? ORDER BY base_from_usda_fas_data_id ASC `
  107. _, err = o.Raw(sql, startDate).QueryRows(&list)
  108. return
  109. }
  110. type BaseFromUsdaFasDataResp struct {
  111. Ret int
  112. Msg string
  113. ErrMsg string
  114. ErrCode string
  115. Data BaseFromUsdaFasDataIndexAndDataResp
  116. }
  117. // ComTradeIndexDataResp 分页列表响应体
  118. type BaseFromUsdaFasDataIndexAndDataResp struct {
  119. List []*BaseFromUsdaFasData
  120. Paging *paging.PagingItem `description:"分页数据"`
  121. }
  122. // MultiAddBaseFromComTradeData 批量添加数据
  123. func MultiAddBaseFromUsdaFasDataIndex(items []*BaseFromUsdaFasData) (lastId int64, err error) {
  124. num := len(items)
  125. if num <= 0 {
  126. return
  127. }
  128. o := orm.NewOrm()
  129. lastId, err = o.InsertMulti(num, items)
  130. return
  131. }