github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/central/mongo/service/impl/impl_org_chat_msg.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 "gopkg.in/mgo.v2/bson" 8 ) 9 10 type OrgChatMsgImpl struct { 11 ChatMsgs []interface{} 12 LeagueId string 13 } 14 15 func NewOrgChatMsgImpl(txs []interface{}, orgid string) *OrgChatMsgImpl { 16 return &OrgChatMsgImpl{txs, orgid} 17 } 18 19 func (svc *OrgChatMsgImpl) Insert() error { 20 leaguetxnskey := mongokey.NewLeagueTxnsPrefixKey(svc.LeagueId) 21 session, col := mongo.KeyProvider(leaguetxnskey) 22 defer session.Close() 23 return col.Insert(svc.ChatMsgs...) 24 } 25 26 func (svc *OrgChatMsgImpl) GetChatList(page,size int) (int,interface{}, error) { 27 leaguetxnskey := mongokey.NewLeagueTxnsPrefixKey(svc.LeagueId) 28 session, col := mongo.KeyProvider(leaguetxnskey) 29 defer session.Close() 30 31 if page <= 0 { 32 page = 1 33 } 34 35 skip := size * (page-1) 36 37 var htor []*entity.OrgChatDto 38 query := col.Find(bson.M{}) 39 40 total,err := query.Count() 41 42 if err != nil { 43 return 0,nil, err 44 } 45 46 err = query.Sort("-blockTime").Skip(skip).Limit(size).All(&htor) 47 if err != nil { 48 return 0,nil, err 49 } 50 51 52 return total,htor, nil 53 }