This commit is contained in:
parent
8fc078e3c9
commit
7d22149037
|
@ -2319,7 +2319,7 @@ func (m *Mongo) CreateStreamer(ctx *gin.Context, streamer *dbstruct.Streamer) er
|
|||
|
||||
func (m *Mongo) UpdateStreamer(ctx *gin.Context, streamer *dbstruct.Streamer) error {
|
||||
col := m.getColStreamer()
|
||||
set := util.EntityToM(streamer)
|
||||
set := util.DeepEntityToM(streamer)
|
||||
set["ut"] = time.Now().Unix()
|
||||
filter := qmgo.M{
|
||||
"mid": util.DerefInt64(streamer.Mid),
|
||||
|
|
|
@ -35,6 +35,23 @@ func StringToMd5(s string) string {
|
|||
|
||||
// 将实体类结构体指针转为bson.M,采用反射
|
||||
func EntityToM(p any) qmgo.M {
|
||||
set := qmgo.M{}
|
||||
pType := reflect.TypeOf(p).Elem()
|
||||
pVal := reflect.ValueOf(p).Elem()
|
||||
for i := 0; i < pType.NumField(); i++ {
|
||||
name := pType.Field(i).Tag.Get("bson")
|
||||
if name != "" {
|
||||
field := pVal.Field(i)
|
||||
if name != "_id" && !field.IsNil() {
|
||||
value := field.Elem().Interface()
|
||||
set[name] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func DeepEntityToM(p any) qmgo.M {
|
||||
set := qmgo.M{}
|
||||
pType := reflect.TypeOf(p).Elem()
|
||||
pVal := reflect.ValueOf(p).Elem()
|
||||
|
|
Loading…
Reference in New Issue