func (msg *UserMsgItem) SafeMapTimeoutCall(key interface{}) { // 超时未删除则保存到db c := common.MongoCollection(MSG_DB, MSG_USER_MSG_TABLE) if err := c.Insert(msg); err != nil { syslog.Info(err, *msg) } }
func DeleteUserDetailInfoByUid(uid uint64) error { c := common.MongoCollection("dudb", "user_detail_info") if err := c.Remove(bson.M{"uid": uid}); err != nil { return errors.As(err, uid) } return nil }
func DeleteUserInfoByUid(uid uint64) error { c := common.MongoCollection(USER_DB, USER_INFO_TABLE) if err := c.Remove(bson.M{"uid": uid}); err != nil { return errors.As(err, uid) } return nil }
func SetUserInfo(sel, set map[string]interface{}) error { c := common.MongoCollection(USER_DB, USER_INFO_TABLE) if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil { return errors.As(err, sel, set) } return nil }
func SetUserDetailInfo(sel, set map[string]interface{}) error { c := common.MongoCollection("dudb", "user_detail_info") if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil { return errors.As(err, sel, set) } return nil }
func SetTeamMember(sel, set map[string]interface{}) error { c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE) if err := c.Update(bson.M(sel), bson.M{"$set": bson.M(set)}); err != nil { return errors.As(err, sel, set) } return nil }
func deleteFile(filelist []string) error { c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE) _, err := c.RemoveAll(bson.M{"filename": bson.M{"$in": filelist}}) if err != nil && err != mgo.ErrNotFound { return errors.As(err, filelist) } return nil }
func GetUserCount() (uint64, error) { c := common.MongoCollection(USER_DB, USER_INFO_TABLE) count, err := c.Find(nil).Count() if err != nil { return 0, errors.As(err) } return uint64(count), nil }
func GetTeamList(sel map[string]interface{}, start, count int) ([]TeamInfo, error) { c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE) team_list := []TeamInfo{} err := c.Find(bson.M(sel)).Skip(start).Limit(count).All(&team_list) return team_list, errors.As(err, sel) }
func GetUserDetailInfoByUid(uid uint64) (*UserDetailInfo, error) { user := &UserDetailInfo{} c := common.MongoCollection("dudb", "user_detail_info") if err := c.Find(bson.M{"uid": uid}).One(user); err != nil { return nil, errors.As(err, uid) } return user, nil }
func SaveUserDetailInfo(user *UserDetailInfo) error { c := common.MongoCollection("dudb", "user_detail_info") if err := c.Insert(user); err != nil { return errors.As(err, *user) } return nil }
func UserMsgInit() error { c := common.MongoCollection(MSG_DB, MSG_USER_MSG_TABLE) index := mgo.Index{ Key: []string{"touid", "msgid"}, } return errors.As(c.EnsureIndex(index)) }
func DeleteTeamMember(teamid, uid uint64) error { c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE) err := c.Remove(bson.M{"teamid": teamid, "uid": uid}) if err != mgo.ErrNotFound { return errors.As(err, uid, teamid) } return nil }
func GetUserInfo(sel map[string]interface{}) (*UserInfo, error) { c := common.MongoCollection(USER_DB, USER_INFO_TABLE) user := &UserInfo{} if err := c.Find(bson.M(sel)).One(user); err != nil { return nil, errors.As(err, sel) } return user, nil }
func DeleteTeam(teamid uint64) error { c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE) err := c.Remove(bson.M{"teamid": teamid}) if err != mgo.ErrNotFound { return errors.As(err, teamid) } return nil }
func DeleteFriend(uid, fid uint64) error { c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE) err := c.Remove(bson.M{"fuid": fid, "uid": uid}) if err != mgo.ErrNotFound { return errors.As(err, fid) } return nil }
func addFile(file *File) error { c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE) sel := bson.M{"filename": file.Filename} set := bson.M{ "$set": bson.M{"expiredtime": file.ExpiredTime}, "$setOnInsert": bson.M{"createtime": file.CreateTime}, } _, err := c.Upsert(sel, set) return errors.As(err, *file) }
func FriendInit() error { c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE) index := mgo.Index{ Key: []string{"uid", "fuid"}, Unique: true, DropDups: true, } return errors.As(c.EnsureIndex(index)) }
func TeamMemberInit() error { c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE) index := mgo.Index{ Key: []string{"teamid", "uid"}, Unique: true, DropDups: true, } return errors.As(c.EnsureIndex(index)) }
func GetNextUserId() (uint64, error) { c := common.MongoCollection(USER_DB, USER_INFO_TABLE) userInfo := &UserInfo{} if err := c.Find(nil).Sort("-uid").One(&userInfo); err != nil { if err == mgo.ErrNotFound { return uint64(MIN_USER_ID), nil } return 0, errors.As(err) } return userInfo.Uid + 1, nil }
func AddFriend(friend *Friend) error { //sel := map[string]interface{}{"uid":friend.Uid, "fuid":friend.FUid} //set := map[string]interface{}{"type":friend.Type} if err := DeleteFriend(friend.Uid, friend.FUid); err != nil { return errors.As(err, *friend) } c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE) friend.CreateDT = time.Now().Format(common.DATETIME_FMT) friend.UpdateDT = time.Now().Format(common.DATETIME_FMT) return errors.As(c.Insert(friend), *friend) }
func GetFriendList(uid uint64, typ int) ([]uint64, error) { c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE) friend := &Friend{} uids := []uint64{} iter := c.Find(bson.M{"uid": uid, "type": typ}).Iter() defer iter.Close() for iter.Next(friend) { uids = append(uids, friend.FUid) } return uids, nil }
func GetFriend(uid, fid uint64) *Friend { c := common.MongoCollection(USER_DB, USER_FRIEND_TABLE) friend := &Friend{} iter := c.Find(bson.M{"fuid": fid, "uid": uid}).Iter() defer iter.Close() if iter.Next(friend) { return friend } return nil }
func GetTeamMember(teamid, uid uint64) *TeamMember { c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE) tm := &TeamMember{} iter := c.Find(bson.M{"teamid": teamid, "uid": uid}).Iter() defer iter.Close() if iter.Next(tm) { return tm } return nil }
func GetTeam(teamid uint64) *TeamInfo { c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE) team := &TeamInfo{} iter := c.Find(bson.M{"teamid": teamid}).Iter() defer iter.Close() if iter.Next(team) { return team } return nil }
func GetSysTeamList() ([]TeamInfo, error) { c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE) teamList := []TeamInfo{} team := &TeamInfo{} iter := c.Find(bson.M{"teamtype": 1}).Iter() defer iter.Close() for iter.Next(team) { teamList = append(teamList, *team) } return teamList, nil }
func (this *FileMgr) RemoveExpiredFile() error { c := common.MongoCollection(FILE_DB, FILE_QINIU_FILE_TABLE) expiredTime := time.Now().Unix() iter := c.Find(bson.M{"expiredtime": bson.M{"$lt": expiredTime}}).Iter() defer iter.Close() file := &File{} keys := []string{} for iter.Next(file) { keys = append(keys, file.Filename) } QiniuDeleteFiles(keys) return nil }
func UserInfoInit() error { c := common.MongoCollection(USER_DB, USER_INFO_TABLE) index := mgo.Index{ Key: []string{"uid"}, Unique: true, DropDups: true, Background: true, } if err := c.EnsureIndex(index); err != nil { return errors.As(err, index) } return nil }
func UserDetailInfoInit() error { c := common.MongoCollection("dudb", "user_detail_info") index := mgo.Index{ Key: []string{"uid"}, Unique: true, DropDups: true, Background: true, } if err := c.EnsureIndex(index); err != nil { return errors.As(err, index) } return nil }
func GetTeamMemberList(teamid uint64) ([]uint64, error) { c := common.MongoCollection(TEAM_DB, TEAM_MEMBER_TABLE) tm := &TeamMember{} uids := []uint64{} iter := c.Find(bson.M{"teamid": teamid}).Iter() defer iter.Close() for iter.Next(tm) { uids = append(uids, tm.Uid) } return uids, nil }