base_from_trade_index.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. package data_manage
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "gorm.io/gorm"
  7. "time"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. type BaseFromTradeShanghaiIndex struct {
  11. BaseFromTradeShangHaiIndexId int `orm:"column(base_from_trade_shanghai_index_id);pk" gorm:"primaryKey"`
  12. Rank int
  13. DealShortName string
  14. DealName string
  15. DealCode string
  16. DealValue string
  17. DealChange string
  18. BuyShortName string
  19. BuyName string
  20. BuyCode string
  21. BuyValue string
  22. BuyChange string
  23. SoldShortName string
  24. SoldName string
  25. SoldCode string
  26. SoldValue string
  27. SoldChange string
  28. Frequency string
  29. ClassifyName string
  30. ClassifyType string
  31. CreateTime time.Time
  32. ModifyTime time.Time
  33. DataTime string
  34. }
  35. type BaseFromTradeCffexIndex struct {
  36. BaseFromTradeCffexIndexId int `orm:"column(base_from_trade_cffex_index_id);pk" gorm:"primaryKey"`
  37. Rank int
  38. DealShortName string
  39. DealName string
  40. DealCode string
  41. DealValue string
  42. DealChange string
  43. BuyShortName string
  44. BuyName string
  45. BuyCode string
  46. BuyValue string
  47. BuyChange string
  48. SoldShortName string
  49. SoldName string
  50. SoldCode string
  51. SoldValue string
  52. SoldChange string
  53. Frequency string
  54. ClassifyName string
  55. ClassifyType string
  56. CreateTime time.Time
  57. ModifyTime time.Time
  58. DataTime string
  59. }
  60. type BaseFromTradeIneIndex struct {
  61. BaseFromTradeIneIndexId int `orm:"column(base_from_trade_ine_index_id);pk" gorm:"primaryKey"`
  62. Rank int
  63. DealShortName string
  64. DealName string
  65. DealCode string
  66. DealValue string
  67. DealChange string
  68. BuyShortName string
  69. BuyName string
  70. BuyCode string
  71. BuyValue string
  72. BuyChange string
  73. SoldShortName string
  74. SoldName string
  75. SoldCode string
  76. SoldValue string
  77. SoldChange string
  78. Frequency string
  79. ClassifyName string
  80. ClassifyType string
  81. CreateTime time.Time
  82. ModifyTime time.Time
  83. DataTime string
  84. }
  85. type BaseFromTradeEicIndex struct {
  86. BaseFromEicIndexId int `orm:"column(base_from_eic_index_id);pk" gorm:"primaryKey"`
  87. Country string
  88. Type string
  89. EicCode string
  90. ShortName string
  91. Name string
  92. Status string
  93. GasDayStartedOn string
  94. GasInStorage string
  95. GasInStorageCode string
  96. Full string
  97. FullCode string
  98. Trend string
  99. TrendCode string
  100. Injection string
  101. InjectionCode string
  102. Withdrawal string
  103. WithdrawalCode string
  104. WorkingGasVolume string
  105. WorkingGasVolumeCode string
  106. InjectionCapacity string
  107. InjectionCapacityCode string
  108. WithdrawalCapacity string
  109. WithdrawalCapacityCode string
  110. Info string
  111. CreateTime time.Time
  112. ModifyTime time.Time
  113. }
  114. func GetBaseFromTradeIndexByParam(exchange, date, classifyName, classifyType string) (list []*BaseFromTradeShanghaiIndex, err error) {
  115. o := global.DbMap[utils.DbNameIndex]
  116. if classifyName == "" {
  117. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where data_time=?"
  118. err = o.Raw(sql, date).Find(&list).Error
  119. return
  120. } else if classifyType == "" {
  121. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where data_time=? and classify_name=? ORDER BY classify_type,`rank`"
  122. err = o.Raw(sql, date, classifyName).Find(&list).Error
  123. return
  124. } else {
  125. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where data_time=? and classify_name=? and classify_type=?"
  126. err = o.Raw(sql, date, classifyName, classifyType).Find(&list).Error
  127. return
  128. }
  129. }
  130. func GetExchangeClassify(exchange, dataTime string) (classifyName []string, err error) {
  131. o := global.DbMap[utils.DbNameIndex]
  132. sql := "SELECT DISTINCT classify_name FROM base_from_trade_" + exchange + fmt.Sprintf("_index where data_time=? ORDER BY %s DESC", utils.GenerateQuerySql(utils.ConvertColumn, &utils.QueryParam{ConvertColumn: "classify_name"}))
  133. //sql := "SELECT DISTINCT classify_name FROM base_from_trade_" + exchange + "_index where data_time=? ORDER BY CONVERT(classify_name using gbk) DESC"
  134. err = o.Raw(sql, dataTime).Scan(&classifyName).Error
  135. return
  136. }
  137. func GetLatestDate(exchange string) (dataTime string, err error) {
  138. o := global.DbMap[utils.DbNameIndex]
  139. sql := "SELECT data_time FROM base_from_trade_" + exchange + "_index ORDER BY data_time desc limit 1"
  140. err = o.Raw(sql).Scan(&dataTime).Error
  141. dataTime = utils.GormDateStrToDateStr(dataTime)
  142. return
  143. }
  144. func GetExchangeClassifyContract(exchange, Classify, dataTime string) (classifyName []*string, err error) {
  145. o := global.DbMap[utils.DbNameIndex]
  146. sql := "SELECT DISTINCT classify_type FROM base_from_trade_" + exchange + "_index where classify_name=? and data_time=?"
  147. err = o.Raw(sql, Classify, dataTime).Scan(&classifyName).Error
  148. return
  149. }
  150. func GetContinentEicDate(date string) (data []*BaseFromTradeEicIndex, err error) {
  151. o := global.DbMap[utils.DbNameIndex]
  152. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and type='continent' "
  153. err = o.Raw(sql, date).Find(&data).Error
  154. return
  155. }
  156. func GetCountryEicDate(date string) (data []*BaseFromTradeEicIndex, err error) {
  157. o := global.DbMap[utils.DbNameIndex]
  158. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and type='country' "
  159. err = o.Raw(sql, date).Find(&data).Error
  160. return
  161. }
  162. func GetSSOEicDate(date, country string) (data []*BaseFromTradeEicIndex, err error) {
  163. o := global.DbMap[utils.DbNameIndex]
  164. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and country=? and type='SSO' "
  165. err = o.Raw(sql, date, country).Find(&data).Error
  166. return
  167. }
  168. func GetStorageEicDate(date, country string) (data []*BaseFromTradeEicIndex, err error) {
  169. o := global.DbMap[utils.DbNameIndex]
  170. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and country=? " +
  171. " and (type='Storage Facility' or type='Storage Group') "
  172. err = o.Raw(sql, date, country).Find(&data).Error
  173. return
  174. }
  175. func GetEicDate() (date []*BaseFromTradeEicIndex, err error) {
  176. o := global.DbMap[utils.DbNameIndex]
  177. sql := "SELECT * FROM base_from_trade_eic_index ORDER BY gas_day_started_on desc limit 1"
  178. err = o.Raw(sql).Find(&date).Error
  179. return
  180. }
  181. func GetEicHistoryDate(code string) (date []*BaseFromTradeEicIndex, err error) {
  182. o := global.DbMap[utils.DbNameIndex]
  183. sql := "SELECT * FROM base_from_trade_eic_index WHERE eic_code=? ORDER BY gas_day_started_on desc limit 30"
  184. err = o.Raw(sql, code).Find(&date).Error
  185. return
  186. }
  187. func GetEicHistoryDateByDate(code, startDate, endDate string) (date []*BaseFromTradeEicIndex, err error) {
  188. o := global.DbMap[utils.DbNameIndex]
  189. sql := "SELECT * FROM base_from_trade_eic_index WHERE eic_code=? and gas_day_started_on between ? and ? ORDER BY gas_day_started_on desc"
  190. err = o.Raw(sql, code, startDate, endDate).Find(&date).Error
  191. return
  192. }
  193. type BaseFromCoalmineJsmIndex struct {
  194. BaseFromCoalmineJsmIndexId int `orm:"column(base_from_coalmine_jsm_index_id);pk" gorm:"primaryKey"`
  195. IndexName string `description:"持买单量指标名称"`
  196. IndexCode string `description:"持买单量指标编码"`
  197. Exchange string `description:"样本统计类别"`
  198. DealValue string `description:"成交量"`
  199. DataTime string `description:"数据日期"`
  200. Source string `description:"来源"`
  201. Province string `description:"省份"`
  202. Description string `description:"描述"`
  203. Unit string `description:"单位"`
  204. Frequency string `description:"频率"`
  205. CreateTime string `description:"插入时间"`
  206. ModifyTime string `description:"修改时间"`
  207. }
  208. func (baseFromCoalmineJsmIndex *BaseFromCoalmineJsmIndex) AfterFind(tx *gorm.DB) (err error) {
  209. baseFromCoalmineJsmIndex.CreateTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineJsmIndex.CreateTime)
  210. baseFromCoalmineJsmIndex.ModifyTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineJsmIndex.ModifyTime)
  211. baseFromCoalmineJsmIndex.DataTime = utils.GormDateStrToDateStr(baseFromCoalmineJsmIndex.DataTime)
  212. return
  213. }
  214. // GetBaseFromCoalmineIndex 查询数据
  215. func GetBaseFromCoalmineIndex(startDate, endDate string) (items []*BaseFromCoalmineJsmIndex, err error) {
  216. o := global.DbMap[utils.DbNameIndex]
  217. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE data_time between ? and ? `
  218. err = o.Raw(sql, startDate, endDate).Find(&items).Error
  219. return
  220. }
  221. type BaseFromCoalmineCompanyIndex struct {
  222. BaseFromCoalmineCompanyIndexId int `gorm:"column:base_from_coalmine_company_index_id;primaryKey"`
  223. IndexName string `description:"持买单量指标名称"`
  224. IndexCode string `description:"持买单量指标编码"`
  225. DealValue string `description:"成交量"`
  226. DataTime string `description:"数据日期"`
  227. Source string `description:"来源"`
  228. Province string `description:"省份"`
  229. City string `description:"城市"`
  230. GroupName string `description:"集团名称"`
  231. Unit string `description:"单位"`
  232. Frequency string `description:"频率"`
  233. CreateTime string `description:"插入时间"`
  234. ModifyTime string `description:"修改时间"`
  235. }
  236. func (baseFromCoalmineCompanyIndex *BaseFromCoalmineCompanyIndex) AfterFind(tx *gorm.DB) (err error) {
  237. baseFromCoalmineCompanyIndex.CreateTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineCompanyIndex.CreateTime)
  238. baseFromCoalmineCompanyIndex.ModifyTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineCompanyIndex.ModifyTime)
  239. baseFromCoalmineCompanyIndex.DataTime = utils.GormDateStrToDateStr(baseFromCoalmineCompanyIndex.DataTime)
  240. return
  241. }
  242. // GetBaseFromCoalmineCompanyIndex 查询公司指标
  243. func GetBaseFromCoalmineCompanyIndex(startDate, endDate string) (items []*BaseFromCoalmineCompanyIndex, err error) {
  244. o := global.DbMap[utils.DbNameIndex]
  245. sql := `SELECT * FROM base_from_coalmine_company_index WHERE data_time between ? and ? `
  246. err = o.Raw(sql, startDate, endDate).Find(&items).Error
  247. return
  248. }
  249. // BaseFromCoalmineFirmIndex 煤矿产量周度公司数据表
  250. type BaseFromCoalmineFirmIndex struct {
  251. BaseFromCoalmineFirmIndexID int `gorm:"column:base_from_coalmine_firm_index_id;primaryKey"`
  252. IndexName string // 省份/企业名称
  253. IndexCode string // 持买单量指标编码
  254. DataTime string // 指标时间
  255. DataTimeDate string // 指标时间
  256. DealValue string // 数据量
  257. GroupName string // 集团名
  258. Source string // 来源
  259. Unit string // 来源
  260. Frequency string `description:"频率"`
  261. CreateTime string `description:"插入时间"`
  262. ModifyTime string `description:"修改时间"`
  263. }
  264. func (baseFromCoalmineFirmIndex *BaseFromCoalmineFirmIndex) AfterFind(tx *gorm.DB) (err error) {
  265. baseFromCoalmineFirmIndex.CreateTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineFirmIndex.CreateTime)
  266. baseFromCoalmineFirmIndex.ModifyTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineFirmIndex.ModifyTime)
  267. baseFromCoalmineFirmIndex.DataTime = utils.GormDateStrToDateStr(baseFromCoalmineFirmIndex.DataTime)
  268. return
  269. }
  270. // 查询指标
  271. func GetBaseFromCoalmineFirmIndex(dataTime string) (items []*BaseFromCoalmineFirmIndex, err error) {
  272. o := global.DbMap[utils.DbNameIndex]
  273. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE data_time LIKE `
  274. sql = sql + "'" + dataTime + "%" + "'"
  275. err = o.Raw(sql).Find(&items).Error
  276. fmt.Println(sql)
  277. return
  278. }
  279. // BaseFromCoalmineCoastalIndex 沿海八省动力煤用户供耗存数据指标表
  280. type BaseFromCoalmineCoastalIndex struct {
  281. BaseFromCoalmineCoastalIndexID int `orm:"column(base_from_coalmine_coastal_index_id);pk" gorm:"primaryKey"`
  282. IndexName string // 省份/企业名称
  283. IndexCode string // 持买单量指标编码
  284. DataTime string // 指标时间
  285. DealValue string // 数据量
  286. GroupName string // 地区
  287. Source string // 来源
  288. Unit string //单位
  289. Frequency string `description:"频率"`
  290. CreateTime string `description:"插入时间"`
  291. ModifyTime string `description:"修改时间"`
  292. }
  293. func (baseFromCoalmineCoastalIndex *BaseFromCoalmineCoastalIndex) AfterFind(tx *gorm.DB) (err error) {
  294. baseFromCoalmineCoastalIndex.CreateTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineCoastalIndex.CreateTime)
  295. baseFromCoalmineCoastalIndex.ModifyTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineCoastalIndex.ModifyTime)
  296. baseFromCoalmineCoastalIndex.DataTime = utils.GormDateStrToDateStr(baseFromCoalmineCoastalIndex.DataTime)
  297. return
  298. }
  299. // 查询指标
  300. func GetBaseFromCoalmineCoastalIndex(startDate, endDate string) (items []*BaseFromCoalmineCoastalIndex, err error) {
  301. o := global.DbMap[utils.DbNameIndex]
  302. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE data_time between ? and ? `
  303. err = o.Raw(sql, startDate, endDate).Find(&items).Error
  304. return
  305. }
  306. // BaseFromCoalmineInlandIndex 内陆动力煤用户供耗存数据指标表
  307. type BaseFromCoalmineInlandIndex struct {
  308. BaseFromCoalmineInlandIndexID int `orm:"column(base_from_coalmine_inland_index_id);pk" gorm:"primaryKey"`
  309. IndexName string // 省份/企业名称
  310. IndexCode string // 持买单量指标编码
  311. DataTime string // 指标时间
  312. DealValue string // 数据量
  313. GroupName string // 地区
  314. Source string // 来源
  315. Unit string // 来源
  316. Frequency string `description:"频率"`
  317. CreateTime string `description:"插入时间"`
  318. ModifyTime string `description:"修改时间"`
  319. }
  320. func (baseFromCoalmineInlandIndex *BaseFromCoalmineInlandIndex) AfterFind(tx *gorm.DB) (err error) {
  321. baseFromCoalmineInlandIndex.CreateTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineInlandIndex.CreateTime)
  322. baseFromCoalmineInlandIndex.ModifyTime = utils.GormDateStrToDateTimeStr(baseFromCoalmineInlandIndex.ModifyTime)
  323. baseFromCoalmineInlandIndex.DataTime = utils.GormDateStrToDateStr(baseFromCoalmineInlandIndex.DataTime)
  324. return
  325. }
  326. // 查询指标
  327. func GetBaseFromCoalmineInlandIndex(startDate, endDate string) (items []*BaseFromCoalmineInlandIndex, err error) {
  328. o := global.DbMap[utils.DbNameIndex]
  329. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE data_time between ? and ? `
  330. err = o.Raw(sql, startDate, endDate).Find(&items).Error
  331. return
  332. }
  333. type BaseFromCoalmineClassifyItem struct {
  334. ClassifyId int
  335. ClassifyName string
  336. Child []CoalChild
  337. }
  338. type CoalChild struct {
  339. ClassifyId int
  340. ClassifyName string
  341. }
  342. type CoalmineDataResp struct {
  343. IndexName string
  344. IndexCode string // 持买单量指标编码
  345. Unit string // 来源
  346. Frequency string
  347. ModifyTime string
  348. DataList []DataList
  349. }
  350. type CoalmineDataPageResp struct {
  351. IndexName string
  352. IndexCode string // 持买单量指标编码
  353. Unit string // 来源
  354. Frequency string
  355. ModifyTime string
  356. Paging *paging.PagingItem `description:"分页数据" gorm:"-"`
  357. DataList []DataList `gorm:"-"`
  358. }
  359. type CoalmineSingalDataResp struct {
  360. IndexName string
  361. IndexCode string // 持买单量指标编码
  362. Unit string // 来源
  363. GroupId int // 二级id
  364. GroupName string // 二级名称
  365. Frequency string
  366. ModifyTime string
  367. ClassifyId int
  368. DataList []DataList
  369. }
  370. type DataList struct {
  371. Value string
  372. DataTime string
  373. }
  374. type FrequencyResp struct {
  375. Frequency int
  376. }
  377. // GetFrequencyFromCoal 获取指标信息
  378. func GetFrequencyFromCoal(suffix string) (list *string, err error) {
  379. o := global.DbMap[utils.DbNameIndex]
  380. sql := `SELECT DISTINCT frequency FROM base_from_coalmine_%s `
  381. sql = fmt.Sprintf(sql, suffix)
  382. err = o.Raw(sql).Scan(&list).Error
  383. return
  384. }
  385. // 查询数据
  386. func GetBaseFromCoalmineIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineJsmIndex, err error) {
  387. o := global.DbMap[utils.DbNameIndex]
  388. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE frequency=? AND province=?`
  389. err = o.Raw(sql, frequency, groupName).Find(&items).Error
  390. return
  391. }
  392. // 查询数据
  393. func GetGroupNameFromCoalmineIndex(suffix string) (items []*string, err error) {
  394. o := global.DbMap[utils.DbNameIndex]
  395. sql := `SELECT DISTINCT group_name FROM base_from_coalmine_%s `
  396. sql = fmt.Sprintf(sql, suffix)
  397. err = o.Raw(sql).Find(&items).Error
  398. return
  399. }
  400. // 查询数据
  401. func GetProvinceFromCoalmineIndex(suffix string) (items []*string, err error) {
  402. o := global.DbMap[utils.DbNameIndex]
  403. sql := `SELECT DISTINCT province FROM base_from_coalmine_%s `
  404. sql = fmt.Sprintf(sql, suffix)
  405. err = o.Raw(sql).Find(&items).Error
  406. return
  407. }
  408. // 查询数据
  409. func GetClassifyCoalmineIndexByGroupName(groupName string) (items []*string, err error) {
  410. o := global.DbMap[utils.DbNameIndex]
  411. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_jsm_index WHERE province=? `
  412. err = o.Raw(sql, groupName).Find(&items).Error
  413. return
  414. }
  415. // 查询数据
  416. func GetPageFromCoalmineIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineJsmIndex, err error) {
  417. o := global.DbMap[utils.DbNameIndex]
  418. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  419. err = o.Raw(sql, frequency, classify, startSize, pageSize).Find(&items).Error
  420. return
  421. }
  422. // 查询数据
  423. func GetCountFromJsm(indexCode string) (item int, err error) {
  424. o := global.DbMap[utils.DbNameIndex]
  425. sql := `SELECT COUNT(1) FROM base_from_coalmine_jsm_index WHERE index_code=? `
  426. err = o.Raw(sql, indexCode).First(&item).Error
  427. return
  428. }
  429. func GetClassifyCompanyByGroupName(groupName string) (items []*string, err error) {
  430. o := global.DbMap[utils.DbNameIndex]
  431. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_company_index WHERE group_name=? `
  432. err = o.Raw(sql, groupName).Find(&items).Error
  433. return
  434. }
  435. func GetClassifyJsmByGroupName(groupName string) (items []*string, err error) {
  436. o := global.DbMap[utils.DbNameIndex]
  437. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_jsm_index WHERE province=? `
  438. err = o.Raw(sql, groupName).Find(&items).Error
  439. return
  440. }
  441. // 查询公司指标
  442. func GetPageFromCoalmineCompanyIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineCompanyIndex, err error) {
  443. o := global.DbMap[utils.DbNameIndex]
  444. sql := `SELECT * FROM base_from_coalmine_company_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  445. err = o.Raw(sql, frequency, classify, startSize, pageSize).Find(&items).Error
  446. return
  447. }
  448. func GetCountFromCompany(indexCode string) (item int, err error) {
  449. o := global.DbMap[utils.DbNameIndex]
  450. sql := `SELECT COUNT(1) FROM base_from_coalmine_company_index WHERE index_code=? `
  451. err = o.Raw(sql, indexCode).First(&item).Error
  452. return
  453. }
  454. func GetCountFromFirm(indexCode string) (item int, err error) {
  455. o := global.DbMap[utils.DbNameIndex]
  456. sql := `SELECT COUNT(1) FROM base_from_coalmine_firm_index WHERE index_code=? `
  457. err = o.Raw(sql, indexCode).First(&item).Error
  458. return
  459. }
  460. func GetClassifyFirmByGroupName(groupName string) (items []*string, err error) {
  461. o := global.DbMap[utils.DbNameIndex]
  462. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_firm_index WHERE group_name=? `
  463. err = o.Raw(sql, groupName).Find(&items).Error
  464. return
  465. }
  466. // 查询指标
  467. func GetPageFromCoalmineFirmIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineFirmIndex, err error) {
  468. o := global.DbMap[utils.DbNameIndex]
  469. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE frequency=? AND index_code=? ORDER BY data_time_date DESC LIMIT ?,? `
  470. err = o.Raw(sql, frequency, classify, startSize, pageSize).Find(&items).Error
  471. return
  472. }
  473. func GetCountFromCoastal(indexCode string) (item int, err error) {
  474. o := global.DbMap[utils.DbNameIndex]
  475. sql := `SELECT COUNT(1) FROM base_from_coalmine_coastal_index WHERE index_code=? `
  476. err = o.Raw(sql, indexCode).First(&item).Error
  477. return
  478. }
  479. func GetClassifyCoastalByGroupName(groupName string) (items []*string, err error) {
  480. o := global.DbMap[utils.DbNameIndex]
  481. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_coastal_index WHERE group_name=? `
  482. err = o.Raw(sql, groupName).Find(&items).Error
  483. return
  484. }
  485. // 查询指标
  486. func GetPageFromCoalmineCoastalIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineCoastalIndex, err error) {
  487. o := global.DbMap[utils.DbNameIndex]
  488. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  489. err = o.Raw(sql, frequency, classify, startSize, pageSize).Find(&items).Error
  490. return
  491. }
  492. func GetCountFromInland(indexCode string) (item int, err error) {
  493. o := global.DbMap[utils.DbNameIndex]
  494. sql := `SELECT COUNT(1) FROM base_from_coalmine_inland_index WHERE index_code=? `
  495. err = o.Raw(sql, indexCode).First(&item).Error
  496. return
  497. }
  498. func GetClassifyInlandByGroupName(groupName string) (items []*string, err error) {
  499. o := global.DbMap[utils.DbNameIndex]
  500. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_inland_index WHERE group_name=? `
  501. err = o.Raw(sql, groupName).Find(&items).Error
  502. return
  503. }
  504. // 查询指标
  505. func GetPageFromCoalmineInlandIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineInlandIndex, err error) {
  506. o := global.DbMap[utils.DbNameIndex]
  507. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  508. err = o.Raw(sql, frequency, classify, startSize, pageSize).Find(&items).Error
  509. return
  510. }
  511. // 查询公司指标
  512. func GetBaseFromCoalmineCompanyIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineCompanyIndex, err error) {
  513. o := global.DbMap[utils.DbNameIndex]
  514. sql := `SELECT * FROM base_from_coalmine_company_index WHERE frequency=? AND group_name=? `
  515. err = o.Raw(sql, frequency, groupName).Find(&items).Error
  516. return
  517. }
  518. // 查询指标
  519. func GetBaseFromCoalmineFirmIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineFirmIndex, err error) {
  520. o := global.DbMap[utils.DbNameIndex]
  521. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE frequency=? AND group_name=? `
  522. err = o.Raw(sql, frequency, groupName).Find(&items).Error
  523. return
  524. }
  525. // 查询指标
  526. func GetBaseFromCoalmineCoastalIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineCoastalIndex, err error) {
  527. o := global.DbMap[utils.DbNameIndex]
  528. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE frequency=? AND group_name=? `
  529. err = o.Raw(sql, frequency, groupName).Find(&items).Error
  530. return
  531. }
  532. // 查询指标
  533. func GetBaseFromCoalmineInlandIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineInlandIndex, err error) {
  534. o := global.DbMap[utils.DbNameIndex]
  535. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE frequency=? AND group_name=? `
  536. err = o.Raw(sql, frequency, groupName).Find(&items).Error
  537. return
  538. }
  539. // 查询数据
  540. func GetBaseFromCoalmineIndexByCode(indexCode string) (items []*BaseFromCoalmineJsmIndex, err error) {
  541. o := global.DbMap[utils.DbNameIndex]
  542. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE index_code=?`
  543. err = o.Raw(sql, indexCode).Find(&items).Error
  544. return
  545. }
  546. // 查询公司指标
  547. func GetBaseFromCoalmineCompanyIndexByCode(indexCode string) (items []*BaseFromCoalmineCompanyIndex, err error) {
  548. o := global.DbMap[utils.DbNameIndex]
  549. sql := `SELECT * FROM base_from_coalmine_company_index WHERE index_code=? `
  550. err = o.Raw(sql, indexCode).Find(&items).Error
  551. return
  552. }
  553. // 查询指标
  554. func GetBaseFromCoalmineFirmIndexByCode(indexCode string) (items []*BaseFromCoalmineFirmIndex, err error) {
  555. o := global.DbMap[utils.DbNameIndex]
  556. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE index_code=? `
  557. err = o.Raw(sql, indexCode).Find(&items).Error
  558. return
  559. }
  560. // 查询指标
  561. func GetBaseFromCoalmineCoastalIndexByCode(indexCode string) (items []*BaseFromCoalmineCoastalIndex, err error) {
  562. o := global.DbMap[utils.DbNameIndex]
  563. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE index_code=? `
  564. err = o.Raw(sql, indexCode).Find(&items).Error
  565. return
  566. }
  567. // 查询指标
  568. func GetBaseFromCoalmineInlandIndexByCode(indexCode string) (items []*BaseFromCoalmineInlandIndex, err error) {
  569. o := global.DbMap[utils.DbNameIndex]
  570. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE index_code=? `
  571. err = o.Raw(sql, indexCode).Find(&items).Error
  572. return
  573. }
  574. type BaseFromTradeEicIndexV2 struct {
  575. BaseFromEicIndexId int `orm:"column(base_from_eic_index_id);pk" gorm:"primaryKey"`
  576. Type string
  577. EicCode string
  578. Name string
  579. Status string
  580. GasDayStart string
  581. GasInStorage float64
  582. GasInStorageCode string
  583. Consumption string
  584. ConsumptionCode string
  585. ConsumptionFull string
  586. ConsumptionFullCode string
  587. Full float64
  588. FullCode string
  589. Trend float64
  590. TrendCode string
  591. Injection float64
  592. InjectionCode string
  593. Withdrawal float64
  594. WithdrawalCode string
  595. WorkingGasVolume float64
  596. WorkingGasVolumeCode string
  597. InjectionCapacity float64
  598. InjectionCapacityCode string
  599. WithdrawalCapacity float64
  600. WithdrawalCapacityCode string
  601. Info string
  602. Parent string
  603. CreateTime time.Time
  604. ModifyTime time.Time
  605. Children []BaseFromTradeEicIndexV2 `gorm:"-"`
  606. }
  607. func GetEicDateV2() (date []*BaseFromTradeEicIndexV2, err error) {
  608. o := global.DbMap[utils.DbNameIndex]
  609. sql := "SELECT * FROM base_from_trade_eic_index_v2 ORDER BY gas_day_start desc limit 1"
  610. err = o.Raw(sql).Find(&date).Error
  611. return
  612. }
  613. func GetEicDataV2(date string) (data []*BaseFromTradeEicIndexV2, err error) {
  614. o := global.DbMap[utils.DbNameIndex]
  615. sql := "SELECT * FROM base_from_trade_eic_index_v2 where gas_day_start=? "
  616. err = o.Raw(sql, date).Find(&data).Error
  617. return
  618. }
  619. func GetEicHistoryDateByDateV2(code, startDate, endDate string) (date []*BaseFromTradeEicIndexV2, err error) {
  620. o := global.DbMap[utils.DbNameIndex]
  621. sql := "SELECT * FROM base_from_trade_eic_index_v2 WHERE eic_code=? and gas_day_start between ? and ? ORDER BY gas_day_start desc"
  622. err = o.Raw(sql, code, startDate, endDate).Find(&date).Error
  623. return
  624. }
  625. func GetEicHistoryDateV2(code string) (date []*BaseFromTradeEicIndexV2, err error) {
  626. o := global.DbMap[utils.DbNameIndex]
  627. sql := "SELECT * FROM base_from_trade_eic_index_v2 WHERE eic_code=? ORDER BY gas_day_start desc limit 30"
  628. err = o.Raw(sql, code).Find(&date).Error
  629. return
  630. }
  631. func GetContinentAndCountryEicDateV2(date string) (data []*BaseFromTradeEicIndexV2, err error) {
  632. o := global.DbMap[utils.DbNameIndex]
  633. sql := "SELECT * FROM base_from_trade_eic_index_v2 where gas_day_start=? and (type='continent' OR type='country') "
  634. err = o.Raw(sql, date).Find(&data).Error
  635. return
  636. }
  637. func GetSSOAndFacEicDateV2(date, name string) (data []*BaseFromTradeEicIndexV2, err error) {
  638. o := global.DbMap[utils.DbNameIndex]
  639. sql := "SELECT * FROM base_from_trade_eic_index_v2 where gas_day_start=? and (type='sso' OR type='fac') "
  640. err = o.Raw(sql, date).Find(&data).Error
  641. return
  642. }
  643. func GetBaseFromTradeIndexByDate(exchange, startDate, endDate string) (list []*BaseFromTradeShanghaiIndex, err error) {
  644. o := global.DbMap[utils.DbNameIndex]
  645. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where `rank` < 50 and data_time between ? and ? order by data_time asc"
  646. err = o.Raw(sql, startDate, endDate).Find(&list).Error
  647. return
  648. }
  649. func GetFirstBaseFromTradeIndexByDate(exchange string) (item *BaseFromTradeShanghaiIndex, err error) {
  650. o := global.DbMap[utils.DbNameIndex]
  651. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where `rank` < 50 order by data_time asc"
  652. err = o.Raw(sql).First(&item).Error
  653. return
  654. }
  655. type BaseFromCoalmineClassify struct {
  656. BaseFromCoalmineClassifyId int `orm:"column(base_from_coalmine_classify_id);pk" gorm:"primaryKey"`
  657. ClassifyName string // 分类名称
  658. Suffix string // 表名后缀
  659. CreateTime time.Time
  660. }
  661. func GetCoalmineClassifyList() (list []*BaseFromCoalmineClassify, err error) {
  662. o := global.DbMap[utils.DbNameIndex]
  663. sql := "SELECT * FROM base_from_coalmine_classify"
  664. err = o.Raw(sql).Find(&list).Error
  665. return
  666. }