base_from_icpi.go 5.1 KB

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