1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package bus
- import (
- "assetcenter/db"
- "assetcenter/db/repo"
- "context"
- "errors"
- "time"
- "github.com/nats-io/nats.go"
- "infish.cn/comm"
- )
- func newReplayer() *comm.NatsMsgReplyer {
- return &comm.NatsMsgReplyer{
- Subject: "queentree.asset.op.enable",
- Entity: func() interface{} { return &comm.PublicAssetReq{} },
- Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
- req := entity.(*comm.PublicAssetReq)
- asset := &struct {
- Enable *bool `bson:"enable,omitempty" json:"enable"`
- CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
- UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
- }{
- Enable: &req.Enable,
- }
- if *asset.Enable {
- asset.CreateTime = time.Now()
- }
- ctx := &repo.RepoSession{
- Ctx: context.Background(),
- Client: db.MongoClient,
- }
- //跟新数据库状态
- dbConf := repo.GetDatabaseCollectionSimple(ctx, req.DbId, req.DefineId)
- if dbConf == nil || len(dbConf.Db.Name) < 1 {
- return false, errors.New("db con err")
- }
- asset.UpdateTime = time.Now()
- id := req.Id
- collectionName := dbConf.AssetConf.Collection
- ret, err := repo.RepoUpdateSeDbDoc(ctx, dbConf.Db.Name, collectionName, id, asset)
- if err != nil {
- return false, err
- }
- return ret, nil
- },
- }
- }
|