com_trade_data.go 2.7 KB

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