github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/central/mongo/service/impl/impl_org.go (about) 1 package impl 2 3 import ( 4 "github.com/sixexorg/magnetic-ring/central/entity" 5 "github.com/sixexorg/magnetic-ring/central/mongo" 6 "github.com/sixexorg/magnetic-ring/central/mongokey" 7 "github.com/sixexorg/magnetic-ring/common" 8 "gopkg.in/mgo.v2/bson" 9 ) 10 11 type LeagueHeightImpl struct { 12 Heightor *entity.LeagueHeightor 13 LeagueId common.Address 14 } 15 16 func NewLeagueHeightImpl(heightor *entity.LeagueHeightor,orgid common.Address) *LeagueHeightImpl { 17 return &LeagueHeightImpl{heightor,orgid} 18 } 19 20 func (svc *LeagueHeightImpl) Insert() error { 21 session,col := mongo.KeyProvider(mongokey.COL_LEAGUE_HEIGHT) 22 defer session.Close() 23 24 if svc.Heightor.Id == "" { 25 svc.Heightor.Id = svc.LeagueId.ToString() 26 } 27 28 return col.Insert(svc.Heightor) 29 } 30 31 func (svc *LeagueHeightImpl) UpdateById(address common.Address,newHeight uint64) error { 32 session,col := mongo.KeyProvider(mongokey.COL_LEAGUE_HEIGHT) 33 defer session.Close() 34 //svc.Heightor.Height=newHeight 35 36 return col.Update(bson.M{"id":address.ToString()},bson.M{"$set":bson.M{"height":newHeight}}) 37 } 38 39 func (svc *LeagueHeightImpl) GetHeightor()(*entity.LeagueHeightor,error) { 40 session,col := mongo.KeyProvider(mongokey.COL_LEAGUE_HEIGHT) 41 defer session.Close() 42 43 htor := new(entity.LeagueHeightor) 44 err := col.Find(bson.M{"id":svc.LeagueId.ToString()}).One(htor) 45 if err != nil { 46 return nil,err 47 } 48 return htor,nil 49 }