icpi.go 4.6 KB

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