12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- // 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 BaseFromLyIndex struct {
- BaseFromLyIndexId int `gorm:"column:base_from_ly_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;"` // 修改时间
- BaseFromLyClassifyId int `gorm:"column:base_from_ly_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:单位;"` // 单位
- EdbExist int `gorm:"column:edb_exist;type:tinyint(4) UNSIGNED;comment:指标库是否已添加:0-否;1-是;not null;default:0;"` // 指标库是否已添加:0-否;1-是
- 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;"` // 数据最新值
- }
- // AddLyIndexList 批量插入指标记录列表
- func AddLyIndexList(items []*BaseFromLyIndex) (err error) {
- //o := orm.NewOrm()
- //_, err = o.InsertMulti(len(items), items)
- err = global.DEFAULT_DB.CreateInBatches(items, len(items)).Error
- return
- }
- // AddLyIndex 添加指标
- func AddLyIndex(item *BaseFromLyIndex) (int64, error) {
- item.CreateTime = time.Now()
- //o := orm.NewOrm()
- //id, err := o.Insert(item)
- err := global.DEFAULT_DB.Create(item).Error
- if err != nil {
- return 0, err
- }
- id := int64(item.BaseFromLyIndexId)
- return id, nil
- }
- // GetLyIndexByCode 查询指标编码是否存在
- func GetLyIndexByCode(indexCode string) (item *BaseFromLyIndex, err error) {
- //o := orm.NewOrm()
- sql := `SELECT * FROM base_from_ly_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
- }
|