com_trade_data.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ComTradeData 联合国商品贸易数据表
  7. type ComTradeData struct {
  8. ComTradeDataId int `orm:"column(com_trade_data_id);pk"`
  9. ComTradeId int `description:"指标id"`
  10. IndexCode string `description:"联合国商品贸易编码"`
  11. Flow string `description:"贸易流向:X(Export:出口);M(Import:进口)"`
  12. ReporterCode int `description:"出口国id"`
  13. ReporterName string `description:"出口国名称"`
  14. PartnerCode int `description:"进口国id"`
  15. PartnerName string `description:"进口国名称"`
  16. Partner2Code int `description:"第二进口国id"`
  17. Partner2Name string `description:"第二进口国名称"`
  18. DateType int `description:"日期类型,1:年度,2:月度"`
  19. DataTime string `description:"数据日期"`
  20. IndexTradeCode string `description:"离岸价编码"`
  21. TradeValue float64 `description:"离岸价(美元)"`
  22. IndexNetWeightCode string `description:"净重编码"`
  23. NetWeightValue float64 `description:"净重/公斤"`
  24. ModifyTime time.Time `description:"最新更新时间"`
  25. CreateTime time.Time `description:"创建时间"`
  26. }
  27. // GetAllComTradeDataList 获取联合国商品贸易数据列表
  28. func GetAllComTradeDataList(startDate string) (list []*ComTradeData, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT * FROM com_trade_data WHERE create_time>=? ORDER BY com_trade_data_id ASC `
  31. _, err = o.Raw(sql, startDate).QueryRows(&list)
  32. return
  33. }
  34. // AddBaseFromComTradeData 添加数据
  35. func AddBaseFromComTradeData(item *ComTradeData) (lastId int64, err error) {
  36. o := orm.NewOrm()
  37. lastId, err = o.Insert(item)
  38. return
  39. }
  40. // MultiAddBaseFromComTradeData 批量添加数据
  41. func MultiAddBaseFromComTradeData(items []*ComTradeData) (lastId int64, err error) {
  42. num := len(items)
  43. if num <= 0 {
  44. return
  45. }
  46. o := orm.NewOrm()
  47. lastId, err = o.InsertMulti(num, items)
  48. return
  49. }
  50. // GetBaseFromComTradeMaxDate 获取un数据中的最大日期数据
  51. func GetBaseFromComTradeMaxDate() (max_date time.Time, err error) {
  52. o := orm.NewOrm()
  53. sql := ` SELECT max(a.create_time)as max_date FROM com_trade_data as a `
  54. err = o.Raw(sql).QueryRow(&max_date)
  55. return
  56. }