admin
2020-08-22 813d2cae75cbae3f216de5f493af643c5a560c82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package com.yeshi.buwan.controller.parser;
 
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.service.imp.CommentService;
import com.yeshi.buwan.service.imp.MaskKeyService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.service.imp.UserService;
import com.yeshi.buwan.service.imp.push.PushService;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.annotation.RequireUid;
import com.yeshi.buwan.vo.AcceptData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
@Controller
public class CommentParser {
    @Resource
    private SystemService systemService;
    @Resource
    private CommentService commentService;
    @Resource
    private UserService userService;
    @Resource
    private PushService pushService;
    @Resource
    private MaskKeyService maskKeyService;
 
    public SystemService getSystemService() {
        return systemService;
    }
 
    public void setSystemService(SystemService systemService) {
        this.systemService = systemService;
    }
 
    public CommentService getCommentService() {
        return commentService;
    }
 
    public void setCommentService(CommentService commentService) {
        this.commentService = commentService;
    }
 
    public UserService getUserService() {
        return userService;
    }
 
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
 
    @RequireUid
    public void getReadState(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        boolean have = commentService.isHaveNewMessage(acceptData.getUid());
        JSONObject object = new JSONObject();
        object.put("Read", have);
        out.print(JsonUtil.loadTrueJson(object.toString()));
 
    }
 
    public void login(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String name = request.getParameter("Name");
        String portrait = request.getParameter("Portrait");
        String openid = request.getParameter("OpenId");
        String sex = request.getParameter("Sex");// 1-男 2-女
        String loginType = request.getParameter("LoginType");// 登录类型
 
 
        if (StringUtil.isNullOrEmpty(name)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(portrait)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(openid)) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
        LoginUser lu = userService.getLoginUser(openid, detailSystem.getId(), Integer.parseInt(loginType), portrait,
                name, UserParser.getIp(request) + ":" + request.getRemotePort());
        if (lu != null) {
            JSONObject object = new JSONObject();
            object.put("LoginUid", lu.getId());
            out.print(JsonUtil.loadTrueJson(object.toString()));
        } else {
            out.print(JsonUtil.loadFalseJson("登录失败"));
        }
 
    }
 
    public void getVideoCommentList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String videoId = request.getParameter("VideoId");
        String thirdType = request.getParameter("ThirdType");
        String page = request.getParameter("Page");
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传videoId"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(page)) {
            out.print(JsonUtil.loadFalseJson("请上传page"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(thirdType)) {
            out.print(JsonUtil.loadFalseJson("请上传thirdType"));
            return;
        }
        int pageIndex = Integer.parseInt(page);
 
        java.util.List<Comment2> list1 = commentService.getComment2List(videoId, thirdType, pageIndex);
        List<Comment2> list = new ArrayList<Comment2>();
        if (list1 != null)
            for (Comment2 cm : list1)
                list.add(cm);
        long count = commentService.getComment2ListCount(videoId, thirdType);
 
        JSONObject object = new JSONObject();
        JSONArray array = new JSONArray();
        for (int j = 0; j < list.size(); j++) {
            JSONObject obj = JSONObject.fromObject(StringUtil.outPutResultJson(list.get(j)));
            JSONArray ar = new JSONArray();
            if (list.get(j).getReplyList() != null)
                for (CommentReply cr : list.get(j).getReplyList())
                    ar.add(StringUtil.outPutResultJson(cr));
            obj.put("ReplyList", ar);
            array.add(obj);
        }
        object.put("data", array);
        object.put("count", count);
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
    @RequireUid
    public void getMyCommentReply(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String page = request.getParameter("Page");
        int pageIndex = StringUtil.getPage(page);
        if (pageIndex == 0) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        List<CommentReply> list = commentService.getCommentReplyList(acceptData.getUid(), pageIndex);
        long count = commentService.getCommentReplyListCount(acceptData.getUid());
 
        JSONObject object = new JSONObject();
 
        JSONArray array = new JSONArray();
        for (int i = 0; i < list.size(); i++)
            array.add(StringUtil.outPutResultJson(list.get(i)));
        commentService.setCommentReplyRead(acceptData.getUid());
        object.put("data", array);
        object.put("count", count);
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
    @RequireUid
    public void replayComment(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String commentReplyId = request.getParameter("CommentReplyId");
        String commentId = request.getParameter("CommentId");
        String content = request.getParameter("Content");
 
        if (StringUtil.isNullOrEmpty(commentId)) {
            out.print(JsonUtil.loadFalseJson("请上传commentId"));
            return;
        }
 
        if (StringUtil.match("[\\d]{6,}", content)) {
            out.print(JsonUtil.loadFalseJson("信息格式不正确"));
            return;
        }
 
        Serializable repid = commentService.replyComment(commentId, commentReplyId, acceptData.getUid(), content);
        if (repid != null) {
            pushService.pushCommentReplay(commentId, commentReplyId, repid + "");
        }
        out.print(JsonUtil.loadTrueJson(""));
    }
 
    @RequireUid
    public void comment(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String videoId = request.getParameter("VideoId");
        String thirdType = request.getParameter("ThirdType");
        String content = request.getParameter("Content");
 
        if (StringUtil.isNullOrEmpty(videoId)) {
            out.print(JsonUtil.loadFalseJson("请上传VideoId"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(acceptData.getPlatform())) {
            out.print(JsonUtil.loadFalseJson("请上传Platform"));
            return;
        }
 
        if (StringUtil.match("[\\d]{6,}", content)) {
            out.print(JsonUtil.loadFalseJson("信息格式不正确"));
            return;
        }
 
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
 
        Comment2 comment = new Comment2();
        content = maskKeyService.maskAction(content);
        comment.setContent(content);
        comment.setCreatetime(System.currentTimeMillis() + "");
        comment.setShow(true);
        comment.setThirdType(thirdType);
        comment.setUser(new LoginUser(acceptData.getUid()));
        comment.setVideo(new VideoInfo(videoId));
        comment.setDetailsystem(detailSystem.getId());
        commentService.addComment2(comment);
 
        out.print(JsonUtil.loadTrueJson(""));
 
    }
}