123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- // ComTradeIndex 联合国商品贸易数据指标表
- type ComTradeIndex struct {
- ComTradeId int `orm:"column(com_trade_id);pk"`
- IndexCode string `description:"联合国商品贸易编码"`
- IndexName string `description:"联合国商品名称"`
- IndexNameCn string `description:"联合国商品名称(中文)"`
- UpdateTime time.Time `description:"数据最近更新时间"`
- CreateTime time.Time `description:"创建时间"`
- }
- // ComTradeCodeMapping 联合国商品贸易数据指标编码与分类编码的关系表
- type ComTradeCodeMapping struct {
- Code string `orm:"column(code);pk"`
- IndexCode string `description:"联合国商品贸易编码"`
- Type int `description:"1:价格;2:重量"`
- Name string `description:"指标名称"`
- CreateTime time.Time `description:"创建时间"`
- }
- // 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:"创建时间"`
- }
- // ComTradeIndexAndDataResp 返回给外部使用的数据表
- type ComTradeIndexAndDataResp struct {
- IndexList []*ComTradeIndex
- MappingList []*ComTradeCodeMapping
- }
- // GetComTradeIndex 获取指标列表
- func GetComTradeIndex(startDate, endDate string) (list []*ComTradeIndex, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM com_trade_index WHERE create_time>=? AND create_time<=? ORDER BY com_trade_id ASC `
- _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
- return
- }
- // GetComTradeCodeMappingList 获取联合国商品贸易数据指标编码与分类编码的关系列表
- func GetComTradeCodeMappingList(startDate, endDate string) (list []*ComTradeCodeMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM com_trade_code_mapping WHERE create_time>=? AND create_time<=? ORDER BY create_time ASC `
- _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
- return
- }
- // GetComTradeDataList 获取联合国商品贸易数据列表
- func GetComTradeDataList(startDate, endDate string, startSize, pageSize int) (total int, list []*ComTradeData, err error) {
- o := orm.NewOrm()
- totalSql := `SELECT count(1) total FROM com_trade_data WHERE create_time>=? AND create_time<=? `
- err = o.Raw(totalSql, startDate, endDate).QueryRow(&total)
- if err != nil {
- return
- }
- sql := `SELECT * FROM com_trade_data WHERE create_time>=? AND create_time<=? ORDER BY com_trade_data_id ASC LIMIT ?,?`
- _, err = o.Raw(sql, startDate, endDate, startSize, pageSize).QueryRows(&list)
- return
- }
- // ComTradeIndexDataResp 分页列表响应体
- type ComTradeIndexDataResp struct {
- List []*ComTradeData
- Paging *paging.PagingItem `description:"分页数据"`
- }
|