|
|
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 SystemEditAticleCommentShowLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewSystemEditAticleCommentShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentShowLogic {
|
|
|
return &SystemEditAticleCommentShowLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *types.SystemEditCommentShowRequest) (resp *types.SystemEditCommentShowResponse, err error) {
|
|
|
|
|
|
resp = &types.SystemEditCommentShowResponse{
|
|
|
Id: []int64{},
|
|
|
}
|
|
|
if req.Show == 1 {
|
|
|
for _, val := range req.Id {
|
|
|
err = l.enableShow(val, req.CompanyId)
|
|
|
if err != nil {
|
|
|
err = xerr.NewErrMsgErr("操作失败", err)
|
|
|
} else {
|
|
|
resp.Id = append(resp.Id, val)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if req.Show == 2 {
|
|
|
for _, val := range req.Id {
|
|
|
err = l.disableShow(val, req.CompanyId)
|
|
|
if err != nil {
|
|
|
err = xerr.NewErrMsgErr("操作失败", err)
|
|
|
} else {
|
|
|
resp.Id = append(resp.Id, val)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyId int64) error {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("删除评论信息失败", err)
|
|
|
}
|
|
|
if commetInfo.CompanyId != commentId {
|
|
|
return xerr.NewErrMsg("没有操作权限")
|
|
|
}
|
|
|
if commetInfo.Show == domain.CommentShowDisable {
|
|
|
return nil
|
|
|
}
|
|
|
commetInfo.Show = domain.CommentShowDisable
|
|
|
// 变更回复数量
|
|
|
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 commetInfo.Pid != 0 {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 减少最顶层的评论回复计数
|
|
|
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
//减少加段落评论计数
|
|
|
if commetInfo.SectionId > 0 {
|
|
|
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 减少文章的评论数
|
|
|
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}, true)
|
|
|
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("删除评论信息失败", err)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (l *SystemEditAticleCommentShowLogic) enableShow(commentId int64, companyId int64) error {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("删除评论信息失败", err)
|
|
|
}
|
|
|
if commetInfo.CompanyId != commentId {
|
|
|
return xerr.NewErrMsg("没有操作权限")
|
|
|
}
|
|
|
if commetInfo.Show == domain.CommentShowEnable {
|
|
|
return nil
|
|
|
}
|
|
|
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 commetInfo.Pid != 0 {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, commetInfo.Pid)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 增加最顶层的评论回复计数
|
|
|
if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId {
|
|
|
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, commetInfo.TopId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
//增加加段落评论计数
|
|
|
if commetInfo.SectionId > 0 {
|
|
|
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, 1, commetInfo.SectionId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 增加文章的评论数
|
|
|
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, commetInfo.ArticleId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}, true)
|
|
|
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("删除评论信息失败", err)
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|