icpi.go 4.9 KB

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