base_from_icpi.go 4.2 KB

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