|
|
|
@ -450,7 +450,7 @@ func (d *DataBases) GetUserTags(userID string) ([]Tag, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return tags, err
|
|
|
|
|
}
|
|
|
|
|
if err = cursor.Decode(tags); err != nil {
|
|
|
|
|
if err = cursor.All(ctx, &tags); err != nil {
|
|
|
|
|
return tags, err
|
|
|
|
|
}
|
|
|
|
|
return tags, nil
|
|
|
|
@ -481,13 +481,11 @@ func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserIDList []s
|
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
|
|
|
|
var tag Tag
|
|
|
|
|
err := c.FindOne(ctx, bson.M{"tagID": tagID, "userID": userID}).Decode(&tag)
|
|
|
|
|
if err := c.FindOne(ctx, bson.M{"tagID": tagID, "userID": userID}).Decode(&tag); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if newName != "" {
|
|
|
|
|
_, err = c.UpdateOne(ctx, bson.M{"userID": userID, "tagID": tagID}, bson.D{
|
|
|
|
|
{"$set", bson.D{
|
|
|
|
|
{"tagName", newName},
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
_, err := c.UpdateOne(ctx, bson.M{"userID": userID, "tagID": tagID}, bson.M{"$set": bson.M{"tagName": newName}})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -497,15 +495,17 @@ func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserIDList []s
|
|
|
|
|
for _, v := range reduceUserIDList {
|
|
|
|
|
for i2, v2 := range tag.UserList {
|
|
|
|
|
if v == v2 {
|
|
|
|
|
tag.UserList = append(tag.UserList[:i2], tag.UserList[i2+1:]...)
|
|
|
|
|
tag.UserList[i2] = ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_, err = c.UpdateOne(ctx, bson.M{"userID": userID, "tagID": tagID}, bson.D{
|
|
|
|
|
{"$set", bson.D{
|
|
|
|
|
{"userList", tag.UserList},
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
var newUserList []string
|
|
|
|
|
for _, v := range tag.UserList {
|
|
|
|
|
if v != "" {
|
|
|
|
|
newUserList = append(newUserList, v)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_, err := c.UpdateOne(ctx, bson.M{"userID": userID, "tagID": tagID}, bson.M{"$set": bson.M{"userList": newUserList}})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -533,9 +533,10 @@ type TagSendLog struct {
|
|
|
|
|
|
|
|
|
|
func (d *DataBases) SaveTagSendLog(sendReq *officePb.SendMsg2TagReq) error {
|
|
|
|
|
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(cTag)
|
|
|
|
|
var tag Tag
|
|
|
|
|
_ = c.FindOne(ctx, bson.M{"userID": sendReq.SendID, "tagID": sendReq.TagID}).Decode(&tag)
|
|
|
|
|
c = d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
|
|
|
|
tagSendLog := TagSendLog{
|
|
|
|
|
TagID: sendReq.TagID,
|
|
|
|
|
TagName: tag.TagName,
|
|
|
|
@ -544,21 +545,22 @@ func (d *DataBases) SaveTagSendLog(sendReq *officePb.SendMsg2TagReq) error {
|
|
|
|
|
Content: sendReq.Content,
|
|
|
|
|
ContentType: sendReq.ContentType,
|
|
|
|
|
SendTime: time.Now().Unix(),
|
|
|
|
|
UserList: tag.UserList,
|
|
|
|
|
}
|
|
|
|
|
_, err := c.InsertOne(ctx, tagSendLog)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32) ([]*TagSendLog, error) {
|
|
|
|
|
var tagSendLogs []*TagSendLog
|
|
|
|
|
func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32) ([]TagSendLog, error) {
|
|
|
|
|
var tagSendLogs []TagSendLog
|
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
|
|
|
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
|
|
|
|
findOpts := options.Find().SetSort(-1).SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1))
|
|
|
|
|
cursor, err := c.Find(ctx, bson.M{"sendID": userID}, findOpts)
|
|
|
|
|
cursor, err := c.Find(ctx, bson.D{{"sendID", userID}}, findOpts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return tagSendLogs, err
|
|
|
|
|
}
|
|
|
|
|
err = cursor.Decode(&tagSendLogs)
|
|
|
|
|
err = cursor.All(ctx, tagSendLogs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return tagSendLogs, err
|
|
|
|
|
}
|
|
|
|
|