作者 tangxvhui

调试点赞数量统计,评论回复数量统计

... ... @@ -85,7 +85,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr
return err
}
//增加浏览计数
err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo.Id)
return err
}, true)
if err != nil {
... ...
... ... @@ -93,7 +93,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
return err
}
// 减少文章的点赞数量
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo.Id)
if err != nil {
return err
}
... ... @@ -166,7 +166,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi
return err
}
// 减少评论的点赞数量
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo)
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo.Id)
if err != nil {
return err
}
... ... @@ -239,7 +239,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
return err
}
// 增加文章的点赞数量
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo.Id)
if err != nil {
return err
}
... ... @@ -320,7 +320,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ
return err
}
// 增加评论的点赞数量
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo)
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo.Id)
if err != nil {
return err
}
... ...
... ... @@ -153,13 +153,20 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
//保存数据
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
// 增加文章评论计数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo)
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id)
if err != nil {
return err
}
//增加评论回复计数
if pComment != nil {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment)
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id)
if err != nil {
return err
}
}
// 增加最顶层的评论回复计数
if newComment.TopId != 0 && newComment.Pid != newComment.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, newComment.TopId)
if err != nil {
return err
}
... ...
... ... @@ -46,11 +46,12 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
queryOption = domain.NewQueryOptions().WithFindOnly().
MustWithKV("articleId", commentInfo.ArticleId).
MustWithKV("userId", req.UserId)
// 获取我点赞的评论
// 获取我点赞的评论
_, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
// 我点赞的
flagMap := map[int64]struct{}{}
for _, val := range userFlagList {
flagMap[val.CommentId] = struct{}{}
... ... @@ -96,6 +97,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
Name: val.Name,
})
}
// 回复的评论
allReply := []types.ArticleCommentItem{}
for _, val := range replyCommenList {
reply := types.ArticleCommentItem{
... ...
... ... @@ -205,15 +205,13 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
}
// 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error {
var (
err error
m *models.ArticleComment
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.ArticleComment{Id: commnetId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr))
return nil, tx.Error
... ... @@ -226,15 +224,13 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co
}
// 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error {
var (
err error
m *models.ArticleComment
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.ArticleComment{Id: commnetId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr))
return nil, tx.Error
... ...
... ... @@ -203,16 +203,14 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
}
// 点赞数量变动
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error {
//
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.Article{Id: articleId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(map[string]interface{}{
"count_love": gorm.Expr("count_love+?", incr),
... ... @@ -227,15 +225,13 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn
}
// 浏览数量变动
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error {
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.Article{Id: articleId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(map[string]interface{}{
"version": gorm.Expr("version+1"),
... ... @@ -250,15 +246,13 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn
}
// 评论数量变动
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error {
var (
err error
m *models.Article
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
m = &models.Article{Id: articleId}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(map[string]interface{}{
"version": gorm.Expr("version+1"),
... ...
... ... @@ -38,9 +38,9 @@ type ArticleRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //浏览数量变动
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动
}
type ArticleTarget int
... ...
... ... @@ -57,6 +57,6 @@ type ArticleCommentRepository interface {
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error)
IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动
IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error // 评论回复数量变动
IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error //点赞数量变动
IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error // 评论回复数量变动
}
... ...