package com.yeshi.buwan.controller.parser; import com.google.gson.GsonBuilder; 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.util.wx.MyWXLoginUtil; import com.yeshi.buwan.vo.AcceptData; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.yeshi.utils.entity.wx.WeiXinUser; import org.yeshi.utils.wx.WXUtil; 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; @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 wxLogin(AcceptData acceptData, String code, HttpServletRequest request, PrintWriter out) { if (StringUtil.isNullOrEmpty(code)) { out.print(JsonUtil.loadFalseJson("code为空")); return; } //通过code换取个人信息 WeiXinUser weiXinUser = MyWXLoginUtil.getUserInfo(code, MyWXLoginUtil.WEIXIN_APPID, MyWXLoginUtil.WEIXIN_SECRET); if (weiXinUser == null) { out.print(JsonUtil.loadFalseJson("获取授权信息失败")); return; } DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); LoginUser lu = userService.getLoginUser(weiXinUser.getOpenid(), detailSystem.getId(), 2, weiXinUser.getHeadimgurl(), weiXinUser.getNickname(), UserParser.getIp(request) + ":" + request.getRemotePort()); if (lu != null) { JSONObject object = new JSONObject(); object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu)); 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 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())); } @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 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("")); } }