76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package mline
|
|
|
|
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 ModelMline struct {
|
|
modules.MCompModel
|
|
module *Mline
|
|
}
|
|
|
|
func (this *ModelMline) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableMline
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Mline)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(comm.TableMail), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取章节信息
|
|
func (this *ModelMline) getMainlineList(uid string) (mLine []*pb.DBMline, err error) {
|
|
mLine = make([]*pb.DBMline, 0)
|
|
this.GetList(uid, &mLine)
|
|
return
|
|
}
|
|
|
|
func (this *ModelMline) getMainlineListByObj(uid string, obj string) (mLine *pb.DBMline, err error) {
|
|
mLine = &pb.DBMline{}
|
|
err = this.GetListObj(uid, obj, mLine)
|
|
return
|
|
}
|
|
|
|
// 修改章节信息
|
|
func (this *ModelMline) modifyMlineData(uid string, objId string, data map[string]interface{}) error {
|
|
return this.module.modelMline.ChangeList(uid, objId, data)
|
|
}
|
|
|
|
// 增加新的章节数据
|
|
func (this *ModelMline) addNewChapter(uId string, data *pb.DBMline) (err error) {
|
|
update := make(map[string]*pb.DBMline)
|
|
update[data.Id] = data
|
|
if err = this.AddLists(uId, update); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// 增加新的章节数据
|
|
func (this *ModelMline) cleanChapter(uId string) (err error) {
|
|
|
|
if err = this.DelByUId(uId); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 清除数据
|
|
func (this *ModelMline) cleanChapterDataById(uId string, ids ...string) (err error) {
|
|
if err = this.DelListlds(uId, ids); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return nil
|
|
}
|