coal_data.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type BaseFromCoalmineMapping struct {
  8. BaseFromCoalmineMappingId int `orm:"column(base_from_coalmine_mapping_id);pk"`
  9. IndexName string `description:"持买单量指标名称"`
  10. IndexCode string `description:"持买单量指标编码"`
  11. CreateTime string `description:"时间"`
  12. }
  13. // GetCoalItemList 模糊查询Smm数据库指标列表
  14. func GetCoalItemList(keyword string) (items []*BaseFromCoalmineMapping, err error) {
  15. o := orm.NewOrmUsingDB("data")
  16. sql := "SELECT * FROM base_from_coalmine_mapping WHERE CONCAT(index_name,index_code) LIKE ? "
  17. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  18. return
  19. }
  20. func GetCoalCompanyMaxCount(suffix, classifyName string) (count int, err error) {
  21. o := orm.NewOrmUsingDB("data")
  22. sql := `SELECT
  23. MAX( t.num ) AS count
  24. FROM
  25. (
  26. SELECT
  27. COUNT( 1 ) AS num
  28. FROM
  29. base_from_coalmine_%s
  30. WHERE
  31. group_name =?
  32. GROUP BY
  33. index_name ) AS t `
  34. sql = fmt.Sprintf(sql, suffix)
  35. err = o.Raw(sql, classifyName).QueryRow(&count)
  36. return
  37. }
  38. func GetCoalJsmMaxCount(classifyName string) (count int, err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. sql := `SELECT
  41. MAX( t.num ) AS count
  42. FROM
  43. (
  44. SELECT
  45. COUNT( 1 ) AS num
  46. FROM
  47. base_from_coalmine_jsm_index
  48. WHERE
  49. province =?
  50. GROUP BY
  51. index_name ) AS t `
  52. err = o.Raw(sql, classifyName).QueryRow(&count)
  53. return
  54. }
  55. func GetCoalCount(suffix, indexCode string) (count int, err error) {
  56. o := orm.NewOrmUsingDB("data")
  57. sql := `SELECT
  58. COUNT( 1 ) AS num
  59. FROM
  60. base_from_coalmine_%s
  61. WHERE
  62. index_code =? `
  63. sql = fmt.Sprintf(sql, suffix)
  64. err = o.Raw(sql, indexCode).QueryRow(&count)
  65. return
  66. }
  67. type BaseFromCoalmineIndex struct {
  68. BaseFromCoalmineCompanyIndexId int
  69. IndexName string `description:"持买单量指标名称"`
  70. IndexCode string `description:"持买单量指标编码"`
  71. DealValue string `description:"成交量"`
  72. DataTime string `description:"数据日期"`
  73. Source string `description:"来源"`
  74. Province string `description:"省份"`
  75. City string `description:"城市"`
  76. GroupName string `description:"集团名称"`
  77. Unit string `description:"单位"`
  78. Frequency string `description:"频率"`
  79. CreateTime string `description:"插入时间"`
  80. ModifyTime string `description:"修改时间"`
  81. }
  82. func GetBaseFromCoalIndexByCode(suffix, indexCode string) (items []*BaseFromCoalmineIndex, err error) {
  83. o := orm.NewOrmUsingDB("data")
  84. sql := `SELECT * FROM base_from_coalmine_%s WHERE index_code=? ORDER BY data_time DESC`
  85. sql = fmt.Sprintf(sql, suffix)
  86. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  87. return
  88. }
  89. func GetClassifyFromCoalByGroupName(suffix, groupName string) (items []*string, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_%s WHERE group_name=? `
  92. sql = fmt.Sprintf(sql, suffix)
  93. _, err = o.Raw(sql, groupName).QueryRows(&items)
  94. return
  95. }