1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Package models
- // @Author gmy 2024/8/7 9:38:00
- package models
- import (
- "eta/eta_index_lib/global"
- "eta/eta_index_lib/utils"
- "github.com/beego/beego/v2/client/orm"
- )
- type BaseFromRzdIndex struct {
- BaseFromRzdIndexId int `gorm:"column:base_from_rzd_index_id;prmaryKey"`
- //BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id);pk"`
- CreateTime string `orm:"column(create_time)"`
- ModifyTime string `orm:"column(modify_time)"`
- BaseFromLyClassifyId int `orm:"column(base_from_rzd_classify_id)"`
- IndexCode string `orm:"column(index_code)"`
- IndexName string `orm:"column(index_name)"`
- Frequency string `orm:"column(frequency)"`
- Unit string `orm:"column(unit)"`
- }
- // 在 init 函数中注册模型
- func init() {
- orm.RegisterModel(new(BaseFromRzdIndex))
- }
- // 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
- }
|