Example #1
0
// 获得回复对应的主贴信息
func FindRecentReplies(comments []*model.Comment) []map[string]interface{} {
	if len(comments) == 0 {
		return nil
	}
	count := len(comments)
	commentMap := make(map[int]*model.Comment, count)
	tidMap := make(map[int]int, count)
	for _, comment := range comments {
		commentMap[comment.Objid] = comment
		tidMap[comment.Objid] = comment.Objid
	}
	tids := util.MapIntKeys(tidMap)
	topics := FindTopicsByTids(tids)
	if len(topics) == 0 {
		return nil
	}
	result := make([]map[string]interface{}, len(topics))
	for i, topic := range topics {
		oneReply := make(map[string]interface{})
		oneReply["tid"] = topic.Tid
		oneReply["title"] = topic.Title
		oneReply["cmt_content"] = decodeCmtContent(commentMap[topic.Tid])
		oneReply["replytime"] = commentMap[topic.Tid].Ctime
		result[i] = oneReply
	}
	return result
}
Example #2
0
// 获得回复最多的10条帖子(TODO:避免一直显示相同的)
func FindHotTopics() []map[string]interface{} {
	topicExList, err := model.NewTopicEx().Order("reply DESC").Limit("0,10").FindAll()
	if err != nil {
		logger.Errorln("topic service FindHotReplies error:", err)
		return nil
	}
	tidMap := make(map[int]int, len(topicExList))
	topicExMap := make(map[int]*model.TopicEx, len(topicExList))
	for _, topicEx := range topicExList {
		tidMap[topicEx.Tid] = topicEx.Tid
		topicExMap[topicEx.Tid] = topicEx
	}
	tids := util.MapIntKeys(tidMap)
	topics := FindTopicsByTids(tids)
	if topics == nil {
		return nil
	}

	uidMap := make(map[int]int, len(topics))
	for _, topic := range topics {
		uidMap[topic.Uid] = topic.Uid
	}
	userMap := getUserInfos(uidMap)
	result := make([]map[string]interface{}, len(topics))
	for i, topic := range topics {
		oneTopic := make(map[string]interface{})
		util.Struct2Map(oneTopic, topic)
		util.Struct2Map(oneTopic, topicExMap[topic.Tid])
		oneTopic["user"] = userMap[topic.Uid]
		result[i] = oneTopic
	}
	return result
}
Example #3
0
// 提供给其他service调用(包内)
func getWikis(ids map[int]int) map[int]*model.Wiki {
	wikis := FindWikisByIds(util.MapIntKeys(ids))
	wikiMap := make(map[int]*model.Wiki, len(wikis))
	for _, wiki := range wikis {
		wikiMap[wiki.Id] = wiki
	}
	return wikiMap
}
Example #4
0
// 提供给其他service调用(包内)
func getTopics(tids map[int]int) map[int]*model.Topic {
	topics := FindTopicsByTids(util.MapIntKeys(tids))
	topicMap := make(map[int]*model.Topic, len(topics))
	for _, topic := range topics {
		topicMap[topic.Tid] = topic
	}
	return topicMap
}
Example #5
0
// 提供给其他service调用(包内)
func getArticles(ids map[int]int) map[int]*model.Article {
	articles := FindArticlesByIds(util.MapIntKeys(ids))
	articleMap := make(map[int]*model.Article, len(articles))
	for _, article := range articles {
		articleMap[article.Id] = article
	}
	return articleMap
}
Example #6
0
// 提供给其他service调用(包内)
func getResources(ids map[int]int) map[int]*model.Resource {
	resources := FindResourcesByIds(util.MapIntKeys(ids))
	resourceMap := make(map[int]*model.Resource, len(resources))
	for _, resource := range resources {
		resourceMap[resource.Id] = resource
	}
	return resourceMap
}
Example #7
0
// 提供给其他service调用(包内)
func getProjects(ids map[int]int) map[int]*model.OpenProject {
	projects := FindProjectsByIds(util.MapIntKeys(ids))
	projectMap := make(map[int]*model.OpenProject, len(projects))
	for _, project := range projects {
		projectMap[project.Id] = project
	}
	return projectMap
}
Example #8
0
// 提供给其他service调用(包内)
func getComments(cids map[int]int) map[int]*model.Comment {
	comments := FindCommentsByIds(util.MapIntKeys(cids))
	commentMap := make(map[int]*model.Comment, len(comments))
	for _, comment := range comments {
		commentMap[comment.Cid] = comment
	}
	return commentMap
}
Example #9
0
// 获取用户信息
func getUserInfos(uids map[int]int) map[int]*model.User {
	// 获取用户信息
	inUids := util.Join(util.MapIntKeys(uids), ",")
	users, err := model.NewUser().Where("uid in(" + inUids + ")").FindAll()
	if err != nil {
		logger.Errorln("user service getUserInfos Error:", err)
		return map[int]*model.User{}
	}
	userMap := make(map[int]*model.User, len(users))
	for _, user := range users {
		userMap[user.Uid] = user
	}
	return userMap
}
Example #10
0
// 填充评论对应的主体信息
func FillCommentObjs(comments []*model.Comment, cmtObj CommentObjecter) {
	if len(comments) == 0 {
		return
	}
	count := len(comments)
	commentMap := make(map[int][]*model.Comment, count)
	idMap := make(map[int]int, count)
	for _, comment := range comments {
		if _, ok := commentMap[comment.Objid]; !ok {
			commentMap[comment.Objid] = make([]*model.Comment, 0, count)
		}
		commentMap[comment.Objid] = append(commentMap[comment.Objid], comment)
		idMap[comment.Objid] = 1
	}
	ids := util.MapIntKeys(idMap)
	cmtObj.SetObjinfo(ids, commentMap)
}