51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package svc
|
|
|
|
import (
|
|
"errors"
|
|
"net/rpc"
|
|
|
|
"github.com/globalsign/mgo"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
"mongo.games.com/game/dbproxy/mongo"
|
|
"mongo.games.com/game/model"
|
|
)
|
|
|
|
var ErrCustomLogAwardNotFound = errors.New("CustomLogAward not found")
|
|
|
|
func DbCustomLogAwardCollection(plt string) *mongo.Collection {
|
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, model.DbCustomLogAwardDBName)
|
|
if s != nil {
|
|
d, first := s.DB().C(model.DbCustomLogAwardCollName)
|
|
if first {
|
|
d.EnsureIndex(mgo.Index{Key: []string{"cycleid"}, Background: true, Sparse: true})
|
|
d.EnsureIndex(mgo.Index{Key: []string{"-startts", "cycleid"}, Background: true, Sparse: true})
|
|
d.EnsureIndex(mgo.Index{Key: []string{"startts"}, Background: true, Sparse: true})
|
|
d.EnsureIndex(mgo.Index{Key: []string{"endts"}, Background: true, Sparse: true})
|
|
d.EnsureIndex(mgo.Index{Key: []string{"-endts"}, Background: true, Sparse: true})
|
|
d.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true})
|
|
}
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type DBCustomLogAwardSvc struct {
|
|
}
|
|
|
|
func (this *DBCustomLogAwardSvc) Find(req *model.CustomLogAwardFindReq, res *model.CustomLogAwardFindRes) error {
|
|
c := DbCustomLogAwardCollection(req.Platform)
|
|
if c == nil {
|
|
return ErrCustomLogAwardNotFound
|
|
}
|
|
|
|
if err := c.Find(bson.M{"startts": bson.M{"$gte": req.StartTs, "$lte": req.EndTs}}).Sort("startts").All(&res.List); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
rpc.Register(new(DBCustomLogAwardSvc))
|
|
}
|