base_from_mtjh.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type BaseFromMtjhMapping struct {
  9. BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk" gorm:"primaryKey" `
  10. IndexName string `description:"持买单量指标名称"`
  11. IndexCode string `description:"持买单量指标编码"`
  12. CreateTime time.Time `description:"时间"`
  13. Area string `description:"区域"`
  14. Port string `description:"港口或码头"`
  15. Variety string `description:"品种"`
  16. Unit string `description:"单位"`
  17. Frequency string `description:"频率"`
  18. }
  19. type BaseFromMtjhIndex struct {
  20. BaseFromMtjhIndexId int `orm:"column(base_from_mtjh_index_id);pk" gorm:"primaryKey" `
  21. IndexName string `description:"持买单量指标名称"`
  22. IndexCode string `description:"持买单量指标编码"`
  23. DealValue string `description:"成交量"`
  24. DataTime string `description:"数据日期"`
  25. Area string `description:"区域"`
  26. Port string `description:"港口或码头"`
  27. Unit string `description:"单位"`
  28. Frequency string `description:"频率"`
  29. Variety string `description:"品种"`
  30. CreateTime time.Time `description:"插入时间"`
  31. ModifyTime time.Time `description:"修改时间"`
  32. }
  33. type BaseFromMtjhIndexItem struct {
  34. BaseFromMtjhIndexId int `orm:"column(base_from_mtjh_index_id);pk" gorm:"primaryKey" `
  35. IndexName string `description:"持买单量指标名称"`
  36. IndexCode string `description:"持买单量指标编码"`
  37. DealValue string `description:"成交量"`
  38. DataTime string `description:"数据日期"`
  39. Area string `description:"区域"`
  40. Port string `description:"港口或码头"`
  41. Unit string `description:"单位"`
  42. Frequency string `description:"频率"`
  43. Variety string `description:"品种"`
  44. CreateTime string `description:"插入时间"`
  45. ModifyTime string `description:"修改时间"`
  46. }
  47. func GetMtjhClassifyList() (list []*BaseFromMtjhMapping, err error) {
  48. sql := "SELECT * FROM base_from_mtjh_mapping group by area"
  49. err = global.DmSQL["data"].Raw(sql).Scan(&list).Error
  50. return
  51. }
  52. type BaseFromMtjhMappingItem struct {
  53. BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk" gorm:"primaryKey" `
  54. IndexName string `description:"持买单量指标名称"`
  55. IndexCode string `description:"持买单量指标编码"`
  56. CreateTime string `description:"时间"`
  57. Area string `description:"区域"`
  58. Port string `description:"港口或码头"`
  59. Variety string `description:"品种"`
  60. Unit string `description:"单位"`
  61. Frequency string `description:"频率"`
  62. }
  63. func GetMtjhMapping(condition string, pars []interface{}) (items []*BaseFromMtjhMappingItem, err error) {
  64. sql := ` SELECT * FROM base_from_mtjh_mapping WHERE 1=1 `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. sql += ` ORDER BY base_from_mtjh_mapping_id asc`
  69. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
  70. return
  71. }
  72. type BaseFromMtjhIndexList struct {
  73. BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk" gorm:"primaryKey" `
  74. IndexName string `description:"持买单量指标名称"`
  75. IndexCode string `description:"持买单量指标编码"`
  76. Area string `description:"区域"`
  77. Port string `description:"港口或码头"`
  78. Unit string `description:"单位"`
  79. Frequency string `description:"频率"`
  80. CreateTime string `description:"插入时间"`
  81. ModifyTime string `description:"修改时间"`
  82. Variety string `description:"品种"`
  83. DataList []*BaseFromMtjhIndexItem
  84. Paging *paging.PagingItem `description:"分页数据"`
  85. }
  86. func GetMtjhIndexDataCount(indexCode string) (count int, err error) {
  87. sql := ` SELECT COUNT(1) AS count FROM base_from_mtjh_index WHERE index_code=? `
  88. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error
  89. return
  90. }
  91. func GetMtjhIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromMtjhIndexItem, err error) {
  92. sql := ` SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  93. err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Scan(&items).Error
  94. return
  95. }
  96. // GetMtjhItemList 模糊查询煤炭江湖数据库指标列表
  97. func GetMtjhItemList(keyword string) (items []*BaseFromMtjhMappingItem, err error) {
  98. sql := "SELECT * FROM base_from_mtjh_mapping WHERE CONCAT(index_name,index_code) LIKE ? "
  99. err = global.DmSQL["data"].Raw(sql, utils.GetLikeKeyword(keyword)).Scan(&items).Error
  100. return
  101. }
  102. // 查询数据
  103. func GetBaseFromMtjhIndexByCode(indexCode string) (items []*BaseFromMtjhIndexItem, err error) {
  104. sql := `SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC `
  105. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&items).Error
  106. return
  107. }
  108. // GetMtjhMappingItemByCode
  109. func GetMtjhMappingItemByCode(indexCode string) (item *BaseFromMtjhMappingItem, err error) {
  110. o := global.DmSQL["data"]
  111. sql := "SELECT * FROM base_from_mtjh_mapping WHERE index_code=? "
  112. err = o.Raw(sql, indexCode).First(&item).Error
  113. return
  114. }
  115. // GetMtjhFrequencyByArea
  116. func GetMtjhFrequencyByArea(area string) (items []*string, err error) {
  117. sql := "SELECT frequency FROM base_from_mtjh_index WHERE area=? group by area "
  118. err = global.DmSQL["data"].Raw(sql, area).Scan(&items).Error
  119. return
  120. }
  121. func GetClassifyMtjhByArea(area string) (items []*string, err error) {
  122. sql := `SELECT DISTINCT index_code FROM base_from_mtjh_index WHERE area=? `
  123. err = global.DmSQL["data"].Raw(sql, area).Scan(&items).Error
  124. return
  125. }
  126. func GetCoalMtjhMaxCount(area string) (count int, err error) {
  127. o := global.DmSQL["data"]
  128. sql := `SELECT
  129. MAX( t.num ) AS count
  130. FROM
  131. (
  132. SELECT
  133. COUNT( 1 ) AS num
  134. FROM
  135. base_from_mtjh_index
  136. WHERE
  137. area =?
  138. GROUP BY
  139. index_name ) AS t `
  140. err = o.Raw(sql, area).Scan(&count).Error
  141. return
  142. }
  143. func GetMtjhCount(indexCode string) (count int, err error) {
  144. o := global.DmSQL["data"]
  145. sql := `SELECT
  146. COUNT( 1 ) AS num
  147. FROM
  148. base_from_mtjh_index
  149. WHERE
  150. index_code =? `
  151. err = o.Raw(sql, indexCode).Scan(&count).Error
  152. return
  153. }
  154. func GetMtjhIndexLatestDate(indexCode string) (ModifyTime string, err error) {
  155. o := global.DmSQL["data"]
  156. sql := ` SELECT modify_time FROM base_from_mtjh_index WHERE index_code=? ORDER BY modify_time DESC limit 1 `
  157. err = o.Raw(sql, indexCode).Scan(&ModifyTime).Error
  158. return
  159. }