com_trade_index.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ComTradeIndex 联合国商品贸易数据指标表
  8. type ComTradeIndex struct {
  9. ComTradeId int `orm:"column(com_trade_id);pk"`
  10. IndexCode string `description:"联合国商品贸易编码"`
  11. IndexName string `description:"联合国商品名称"`
  12. IndexNameCn string `description:"联合国商品名称(中文)"`
  13. UpdateTime time.Time `description:"数据最近更新时间"`
  14. CreateTime time.Time `description:"创建时间"`
  15. }
  16. // GetComTradeIndexList 获取指标数据列表
  17. func GetComTradeIndexList(condition string, pars []interface{}) (list []*ComTradeIndex, err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. sql := `SELECT * FROM com_trade_index WHERE 1=1 `
  20. if condition != "" {
  21. sql += condition
  22. }
  23. sql += `ORDER BY com_trade_id DESC `
  24. _, err = o.Raw(sql, pars).QueryRows(&list)
  25. return
  26. }
  27. // GetComTradeIndexByIdList 获取指标数据列表
  28. func GetComTradeIndexByIdList(idList []int) (list []*ComTradeIndex, err error) {
  29. num := len(idList)
  30. if num <= 0 {
  31. return
  32. }
  33. o := orm.NewOrmUsingDB("data")
  34. sql := `SELECT * FROM com_trade_index WHERE com_trade_id in (` + utils.GetOrmInReplace(num) + `) `
  35. _, err = o.Raw(sql, idList).QueryRows(&list)
  36. return
  37. }
  38. // GetAllComTradeIndexList 获取指标数据列表
  39. func GetAllComTradeIndexList() (list []*ComTradeIndex, err error) {
  40. o := orm.NewOrmUsingDB("data")
  41. sql := `SELECT * FROM com_trade_index ORDER BY com_trade_id DESC `
  42. _, err = o.Raw(sql).QueryRows(&list)
  43. return
  44. }
  45. // ComTradeCodeMapping 联合国商品贸易数据指标编码与分类编码的关系表
  46. type ComTradeCodeMapping struct {
  47. Code int `orm:"column(code);pk"`
  48. IndexCode string `description:"联合国商品贸易编码"`
  49. Type int `description:"1:价格;2:重量"`
  50. Name string `description:"指标名称"`
  51. CreateTime time.Time `description:"创建时间"`
  52. }
  53. // GetComTradeIndex 根据指标code获取指标信息
  54. func GetComTradeIndex(indexCode string) (item *ComTradeCodeMapping, err error) {
  55. o := orm.NewOrmUsingDB("data")
  56. sql := `SELECT * FROM com_trade_code_mapping WHERE code=? `
  57. err = o.Raw(sql, indexCode).QueryRow(&item)
  58. return
  59. }