com_trade_index.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  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. // ComTradeCodeMapping 联合国商品贸易数据指标编码与分类编码的关系表
  17. type ComTradeCodeMapping struct {
  18. Code string `orm:"column(code);pk"`
  19. IndexCode string `description:"联合国商品贸易编码"`
  20. Type int `description:"1:价格;2:重量"`
  21. Name string `description:"指标名称"`
  22. CreateTime time.Time `description:"创建时间"`
  23. }
  24. // ComTradeData 联合国商品贸易数据表
  25. type ComTradeData struct {
  26. ComTradeDataId int `orm:"column(com_trade_data_id);pk"`
  27. ComTradeId int `description:"指标id"`
  28. IndexCode string `description:"联合国商品贸易编码"`
  29. Flow string `description:"贸易流向:X(Export:出口);M(Import:进口)"`
  30. ReporterCode int `description:"出口国id"`
  31. ReporterName string `description:"出口国名称"`
  32. PartnerCode int `description:"进口国id"`
  33. PartnerName string `description:"进口国名称"`
  34. Partner2Code int `description:"第二进口国id"`
  35. Partner2Name string `description:"第二进口国名称"`
  36. DateType int `description:"日期类型,1:年度,2:月度"`
  37. DataTime string `description:"数据日期"`
  38. IndexTradeCode string `description:"离岸价编码"`
  39. TradeValue float64 `description:"离岸价(美元)"`
  40. IndexNetWeightCode string `description:"净重编码"`
  41. NetWeightValue float64 `description:"净重/公斤"`
  42. ModifyTime time.Time `description:"最新更新时间"`
  43. CreateTime time.Time `description:"创建时间"`
  44. }
  45. // ComTradeIndexAndDataResp 返回给外部使用的数据表
  46. type ComTradeIndexAndDataResp struct {
  47. IndexList []*ComTradeIndex
  48. MappingList []*ComTradeCodeMapping
  49. }
  50. // GetComTradeIndex 获取指标列表
  51. func GetComTradeIndex(startDate, endDate string) (list []*ComTradeIndex, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT * FROM com_trade_index WHERE create_time>=? AND create_time<=? ORDER BY com_trade_id ASC `
  54. _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
  55. return
  56. }
  57. // GetComTradeCodeMappingList 获取联合国商品贸易数据指标编码与分类编码的关系列表
  58. func GetComTradeCodeMappingList(startDate, endDate string) (list []*ComTradeCodeMapping, err error) {
  59. o := orm.NewOrm()
  60. sql := `SELECT * FROM com_trade_code_mapping WHERE create_time>=? AND create_time<=? ORDER BY create_time ASC `
  61. _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
  62. return
  63. }
  64. // GetComTradeDataList 获取联合国商品贸易数据列表
  65. func GetComTradeDataList(startDate, endDate string, startSize, pageSize int) (total int, list []*ComTradeData, err error) {
  66. o := orm.NewOrm()
  67. totalSql := `SELECT count(1) total FROM com_trade_data WHERE create_time>=? AND create_time<=? `
  68. err = o.Raw(totalSql, startDate, endDate).QueryRow(&total)
  69. if err != nil {
  70. return
  71. }
  72. sql := `SELECT * FROM com_trade_data WHERE create_time>=? AND create_time<=? ORDER BY com_trade_data_id ASC LIMIT ?,?`
  73. _, err = o.Raw(sql, startDate, endDate, startSize, pageSize).QueryRows(&list)
  74. return
  75. }
  76. // ComTradeIndexDataResp 分页列表响应体
  77. type ComTradeIndexDataResp struct {
  78. List []*ComTradeData
  79. Paging *paging.PagingItem `description:"分页数据"`
  80. }