Ver código fonte

fix:sql分组调整

Roc 2 anos atrás
pai
commit
ce76d0273b

+ 2 - 2
models/tables/yb_community_question_comment/query.go

@@ -105,7 +105,7 @@ func GetNumCommentByCommunityQuestionIds(communityQuestionIds []uint32) (item []
 // GetLastHotListByCommunityQuestionIds 根据问答id列表获取最近精选的留言
 func GetLastHotListByCommunityQuestionIds(communityQuestionIds []uint32) (items []*YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE community_question_id IN (?) AND enabled = 1 AND is_hot = 1 AND type = 1)", communityQuestionIds).
+		Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE community_question_id IN (?) AND enabled = 1 AND is_hot = 1 AND type = 1)", communityQuestionIds).Group("community_question_id").
 		Find(&items).Error
 	return
 }
@@ -113,7 +113,7 @@ func GetLastHotListByCommunityQuestionIds(communityQuestionIds []uint32) (items
 // GetLastMyListByCommunityQuestionIds 根据问答id列表获取我最近的留言
 func GetLastMyListByCommunityQuestionIds(userId uint64, communityQuestionIds []uint32) (items []*YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE user_id=? AND community_question_id IN (?) AND enabled = 1 AND type = 1)", userId, communityQuestionIds).
+		Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE user_id=? AND community_question_id IN (?) AND enabled = 1 AND type = 1)", userId, communityQuestionIds).Group("community_question_id").
 		Find(&items).Error
 	return
 }

+ 3 - 3
models/tables/yb_community_question_like_tease/query.go

@@ -45,7 +45,7 @@ func GetLikeNumCommentByCommunityQuestionIds(communityQuestionIds []uint32) (ite
 	}
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeTease{}).
 		Select("community_question_id, count(1) total").
-		Where("community_question_id in (?) AND enabled=1  AND op_type=1", communityQuestionIds).Scan(&items).Error
+		Where("community_question_id in (?) AND enabled=1  AND op_type=1", communityQuestionIds).Group("community_question_id").Scan(&items).Error
 	return
 }
 
@@ -56,7 +56,7 @@ func GetTeaseNumCommentByCommunityQuestionIds(communityQuestionIds []uint32) (it
 	}
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeTease{}).
 		Select("community_question_id, count(1) total").
-		Where("community_question_id in (?) AND enabled=1  AND op_type=2", communityQuestionIds).Scan(&items).Error
+		Where("community_question_id in (?) AND enabled=1  AND op_type=2", communityQuestionIds).Group("community_question_id").Scan(&items).Error
 	return
 }
 
@@ -66,7 +66,7 @@ func GetByUserIdAndCommunityQuestionIds(userId uint64, communityQuestionIds []ui
 		return
 	}
 	err = global.DEFAULT_MYSQL.
-		Where("user_id = ? AND enabled=1  AND community_question_id in (?)", userId, communityQuestionIds).
+		Where("user_id = ? AND enabled=1  AND community_question_id in (?)", userId, communityQuestionIds).Group("community_question_id").
 		Find(&items).Error
 	return
 }