正在显示
8 个修改的文件
包含
31 行增加
和
32 行删除
| @@ -85,7 +85,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr | @@ -85,7 +85,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr | ||
| 85 | return err | 85 | return err |
| 86 | } | 86 | } |
| 87 | //增加浏览计数 | 87 | //增加浏览计数 |
| 88 | - err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo) | 88 | + err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo.Id) |
| 89 | return err | 89 | return err |
| 90 | }, true) | 90 | }, true) |
| 91 | if err != nil { | 91 | if err != nil { |
| @@ -93,7 +93,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | @@ -93,7 +93,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | ||
| 93 | return err | 93 | return err |
| 94 | } | 94 | } |
| 95 | // 减少文章的点赞数量 | 95 | // 减少文章的点赞数量 |
| 96 | - err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo) | 96 | + err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo.Id) |
| 97 | if err != nil { | 97 | if err != nil { |
| 98 | return err | 98 | return err |
| 99 | } | 99 | } |
| @@ -166,7 +166,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi | @@ -166,7 +166,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi | ||
| 166 | return err | 166 | return err |
| 167 | } | 167 | } |
| 168 | // 减少评论的点赞数量 | 168 | // 减少评论的点赞数量 |
| 169 | - err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo) | 169 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo.Id) |
| 170 | if err != nil { | 170 | if err != nil { |
| 171 | return err | 171 | return err |
| 172 | } | 172 | } |
| @@ -239,7 +239,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ | @@ -239,7 +239,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ | ||
| 239 | return err | 239 | return err |
| 240 | } | 240 | } |
| 241 | // 增加文章的点赞数量 | 241 | // 增加文章的点赞数量 |
| 242 | - err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo) | 242 | + err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo.Id) |
| 243 | if err != nil { | 243 | if err != nil { |
| 244 | return err | 244 | return err |
| 245 | } | 245 | } |
| @@ -320,7 +320,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ | @@ -320,7 +320,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ | ||
| 320 | return err | 320 | return err |
| 321 | } | 321 | } |
| 322 | // 增加评论的点赞数量 | 322 | // 增加评论的点赞数量 |
| 323 | - err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo) | 323 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo.Id) |
| 324 | if err != nil { | 324 | if err != nil { |
| 325 | return err | 325 | return err |
| 326 | } | 326 | } |
| @@ -153,13 +153,20 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -153,13 +153,20 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 153 | //保存数据 | 153 | //保存数据 |
| 154 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 154 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
| 155 | // 增加文章评论计数 | 155 | // 增加文章评论计数 |
| 156 | - err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo) | 156 | + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id) |
| 157 | if err != nil { | 157 | if err != nil { |
| 158 | return err | 158 | return err |
| 159 | } | 159 | } |
| 160 | //增加评论回复计数 | 160 | //增加评论回复计数 |
| 161 | if pComment != nil { | 161 | if pComment != nil { |
| 162 | - err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment) | 162 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id) |
| 163 | + if err != nil { | ||
| 164 | + return err | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + // 增加最顶层的评论回复计数 | ||
| 168 | + if newComment.TopId != 0 && newComment.Pid != newComment.TopId { | ||
| 169 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, newComment.TopId) | ||
| 163 | if err != nil { | 170 | if err != nil { |
| 164 | return err | 171 | return err |
| 165 | } | 172 | } |
| @@ -51,6 +51,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -51,6 +51,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | ||
| 51 | if err != nil { | 51 | if err != nil { |
| 52 | return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | 52 | return nil, xerr.NewErrMsgErr("获取评论信息失败", err) |
| 53 | } | 53 | } |
| 54 | + // 我点赞的 | ||
| 54 | flagMap := map[int64]struct{}{} | 55 | flagMap := map[int64]struct{}{} |
| 55 | for _, val := range userFlagList { | 56 | for _, val := range userFlagList { |
| 56 | flagMap[val.CommentId] = struct{}{} | 57 | flagMap[val.CommentId] = struct{}{} |
| @@ -96,6 +97,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -96,6 +97,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | ||
| 96 | Name: val.Name, | 97 | Name: val.Name, |
| 97 | }) | 98 | }) |
| 98 | } | 99 | } |
| 100 | + // 回复的评论 | ||
| 99 | allReply := []types.ArticleCommentItem{} | 101 | allReply := []types.ArticleCommentItem{} |
| 100 | for _, val := range replyCommenList { | 102 | for _, val := range replyCommenList { |
| 101 | reply := types.ArticleCommentItem{ | 103 | reply := types.ArticleCommentItem{ |
| @@ -205,15 +205,13 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | @@ -205,15 +205,13 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | ||
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | // 点赞数量变动 | 207 | // 点赞数量变动 |
| 208 | -func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { | 208 | +func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error { |
| 209 | var ( | 209 | var ( |
| 210 | err error | 210 | err error |
| 211 | m *models.ArticleComment | 211 | m *models.ArticleComment |
| 212 | tx = conn.DB() | 212 | tx = conn.DB() |
| 213 | ) | 213 | ) |
| 214 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 215 | - return err | ||
| 216 | - } | 214 | + m = &models.ArticleComment{Id: commnetId} |
| 217 | queryFunc := func() (interface{}, error) { | 215 | queryFunc := func() (interface{}, error) { |
| 218 | tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr)) | 216 | tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr)) |
| 219 | return nil, tx.Error | 217 | return nil, tx.Error |
| @@ -226,15 +224,13 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co | @@ -226,15 +224,13 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co | ||
| 226 | } | 224 | } |
| 227 | 225 | ||
| 228 | // 点赞数量变动 | 226 | // 点赞数量变动 |
| 229 | -func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { | 227 | +func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error { |
| 230 | var ( | 228 | var ( |
| 231 | err error | 229 | err error |
| 232 | m *models.ArticleComment | 230 | m *models.ArticleComment |
| 233 | tx = conn.DB() | 231 | tx = conn.DB() |
| 234 | ) | 232 | ) |
| 235 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 236 | - return err | ||
| 237 | - } | 233 | + m = &models.ArticleComment{Id: commnetId} |
| 238 | queryFunc := func() (interface{}, error) { | 234 | queryFunc := func() (interface{}, error) { |
| 239 | tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr)) | 235 | tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr)) |
| 240 | return nil, tx.Error | 236 | return nil, tx.Error |
| @@ -203,16 +203,14 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | @@ -203,16 +203,14 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | ||
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | // 点赞数量变动 | 205 | // 点赞数量变动 |
| 206 | -func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { | 206 | +func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error { |
| 207 | // | 207 | // |
| 208 | var ( | 208 | var ( |
| 209 | err error | 209 | err error |
| 210 | m *models.Article | 210 | m *models.Article |
| 211 | tx = conn.DB() | 211 | tx = conn.DB() |
| 212 | ) | 212 | ) |
| 213 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 214 | - return err | ||
| 215 | - } | 213 | + m = &models.Article{Id: articleId} |
| 216 | queryFunc := func() (interface{}, error) { | 214 | queryFunc := func() (interface{}, error) { |
| 217 | tx = tx.Model(m).Updates(map[string]interface{}{ | 215 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 218 | "count_love": gorm.Expr("count_love+?", incr), | 216 | "count_love": gorm.Expr("count_love+?", incr), |
| @@ -227,15 +225,13 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | @@ -227,15 +225,13 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | ||
| 227 | } | 225 | } |
| 228 | 226 | ||
| 229 | // 浏览数量变动 | 227 | // 浏览数量变动 |
| 230 | -func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { | 228 | +func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error { |
| 231 | var ( | 229 | var ( |
| 232 | err error | 230 | err error |
| 233 | m *models.Article | 231 | m *models.Article |
| 234 | tx = conn.DB() | 232 | tx = conn.DB() |
| 235 | ) | 233 | ) |
| 236 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 237 | - return err | ||
| 238 | - } | 234 | + m = &models.Article{Id: articleId} |
| 239 | queryFunc := func() (interface{}, error) { | 235 | queryFunc := func() (interface{}, error) { |
| 240 | tx = tx.Model(m).Updates(map[string]interface{}{ | 236 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 241 | "version": gorm.Expr("version+1"), | 237 | "version": gorm.Expr("version+1"), |
| @@ -250,15 +246,13 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | @@ -250,15 +246,13 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | ||
| 250 | } | 246 | } |
| 251 | 247 | ||
| 252 | // 评论数量变动 | 248 | // 评论数量变动 |
| 253 | -func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { | 249 | +func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error { |
| 254 | var ( | 250 | var ( |
| 255 | err error | 251 | err error |
| 256 | m *models.Article | 252 | m *models.Article |
| 257 | tx = conn.DB() | 253 | tx = conn.DB() |
| 258 | ) | 254 | ) |
| 259 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 260 | - return err | ||
| 261 | - } | 255 | + m = &models.Article{Id: articleId} |
| 262 | queryFunc := func() (interface{}, error) { | 256 | queryFunc := func() (interface{}, error) { |
| 263 | tx = tx.Model(m).Updates(map[string]interface{}{ | 257 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 264 | "version": gorm.Expr("version+1"), | 258 | "version": gorm.Expr("version+1"), |
| @@ -38,9 +38,9 @@ type ArticleRepository interface { | @@ -38,9 +38,9 @@ type ArticleRepository interface { | ||
| 38 | UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) | 38 | UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) |
| 39 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) | 39 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) |
| 40 | Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error) | 40 | Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error) |
| 41 | - IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //点赞数量变动 | ||
| 42 | - IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动 | ||
| 43 | - IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //浏览数量变动 | 41 | + IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动 |
| 42 | + IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动 | ||
| 43 | + IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动 | ||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | type ArticleTarget int | 46 | type ArticleTarget int |
| @@ -57,6 +57,6 @@ type ArticleCommentRepository interface { | @@ -57,6 +57,6 @@ type ArticleCommentRepository interface { | ||
| 57 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | 57 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) |
| 58 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) | 58 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) |
| 59 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) | 59 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) |
| 60 | - IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动 | ||
| 61 | - IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error // 评论回复数量变动 | 60 | + IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error //点赞数量变动 |
| 61 | + IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error // 评论回复数量变动 | ||
| 62 | } | 62 | } |
-
请 注册 或 登录 后发表评论