package com.newvideo.controller.parser; import java.io.PrintWriter; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.newvideo.domain.LoginUser; import com.newvideo.domain.UserInfo; import com.newvideo.domain.shop.ShopGoodsItem; import com.newvideo.domain.shop.ShopItemCollect; import com.newvideo.domain.shop.ShopItemComment; import com.newvideo.service.imp.shop.ShopService; import com.newvideo.util.JsonUtil; import com.newvideo.util.StringUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @Controller public class ShopParser { @Resource private ShopService shopService; public void getGoodsItemList(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 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(page)) { out.print(JsonUtil.loadFalseJson("请上传Page")); return; } int pageIndex = Integer.parseInt(page); pageIndex = pageIndex < 1 ? 1 : pageIndex; List list = shopService.getGoodsList(uid, pageIndex); JSONObject object = new JSONObject(); object.put("count", 1000 + ""); JSONArray array = new JSONArray(); for (int i = 0; i < list.size(); i++) array.add(StringUtil.outPutResultJson(list.get(i))); object.put("data", array); out.print(JsonUtil.loadTrueJson(object.toString())); } public void getGoodsItemDetail(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 id = request.getParameter("Id"); 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(id)) { out.print(JsonUtil.loadFalseJson("请上传Id")); return; } ShopGoodsItem item = shopService.getGoodsDetail(Long.parseLong(id)); item.setCommentcount(item.getCommentcount() + 1); List commentList = shopService.shopItemCommentList(item.getId(), 1); ShopItemComment sc = new ShopItemComment(); sc.setUser(item.getLoginUser()); sc.setContent(item.getTitle()); sc.setCreatetime(item.getCreatetime() + ""); commentList.add(0, sc); boolean isC = shopService.isCollect(item.getId(), uid); long ccount = shopService.shopItemCommentCount(item.getId()); Gson gson = new GsonBuilder().create(); JSONObject comment = new JSONObject(); comment.put("count", ccount + 1); comment.put("data", StringUtil.outPutResultJson(commentList)); JSONObject object = new JSONObject(); object.put("comment", comment); object.put("Item", StringUtil.outPutResultJson(item)); object.put("collect", isC); out.print(JsonUtil.loadTrueJson(object.toString())); } public void getCommentList(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 page = request.getParameter("Page"); String id = request.getParameter("Id"); 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(page)) { out.print(JsonUtil.loadFalseJson("请上传Page")); return; } int pageIndex = Integer.parseInt(page); pageIndex = pageIndex < 1 ? 1 : pageIndex; ShopGoodsItem item = shopService.getGoodsDetail(Long.parseLong(id)); ShopItemComment sc = new ShopItemComment(); sc.setUser(item.getLoginUser()); sc.setContent(item.getTitle()); sc.setCreatetime(item.getCreatetime() + ""); List list = shopService.shopItemCommentList(Long.parseLong(id), pageIndex); if (pageIndex == 1) list.add(0, sc); long count = shopService.shopItemCommentCount(Long.parseLong(id)); Gson gson = new GsonBuilder().create(); JSONObject object = new JSONObject(); object.put("count", count + 1); object.put("data", StringUtil.outPutResultJson(list)); out.print(JsonUtil.loadTrueJson(object.toString())); } public void addComment(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 loginUid = request.getParameter("LoginUid"); String id = request.getParameter("Id"); String content = request.getParameter("Content"); 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(loginUid)) { out.print(JsonUtil.loadFalseJson("请上传LoginUid")); return; } if (StringUtil.isNullOrEmpty(id)) { out.print(JsonUtil.loadFalseJson("请上传Id")); return; } if (StringUtil.isNullOrEmpty(content)) { out.print(JsonUtil.loadFalseJson("请上传Content")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } if (StringUtil.match("[\\d]{6,}", content)) { out.print(JsonUtil.loadFalseJson("信息格式不正确")); return; } ShopItemComment sc = new ShopItemComment(); sc.setContent(content); sc.setCreatetime(System.currentTimeMillis() + ""); sc.setItemid(Long.parseLong(id)); sc.setShow(true); sc.setUser(new LoginUser(loginUid)); shopService.addshopItemComment(sc); out.print(JsonUtil.loadTrueJson("")); } public void addCollect(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 id = request.getParameter("Id"); 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(id)) { out.print(JsonUtil.loadFalseJson("请上传Id")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } ShopItemCollect sc = new ShopItemCollect(); sc.setCreatetime(System.currentTimeMillis() + ""); sc.setItemid(Long.parseLong(id)); sc.setUser(new UserInfo(uid)); shopService.addshopItemCollect(sc); out.print(JsonUtil.loadTrueJson("")); } public void cancelCollect(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 id = request.getParameter("Id"); 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(id)) { out.print(JsonUtil.loadFalseJson("请上传Id")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } String[] ids = id.split(","); for (String idStr : ids) { ShopItemCollect sc = new ShopItemCollect(); sc.setCreatetime(System.currentTimeMillis() + ""); sc.setItemid(Long.parseLong(idStr)); sc.setUser(new UserInfo(uid)); shopService.cancelshopItemCollect(sc); } out.print(JsonUtil.loadTrueJson("")); } // 获取收藏商品列表 public void getCollectList(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 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(page)) { out.print(JsonUtil.loadFalseJson("请上传Page")); return; } if (StringUtil.isNullOrEmpty(platform)) { out.print(JsonUtil.loadFalseJson("请上传Platform")); return; } int pageIndex = Integer.parseInt(page); pageIndex = pageIndex < 1 ? 1 : pageIndex; List list = shopService.collectList(uid, pageIndex); long count = shopService.collectCount(uid, pageIndex); JSONObject object = new JSONObject(); object.put("count", count); object.put("data", StringUtil.outPutResultJson(list)); out.print(JsonUtil.loadTrueJson(object.toString())); } }