123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package data_manage
- import (
- sql2 "database/sql"
- "eta/eta_task/global"
- "eta/eta_task/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "gorm.io/gorm"
- "time"
- )
- type BaseFromTradeGuangzhouIndex struct {
- BaseFromTradeGuangzhouIndexId int `gorm:"column:base_from_trade_guangzhou_index_id;primaryKey;autoIncrement"`
- BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
- BaseFromTradeGuangzhouContractId int `description:"合约id"`
- IndexCode string `description:"指标编码"`
- IndexName string `description:"指标名称"`
- Frequency string `description:"频率"`
- Unit string `description:"单位"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- CreateTime time.Time `description:"创建日期"`
- ModifyTime time.Time `description:"修改日期"`
- Value float64 `description:"数据值"`
- }
- func (m *BaseFromTradeGuangzhouIndex) AfterFind(db *gorm.DB) (err error) {
- m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
- m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
- return
- }
- func AddBaseFromTradeGuangzhouIndex(item *BaseFromTradeGuangzhouIndex) (lastId int64, err error) {
- saveItem := *item
- o := global.DbMap[utils.DbNameIndex]
- //lastId, err = o.InsertOrUpdate(item)
- result := o.FirstOrCreate(item, "base_from_trade_guangzhou_index_id = ?", item.BaseFromTradeGuangzhouIndexId)
- if result.Error != nil {
- err = result.Error
- return
- }
- if result.RowsAffected == 0 {
- saveItem.BaseFromTradeGuangzhouIndexId = 0
- result = o.Model(item).Where("base_from_trade_guangzhou_index_id = ?", item.BaseFromTradeGuangzhouIndexId).Updates(saveItem)
- if result.Error != nil {
- err = result.Error
- return
- }
- }
- return int64(item.BaseFromTradeGuangzhouIndexId), nil
- }
- func GetBaseFromTradeGuangzhouIndexAll() (list []*BaseFromTradeGuangzhouIndex, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := `SELECT * FROM base_from_trade_guangzhou_index `
- err = o.Raw(sql).Find(&list).Error
- return
- }
- type GuangzhouIndexResp struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Data []*BaseFromTradeGuangzhouIndex
- }
- type BaseFromTradeGuangzhouClassify struct {
- BaseFromTradeGuangzhouClassifyId int `gorm:"column:base_from_trade_guangzhou_classify_id;primaryKey;autoIncrement"`
- ClassifyName string `description:"分类名称"`
- ClassifyCode string `description:"分类编码"`
- ParentId int `description:"分类父级id"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"创建时间"`
- }
- type GuangzhouClassifyResp struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Data []*BaseFromTradeGuangzhouClassify
- }
- func GetBaseFromTradeGuangzhouClassifyAll() (list []*BaseFromTradeGuangzhouClassify, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := `SELECT * FROM base_from_trade_guangzhou_classify `
- err = o.Raw(sql).Find(&list).Error
- return
- }
- func AddBaseFromTradeGuangzhouClassify(item *BaseFromTradeGuangzhouClassify) (lastId int64, err error) {
- err = global.DbMap[utils.DbNameIndex].Create(item).Error
- if err != nil {
- return
- }
- lastId = int64(item.BaseFromTradeGuangzhouClassifyId)
- return
- }
- type BaseFromTradeGuangzhouContract struct {
- BaseFromTradeGuangzhouContractId int `gorm:"column:base_from_trade_guangzhou_contract_id;primaryKey;autoIncrement"`
- BaseFromTradeGuangzhouClassifyId int `description:"分类id"`
- ClassifyCode string `description:"分类编码"`
- Contract string `description:"合约编码"`
- TradeDate string `description:"合约日期"`
- }
- func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouContract(item *BaseFromTradeGuangzhouContract) (err error) {
- err = global.DbMap[utils.DbNameIndex].Create(item).Error
- return
- }
- type GuangzhouContractResp struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Data []*BaseFromTradeGuangzhouContract
- }
- func GetBaseFromTradeGuangzhouContractAll() (list []*BaseFromTradeGuangzhouContract, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := `SELECT * FROM base_from_trade_guangzhou_contract `
- err = o.Raw(sql).Find(&list).Error
- return
- }
- // GetBaseFromTradeGuangzhouMaxDate 获取广州期货交易所最大数据
- func GetBaseFromTradeGuangzhouMaxDate() (maxDate time.Time, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := ` SELECT max(a.create_time) AS max_date FROM base_from_trade_guangzhou_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
- }
- type BaseFromTradeGuangzhouData struct {
- BaseFromTradeGuangzhouDataId int `gorm:"column:base_from_trade_guangzhou_data_id;primaryKey;autoIncrement"`
- BaseFromTradeGuangzhouIndexId int `description:"指标id"`
- IndexCode string `description:"指标编码"`
- DataTime string `description:"数据日期"`
- Value float64 `description:"数据值"`
- QtySub float64 `description:"增减"`
- CreateTime time.Time `description:"创建日期"`
- ModifyTime time.Time `description:"修改日期"`
- }
- // GetAllBaseFromTradeGuangzhouDataList 获取广州期货交易所数据
- func GetAllBaseFromTradeGuangzhouDataList(startDate string) (list []*BaseFromTradeGuangzhouData, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := `SELECT * FROM base_from_trade_guangzhou_data WHERE create_time>=? ORDER BY base_from_trade_guangzhou_data_id ASC `
- err = o.Raw(sql, startDate).Find(&list).Error
- return
- }
- type BaseFromTradeGuangzhouDataResp struct {
- Ret int
- Msg string
- ErrMsg string
- ErrCode string
- Data BaseFromTradeGuangzhouIndexAndDataResp
- }
- // BaseFromTradeGuangzhouIndexAndDataResp 分页列表响应体
- type BaseFromTradeGuangzhouIndexAndDataResp struct {
- List []*BaseFromTradeGuangzhouData
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // MultiAddBaseFromTradeGuangzhouData 批量添加数据
- func MultiAddBaseFromTradeGuangzhouData(items []*BaseFromTradeGuangzhouData) (lastId int64, err error) {
- num := len(items)
- if num <= 0 {
- return
- }
- o := global.DbMap[utils.DbNameIndex]
- err = o.CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
|