|
@@ -5,6 +5,11 @@ import ( |
|
@@ -5,6 +5,11 @@ 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"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
11
|
+
|
|
|
12
|
+ "text/template"
|
8
|
|
13
|
|
9
|
"github.com/zeromicro/go-zero/core/logx"
|
14
|
"github.com/zeromicro/go-zero/core/logx"
|
10
|
)
|
15
|
)
|
|
@@ -23,8 +28,182 @@ func NewMiniCreateArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCo |
|
@@ -23,8 +28,182 @@ func NewMiniCreateArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCo |
23
|
}
|
28
|
}
|
24
|
}
|
29
|
}
|
25
|
|
30
|
|
|
|
31
|
+// 填写评论
|
26
|
func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.MiniCreateArticleCommentRequest) (resp *types.MiniCreateArticleCommentResponse, err error) {
|
32
|
func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.MiniCreateArticleCommentRequest) (resp *types.MiniCreateArticleCommentResponse, err error) {
|
27
|
- // todo: add your logic here and delete this line
|
33
|
+ var conn = l.svcCtx.DefaultDBConn()
|
|
|
34
|
+ // 获取评论填写人的信息
|
|
|
35
|
+ fromUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.FromUserId)
|
|
|
36
|
+ if err != nil {
|
|
|
37
|
+ return nil, xerr.NewErrMsgErr("获取评论人信息失败", err)
|
|
|
38
|
+ }
|
|
|
39
|
+ companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
|
|
|
40
|
+ if err != nil {
|
|
|
41
|
+ return nil, xerr.NewErrMsgErr("获取公司信息失败", err)
|
|
|
42
|
+ }
|
|
|
43
|
+ // 获取文章
|
|
|
44
|
+ articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArtitcleId)
|
|
|
45
|
+ if err != nil {
|
|
|
46
|
+ return nil, xerr.NewErrMsgErr("获取文章信息失败", err)
|
|
|
47
|
+ }
|
|
|
48
|
+ if articleInfo.CompanyId != req.CompanyId {
|
|
|
49
|
+ return nil, xerr.NewErrMsg("没有评论权限")
|
|
|
50
|
+ }
|
|
|
51
|
+ //查看评论权限,
|
|
|
52
|
+ //临时注释
|
|
|
53
|
+ // if len(articleInfo.WhoReview) > 0 {
|
|
|
54
|
+ // ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId)
|
|
|
55
|
+ // if ok < 0 {
|
|
|
56
|
+ // return nil, xerr.NewErrMsg("没有评论权限")
|
|
|
57
|
+ // }
|
|
|
58
|
+ // }
|
|
|
59
|
+ // 对段落进行评论
|
|
|
60
|
+ var selctionInfo *domain.ArticleSection
|
|
|
61
|
+ if req.SectionId > 0 {
|
|
|
62
|
+ //获取段落
|
|
|
63
|
+ selctionInfo, err = l.svcCtx.ArticleSectionRepository.FindOne(l.ctx, conn, req.SectionId)
|
|
|
64
|
+ if err != nil {
|
|
|
65
|
+ return nil, xerr.NewErrMsgErr("获取文章段落信息失败", err)
|
|
|
66
|
+ }
|
|
|
67
|
+ if selctionInfo.ArticleId != articleInfo.Id {
|
|
|
68
|
+ return nil, xerr.NewErrMsg("获取文章段落信息失败")
|
|
|
69
|
+ }
|
|
|
70
|
+ }
|
|
|
71
|
+ // 回复哪个评论
|
|
|
72
|
+ var pComment *domain.ArticleComment
|
|
|
73
|
+ if req.Pid > 0 {
|
|
|
74
|
+ pComment, err = l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Pid)
|
|
|
75
|
+ if err != nil {
|
|
|
76
|
+ return nil, xerr.NewErrMsgErr("获取上一层级的评论信息失败", err)
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ if pComment.ArticleId != articleInfo.Id {
|
|
|
80
|
+ if err != nil {
|
|
|
81
|
+ return nil, xerr.NewErrMsg("评论信息与文章不匹配")
|
|
|
82
|
+ }
|
|
|
83
|
+ }
|
|
|
84
|
+ }
|
|
|
85
|
+ var atWhoList []*domain.User
|
|
|
86
|
+ if len(req.AtWho) > 0 {
|
|
|
87
|
+ queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", req.AtWho)
|
|
|
88
|
+ _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
|
|
|
89
|
+ if err != nil {
|
|
|
90
|
+ return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
|
|
|
91
|
+ }
|
|
|
92
|
+ }
|
|
|
93
|
+ // 处理文本内容
|
|
|
94
|
+ // content:=
|
|
|
95
|
+ content := template.HTMLEscapeString(req.Content)
|
|
|
96
|
+
|
|
|
97
|
+ newComment := domain.ArticleComment{
|
|
|
98
|
+ Id: 0,
|
|
|
99
|
+ CompanyId: req.CompanyId,
|
|
|
100
|
+ CreatedAt: 0,
|
|
|
101
|
+ UpdatedAt: 0,
|
|
|
102
|
+ DeletedAt: 0,
|
|
|
103
|
+ Version: 0,
|
|
|
104
|
+ Pid: req.Pid,
|
|
|
105
|
+ TopId: 0,
|
|
|
106
|
+ ArticleId: req.ArtitcleId,
|
|
|
107
|
+ SectionId: req.SectionId,
|
|
|
108
|
+ SectionContent: "",
|
|
|
109
|
+ FromUserId: req.FromUserId,
|
|
|
110
|
+ FromUser: domain.UserSimple{
|
|
|
111
|
+ Id: fromUser.Id,
|
|
|
112
|
+ Name: fromUser.Name,
|
|
|
113
|
+ Avatar: fromUser.Avatar,
|
|
|
114
|
+ Position: fromUser.Position,
|
|
|
115
|
+ Company: companyInfo.Name,
|
|
|
116
|
+ CompanyId: companyInfo.Id,
|
|
|
117
|
+ },
|
|
|
118
|
+ ToUserId: 0,
|
|
|
119
|
+ ToUser: domain.UserSimple{},
|
|
|
120
|
+ Content: content,
|
|
|
121
|
+ CountReply: 0,
|
|
|
122
|
+ CountUserLove: 0,
|
|
|
123
|
+ CountAdminLove: 0,
|
|
|
124
|
+ Show: 0,
|
|
|
125
|
+ AtWho: []domain.UserSimple{},
|
|
|
126
|
+ }
|
|
|
127
|
+
|
|
|
128
|
+ if selctionInfo != nil {
|
|
|
129
|
+ newComment.SectionContent = selctionInfo.Content
|
|
|
130
|
+ }
|
|
|
131
|
+ if pComment != nil {
|
|
|
132
|
+ newComment.TopId = pComment.TopId
|
|
|
133
|
+ if pComment.TopId == 0 {
|
|
|
134
|
+ newComment.TopId = pComment.Id
|
|
|
135
|
+ }
|
|
|
136
|
+ newComment.ToUser = pComment.FromUser
|
|
|
137
|
+ newComment.ToUserId = pComment.FromUserId
|
|
|
138
|
+ newComment.SectionId = pComment.SectionId
|
|
|
139
|
+ }
|
|
|
140
|
+ for i := range atWhoList {
|
|
|
141
|
+ newComment.AtWho = append(newComment.AtWho, domain.UserSimple{
|
|
|
142
|
+ Id: atWhoList[i].Id,
|
|
|
143
|
+ Name: atWhoList[i].Name,
|
|
|
144
|
+ Avatar: atWhoList[i].Avatar,
|
|
|
145
|
+ Position: atWhoList[i].Position,
|
|
|
146
|
+ Company: companyInfo.Name,
|
|
|
147
|
+ CompanyId: companyInfo.Id,
|
|
|
148
|
+ })
|
|
|
149
|
+ }
|
|
|
150
|
+ //保存数据
|
|
|
151
|
+ err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
152
|
+ // 增加平评论计数
|
|
|
153
|
+ err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo)
|
|
|
154
|
+ if err != nil {
|
|
|
155
|
+ return err
|
|
|
156
|
+ }
|
|
|
157
|
+ //保存评论
|
|
|
158
|
+ _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment)
|
|
|
159
|
+ if err != nil {
|
|
|
160
|
+ return err
|
|
|
161
|
+ }
|
|
|
162
|
+ return nil
|
|
|
163
|
+ }, true)
|
|
|
164
|
+
|
|
|
165
|
+ if err != nil {
|
|
|
166
|
+ return nil, xerr.NewErrMsgErr("保存评论失败", err)
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ resp = &types.MiniCreateArticleCommentResponse{
|
|
|
170
|
+ Id: newComment.Id,
|
|
|
171
|
+ Pid: newComment.Pid,
|
|
|
172
|
+ TopId: newComment.TopId,
|
|
|
173
|
+ ArtitcleId: newComment.ArticleId,
|
|
|
174
|
+ SectionId: newComment.ArticleId,
|
|
|
175
|
+ FromUserId: newComment.FromUserId,
|
|
|
176
|
+ FromUser: types.CommentAuthor{
|
|
|
177
|
+ Id: newComment.FromUser.Id,
|
|
|
178
|
+ Name: newComment.FromUser.Name,
|
|
|
179
|
+ Avatar: newComment.FromUser.Avatar,
|
|
|
180
|
+ Position: newComment.FromUser.Position,
|
|
|
181
|
+ Company: newComment.FromUser.Company,
|
|
|
182
|
+ },
|
|
|
183
|
+ ToUserId: newComment.ToUserId,
|
|
|
184
|
+ ToUser: types.CommentAuthor{
|
|
|
185
|
+ Id: newComment.ToUser.Id,
|
|
|
186
|
+ Name: newComment.ToUser.Name,
|
|
|
187
|
+ Avatar: newComment.ToUser.Avatar,
|
|
|
188
|
+ Position: newComment.ToUser.Position,
|
|
|
189
|
+ Company: newComment.ToUser.Company,
|
|
|
190
|
+ },
|
|
|
191
|
+ SectionContent: newComment.SectionContent,
|
|
|
192
|
+ CountReply: 0,
|
|
|
193
|
+ CountUserLove: 0,
|
|
|
194
|
+ CountAdminLove: 0,
|
|
|
195
|
+ AtWho: []types.CommentAuthor{},
|
|
|
196
|
+ }
|
|
|
197
|
+
|
|
|
198
|
+ for _, val := range newComment.AtWho {
|
|
|
199
|
+ resp.AtWho = append(resp.AtWho, types.CommentAuthor{
|
|
|
200
|
+ Id: val.Id,
|
|
|
201
|
+ Name: val.Name,
|
|
|
202
|
+ Avatar: val.Avatar,
|
|
|
203
|
+ Position: val.Position,
|
|
|
204
|
+ Company: val.Company,
|
|
|
205
|
+ })
|
|
|
206
|
+ }
|
28
|
|
207
|
|
29
|
- return
|
208
|
+ return resp, nil
|
30
|
} |
209
|
} |