作者 郑周

Merge branch 'dev' into test

... ... @@ -374,7 +374,7 @@ type (
SystemArticleSearchRequest {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
Author int64 `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
... ... @@ -389,6 +389,7 @@ type (
SystemArticleSearch {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"author"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
... ...
... ... @@ -258,7 +258,7 @@ type (
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
... ...
... ... @@ -30,7 +30,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("title", req.Title).
WithKV("author", req.Author).
WithKV("authorId", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
... ... @@ -41,6 +41,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
Total: int(total),
List: make([]types.SystemArticleSearch, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(articles, func(item *domain.Article, index int) {
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
... ... @@ -49,6 +50,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
resp.List = append(resp.List, types.SystemArticleSearch{
Id: item.Id,
Title: item.Title,
AuthorId: item.AuthorId,
Author: item.Author.Name,
Images: images,
CreatedAt: item.CreatedAt,
... ... @@ -58,6 +60,16 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
Tags: nil,
TargetUser: int(item.TargetUser),
})
authorIds = append(authorIds, item.AuthorId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(resp.List, func(item types.SystemArticleSearch, index int) {
for _, user := range users {
if user.Id == item.AuthorId {
resp.List[index].Author = user.Name
}
}
})
return resp, nil
}
... ...
... ... @@ -2,7 +2,6 @@ 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"
... ... @@ -29,61 +28,69 @@ func NewMiniDeleteArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCo
// 小程序端人人员删除评论
func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.MiniDeleteArticleCommentRequest) (resp *types.MiniDeleteArticleCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.FromUserId != req.UserId {
if commentInfo.FromUserId != req.UserId {
return nil, xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
if commentInfo.Show == domain.CommentShowDisable {
resp = &types.MiniDeleteArticleCommentResponse{
Id: commetInfo.Id,
Id: commentInfo.Id,
}
return resp, nil
}
commetInfo.Show = domain.CommentShowDisable
commentInfo.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)
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commentInfo)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
if commentInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.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 commentInfo.TopId != 0 && commentInfo.Pid != commentInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.TopId)
if err != nil {
return err
}
}
//减少加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
if commentInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commentInfo.SectionId)
if err != nil {
return err
}
}
// 减少文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commentInfo.ArticleId)
if err != nil {
return err
}
//// 评论被隐藏消息
//var messageLogic = message.NewMiniSystemLogic(l.ctx, l.svcCtx)
//err = messageLogic.AbnormalCommentHidden(c, commentInfo.CompanyId, commentInfo.FromUserId, commentInfo.Content)
//if err != nil {
// return err
//}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
resp = &types.MiniDeleteArticleCommentResponse{Id: commetInfo.Id}
resp = &types.MiniDeleteArticleCommentResponse{Id: commentInfo.Id}
return resp, nil
}
... ...
... ... @@ -35,9 +35,11 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
WithKV("articleId", req.ArticleId).
WithKV("topId", req.TopId).
WithKV("show", req.Show).
WithKV("fromUserName", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
if req.Author > 0 {
queryOptions = queryOptions.WithKV("fromUserId", req.Author)
}
total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章评论失败", err)
... ... @@ -46,6 +48,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
Total: total,
List: make([]types.SystemArticleCommentSearchItem, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(comments, func(item *domain.ArticleComment, index int) {
resp.List = append(resp.List, types.SystemArticleCommentSearchItem{
Id: item.Id,
... ... @@ -68,6 +71,22 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
Content: item.Content,
Show: int(item.Show),
})
authorIds = append(authorIds, item.FromUserId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(resp.List, func(item types.SystemArticleCommentSearchItem, index int) {
for _, user := range users {
if user.Id == item.FromUserId {
resp.List[index].FromUser = types.CommentAuthor{
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
Company: item.FromUser.Company,
}
}
}
})
return
}
... ...
... ... @@ -2,6 +2,7 @@ package comment
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -61,49 +62,57 @@ func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *type
func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyId int64) error {
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId)
if err != nil {
return xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.CompanyId != companyId {
if commentInfo.CompanyId != companyId {
return xerr.NewErrMsg("没有操作权限")
}
if commetInfo.Show == domain.CommentShowDisable {
if commentInfo.Show == domain.CommentShowDisable {
return nil
}
commetInfo.Show = domain.CommentShowDisable
commentInfo.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)
_, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commentInfo)
if err != nil {
return err
}
// 减少上级评论的回复数量
if commetInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid)
if commentInfo.Pid != 0 {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.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 commentInfo.TopId != 0 && commentInfo.Pid != commentInfo.TopId {
err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commentInfo.TopId)
if err != nil {
return err
}
}
//减少加段落评论计数
if commetInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
if commentInfo.SectionId > 0 {
err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commentInfo.SectionId)
if err != nil {
return err
}
}
// 减少文章的评论数
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commentInfo.ArticleId)
if err != nil {
return err
}
// 评论被隐藏消息
var messageLogic = message.NewMiniSystemLogic(l.ctx, l.svcCtx)
err = messageLogic.AbnormalCommentHidden(c, commentInfo.CompanyId, commentInfo.FromUserId, commentInfo.Content)
if err != nil {
return err
}
return nil
}, true)
... ...
... ... @@ -165,14 +165,14 @@ type SystemArticleCommentSearchMeResponse struct {
}
type SystemArticleCommentSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
type SystemArticleCommentSearchResponse struct {
... ... @@ -1156,7 +1156,7 @@ type SystemArticleGetResponse struct {
type SystemArticleSearchRequest struct {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
Author int64 `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
... ... @@ -1172,6 +1172,7 @@ type SystemArticleSearchResponse struct {
type SystemArticleSearch struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"author"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
... ...
... ... @@ -127,9 +127,6 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["title"]; ok && v.(string) != "" {
tx = tx.Where("title like ?", "%"+v.(string)+"%")
}
if v, ok := queryOptions["author"]; ok && v.(string) != "" {
tx = tx.Where(`author #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
}
... ...