package com.newvideo.controller.parser; import java.io.PrintWriter; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import com.newvideo.domain.Comment2; import com.newvideo.domain.CommentReply; import com.newvideo.domain.DetailSystem; import com.newvideo.domain.LoginUser; import com.newvideo.domain.VideoInfo; import com.newvideo.service.imp.CommentService; import com.newvideo.service.imp.SystemService; import com.newvideo.service.imp.UserService; import com.newvideo.service.imp.push.PushService; import com.newvideo.util.JsonUtil; import com.newvideo.util.StringUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @Controller public class CommentParser { @Resource private SystemService systemService; @Resource private CommentService commentService; @Resource private UserService userService; @Resource private PushService pushService; 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; } public void getReadState(String uid, HttpServletRequest request, PrintWriter out) { String method = request.getParameter("Method"); String system = request.getParameter("System"); String sign = request.getParameter("Sign"); String platform = request.getParameter("Platform"); String version = request.getParameter("Version"); String packageName = request.getParameter("Package"); if (StringUtil.isNullOrEmpty(method)) { out.print(JsonUtil.loadFalseJson("请上传Method")); return; } if (StringUtil.isNullOrEmpty(uid)) { out.print(JsonUtil.loadFalseJson("请上传Uid")); return; } if (StringUtil.isNullOrEmpty(system)) { out.print(JsonUtil.loadFalseJson("请上传System")); return; } if (StringUtil.isNullOrEmpty(sign)) { out.print(JsonUtil.loadFalseJson("请上传Sign")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } boolean have = commentService.isHaveNewMessage(uid); JSONObject object = new JSONObject(); object.put("Read", have); out.print(JsonUtil.loadTrueJson(object.toString())); } public void login(String uid, HttpServletRequest request, PrintWriter out) { String method = request.getParameter("Method"); String system = request.getParameter("System"); String sign = request.getParameter("Sign"); String platform = request.getParameter("Platform"); String version = request.getParameter("Version"); String packageName = request.getParameter("Package"); 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(method)) { out.print(JsonUtil.loadFalseJson("请上传Method")); return; } if (StringUtil.isNullOrEmpty(uid)) { out.print(JsonUtil.loadFalseJson("请上传Uid")); return; } if (StringUtil.isNullOrEmpty(system)) { out.print(JsonUtil.loadFalseJson("请上传System")); return; } if (StringUtil.isNullOrEmpty(sign)) { out.print(JsonUtil.loadFalseJson("请上传Sign")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } if (StringUtil.isNullOrEmpty(version)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } if (StringUtil.isNullOrEmpty(packageName)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } 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(packageName); LoginUser lu = userService.getLoginUser(openid, detailSystem.getId(), Integer.parseInt(loginType), portrait, name); 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(String uid, HttpServletRequest request, PrintWriter out) { String method = request.getParameter("Method"); String system = request.getParameter("System"); String sign = request.getParameter("Sign"); String platform = request.getParameter("Platform"); String version = request.getParameter("Version"); String packageName = request.getParameter("Package"); String videoId = request.getParameter("VideoId"); String thirdType = request.getParameter("ThirdType"); String page = request.getParameter("Page"); if (StringUtil.isNullOrEmpty(method)) { out.print(JsonUtil.loadFalseJson("请上传Method")); return; } if (StringUtil.isNullOrEmpty(uid)) { out.print(JsonUtil.loadFalseJson("请上传Uid")); return; } if (StringUtil.isNullOrEmpty(system)) { out.print(JsonUtil.loadFalseJson("请上传System")); return; } if (StringUtil.isNullOrEmpty(sign)) { out.print(JsonUtil.loadFalseJson("请上传Sign")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } 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 list1 = commentService.getComment2List(videoId, thirdType, pageIndex); List list = new ArrayList(); 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())); } public void getMyCommentReply(String uid, HttpServletRequest request, PrintWriter out) { String method = request.getParameter("Method"); String page = request.getParameter("Page"); String system = request.getParameter("System"); String sign = request.getParameter("Sign"); String platform = request.getParameter("Platform"); if (StringUtil.isNullOrEmpty(method)) { out.print(JsonUtil.loadFalseJson("请上传Method")); return; } if (StringUtil.isNullOrEmpty(uid)) { out.print(JsonUtil.loadFalseJson("请上传LoginUid")); return; } if (StringUtil.isNullOrEmpty(system)) { out.print(JsonUtil.loadFalseJson("请上传System")); return; } if (StringUtil.isNullOrEmpty(sign)) { out.print(JsonUtil.loadFalseJson("请上传Sign")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } int pageIndex = StringUtil.getPage(page); if (pageIndex == 0) { out.print(JsonUtil.loadFalseJson("请上传Page")); return; } List list = commentService.getCommentReplyList(uid, pageIndex); long count = commentService.getCommentReplyListCount(uid); 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(uid); object.put("data", array); object.put("count", count); out.print(JsonUtil.loadTrueJson(object.toString())); } public void replayComment(String uid, HttpServletRequest request, PrintWriter out) { String method = request.getParameter("Method"); String system = request.getParameter("System"); String sign = request.getParameter("Sign"); String platform = request.getParameter("Platform"); String commentReplyId = request.getParameter("CommentReplyId"); String commentId = request.getParameter("CommentId"); String content = request.getParameter("Content"); if (StringUtil.isNullOrEmpty(method)) { out.print(JsonUtil.loadFalseJson("请上传Method")); return; } if (StringUtil.isNullOrEmpty(uid)) { out.print(JsonUtil.loadFalseJson("请上传LoginUid")); return; } if (StringUtil.isNullOrEmpty(system)) { out.print(JsonUtil.loadFalseJson("请上传System")); return; } if (StringUtil.isNullOrEmpty(sign)) { out.print(JsonUtil.loadFalseJson("请上传Sign")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } if (StringUtil.isNullOrEmpty(commentId)) { out.print(JsonUtil.loadFalseJson("请上传commentId")); return; } if (StringUtil.match("[\\d]{6,}", content)) { out.print(JsonUtil.loadFalseJson("信息格式不正确")); return; } if (1 > 0) { out.print(JsonUtil.loadFalseJson("评论功能已关闭")); return; } Serializable repid = commentService.replyComment(commentId, commentReplyId, uid, content); if (repid != null) { pushService.pushCommentReplay(commentId, commentReplyId, repid + ""); } out.print(JsonUtil.loadTrueJson("")); } public void comment(String uid, HttpServletRequest request, PrintWriter out) { String method = request.getParameter("Method"); String system = request.getParameter("System"); String videoId = request.getParameter("VideoId"); String thirdType = request.getParameter("ThirdType"); String sign = request.getParameter("Sign"); String platform = request.getParameter("Platform"); String packageName = request.getParameter("Package"); String content = request.getParameter("Content"); if (StringUtil.isNullOrEmpty(method)) { out.print(JsonUtil.loadFalseJson("请上传Method")); return; } if (StringUtil.isNullOrEmpty(uid)) { out.print(JsonUtil.loadFalseJson("请上传LoginUid")); return; } if (StringUtil.isNullOrEmpty(system)) { out.print(JsonUtil.loadFalseJson("请上传System")); return; } if (StringUtil.isNullOrEmpty(sign)) { out.print(JsonUtil.loadFalseJson("请上传Sign")); return; } if (StringUtil.isNullOrEmpty(videoId)) { out.print(JsonUtil.loadFalseJson("请上传VideoId")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } if (StringUtil.match("[\\d]{6,}", content)) { out.print(JsonUtil.loadFalseJson("信息格式不正确")); return; } if (1 > 0) { out.print(JsonUtil.loadFalseJson("评论功能已关闭")); return; } DetailSystem detailSystem = systemService.getDetailSystemByPackage(packageName); Comment2 comment = new Comment2(); comment.setContent(content); comment.setCreatetime(System.currentTimeMillis() + ""); comment.setShow(true); comment.setThirdType(thirdType); comment.setUser(new LoginUser(uid)); comment.setVideo(new VideoInfo(videoId)); comment.setDetailsystem(detailSystem.getId()); commentService.addComment2(comment); out.print(JsonUtil.loadTrueJson("")); } }