// @Author gmy 2024/8/7 9:38:00 package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type BaseFromLyIndex struct { BaseFromLyIndexId int `orm:"column(base_from_ly_index_id);pk"` // 指标ID CreateTime string `orm:"column(create_time)"` // 创建时间 ModifyTime string `orm:"column(modify_time)"` // 修改时间 BaseFromLyClassifyId int `orm:"column(base_from_ly_classify_id)"` // 原始数据指标分类id IndexCode string `orm:"column(index_code)"` // 指标编码 IndexName string `orm:"column(index_name)"` // 指标名称 Frequency string `orm:"column(frequency)"` // 频度 Unit string `orm:"column(unit)"` // 单位 EdbExist int `orm:"column(edb_exist)"` // 指标库是否已添加:0-否;1-是 } // 在 init 函数中注册模型 func init() { orm.RegisterModel(new(BaseFromLyIndex)) } // AddLyIndexList 批量插入指标记录列表 func AddLyIndexList(items []*BaseFromLyIndex) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.InsertMulti(len(items), items) return } // AddLyIndex 添加指标 func AddLyIndex(item *BaseFromLyIndex) (int64, error) { item.CreateTime = time.Now().Format("2006-01-02 15:04:05") o := orm.NewOrmUsingDB("data") id, err := o.Insert(item) if err != nil { return 0, err } return id, nil } // GetLyIndexByCode 查询指标编码是否存在 func GetLyIndexByCode(indexCode string) (item *BaseFromLyIndex, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_ly_index WHERE index_code=?` err = o.Raw(sql, indexCode).QueryRow(&item) return }