1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- // Package models
- // @Author gmy 2024/8/7 9:38:00
- package models
- import (
- "eta/eta_index_lib/global"
- "eta/eta_index_lib/utils"
- "time"
- )
- type BaseFromRzdIndex struct {
- BaseFromRzdIndexId int `gorm:"column:base_from_rzd_index_id;type:int(11);primaryKey;not null;"`
- CreateTime time.Time `gorm:"column:create_time;type:datetime;comment:创建时间;not null;default:CURRENT_TIMESTAMP;"` // 创建时间
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime;comment:修改时间;not null;default:CURRENT_TIMESTAMP;"` // 修改时间
- BaseFromRzdClassifyId int `gorm:"column:base_from_rzd_classify_id;type:int(11) UNSIGNED;comment:原始数据指标分类id;not null;default:0;"` // 原始数据指标分类id
- IndexCode string `gorm:"column:index_code;type:varchar(255);comment:指标编码;"` // 指标编码
- IndexName string `gorm:"column:index_name;type:varchar(255);comment:指标名称;"` // 指标名称
- Frequency string `gorm:"column:frequency;type:varchar(20);comment:频度;"` // 频度
- Unit string `gorm:"column:unit;type:varchar(30);comment:单位;"` // 单位
- StartDate time.Time `gorm:"column:start_date;type:date;comment:数据开始日期;default:NULL;"` // 数据开始日期
- EndDate time.Time `gorm:"column:end_date;type:date;comment:数据结束日期;default:NULL;"` // 数据结束日期
- LatestValue float64 `gorm:"column:latest_value;type:double;comment:数据最新值;default:NULL;"` // 数据最新值
- }
- // AddRzdIndexList 批量插入指标记录列表
- func AddRzdIndexList(items []*BaseFromRzdIndex) (err error) {
- //o := orm.NewOrm()
- //_, err = o.InsertMulti(len(items), items)
- err = global.DEFAULT_DB.CreateInBatches(items, len(items)).Error
- return
- }
- // AddRzdIndex 添加指标
- func AddRzdIndex(item *BaseFromRzdIndex) (int64, error) {
- //o := orm.NewOrm()
- //id, err := o.Insert(item)
- err := global.DEFAULT_DB.Create(&item).Error
- if err != nil {
- return 0, err
- }
- id := int64(item.BaseFromRzdIndexId)
- return id, nil
- }
- // GetRzdIndexByCode 查询指标编码是否存在
- func GetRzdIndexByCode(indexCode string) (item *BaseFromRzdIndex, err error) {
- //o := orm.NewOrm()
- sql := `SELECT * FROM base_from_rzd_index WHERE index_code=?`
- //err = o.Raw(sql, indexCode).QueryRow(&item)
- err = global.DEFAULT_DB.Raw(sql, indexCode).First(&item).Error
- if utils.IsErrNoRow(err) {
- return nil, nil
- }
- return
- }
|