作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -293,7 +293,7 @@ type (
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId,optional"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
FromUserId int64 `json:"fromUserId,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
// 管理后台的评论列表
func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemListCommentRequest
... ...
... ... @@ -5,6 +5,7 @@ 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/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -12,15 +13,17 @@ import (
type SystemListAticleCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
svcCtx *svc.ServiceContext
userCache map[int64]types.CommentAuthor
}
func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic {
return &SystemListAticleCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
userCache: make(map[int64]types.CommentAuthor),
}
}
... ... @@ -29,7 +32,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
var conn = l.svcCtx.DefaultDBConn()
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size,
req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show, [2]int64{req.BeginTime, req.EndTime},
req.TopId, req.ArticleTitle, req.Content, req.FromUserId, req.Show, [2]int64{req.BeginTime, req.EndTime},
)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论列表失败", err)
... ... @@ -42,18 +45,12 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
for i, val := range commentList {
resp.List[i] = types.SystemCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArticleTitle: val.ArticleTitle,
FromUserId: val.FromUserId,
FromUser: types.CommentAuthor{
Id: val.FromUser.Id,
Name: val.FromUser.Name,
Avatar: val.FromUser.Avatar,
Position: val.FromUser.Position,
Company: val.FromUser.Company,
},
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArticleTitle: val.ArticleTitle,
FromUserId: val.FromUserId,
FromUser: l.getCommentAuthor(conn, val.FromUserId, ""),
CreatedAt: val.CreatedAt,
Content: val.Content,
Show: val.Show,
... ... @@ -65,3 +62,22 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
return resp, nil
}
func (l *SystemListAticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
if u, ok := l.userCache[userid]; ok {
return u
}
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
if err == nil {
commentToUser := types.CommentAuthor{
Id: toUser.Id,
Name: toUser.Name,
Avatar: toUser.Avatar,
Position: toUser.Position,
Company: companyName,
}
l.userCache[toUser.Id] = commentToUser
return commentToUser
}
return types.CommentAuthor{}
}
... ...
... ... @@ -203,7 +203,7 @@ type SystemListCommentRequest struct {
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId,optional"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
FromUserId int64 `json:"fromUserId,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间
... ...
... ... @@ -337,7 +337,7 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
}
func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserName string, show int, createdAtRange [2]int64) (int, []*domain.ArticleCommentShow, error) {
topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*domain.ArticleCommentShow, error) {
if size <= 0 {
size = 20
... ... @@ -358,9 +358,9 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context,
condition = append(condition, "%"+contentLike+"%")
}
if len(fromUserName) > 0 {
where += ` and article_comment.from_user ->>'name' like ? `
condition = append(condition, "%"+fromUserName+"%")
if fromUserId > 0 {
where += ` and article_comment.from_user_id = ? `
condition = append(condition, fromUserId)
}
if show > 0 {
where += ` and article_comment."show" =? `
... ... @@ -425,7 +425,6 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context,
ArticleTitle: val.ArticleTitle,
Id: val.Id,
FromUserId: val.FromUserId,
FromUser: val.FromUser,
Content: val.Content,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
... ...
... ... @@ -55,15 +55,14 @@ type ArticleCommentShow struct {
Id int64 // 评论id
Pid int64
TopId int64
ArticleTitle string // 文章标题
FromUserId int64 // 评论填写人的id
FromUser UserSimple // 评论填写人
Content string // 评论内容
CountReply int // 回复数量
CountUserLove int // 用户点赞数量
CountAdminLove int // 运营点赞数量
Show int // 评论的展示状态(0显示、1不显示)
CreatedAt int64 // 评论的创建时间
ArticleTitle string // 文章标题
FromUserId int64 // 评论填写人的id
Content string // 评论内容
CountReply int // 回复数量
CountUserLove int // 用户点赞数量
CountAdminLove int // 运营点赞数量
Show int // 评论的展示状态(0显示、1不显示)
CreatedAt int64 // 评论的创建时间
}
type ArticleCommentRepository interface {
... ... @@ -78,5 +77,5 @@ type ArticleCommentRepository interface {
Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error)
// 特定的查询
CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
topId int64, articleTitle string, contentLike string, fromUserName string, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error)
topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error)
}
... ...