1
1
package com .gpmall .comment .service ;
2
2
3
+ import com .github .pagehelper .PageHelper ;
4
+ import com .github .pagehelper .PageInfo ;
3
5
import com .gpmall .comment .CommentException ;
4
6
import com .gpmall .comment .ICommentReplyService ;
5
7
import com .gpmall .comment .constant .CommentRetCode ;
8
+ import com .gpmall .comment .convert .CommentConverter ;
6
9
import com .gpmall .comment .dal .entitys .Comment ;
7
10
import com .gpmall .comment .dal .entitys .CommentReply ;
8
11
import com .gpmall .comment .dal .persistence .CommentMapper ;
9
12
import com .gpmall .comment .dal .persistence .CommentReplyMapper ;
10
- import com .gpmall .comment .dto .AddCommentReplyRequest ;
11
- import com .gpmall .comment .dto .AddCommentReplyResponse ;
13
+ import com .gpmall .comment .dto .*;
12
14
import com .gpmall .comment .utils .ExceptionProcessorUtil ;
13
15
import com .gpmall .comment .utils .GlobalIdGeneratorUtil ;
14
16
import org .apache .dubbo .config .annotation .Service ;
17
+ import org .springframework .util .CollectionUtils ;
18
+ import tk .mybatis .mapper .entity .Example ;
15
19
20
+ import java .util .ArrayList ;
16
21
import java .util .Date ;
22
+ import java .util .List ;
17
23
18
24
/**
19
25
* @author heps
@@ -27,13 +33,16 @@ public class CommentReplyServiceImpl implements ICommentReplyService {
27
33
28
34
private final CommentMapper commentMapper ;
29
35
36
+ private final CommentConverter commentConverter ;
37
+
30
38
private final GlobalIdGeneratorUtil globalIdGeneratorUtil ;
31
39
32
40
private static final String COMMENT_GLOBAL_ID_CACHE_KEY = "COMMENT_REPLY_ID" ;
33
41
34
- public CommentReplyServiceImpl (CommentReplyMapper commentReplyMapper , CommentMapper commentMapper , GlobalIdGeneratorUtil globalIdGeneratorUtil ) {
42
+ public CommentReplyServiceImpl (CommentReplyMapper commentReplyMapper , CommentMapper commentMapper , CommentConverter commentConverter , GlobalIdGeneratorUtil globalIdGeneratorUtil ) {
35
43
this .commentReplyMapper = commentReplyMapper ;
36
44
this .commentMapper = commentMapper ;
45
+ this .commentConverter = commentConverter ;
37
46
this .globalIdGeneratorUtil = globalIdGeneratorUtil ;
38
47
}
39
48
@@ -70,4 +79,57 @@ public AddCommentReplyResponse addCommentReply(AddCommentReplyRequest request) {
70
79
}
71
80
return response ;
72
81
}
82
+
83
+ @ Override
84
+ public DeleteCommentReplyResponse deleteCommentReply (DeleteCommentReplyRequest request ) {
85
+ DeleteCommentReplyResponse response = new DeleteCommentReplyResponse ();
86
+ try {
87
+ request .requestCheck ();
88
+ CommentReply commentReply = commentReplyMapper .selectByPrimaryKey (request .getCommentReplyId ());
89
+ if (commentReply == null || (commentReply .getIsDeleted () != null && commentReply .getIsDeleted ())) {
90
+ throw new CommentException (CommentRetCode .CURRENT_COMMENT_REPLY_NOT_EXIST .getCode (), CommentRetCode .CURRENT_COMMENT_REPLY_NOT_EXIST .getMessage ());
91
+ }
92
+ commentReply .setIsDeleted (true );
93
+ commentReply .setDeletionUserId (request .getUserId ());
94
+ commentReply .setDeletionTime (new Date ());
95
+ commentReplyMapper .updateByPrimaryKey (commentReply );
96
+
97
+ response .setCode (CommentRetCode .SUCCESS .getCode ());
98
+ response .setMsg (CommentRetCode .SUCCESS .getMessage ());
99
+ } catch (Exception e ) {
100
+ ExceptionProcessorUtil .handleException (response , e );
101
+ }
102
+ return response ;
103
+ }
104
+
105
+ @ Override
106
+ public CommentReplyListResponse commentReplyList (CommentReplyListRequest request ) {
107
+ CommentReplyListResponse response = new CommentReplyListResponse ();
108
+ try {
109
+ request .requestCheck ();
110
+
111
+ Example example = new Example (CommentReply .class );
112
+ Example .Criteria criteria = example .createCriteria ();
113
+ CommentReply commentReply = commentReplyMapper .selectByPrimaryKey (request .getCommentId ());
114
+ if (commentReply != null ) {
115
+ criteria .andEqualTo ("parentId" , request .getCommentId ());
116
+ } else {
117
+ criteria .andEqualTo ("commentId" , request .getCommentId ());
118
+ }
119
+ PageHelper .startPage (request .getPage (), request .getSize ());
120
+ List <CommentReply > commentReplyList = commentReplyMapper .selectByExample (example );
121
+ PageInfo <CommentReply > pageInfo = new PageInfo <>(commentReplyList );
122
+ if (CollectionUtils .isEmpty (commentReplyList )) {
123
+ response .setCommentReplyDtoList (new ArrayList <>());
124
+ } else {
125
+ response .setCommentReplyDtoList (commentConverter .commentReply2Dto (commentReplyList ));
126
+ }
127
+ response .setTotal (pageInfo .getTotal ());
128
+ response .setPage (request .getPage ());
129
+ response .setSize (request .getSize ());
130
+ } catch (Exception e ) {
131
+ ExceptionProcessorUtil .handleException (response , e );
132
+ }
133
+ return response ;
134
+ }
73
135
}
0 commit comments