1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package data_manage
- import (
- sql2 "database/sql"
- "eta/eta_task/global"
- "eta/eta_task/utils"
- "gorm.io/gorm"
- "time"
- )
- // ComTradeData 联合国商品贸易数据表
- type ComTradeData struct {
- ComTradeDataId int `gorm:"column:com_trade_data_id;primaryKey;autoIncrement"`
- 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:"创建时间"`
- }
- func (m *ComTradeData) AfterFind(db *gorm.DB) (err error) {
- m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
- return
- }
- // GetAllComTradeDataList 获取联合国商品贸易数据列表
- func GetAllComTradeDataList(startDate string) (list []*ComTradeData, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := `SELECT * FROM com_trade_data WHERE create_time>=? ORDER BY com_trade_data_id ASC `
- err = o.Raw(sql, startDate).Find(&list).Error
- return
- }
- // AddBaseFromComTradeData 添加数据
- func AddBaseFromComTradeData(item *ComTradeData) (lastId int64, err error) {
- err = global.DbMap[utils.DbNameIndex].Create(item).Error
- if err != nil {
- return
- }
- lastId = int64(item.ComTradeDataId)
- return
- }
- // MultiAddBaseFromComTradeData 批量添加数据
- func MultiAddBaseFromComTradeData(items []*ComTradeData) (lastId int64, err error) {
- num := len(items)
- if num <= 0 {
- return
- }
- o := global.DbMap[utils.DbNameIndex]
- err = o.CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- // GetBaseFromComTradeMaxDate 获取un数据中的最大日期数据
- func GetBaseFromComTradeMaxDate() (maxDate time.Time, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := ` SELECT max(a.create_time) as max_date FROM com_trade_data as a `
- var timeNull sql2.NullTime
- err = o.Raw(sql).Scan(&timeNull).Error
- if err != nil {
- return
- }
- if timeNull.Valid {
- maxDate = timeNull.Time
- }
- return
- }
|