本文整理汇总了Golang中github.com/leanote/leanote/app/db.ListByQWithFields函数的典型用法代码示例。如果您正苦于以下问题:Golang ListByQWithFields函数的具体用法?Golang ListByQWithFields怎么用?Golang ListByQWithFields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ListByQWithFields函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ToBlog
// ToBlog or Not
func (this *NotebookService) ToBlog(userId, notebookId string, isBlog bool) bool {
// 笔记本
db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"IsBlog": isBlog})
// 更新笔记
q := bson.M{"UserId": bson.ObjectIdHex(userId),
"NotebookId": bson.ObjectIdHex(notebookId)}
data := bson.M{"IsBlog": isBlog}
if isBlog {
data["PublicTime"] = time.Now()
} else {
data["HasSelfDefined"] = false
}
db.UpdateByQMap(db.Notes, q, data)
// noteContents也更新, 这个就麻烦了, noteContents表没有NotebookId
// 先查该notebook下所有notes, 得到id
notes := []info.Note{}
db.ListByQWithFields(db.Notes, q, []string{"_id"}, ¬es)
if len(notes) > 0 {
noteIds := make([]bson.ObjectId, len(notes))
for i, each := range notes {
noteIds[i] = each.NoteId
}
db.UpdateByQMap(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, bson.M{"IsBlog": isBlog})
}
// 重新计算tags
go (func() {
blogService.ReCountBlogTags(userId)
})()
return true
}
示例2: UpdateNotebook
// 更新notebook
func (this *NotebookService) UpdateNotebook(userId, notebookId string, needUpdate bson.M) bool {
needUpdate["UpdatedTime"] = time.Now()
// 如果有IsBlog之类的, 需要特殊处理
if isBlog, ok := needUpdate["IsBlog"]; ok {
// 设为blog/取消
if is, ok2 := isBlog.(bool); ok2 {
q := bson.M{"UserId": bson.ObjectIdHex(userId),
"NotebookId": bson.ObjectIdHex(notebookId)}
db.UpdateByQMap(db.Notes, q, bson.M{"IsBlog": is})
// noteContents也更新, 这个就麻烦了, noteContents表没有NotebookId
// 先查该notebook下所有notes, 得到id
notes := []info.Note{}
db.ListByQWithFields(db.Notes, q, []string{"_id"}, ¬es)
if len(notes) > 0 {
noteIds := make([]bson.ObjectId, len(notes))
for i, each := range notes {
noteIds[i] = each.NoteId
}
db.UpdateByQMap(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, bson.M{"IsBlog": isBlog})
}
}
}
return db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, needUpdate)
}
示例3: ReCountBlogTags
// 重新计算博客的标签
// 在设置设置/取消为博客时调用
func (this *BlogService) ReCountBlogTags(userId string) bool {
// 得到所有博客
notes := []info.Note{}
userIdO := bson.ObjectIdHex(userId)
query := bson.M{"UserId": userIdO, "IsTrash": false, "IsDeleted": false, "IsBlog": true}
db.ListByQWithFields(db.Notes, query, []string{"Tags"}, ¬es)
db.DeleteAll(db.TagCounts, bson.M{"UserId": userIdO, "IsBlog": true})
if notes == nil || len(notes) == 0 {
return true
}
// 统计所有的Tags和数目
tagsCount := map[string]int{}
for _, note := range notes {
tags := note.Tags
if tags != nil && len(tags) > 0 {
for _, tag := range tags {
count := tagsCount[tag]
count++
tagsCount[tag] = count
}
}
}
// 一个个插入
for tag, count := range tagsCount {
db.Insert(db.TagCounts,
info.TagCount{UserId: userIdO, IsBlog: true, Tag: tag, Count: count})
}
return true
}
示例4: CopyNoteImages
// 复制图片, 把note的图片都copy给我, 且修改noteContent图片路径
func (this *NoteImageService) CopyNoteImages(fromNoteId, fromUserId, newNoteId, content, toUserId string) string {
// 得到fromNoteId的noteImages, 如果为空, 则直接返回content
noteImages := []info.NoteImage{}
db.ListByQWithFields(db.NoteImages, bson.M{"NoteId": bson.ObjectIdHex(fromNoteId)}, []string{"ImageId"}, ¬eImages)
if len(noteImages) == 0 {
return content
}
// <img src="/file/outputImage?fileId=12323232" />
// 把fileId=1232替换成新的
replaceMap := map[string]string{}
for _, noteImage := range noteImages {
imageId := noteImage.ImageId.Hex()
ok, newImageId := fileService.CopyImage(fromUserId, imageId, toUserId)
if ok {
replaceMap[imageId] = newImageId
}
}
if len(replaceMap) > 0 {
// 替换之
reg, _ := regexp.Compile("outputImage\\?fileId=([a-z0-9A-Z]{24})")
content = reg.ReplaceAllStringFunc(content, func(each string) string {
// each=outputImage?fileId=541bd2f599c37b4f3r000003
fileId := each[len(each)-24:] // 得到后24位, 也即id
if replaceFileId, ok := replaceMap[fileId]; ok {
return "outputImage?fileId=" + replaceFileId
}
return each
})
}
return content
}
示例5: setNoteUsn
func (this *UpgradeService) setNoteUsn() {
usnI := 1
notes := []info.Note{}
db.ListByQWithFields(db.Notes, bson.M{}, []string{"UserId"}, ¬es)
for _, note := range notes {
db.UpdateByQField(db.Notes, bson.M{"_id": note.NoteId}, "Usn", usnI)
usnI++
}
}
示例6: GetBelongToGroupIds
// 得到我所属的所有分组ids
func (this *GroupService) GetBelongToGroupIds(userId string) []bson.ObjectId {
// 得到UserIds
groupUsers := []info.GroupUser{}
db.ListByQWithFields(db.GroupUsers, bson.M{"UserId": bson.ObjectIdHex(userId)}, []string{"GroupId"}, &groupUsers)
if len(groupUsers) == 0 {
return nil
}
groupIds := make([]bson.ObjectId, len(groupUsers))
for i, each := range groupUsers {
groupIds[i] = each.GroupId
}
return groupIds
}
示例7: GetUsers
// 得到某分组下的用户
func (this *GroupService) GetUsers(groupId string) []info.User {
// 得到UserIds
groupUsers := []info.GroupUser{}
db.ListByQWithFields(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId)}, []string{"UserId"}, &groupUsers)
if len(groupUsers) == 0 {
return nil
}
userIds := make([]bson.ObjectId, len(groupUsers))
for i, each := range groupUsers {
userIds[i] = each.UserId
}
// 得到userInfos
return userService.ListUserInfosByUserIds(userIds)
}
示例8: GetNoteIds
// 通过id, userId得到noteIds
func (this *NoteImageService) GetNoteIds(imageId string) []bson.ObjectId {
noteImages := []info.NoteImage{}
db.ListByQWithFields(db.NoteImages, bson.M{"ImageId": bson.ObjectIdHex(imageId)}, []string{"NoteId"}, ¬eImages)
if noteImages != nil && len(noteImages) > 0 {
noteIds := make([]bson.ObjectId, len(noteImages))
cnt := len(noteImages)
for i := 0; i < cnt; i++ {
noteIds[i] = noteImages[i].NoteId
}
return noteIds
}
return nil
}
示例9: GetAllImageNamesMap
// get all images names
// for upgrade
func (this *FileService) GetAllImageNamesMap(userId string) (m map[string]bool) {
q := bson.M{"UserId": bson.ObjectIdHex(userId)}
files := []info.File{}
db.ListByQWithFields(db.Files, q, []string{"Name"}, &files)
m = make(map[string]bool)
if len(files) == 0 {
return
}
for _, file := range files {
m[file.Name] = true
}
return
}
示例10: ListNoteAbstractsByNoteIds
// 只得到abstract, 不需要content
func (this *NoteService) ListNoteAbstractsByNoteIds(noteIds []bson.ObjectId) (notes []info.NoteContent) {
notes = []info.NoteContent{}
db.ListByQWithFields(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, []string{"_id", "Abstract"}, ¬es)
return
}