icpi.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package data_source
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "gorm.io/gorm"
  7. "time"
  8. )
  9. type BaseFromIcpiIndex struct {
  10. BaseFromIcpiIndexId int `orm:"column(base_from_icpi_index_id);pk" gorm:"primaryKey"`
  11. BaseFromIcpiClassifyId int `description:"分类id"`
  12. IndexCode string `description:"指标编码"`
  13. IndexName string `description:"指标名称"`
  14. Frequency string `description:"频度"`
  15. StartDate time.Time `description:"开始日期"`
  16. EndDate time.Time `description:"结束日期"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. Unit string `description:"单位"`
  20. LatestValue float64 `description:"最新值"`
  21. }
  22. type BaseFromIcpiData struct {
  23. BaseFromIcpiDataId int `orm:"column(base_from_icpi_data_id);pk" gorm:"primaryKey"`
  24. BaseFromIcpiIndexId int `description:"指标id"`
  25. IndexCode string `description:"指标编码"`
  26. DataTime string `description:"日期"`
  27. Value string `description:"值"`
  28. CreateTime time.Time `description:"创建时间"`
  29. ModifyTime time.Time `description:"修改时间"`
  30. }
  31. type BaseFromIcpiClassify struct {
  32. BaseFromIcpiClassifyId int `orm:"column(base_from_icpi_classify_id);pk" gorm:"primaryKey"`
  33. ClassifyName string `description:"分类名称"`
  34. ClassifyNameEn string `description:"英文名称"`
  35. ParentId int `description:"上级id"`
  36. CreateTime string `description:"创建时间"`
  37. ModifyTime string `description:"修改时间"`
  38. }
  39. func (obj *BaseFromIcpiIndex) GetBaseFromIcpiClassifyAll() (list []*BaseFromIcpiClassify, err error) {
  40. o := global.DbMap[utils.DbNameIndex]
  41. sql := `SELECT * FROM base_from_icpi_classify `
  42. err = o.Raw(sql).Find(&list).Error
  43. return
  44. }
  45. type BaseFromIcpiDataView struct {
  46. BaseFromIcpiDataId int `orm:"column(base_from_icpi_data_id);pk" gorm:"primaryKey"`
  47. BaseFromIcpiIndexId int `description:"指标id"`
  48. IndexCode string `description:"指标编码"`
  49. DataTime string `description:"日期"`
  50. Value string `description:"值"`
  51. CreateTime time.Time `description:"创建时间"`
  52. ModifyTime time.Time `description:"修改时间"`
  53. }
  54. func (obj *BaseFromIcpiDataView) AfterFind(tx *gorm.DB) (err error) {
  55. obj.DataTime = utils.GormDateStrToDateStr(obj.DataTime)
  56. return
  57. }
  58. type BaseFromIcpiIndexView struct {
  59. BaseFromIcpiIndexId int `description:"指标id"`
  60. BaseFromIcpiClassifyId int `description:"分类id"`
  61. IndexCode string `description:"指标编码"`
  62. IndexName string `description:"指标名称"`
  63. Frequency string `description:"频度"`
  64. Unit string `description:"单位"`
  65. StartDate string `description:"开始日期"`
  66. EndDate string `description:"结束日期"`
  67. CreateTime string `description:"创建时间"`
  68. ModifyTime string `description:"修改时间"`
  69. DataList []*BaseFromIcpiDataView `gorm:"-"`
  70. Paging *paging.PagingItem `description:"分页数据" gorm:"-"`
  71. }
  72. func (obj *BaseFromIcpiIndexView) AfterFind(tx *gorm.DB) (err error) {
  73. obj.CreateTime = utils.GormDateStrToDateTimeStr(obj.CreateTime)
  74. obj.ModifyTime = utils.GormDateStrToDateTimeStr(obj.ModifyTime)
  75. obj.StartDate = utils.GormDateStrToDateStr(obj.StartDate)
  76. obj.EndDate = utils.GormDateStrToDateStr(obj.EndDate)
  77. return
  78. }
  79. func (obj *BaseFromIcpiIndex) GetIcpiIndex(condition string, pars []interface{}) (items []*BaseFromIcpiIndexView, err error) {
  80. o := global.DbMap[utils.DbNameIndex]
  81. sql := ` SELECT * FROM base_from_icpi_index WHERE 1=1 `
  82. if condition != "" {
  83. sql += condition
  84. }
  85. sql += `ORDER BY base_from_icpi_index_id ASC `
  86. err = o.Raw(sql, pars...).Find(&items).Error
  87. return
  88. }
  89. func (obj *BaseFromIcpiIndex) GetIcpiIndexDataCount(indexCode string) (count int, err error) {
  90. o := global.DbMap[utils.DbNameIndex]
  91. sql := ` SELECT COUNT(1) AS count FROM base_from_icpi_data WHERE index_code=? `
  92. err = o.Raw(sql, indexCode).Scan(&count).Error
  93. return
  94. }
  95. func (obj *BaseFromIcpiIndex) GetIcpiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromIcpiDataView, err error) {
  96. o := global.DbMap[utils.DbNameIndex]
  97. sql := ` SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  98. err = o.Raw(sql, indexCode, startSize, pageSize).Find(&items).Error
  99. return
  100. }
  101. func (obj *BaseFromIcpiIndex) GetIcpiDataMaxCount(classifyId int) (count int, err error) {
  102. o := global.DbMap[utils.DbNameIndex]
  103. sql := `SELECT MAX(t.num) AS count FROM (
  104. SELECT COUNT(1) AS num FROM base_from_icpi_index AS a
  105. INNER JOIN base_from_icpi_data AS b ON a.base_from_icpi_index_id=b.base_from_icpi_index_id
  106. WHERE a.base_from_icpi_classify_id=?
  107. GROUP BY a.base_from_icpi_index_id
  108. )AS t `
  109. err = o.Raw(sql, classifyId).Scan(&count).Error
  110. return
  111. }
  112. func (obj *BaseFromIcpiIndex) GetIcpiIndexDataByCode(indexCode string) (items []*BaseFromIcpiDataView, err error) {
  113. o := global.DbMap[utils.DbNameIndex]
  114. sql := ` SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC `
  115. err = o.Raw(sql, indexCode).Find(&items).Error
  116. return
  117. }