base_from_icpi.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 BaseFromIcpiIndex struct {
  8. BaseFromIcpiIndexId int `orm:"column(base_from_icpi_index_id);pk"`
  9. BaseFromIcpiClassifyId int `description:"分类id"`
  10. IndexCode string `description:"指标编码"`
  11. IndexName string `description:"指标名称"`
  12. Frequency string `description:"频度"`
  13. StartDate time.Time `description:"开始日期"`
  14. EndDate time.Time `description:"结束日期"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. LatestValue float64 `description:"最新值"`
  18. }
  19. func GetBaseFromIcpiIndexMaxDate() (max_date time.Time, err error) {
  20. o := orm.NewOrm()
  21. sql := ` SELECT max(a.data_time)as max_date FROM base_from_icpi_data as a `
  22. err = o.Raw(sql).QueryRow(&max_date)
  23. return
  24. }
  25. type IcpiIndexResp struct {
  26. Ret int
  27. Msg string
  28. ErrMsg string
  29. ErrCode string
  30. Data []*BaseFromIcpiIndex
  31. }
  32. func GetBaseFromIcpiIndexAll(dateStr string) (list []*BaseFromIcpiIndex, err error) {
  33. o := orm.NewOrm()
  34. sql := `SELECT * FROM base_from_icpi_index WHERE end_date>=?`
  35. _, err = o.Raw(sql, dateStr).QueryRows(&list)
  36. return
  37. }
  38. func (obj *BaseFromIcpiIndex) AddBaseFromIcpiIndex(item *BaseFromIcpiIndex) (lastId int64, err error) {
  39. o := orm.NewOrm()
  40. lastId, err = o.Insert(item)
  41. return
  42. }
  43. func (obj *BaseFromIcpiIndex) InsertOrUpdateBaseFromIcpiIndex(item *BaseFromIcpiIndex) (lastId int64, err error) {
  44. o := orm.NewOrm()
  45. lastId, err = o.InsertOrUpdate(item)
  46. return
  47. }
  48. type BaseFromIcpiClassify struct {
  49. BaseFromIcpiClassifyId int `orm:"column(base_from_icpi_classify_id);pk"`
  50. ClassifyName string `description:"分类名称"`
  51. ClassifyNameEn string `description:"英文名称"`
  52. ParentId int `description:"上级id"`
  53. CreateTime string `description:"创建时间"`
  54. ModifyTime string `description:"修改时间"`
  55. }
  56. type IcpiClassifyResp struct {
  57. Ret int
  58. Msg string
  59. ErrMsg string
  60. ErrCode string
  61. Data []*BaseFromIcpiClassify
  62. }
  63. func GetBaseFromIcpiClassifyAll() (list []*BaseFromIcpiClassify, err error) {
  64. o := orm.NewOrm()
  65. sql := `SELECT * FROM base_from_icpi_classify `
  66. _, err = o.Raw(sql).QueryRows(&list)
  67. return
  68. }
  69. func AddBaseFromIcpiClassify(item *BaseFromIcpiClassify) (lastId int64, err error) {
  70. o := orm.NewOrm()
  71. lastId, err = o.Insert(item)
  72. return
  73. }
  74. func InsertOrUpdateBaseFromIcpiClassify(item *BaseFromIcpiClassify) (lastId int64, err error) {
  75. o := orm.NewOrm()
  76. lastId, err = o.InsertOrUpdate(item)
  77. return
  78. }
  79. // GetBaseFromComTradeMaxDate 获取ICPI消费者指数最大数据
  80. func GetBaseFromIcpiMaxDate() (max_date time.Time, err error) {
  81. o := orm.NewOrm()
  82. sql := ` SELECT max(a.create_time)as max_date FROM base_from_icpi_data as a `
  83. err = o.Raw(sql).QueryRow(&max_date)
  84. return
  85. }
  86. type BaseFromIcpiData struct {
  87. BaseFromIcpiDataId int `orm:"column(base_from_icpi_data_id);pk"`
  88. BaseFromIcpiIndexId int `description:"指标id"`
  89. IndexCode string `description:"指标编码"`
  90. DataTime string `description:"日期"`
  91. Value string `description:"值"`
  92. CreateTime time.Time `description:"创建时间"`
  93. ModifyTime time.Time `description:"修改时间"`
  94. }
  95. // GetAllComTradeDataList 获取ICPI消费者指数数据
  96. func GetAllBaseFromIcpiDataList(startDate string) (list []*BaseFromIcpiData, err error) {
  97. o := orm.NewOrm()
  98. sql := `SELECT * FROM base_from_icpi_data WHERE create_time>=? ORDER BY base_from_icpi_data_id ASC `
  99. _, err = o.Raw(sql, startDate).QueryRows(&list)
  100. return
  101. }
  102. type BaseFromIcpiDataResp struct {
  103. Ret int
  104. Msg string
  105. ErrMsg string
  106. ErrCode string
  107. Data BaseFromIcpiDataIndexAndDataResp
  108. }
  109. // ComTradeIndexDataResp 分页列表响应体
  110. type BaseFromIcpiDataIndexAndDataResp struct {
  111. List []*BaseFromIcpiData
  112. Paging *paging.PagingItem `description:"分页数据"`
  113. }
  114. // MultiAddBaseFromComTradeData 批量添加数据
  115. func MultiAddBaseFromIcpiDataIndex(items []*BaseFromIcpiData) (lastId int64, err error) {
  116. num := len(items)
  117. if num <= 0 {
  118. return
  119. }
  120. o := orm.NewOrm()
  121. lastId, err = o.InsertMulti(num, items)
  122. return
  123. }