// Package models // @Author gmy 2024/8/7 9:38:00 package models import ( "errors" "github.com/beego/beego/v2/client/orm" ) type BaseFromRzdIndex struct { 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) return } // AddRzdIndex 添加指标 func AddRzdIndex(item *BaseFromRzdIndex) (int64, error) { o := orm.NewOrm() id, err := o.Insert(item) if err != nil { return 0, err } 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) if errors.Is(err, orm.ErrNoRows) { return nil, nil } return }