base_from_mtjh.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  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"`
  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"`
  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"`
  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. // 查询指标
  48. func GetBaseFromMtjhMapping() (items []*BaseFromMtjhMapping, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT * FROM base_from_mtjh_mapping`
  51. _, err = o.Raw(sql).QueryRows(&items)
  52. return
  53. }
  54. // 查询指标
  55. func GetBaseFromMtjhIndex() (items []*BaseFromMtjhIndex, err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT * FROM base_from_mtjh_index`
  58. _, err = o.Raw(sql).QueryRows(&items)
  59. return
  60. }
  61. // 添加数据
  62. func AddBaseFromMtjhIndex(item *BaseFromMtjhIndex) (lastId int64, err error) {
  63. o := orm.NewOrm()
  64. lastId, err = o.Insert(item)
  65. return
  66. }
  67. func AddBaseFromMtjhIndexMuti(items []*BaseFromMtjhIndex) (lastId int64, err error) {
  68. o := orm.NewOrm()
  69. lastId, err = o.InsertMulti(500, items)
  70. return
  71. }
  72. // 添加指标
  73. func AddBaseFromMtjhMapping(item *BaseFromMtjhMapping) (lastId int64, err error) {
  74. o := orm.NewOrm()
  75. lastId, err = o.Insert(item)
  76. return
  77. }
  78. func AddBaseFromMtjhMappingMuti(items []*BaseFromMtjhMapping) (lastId int64, err error) {
  79. o := orm.NewOrm()
  80. lastId, err = o.InsertMulti(500, items)
  81. return
  82. }
  83. func UpdateBaseFromMtjhIndex(item *BaseFromMtjhIndex) (err error) {
  84. o := orm.NewOrm()
  85. sql := `UPDATE base_from_mtjh_index SET deal_value=? WHERE index_name=? AND data_time = ?`
  86. _, err = o.Raw(sql, item.DealValue, item.IndexName, item.DataTime).Exec()
  87. return
  88. }
  89. func GetMtjhClassifyList() (list []*BaseFromMtjhMapping, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := "SELECT * FROM base_from_mtjh_mapping group by area"
  92. _, err = o.Raw(sql).QueryRows(&list)
  93. return
  94. }
  95. type BaseFromMtjhMappingItem struct {
  96. BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"`
  97. IndexName string `description:"持买单量指标名称"`
  98. IndexCode string `description:"持买单量指标编码"`
  99. CreateTime string `description:"时间"`
  100. Area string `description:"区域"`
  101. Port string `description:"港口或码头"`
  102. Variety string `description:"品种"`
  103. Unit string `description:"单位"`
  104. Frequency string `description:"频率"`
  105. }
  106. func GetMtjhMapping(condition string, pars interface{}) (items []*BaseFromMtjhMappingItem, err error) {
  107. o := orm.NewOrmUsingDB("data")
  108. sql := ` SELECT * FROM base_from_mtjh_mapping WHERE 1=1 `
  109. if condition != "" {
  110. sql += condition
  111. }
  112. sql += ` ORDER BY base_from_mtjh_mapping_id asc`
  113. _, err = o.Raw(sql, pars).QueryRows(&items)
  114. return
  115. }
  116. type BaseFromMtjhIndexList struct {
  117. BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"`
  118. IndexName string `description:"持买单量指标名称"`
  119. IndexCode string `description:"持买单量指标编码"`
  120. Area string `description:"区域"`
  121. Port string `description:"港口或码头"`
  122. Unit string `description:"单位"`
  123. Frequency string `description:"频率"`
  124. CreateTime string `description:"插入时间"`
  125. Variety string `description:"品种"`
  126. DataList []*BaseFromMtjhIndexItem
  127. Paging *paging.PagingItem `description:"分页数据"`
  128. }
  129. func GetMtjhIndexDataCount(indexCode string) (count int, err error) {
  130. o := orm.NewOrmUsingDB("data")
  131. sql := ` SELECT COUNT(1) AS count FROM base_from_mtjh_index WHERE index_code=? `
  132. err = o.Raw(sql, indexCode).QueryRow(&count)
  133. return
  134. }
  135. func GetMtjhIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromMtjhIndexItem, err error) {
  136. o := orm.NewOrmUsingDB("data")
  137. sql := ` SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  138. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  139. return
  140. }
  141. // GetMtjhItemList 模糊查询煤炭江湖数据库指标列表
  142. func GetMtjhItemList(keyword string) (items []*BaseFromMtjhMappingItem, err error) {
  143. o := orm.NewOrmUsingDB("data")
  144. sql := "SELECT * FROM base_from_mtjh_mapping WHERE CONCAT(index_name,index_code) LIKE ? "
  145. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  146. return
  147. }
  148. // 查询数据
  149. func GetBaseFromMtjhIndexByCode(indexCode string) (items []*BaseFromMtjhIndexItem, err error) {
  150. o := orm.NewOrmUsingDB("data")
  151. sql := `SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC `
  152. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  153. return
  154. }
  155. // GetMtjhMappingItemByCode
  156. func GetMtjhMappingItemByCode(indexCode string) (item *BaseFromMtjhMappingItem, err error) {
  157. o := orm.NewOrmUsingDB("data")
  158. sql := "SELECT * FROM base_from_mtjh_mapping WHERE index_code=? "
  159. err = o.Raw(sql, indexCode).QueryRow(&item)
  160. return
  161. }
  162. // GetMtjhFrequencyByArea
  163. func GetMtjhFrequencyByArea(area string) (items []*string, err error) {
  164. o := orm.NewOrmUsingDB("data")
  165. sql := "SELECT frequency FROM base_from_mtjh_index WHERE area=? group by area "
  166. _,err = o.Raw(sql, area).QueryRows(&items)
  167. return
  168. }
  169. func GetClassifyMtjhByArea(area string) (items []*string, err error) {
  170. o := orm.NewOrmUsingDB("data")
  171. sql := `SELECT DISTINCT index_code FROM base_from_mtjh_index WHERE area=? `
  172. _, err = o.Raw(sql, area).QueryRows(&items)
  173. return
  174. }
  175. func GetCoalMtjhMaxCount(area string) (count int, err error) {
  176. o := orm.NewOrmUsingDB("data")
  177. sql := `SELECT
  178. MAX( t.num ) AS count
  179. FROM
  180. (
  181. SELECT
  182. COUNT( 1 ) AS num
  183. FROM
  184. base_from_mtjh_index
  185. WHERE
  186. area =?
  187. GROUP BY
  188. index_name ) AS t `
  189. err = o.Raw(sql, area).QueryRow(&count)
  190. return
  191. }
  192. func GetMtjhCount(indexCode string) (count int, err error) {
  193. o := orm.NewOrmUsingDB("data")
  194. sql := `SELECT
  195. COUNT( 1 ) AS num
  196. FROM
  197. base_from_mtjh_index
  198. WHERE
  199. index_code =? `
  200. err = o.Raw(sql, indexCode).QueryRow(&count)
  201. return
  202. }