icpi.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package data_source
  2. import (
  3. "eta_gn/eta_api/global"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type BaseFromIcpiIndex struct {
  8. BaseFromIcpiIndexId int `gorm:"primaryKey;column:base_from_icpi_index_id;type:int(11);not null"`
  9. BaseFromIcpiClassifyId int `gorm:"column:base_from_icpi_classify_id;type:int(11);default:0"` // 分类
  10. IndexCode string `gorm:"unique;column:index_code;type:varchar(100);default:''"` // 指标编码
  11. IndexName string `gorm:"column:index_name;type:varchar(100);default:''"` // 指标名称
  12. Frequency string `gorm:"column:frequency;type:varchar(20);default:''"` // 频度
  13. Unit string `gorm:"column:unit;type:varchar(20);default:''"` // 单位
  14. StartDate time.Time `gorm:"column:start_date;type:date"` // 开始日期
  15. EndDate time.Time `gorm:"column:end_date;type:date"` // 结束日期
  16. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  17. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
  18. }
  19. type BaseFromIcpiData struct {
  20. BaseFromIcpiDataId int `gorm:"primaryKey;column:base_from_icpi_data_id;type:int(11);not null"`
  21. BaseFromIcpiIndexId int `gorm:"index:idx_base_from_icpi_index_id;column:base_from_icpi_index_id;type:int(11);default:0"` // 指标id
  22. IndexCode string `gorm:"uniqueIndex:idex_code_date;index:idx_index_code;column:index_code;type:varchar(100);default:''"` // 指标编码
  23. DataTime string `gorm:"uniqueIndex:idex_code_date;column:data_time;type:date"` // 数据日期
  24. Value float64 `gorm:"column:value;type:double"` // 数据值
  25. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  26. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
  27. }
  28. type BaseFromIcpiClassify struct {
  29. BaseFromIcpiClassifyId int `gorm:"primaryKey;column:base_from_icpi_classify_id;type:int(11);not null"`
  30. ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称
  31. ClassifyNameEn string `gorm:"column:classify_name_en;type:varchar(255);default:''"` // 英文名称
  32. ParentId int `gorm:"column:parent_id;type:int(11) unsigned;default:0"` // 上级id
  33. ModifyTime string `gorm:"column:modify_time;type:datetime"` // 修改时间
  34. CreateTime string `gorm:"column:create_time;type:datetime"` // 创建时间
  35. }
  36. func (obj *BaseFromIcpiIndex) GetBaseFromIcpiClassifyAll() (list []*BaseFromIcpiClassify, err error) {
  37. sql := `SELECT * FROM base_from_icpi_classify `
  38. err = global.DmSQL["data"].Raw(sql).Find(&list).Error
  39. return
  40. }
  41. type BaseFromIcpiDataView struct {
  42. BaseFromIcpiDataId int `gorm:"primaryKey;column:base_from_icpi_data_id;type:int(11);not null"`
  43. BaseFromIcpiIndexId int `gorm:"index:idx_base_from_icpi_index_id;column:base_from_icpi_index_id;type:int(11);default:0"` // 指标id
  44. IndexCode string `gorm:"uniqueIndex:idex_code_date;index:idx_index_code;column:index_code;type:varchar(100);default:''"` // 指标编码
  45. DataTime string `gorm:"uniqueIndex:idex_code_date;column:data_time;type:date"` // 数据日期
  46. Value string `gorm:"column:value;type:double"` // 数据值
  47. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
  48. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
  49. }
  50. type BaseFromIcpiIndexView struct {
  51. BaseFromIcpiIndexId int `gorm:"primaryKey;column:base_from_icpi_index_id;type:int(11);not null"`
  52. BaseFromIcpiClassifyId int `gorm:"column:base_from_icpi_classify_id;type:int(11);default:0"` // 分类
  53. IndexCode string `gorm:"unique;column:index_code;type:varchar(100);default:''"` // 指标编码
  54. IndexName string `gorm:"column:index_name;type:varchar(100);default:''"` // 指标名称
  55. Frequency string `gorm:"column:frequency;type:varchar(20);default:''"` // 频度
  56. Unit string `gorm:"column:unit;type:varchar(20);default:''"` // 单位
  57. StartDate string `gorm:"column:start_date;type:date"` // 开始日期
  58. EndDate string `gorm:"column:end_date;type:date"` // 结束日期
  59. CreateTime string `gorm:"column:create_time;type:datetime"` // 创建时间
  60. ModifyTime string `gorm:"column:modify_time;type:datetime"` // 修改时间
  61. DataList []*BaseFromIcpiDataView `gorm:"-"`
  62. Paging *paging.PagingItem `description:"分页数据" gorm:"-"`
  63. }
  64. func (obj *BaseFromIcpiIndex) GetIcpiIndex(condition string, pars []interface{}) (items []*BaseFromIcpiIndexView, err error) {
  65. sql := ` SELECT * FROM base_from_icpi_index WHERE 1=1 `
  66. if condition != "" {
  67. sql += condition
  68. }
  69. sql += `ORDER BY base_from_icpi_index_id ASC `
  70. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  71. return
  72. }
  73. func (obj *BaseFromIcpiIndex) GetIcpiIndexDataCount(indexCode string) (count int, err error) {
  74. sql := ` SELECT COUNT(1) AS count FROM base_from_icpi_data WHERE index_code=? `
  75. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error
  76. return
  77. }
  78. func (obj *BaseFromIcpiIndex) GetIcpiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromIcpiDataView, err error) {
  79. sql := ` SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  80. err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Find(&items).Error
  81. return
  82. }
  83. func (obj *BaseFromIcpiIndex) GetIcpiDataMaxCount(classifyId int) (count int, err error) {
  84. sql := `SELECT MAX(t.num) AS count FROM (
  85. SELECT COUNT(1) AS num FROM base_from_icpi_index AS a
  86. INNER JOIN base_from_icpi_data AS b ON a.base_from_icpi_index_id=b.base_from_icpi_index_id
  87. WHERE a.base_from_icpi_classify_id=?
  88. GROUP BY a.base_from_icpi_index_id
  89. )AS t `
  90. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error
  91. return
  92. }
  93. func (obj *BaseFromIcpiIndex) GetIcpiIndexDataByCode(indexCode string) (items []*BaseFromIcpiDataView, err error) {
  94. sql := ` SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC `
  95. err = global.DmSQL["data"].Raw(sql, indexCode).Find(&items).Error
  96. return
  97. }