coal_data.go 3.2 KB

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