|
|
@ -12,6 +12,7 @@ import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/gogo/protobuf/sortkeys"
|
|
|
|
"github.com/gogo/protobuf/sortkeys"
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
"math/rand"
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
|
|
|
|
//"github.com/garyburd/redigo/redis"
|
|
|
|
//"github.com/garyburd/redigo/redis"
|
|
|
@ -435,27 +436,22 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Tag struct {
|
|
|
|
type Tag struct {
|
|
|
|
|
|
|
|
UserID string `bson:"userID"`
|
|
|
|
TagID string `bson:"tagID"`
|
|
|
|
TagID string `bson:"tagID"`
|
|
|
|
TagName string `bson:"tagName"`
|
|
|
|
TagName string `bson:"tagName"`
|
|
|
|
UserList []string `bson:"userList"`
|
|
|
|
UserList []string `bson:"userList"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type TagsStruct struct {
|
|
|
|
|
|
|
|
Uid string `bson:"uid"`
|
|
|
|
|
|
|
|
Tags map[string]Tag `bson:"tags"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type TagSendLogStruct struct {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (d *DataBases) GetUserTags(userID string) ([]Tag, error) {
|
|
|
|
func (d *DataBases) GetUserTags(userID string) ([]Tag, error) {
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
var tagStruct TagsStruct
|
|
|
|
|
|
|
|
var tags []Tag
|
|
|
|
var tags []Tag
|
|
|
|
_ = c.FindOne(ctx, bson.M{"uid": userID}).Decode(&tagStruct)
|
|
|
|
cursor, err := c.Find(ctx, bson.M{"userID": userID})
|
|
|
|
for _, v := range tagStruct.Tags {
|
|
|
|
if err != nil {
|
|
|
|
tags = append(tags, v)
|
|
|
|
return tags, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = cursor.Decode(tags); err != nil {
|
|
|
|
|
|
|
|
return tags, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tags, nil
|
|
|
|
return tags, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -465,58 +461,68 @@ func (d *DataBases) CreateTag(userID, tagName string, userList []string) error {
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
tagID := generateTagID(tagName, userID)
|
|
|
|
tagID := generateTagID(tagName, userID)
|
|
|
|
tag := Tag{
|
|
|
|
tag := Tag{
|
|
|
|
|
|
|
|
UserID: userID,
|
|
|
|
TagID: tagID,
|
|
|
|
TagID: tagID,
|
|
|
|
TagName: tagName,
|
|
|
|
TagName: tagName,
|
|
|
|
UserList: userList,
|
|
|
|
UserList: userList,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err := c.InsertOne(ctx, TagsStruct{
|
|
|
|
_, err := c.InsertOne(ctx, tag)
|
|
|
|
Uid: userID,
|
|
|
|
|
|
|
|
Tags: map[string]Tag{tagID: tag},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *DataBases) DeleteTag(userID, tagID string) error {
|
|
|
|
func (d *DataBases) DeleteTag(userID, tagID string) error {
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
_, err := c.DeleteOne(ctx, bson.M{"uid": userID, "tags": bson.M{"$unset": tagID}})
|
|
|
|
_, err := c.DeleteOne(ctx, bson.M{"userID": userID, "tagID": tagID})
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserList []string, reduceUserIDList []string) error {
|
|
|
|
func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
_, err := c.UpdateOne(ctx, bson.M{"uid": userID, "tags": tagID}, bson.M{"tagName": newName})
|
|
|
|
var tag Tag
|
|
|
|
if err != nil {
|
|
|
|
err := c.FindOne(ctx, bson.M{"tagID": tagID, "userID": userID}).Decode(&tag)
|
|
|
|
return err
|
|
|
|
if newName != "" {
|
|
|
|
|
|
|
|
_, err = c.UpdateOne(ctx, bson.M{"userID": userID, "tagID": tagID}, bson.D{
|
|
|
|
|
|
|
|
{"$set", bson.D{
|
|
|
|
|
|
|
|
{"tagName", newName},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err = c.InsertOne(ctx, bson.M{"uid": userID, "tags": bson.M{tagID: ""}})
|
|
|
|
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
|
|
|
|
|
|
|
tag.UserList = utils.RemoveUserIDRepByMap(tag.UserList)
|
|
|
|
|
|
|
|
for _, v := range reduceUserIDList {
|
|
|
|
|
|
|
|
for i2, v2 := range tag.UserList {
|
|
|
|
|
|
|
|
if v == v2 {
|
|
|
|
|
|
|
|
tag.UserList = append(tag.UserList[:i2], tag.UserList[i2+1:]...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.UpdateOne(ctx, bson.M{"userID": userID, "tagID": tagID}, bson.D{
|
|
|
|
|
|
|
|
{"$set", bson.D{
|
|
|
|
|
|
|
|
{"userList", tag.UserList},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//_, err = c.InsertOne(ctx)
|
|
|
|
|
|
|
|
//if err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *DataBases) GetUserIDListByTagID(userID, tagID string) ([]string, error) {
|
|
|
|
func (d *DataBases) GetUserIDListByTagID(userID, tagID string) ([]string, error) {
|
|
|
|
var tagIDList []string
|
|
|
|
var tag Tag
|
|
|
|
var tagStruct TagsStruct
|
|
|
|
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
_ = c.FindOne(ctx, bson.M{"uid": userID}).Decode(&tagStruct)
|
|
|
|
_ = c.FindOne(ctx, bson.M{"userID": userID, "tagID": tagID}).Decode(&tag)
|
|
|
|
for k, tag := range tagStruct.Tags {
|
|
|
|
return tag.UserList, nil
|
|
|
|
if k == tagID {
|
|
|
|
|
|
|
|
tagIDList = tag.UserList
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tagIDList, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type TagSendLog struct {
|
|
|
|
type TagSendLog struct {
|
|
|
|
TagID string `bson:"tagID"`
|
|
|
|
TagID string `bson:"tagID"`
|
|
|
|
|
|
|
|
TagName string `bson:"tagName"`
|
|
|
|
SendID string `bson:"sendID"`
|
|
|
|
SendID string `bson:"sendID"`
|
|
|
|
SenderPlatformID int32 `bson:"senderPlatformID"`
|
|
|
|
SenderPlatformID int32 `bson:"senderPlatformID"`
|
|
|
|
Content string `bson:"content"`
|
|
|
|
Content string `bson:"content"`
|
|
|
@ -528,8 +534,11 @@ type TagSendLog struct {
|
|
|
|
func (d *DataBases) SaveTagSendLog(sendReq *officePb.SendMsg2TagReq) error {
|
|
|
|
func (d *DataBases) SaveTagSendLog(sendReq *officePb.SendMsg2TagReq) error {
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
|
|
|
|
|
|
|
var tag Tag
|
|
|
|
|
|
|
|
_ = c.FindOne(ctx, bson.M{"userID": sendReq.SendID, "tagID": sendReq.TagID}).Decode(&tag)
|
|
|
|
tagSendLog := TagSendLog{
|
|
|
|
tagSendLog := TagSendLog{
|
|
|
|
TagID: sendReq.TagID,
|
|
|
|
TagID: sendReq.TagID,
|
|
|
|
|
|
|
|
TagName: tag.TagName,
|
|
|
|
SendID: sendReq.SendID,
|
|
|
|
SendID: sendReq.SendID,
|
|
|
|
SenderPlatformID: sendReq.SenderPlatformID,
|
|
|
|
SenderPlatformID: sendReq.SenderPlatformID,
|
|
|
|
Content: sendReq.Content,
|
|
|
|
Content: sendReq.Content,
|
|
|
@ -544,7 +553,8 @@ func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32)
|
|
|
|
var tagSendLogs []*TagSendLog
|
|
|
|
var tagSendLogs []*TagSendLog
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
|
|
|
cursor, err := c.Find(ctx, bson.M{"sendID": userID})
|
|
|
|
findOpts := options.Find().SetSort(-1).SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1))
|
|
|
|
|
|
|
|
cursor, err := c.Find(ctx, bson.M{"sendID": userID}, findOpts)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return tagSendLogs, err
|
|
|
|
return tagSendLogs, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|