|
@@ -5,6 +5,7 @@ import ( |
|
@@ -5,6 +5,7 @@ import ( |
5
|
|
5
|
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
10
|
|
11
|
|
|
@@ -13,15 +14,17 @@ import ( |
|
@@ -13,15 +14,17 @@ import ( |
13
|
|
14
|
|
14
|
type MiniTop5ArticleCommentLogic struct {
|
15
|
type MiniTop5ArticleCommentLogic struct {
|
15
|
logx.Logger
|
16
|
logx.Logger
|
16
|
- ctx context.Context
|
|
|
17
|
- svcCtx *svc.ServiceContext
|
17
|
+ ctx context.Context
|
|
|
18
|
+ svcCtx *svc.ServiceContext
|
|
|
19
|
+ userCache map[int64]types.CommentAuthor
|
18
|
}
|
20
|
}
|
19
|
|
21
|
|
20
|
func NewMiniTop5ArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniTop5ArticleCommentLogic {
|
22
|
func NewMiniTop5ArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniTop5ArticleCommentLogic {
|
21
|
return &MiniTop5ArticleCommentLogic{
|
23
|
return &MiniTop5ArticleCommentLogic{
|
22
|
- Logger: logx.WithContext(ctx),
|
|
|
23
|
- ctx: ctx,
|
|
|
24
|
- svcCtx: svcCtx,
|
24
|
+ Logger: logx.WithContext(ctx),
|
|
|
25
|
+ ctx: ctx,
|
|
|
26
|
+ svcCtx: svcCtx,
|
|
|
27
|
+ userCache: make(map[int64]types.CommentAuthor),
|
25
|
}
|
28
|
}
|
26
|
}
|
29
|
}
|
27
|
|
30
|
|
|
@@ -50,9 +53,15 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 |
|
@@ -50,9 +53,15 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 |
50
|
resp = &types.MiniTop5ArticleCommentResponse{
|
53
|
resp = &types.MiniTop5ArticleCommentResponse{
|
51
|
List: make([]types.ArticleCommentItem, len(commentList)),
|
54
|
List: make([]types.ArticleCommentItem, len(commentList)),
|
52
|
}
|
55
|
}
|
|
|
56
|
+ companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
|
|
|
57
|
+ if err != nil {
|
|
|
58
|
+ return nil, xerr.NewErrMsgErr("获取公司信息失败", err)
|
|
|
59
|
+
|
|
|
60
|
+ }
|
53
|
for i, val := range commentList {
|
61
|
for i, val := range commentList {
|
54
|
item := NewArticleCommentItem(val)
|
62
|
item := NewArticleCommentItem(val)
|
55
|
-
|
63
|
+ item.FromUser = l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name)
|
|
|
64
|
+ item.ToUser = l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name)
|
56
|
if _, ok := flagMap[val.Id]; ok {
|
65
|
if _, ok := flagMap[val.Id]; ok {
|
57
|
item.MeLoveFlag = 1
|
66
|
item.MeLoveFlag = 1
|
58
|
}
|
67
|
}
|
|
@@ -70,6 +79,25 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 |
|
@@ -70,6 +79,25 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 |
70
|
return
|
79
|
return
|
71
|
}
|
80
|
}
|
72
|
|
81
|
|
|
|
82
|
+func (l *MiniTop5ArticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
|
|
|
83
|
+ if u, ok := l.userCache[userid]; ok {
|
|
|
84
|
+ return u
|
|
|
85
|
+ }
|
|
|
86
|
+ toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
|
|
|
87
|
+ if err == nil {
|
|
|
88
|
+ commentToUser := types.CommentAuthor{
|
|
|
89
|
+ Id: toUser.Id,
|
|
|
90
|
+ Name: toUser.Name,
|
|
|
91
|
+ Avatar: toUser.Avatar,
|
|
|
92
|
+ Position: toUser.Position,
|
|
|
93
|
+ Company: companyName,
|
|
|
94
|
+ }
|
|
|
95
|
+ l.userCache[toUser.Id] = commentToUser
|
|
|
96
|
+ return commentToUser
|
|
|
97
|
+ }
|
|
|
98
|
+ return types.CommentAuthor{}
|
|
|
99
|
+}
|
|
|
100
|
+
|
73
|
func NewArticleCommentItem(val *domain.ArticleComment) types.ArticleCommentItem {
|
101
|
func NewArticleCommentItem(val *domain.ArticleComment) types.ArticleCommentItem {
|
74
|
item := types.ArticleCommentItem{
|
102
|
item := types.ArticleCommentItem{
|
75
|
Id: val.Id,
|
103
|
Id: val.Id,
|