This commit is contained in:
zhaocy 2022-06-14 15:32:41 +08:00
parent 924da6fdd8
commit d373a401de
2 changed files with 25 additions and 4 deletions

View File

@ -6,9 +6,18 @@ import (
"go_dreamfactory/lego/sys/redis" "go_dreamfactory/lego/sys/redis"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
"go.mongodb.org/mongo-driver/bson"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Action string
const (
INSERT Action = "insert"
UPDATE Action = "update"
DELETE Action = "delete"
)
type DBModel struct { type DBModel struct {
*MComp_DBComp *MComp_DBComp
pbData proto.Message pbData proto.Message
@ -37,13 +46,21 @@ func (m *DBModel) SetTableName(tableName string) {
m.tableName = tableName m.tableName = tableName
} }
func (m *DBModel) OnChange() { func (m *DBModel) OnChange(key string) {
m.MComp_DBComp.InsertModelLogs(m.tableName, key, m.pbData)
} }
func (m *DBModel) Set(key string, val interface{}) { func (m *DBModel) Set(key string, act Action) {
//调用写入mongo日志接口 //调用写入mongo日志接口
switch act {
case INSERT:
m.MComp_DBComp.InsertModelLogs(m.tableName, key, m.pbData)
case UPDATE:
m.MComp_DBComp.UpdateModelLogs(m.tableName, key, bson.M{"_id": key}, m.pbData)
case DELETE:
m.MComp_DBComp.DeleteModelLogs(m.tableName, key, bson.M{"_id": key})
}
} }
//获取数据 //获取数据

View File

@ -2,6 +2,8 @@ package user
import ( import (
"fmt" "fmt"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"os" "os"
@ -23,7 +25,9 @@ func TestMain(m *testing.M) {
} }
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
// userModel := NewUserModel() userModel := NewUserModel()
userModel.SetData(&pb.DB_UserData{Name: "aaaaa"})
userModel.Set("1_62a729fc0e01ab2819553242", modules.INSERT)
// userModel.Set("1_62a729fc0e01ab2819553242",) // userModel.Set("1_62a729fc0e01ab2819553242",)
// fmt.Printf("%v", userModel.GetData().(*pb.Cache_UserData)) // fmt.Printf("%v", userModel.GetData().(*pb.Cache_UserData))
} }