...
|
...
|
@@ -5,6 +5,11 @@ import ( |
|
|
|
|
|
"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"
|
|
|
|
|
|
"text/template"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
...
|
...
|
@@ -23,8 +28,182 @@ func NewMiniCreateArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCo |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 填写评论
|
|
|
func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.MiniCreateArticleCommentRequest) (resp *types.MiniCreateArticleCommentResponse, err error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
// 获取评论填写人的信息
|
|
|
fromUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.FromUserId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论人信息失败", err)
|
|
|
}
|
|
|
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取公司信息失败", err)
|
|
|
}
|
|
|
// 获取文章
|
|
|
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArtitcleId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取文章信息失败", err)
|
|
|
}
|
|
|
if articleInfo.CompanyId != req.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("没有评论权限")
|
|
|
}
|
|
|
//查看评论权限,
|
|
|
//临时注释
|
|
|
// if len(articleInfo.WhoReview) > 0 {
|
|
|
// ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId)
|
|
|
// if ok < 0 {
|
|
|
// return nil, xerr.NewErrMsg("没有评论权限")
|
|
|
// }
|
|
|
// }
|
|
|
// 对段落进行评论
|
|
|
var selctionInfo *domain.ArticleSection
|
|
|
if req.SectionId > 0 {
|
|
|
//获取段落
|
|
|
selctionInfo, err = l.svcCtx.ArticleSectionRepository.FindOne(l.ctx, conn, req.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取文章段落信息失败", err)
|
|
|
}
|
|
|
if selctionInfo.ArticleId != articleInfo.Id {
|
|
|
return nil, xerr.NewErrMsg("获取文章段落信息失败")
|
|
|
}
|
|
|
}
|
|
|
// 回复哪个评论
|
|
|
var pComment *domain.ArticleComment
|
|
|
if req.Pid > 0 {
|
|
|
pComment, err = l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Pid)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取上一层级的评论信息失败", err)
|
|
|
}
|
|
|
|
|
|
if pComment.ArticleId != articleInfo.Id {
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsg("评论信息与文章不匹配")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
var atWhoList []*domain.User
|
|
|
if len(req.AtWho) > 0 {
|
|
|
queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", req.AtWho)
|
|
|
_, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
|
|
|
}
|
|
|
}
|
|
|
// 处理文本内容
|
|
|
// content:=
|
|
|
content := template.HTMLEscapeString(req.Content)
|
|
|
|
|
|
newComment := domain.ArticleComment{
|
|
|
Id: 0,
|
|
|
CompanyId: req.CompanyId,
|
|
|
CreatedAt: 0,
|
|
|
UpdatedAt: 0,
|
|
|
DeletedAt: 0,
|
|
|
Version: 0,
|
|
|
Pid: req.Pid,
|
|
|
TopId: 0,
|
|
|
ArticleId: req.ArtitcleId,
|
|
|
SectionId: req.SectionId,
|
|
|
SectionContent: "",
|
|
|
FromUserId: req.FromUserId,
|
|
|
FromUser: domain.UserSimple{
|
|
|
Id: fromUser.Id,
|
|
|
Name: fromUser.Name,
|
|
|
Avatar: fromUser.Avatar,
|
|
|
Position: fromUser.Position,
|
|
|
Company: companyInfo.Name,
|
|
|
CompanyId: companyInfo.Id,
|
|
|
},
|
|
|
ToUserId: 0,
|
|
|
ToUser: domain.UserSimple{},
|
|
|
Content: content,
|
|
|
CountReply: 0,
|
|
|
CountUserLove: 0,
|
|
|
CountAdminLove: 0,
|
|
|
Show: 0,
|
|
|
AtWho: []domain.UserSimple{},
|
|
|
}
|
|
|
|
|
|
if selctionInfo != nil {
|
|
|
newComment.SectionContent = selctionInfo.Content
|
|
|
}
|
|
|
if pComment != nil {
|
|
|
newComment.TopId = pComment.TopId
|
|
|
if pComment.TopId == 0 {
|
|
|
newComment.TopId = pComment.Id
|
|
|
}
|
|
|
newComment.ToUser = pComment.FromUser
|
|
|
newComment.ToUserId = pComment.FromUserId
|
|
|
newComment.SectionId = pComment.SectionId
|
|
|
}
|
|
|
for i := range atWhoList {
|
|
|
newComment.AtWho = append(newComment.AtWho, domain.UserSimple{
|
|
|
Id: atWhoList[i].Id,
|
|
|
Name: atWhoList[i].Name,
|
|
|
Avatar: atWhoList[i].Avatar,
|
|
|
Position: atWhoList[i].Position,
|
|
|
Company: companyInfo.Name,
|
|
|
CompanyId: companyInfo.Id,
|
|
|
})
|
|
|
}
|
|
|
//保存数据
|
|
|
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
// 增加平评论计数
|
|
|
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//保存评论
|
|
|
_, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}, true)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("保存评论失败", err)
|
|
|
}
|
|
|
|
|
|
resp = &types.MiniCreateArticleCommentResponse{
|
|
|
Id: newComment.Id,
|
|
|
Pid: newComment.Pid,
|
|
|
TopId: newComment.TopId,
|
|
|
ArtitcleId: newComment.ArticleId,
|
|
|
SectionId: newComment.ArticleId,
|
|
|
FromUserId: newComment.FromUserId,
|
|
|
FromUser: types.CommentAuthor{
|
|
|
Id: newComment.FromUser.Id,
|
|
|
Name: newComment.FromUser.Name,
|
|
|
Avatar: newComment.FromUser.Avatar,
|
|
|
Position: newComment.FromUser.Position,
|
|
|
Company: newComment.FromUser.Company,
|
|
|
},
|
|
|
ToUserId: newComment.ToUserId,
|
|
|
ToUser: types.CommentAuthor{
|
|
|
Id: newComment.ToUser.Id,
|
|
|
Name: newComment.ToUser.Name,
|
|
|
Avatar: newComment.ToUser.Avatar,
|
|
|
Position: newComment.ToUser.Position,
|
|
|
Company: newComment.ToUser.Company,
|
|
|
},
|
|
|
SectionContent: newComment.SectionContent,
|
|
|
CountReply: 0,
|
|
|
CountUserLove: 0,
|
|
|
CountAdminLove: 0,
|
|
|
AtWho: []types.CommentAuthor{},
|
|
|
}
|
|
|
|
|
|
for _, val := range newComment.AtWho {
|
|
|
resp.AtWho = append(resp.AtWho, types.CommentAuthor{
|
|
|
Id: val.Id,
|
|
|
Name: val.Name,
|
|
|
Avatar: val.Avatar,
|
|
|
Position: val.Position,
|
|
|
Company: val.Company,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
return
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|