forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package agentSer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"stat/common/log"
|
||||
"stat/common/utils"
|
||||
"stat/models/channelmod"
|
||||
)
|
||||
|
||||
func RepairData() {
|
||||
wg := utils.NewWaitGroup()
|
||||
wg.Add(func() {
|
||||
ctx := context.Background()
|
||||
if err := FixChannelSecondParentAgent(ctx); err != nil {
|
||||
log.Error("fix data err", log.E(err))
|
||||
}
|
||||
})
|
||||
go wg.RunWaits()
|
||||
}
|
||||
|
||||
func FixChannelSecondParentAgent(ctx context.Context) error {
|
||||
filter := bson.M{
|
||||
channelmod.FN.ChannelInfo.Type: channelmod.ChannelTypeSecond,
|
||||
"$or": bson.A{
|
||||
bson.M{channelmod.FN.ChannelInfo.ParentAgent: bson.M{"$eq": nil}},
|
||||
bson.M{channelmod.FN.ChannelInfo.ParentAgent: bson.M{"$exists": false}},
|
||||
bson.M{channelmod.FN.ChannelInfo.ParentAgent: bson.M{"$eq": ""}},
|
||||
},
|
||||
channelmod.FN.ChannelInfo.ParentChannel: bson.M{"$gt": ""},
|
||||
}
|
||||
count, err := channelmod.CountChannelInfos(ctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
return nil
|
||||
}
|
||||
// 修复
|
||||
channels, err := channelmod.FindManyChannelInfo(ctx, filter)
|
||||
for _, channel := range channels {
|
||||
filter := bson.M{channelmod.FN.ChannelInfo.Channel: channel.Channel}
|
||||
update := bson.M{"$set": bson.M{
|
||||
channelmod.FN.ChannelInfo.ParentAgent: channel.ParentChannel,
|
||||
}}
|
||||
if err = channelmod.UpdateOneChannelInfo(ctx, filter, update); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user