package data_manage import ( "github.com/beego/beego/v2/client/orm" "time" ) // ComTradeData 联合国商品贸易数据表 type ComTradeData struct { ComTradeDataId int `orm:"column(com_trade_data_id);pk"` ComTradeId int `description:"指标id"` IndexCode string `description:"联合国商品贸易编码"` Flow string `description:"贸易流向:X(Export:出口);M(Import:进口)"` ReporterCode int `description:"出口国id"` ReporterName string `description:"出口国名称"` PartnerCode int `description:"进口国id"` PartnerName string `description:"进口国名称"` Partner2Code int `description:"第二进口国id"` Partner2Name string `description:"第二进口国名称"` DateType int `description:"日期类型,1:年度,2:月度"` DataTime string `description:"数据日期"` IndexTradeCode string `description:"离岸价编码"` TradeValue float64 `description:"离岸价(美元)"` IndexNetWeightCode string `description:"净重编码"` NetWeightValue float64 `description:"净重/公斤"` ModifyTime time.Time `description:"最新更新时间"` CreateTime time.Time `description:"创建时间"` } // GetAllComTradeDataList 获取联合国商品贸易数据列表 func GetAllComTradeDataList(startDate string) (list []*ComTradeData, err error) { o := orm.NewOrm() sql := `SELECT * FROM com_trade_data WHERE create_time>=? ORDER BY com_trade_data_id ASC ` _, err = o.Raw(sql, startDate).QueryRows(&list) return } // AddBaseFromComTradeData 添加数据 func AddBaseFromComTradeData(item *ComTradeData) (lastId int64, err error) { o := orm.NewOrm() lastId, err = o.Insert(item) return } // MultiAddBaseFromComTradeData 批量添加数据 func MultiAddBaseFromComTradeData(items []*ComTradeData) (lastId int64, err error) { num := len(items) if num <= 0 { return } o := orm.NewOrm() lastId, err = o.InsertMulti(num, items) return } // GetBaseFromComTradeMaxDate 获取un数据中的最大日期数据 func GetBaseFromComTradeMaxDate() (max_date time.Time, err error) { o := orm.NewOrm() sql := ` SELECT max(a.create_time)as max_date FROM com_trade_data as a ` err = o.Raw(sql).QueryRow(&max_date) return }