去掉不需要的引用

This commit is contained in:
meixiongfeng 2022-06-15 16:23:26 +08:00
parent 1ea06ac54d
commit 25cc58223c
8 changed files with 80 additions and 126 deletions

View File

@ -1,25 +0,0 @@
package dbservice
import (
"go_dreamfactory/modules"
"go_dreamfactory/lego/core"
)
type Api_Comp struct {
modules.MComp_GateComp
service core.IService
module *DBService
}
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options)
this.service = service
this.module = module.(*DBService)
return
}
func (this *Api_Comp) Start() (err error) {
return
}

View File

@ -1,16 +0,0 @@
package dbservice
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
)
// 邮件配置管理组件
type Configure_Comp struct {
cbase.ModuleCompBase
}
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options)
return
}

26
modules/dbservice/core.go Normal file
View File

@ -0,0 +1,26 @@
package dbservice
import (
"go_dreamfactory/lego/core"
"go.mongodb.org/mongo-driver/bson"
)
const (
WriteMaxNum uint32 = 1000 //一次性最处理条数
ErrorMaxNum uint32 = 5 // 数据库操作最大失败次数
TaskMaxNum uint32 = 1000 // 玩家离线消息队列长度
)
var (
ErrorLogCount = make(map[string]uint32, 0)
)
type QueryStruct struct {
Selector bson.M
Query bson.M
}
const (
DB_ModelTable core.SqlTable = "model_log"
)

View File

@ -6,43 +6,43 @@ import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"time"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
const (
WriteMaxNum uint32 = 1000 //一次性最处理条数
ErrorMaxNum uint32 = 5 // 数据库操作最大失败次数
)
var (
ErrorLogCount = make(map[string]uint32, 0)
)
type DB_Comp struct { type DB_Comp struct {
modules.Model_Comp modules.Model_Comp
task chan string
} }
// type data struct { func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
// Table string this.ModuleCompBase.Init(service, module, comp, options)
// Wheremap map[string]interface{} // 如果是insert 条件就是nil del 只有条件 this.task = make(chan string, TaskMaxNum)
// Modifymap map[string]map[string]interface{} return
// }
type QueryStruct struct {
Selector bson.M
Query bson.M
} }
const ( func (this *DB_Comp) Start() (err error) {
DB_ModelTable core.SqlTable = "model_log" err = this.ModuleCompBase.Start()
) go this.run()
return
}
type IModel interface { func (this *DB_Comp) run() {
Model_UpdateDBByLog() (err error) // 读取日志并更新对应的表 for {
Model_InsertDBByLog(data *comm.Autogenerated) (err error) // 插入日志 select {
case v := <-this.task:
this.Model_UpdateDBByLog(v)
case <-time.After(time.Second * 2):
this.Model_UpdateDBByLog("")
}
}
}
func (this *DB_Comp) PushUserTask(uid string) {
this.task <- uid
} }
func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) { func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {

View File

@ -1,40 +0,0 @@
package dbservice
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"time"
)
type DBService_Comp struct {
cbase.ModuleCompBase
task chan string
module *DBService
}
func (this *DBService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options)
this.module = module.(*DBService)
return
}
func (this *DBService_Comp) Start() (err error) {
err = this.ModuleCompBase.Start()
go this.run()
return
}
func (this *DBService_Comp) run() {
for {
select {
case v := <-this.task:
this.module.db_comp.Model_UpdateDBByLog(v)
case <-time.After(time.Second * 2):
this.module.db_comp.Model_UpdateDBByLog("")
}
}
}
func (this *DBService_Comp) PushUserTask(uid string) {
this.task <- uid
}

View File

@ -1,8 +1,6 @@
package dbservice package dbservice
import ( import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"os" "os"
"testing" "testing"
@ -27,20 +25,21 @@ func TestMain(m *testing.M) {
Check: false, Check: false,
Reward: false, Reward: false,
} }
module.db_comp.InsertModelLogs("mail", "uid123", _mail)
//db.InsertModelLogs("mail", "uid123", _mail) //db.InsertModelLogs("mail", "uid123", _mail)
//InsertModelLogs("mail", "uid123", _mail) //InsertModelLogs("mail", "uid123", _mail)
data := &comm.Autogenerated{ // data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), // ID: primitive.NewObjectID().Hex(),
UID: "uid123", // UID: "uid123",
Act: string(comm.LogHandleType_Insert), // Act: string(comm.LogHandleType_Insert),
} // }
data.D = append(data.D, "mail") // D[0] // data.D = append(data.D, "mail") // D[0]
data.D = append(data.D, _mail) // D[1] // data.D = append(data.D, _mail) // D[1]
_, err1 := module.db_comp.DB.InsertOne("model_log", data) // _, err1 := module.db_comp.DB.InsertOne("model_log", data)
if err1 != nil { // if err1 != nil {
log.Errorf("insert model db err %v", err1) // log.Errorf("insert model db err %v", err1)
} // }
//}() //}()
} }
time.Sleep(time.Second * 10) time.Sleep(time.Second * 10)

View File

@ -13,10 +13,7 @@ func NewModule() core.IModule {
type DBService struct { type DBService struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp db_comp *DB_Comp
db_comp *DB_Comp
db_service *DBService_Comp
configure_comp *Configure_Comp
} }
func (this *DBService) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { func (this *DBService) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
@ -31,8 +28,5 @@ func (this *DBService) GetType() core.M_Modules {
func (this *DBService) OnInstallComp() { func (this *DBService) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp) this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
this.db_service = this.RegisterComp(new(DBService_Comp)).(*DBService_Comp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
} }

View File

@ -1,6 +1,7 @@
package pack package pack
import ( import (
"go_dreamfactory/comm"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
@ -17,12 +18,27 @@ const ( //消息回复的头名称
*/ */
type Api_Comp struct { type Api_Comp struct {
modules.MComp_GateComp modules.MComp_GateComp
module *Pack service core.IService
module *Pack
mail comm.Imail
} }
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MComp_GateComp.Init(service, module, comp, options)
this.module = module.(*Pack) this.module = module.(*Pack)
return
}
func (this *Api_Comp) Start() (err error) {
err = this.MComp_GateComp.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.SM_PackModule); err != nil {
return
}
this.mail = module.(comm.Imail)
return return
} }