62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package library
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelLibrary struct {
|
|
modules.MCompModel
|
|
module *Library
|
|
}
|
|
|
|
func (this *modelLibrary) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableLibrary)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Library)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelLibrary) modifyLibraryDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// 获取列表信息
|
|
func (this *modelLibrary) getLibraryList(uid string) []*pb.DBLibrary {
|
|
libs := make([]*pb.DBLibrary, 0)
|
|
err := this.GetList(uid, &libs)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return libs
|
|
}
|
|
|
|
//创建一条信息
|
|
func (this *modelLibrary) createLibrary(uid string, fetter *pb.DBLibrary) (err error) {
|
|
|
|
if err = this.AddList(uid, fetter.Id, fetter); err != nil {
|
|
this.module.Errorf("%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 通过objid 找对应的数据
|
|
func (this *modelLibrary) getOneLibrary(uid, oid string) *pb.DBLibrary {
|
|
fetter := &pb.DBLibrary{}
|
|
err := this.GetListObj(uid, oid, fetter)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return fetter
|
|
}
|