|
|
package comment
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
|
|
type SystemEditAticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewSystemEditAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentLogic {
|
|
|
return &SystemEditAticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 管理后台变更评论的设置
|
|
|
func (l *SystemEditAticleCommentLogic) SystemEditAticleComment(req *types.SystemEditCommentRequest) (resp *types.SystemEditCommentResponse, err error) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
|
|
|
}
|
|
|
if commetInfo.CompanyId != req.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("没有操作权限")
|
|
|
}
|
|
|
commetInfo.CountAdminLove = req.CountAdminLove
|
|
|
var increaseCount int
|
|
|
switch req.Show {
|
|
|
case 1:
|
|
|
// 设置为显示评论
|
|
|
if commetInfo.Show != domain.CommentShowEnable {
|
|
|
commetInfo.Show = domain.CommentShowEnable
|
|
|
increaseCount = 1
|
|
|
}
|
|
|
case 2:
|
|
|
// 设置为隐藏评论
|
|
|
if commetInfo.Show != domain.CommentShowDisable {
|
|
|
commetInfo.Show = domain.CommentShowDisable
|
|
|
increaseCount = -1
|
|
|
}
|
|
|
}
|
|
|
commetInfo.Show = domain.CommentShowEnable
|
|
|
// 变更回复数量
|
|
|
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if increaseCount != 0 {
|
|
|
// 增加上级评论的回复数量
|
|
|
if commetInfo.Pid != 0 {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.Pid)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 增加最顶层的评论回复计数
|
|
|
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, increaseCount, commetInfo.TopId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 增加加段落评论计数
|
|
|
if commetInfo.SectionId > 0 {
|
|
|
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.SectionId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 增加文章的评论数
|
|
|
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, increaseCount, commetInfo.ArticleId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}, true)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("编辑评论信息失败", err)
|
|
|
}
|
|
|
resp = &types.SystemEditCommentResponse{
|
|
|
Id: commetInfo.Id,
|
|
|
}
|
|
|
return resp, nil
|
|
|
|
|
|
} |
...
|
...
|
|