Пример #1
0
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)
	}
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
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
}
Пример #5
0
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
}
Пример #6
0
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
}
Пример #7
0
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
}
Пример #8
0
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
}
Пример #9
0
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)
}
Пример #10
0
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
}
Пример #11
0
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
}
Пример #12
0
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))
}
Пример #13
0
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
}
Пример #14
0
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
}
Пример #15
0
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
}
Пример #16
0
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
}
Пример #17
0
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)
}
Пример #18
0
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))
}
Пример #19
0
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))
}
Пример #20
0
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
}
Пример #21
0
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)
}
Пример #22
0
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
}
Пример #23
0
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
}
Пример #24
0
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
}
Пример #25
0
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
}
Пример #26
0
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

}
Пример #27
0
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
}
Пример #28
0
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
}
Пример #29
0
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
}
Пример #30
0
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
}