Merge pull request '1' (#622) from feat-IRONFANS-163-Robin into test

Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/622
This commit is contained in:
chenhao 2024-07-17 17:13:17 +08:00
commit 4b023d0fc5
2 changed files with 18 additions and 1 deletions

View File

@ -2756,7 +2756,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),

View File

@ -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()