base_from_mtjh.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package data_manage
  2. import (
  3. "eta/eta_mobile/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. ModifyTime string `description:"修改时间"`
  126. Variety string `description:"品种"`
  127. DataList []*BaseFromMtjhIndexItem
  128. Paging *paging.PagingItem `description:"分页数据"`
  129. }
  130. func GetMtjhIndexDataCount(indexCode string) (count int, err error) {
  131. o := orm.NewOrmUsingDB("data")
  132. sql := ` SELECT COUNT(1) AS count FROM base_from_mtjh_index WHERE index_code=? `
  133. err = o.Raw(sql, indexCode).QueryRow(&count)
  134. return
  135. }
  136. func GetMtjhIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromMtjhIndexItem, err error) {
  137. o := orm.NewOrmUsingDB("data")
  138. sql := ` SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  139. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  140. return
  141. }
  142. // GetMtjhItemList 模糊查询煤炭江湖数据库指标列表
  143. func GetMtjhItemList(keyword string) (items []*BaseFromMtjhMappingItem, err error) {
  144. o := orm.NewOrmUsingDB("data")
  145. sql := "SELECT * FROM base_from_mtjh_mapping WHERE CONCAT(index_name,index_code) LIKE ? "
  146. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  147. return
  148. }
  149. // 查询数据
  150. func GetBaseFromMtjhIndexByCode(indexCode string) (items []*BaseFromMtjhIndexItem, err error) {
  151. o := orm.NewOrmUsingDB("data")
  152. sql := `SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC `
  153. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  154. return
  155. }
  156. // GetMtjhMappingItemByCode
  157. func GetMtjhMappingItemByCode(indexCode string) (item *BaseFromMtjhMappingItem, err error) {
  158. o := orm.NewOrmUsingDB("data")
  159. sql := "SELECT * FROM base_from_mtjh_mapping WHERE index_code=? "
  160. err = o.Raw(sql, indexCode).QueryRow(&item)
  161. return
  162. }
  163. // GetMtjhFrequencyByArea
  164. func GetMtjhFrequencyByArea(area string) (items []*string, err error) {
  165. o := orm.NewOrmUsingDB("data")
  166. sql := "SELECT frequency FROM base_from_mtjh_index WHERE area=? group by area "
  167. _, err = o.Raw(sql, area).QueryRows(&items)
  168. return
  169. }
  170. func GetClassifyMtjhByArea(area string) (items []*string, err error) {
  171. o := orm.NewOrmUsingDB("data")
  172. sql := `SELECT DISTINCT index_code FROM base_from_mtjh_index WHERE area=? `
  173. _, err = o.Raw(sql, area).QueryRows(&items)
  174. return
  175. }
  176. func GetCoalMtjhMaxCount(area string) (count int, err error) {
  177. o := orm.NewOrmUsingDB("data")
  178. sql := `SELECT
  179. MAX( t.num ) AS count
  180. FROM
  181. (
  182. SELECT
  183. COUNT( 1 ) AS num
  184. FROM
  185. base_from_mtjh_index
  186. WHERE
  187. area =?
  188. GROUP BY
  189. index_name ) AS t `
  190. err = o.Raw(sql, area).QueryRow(&count)
  191. return
  192. }
  193. func GetMtjhCount(indexCode string) (count int, err error) {
  194. o := orm.NewOrmUsingDB("data")
  195. sql := `SELECT
  196. COUNT( 1 ) AS num
  197. FROM
  198. base_from_mtjh_index
  199. WHERE
  200. index_code =? `
  201. err = o.Raw(sql, indexCode).QueryRow(&count)
  202. return
  203. }
  204. func GetMtjhIndexLatestDate(indexCode string) (ModifyTime string, err error) {
  205. o := orm.NewOrmUsingDB("data")
  206. sql := ` SELECT modify_time FROM base_from_mtjh_index WHERE index_code=? ORDER BY modify_time DESC limit 1 `
  207. err = o.Raw(sql, indexCode).QueryRow(&ModifyTime)
  208. return
  209. }