/** * 查询公共连接分类列表 * * @param page 当前页 * @param pageNum 每页显示条数 * @return 公共连接分类列表json */ @GET @Path("/list/commonlinktype") @Produces({MediaType.APPLICATION_JSON}) public JSONObject findCommonlinkTypeList( @DefaultValue("1") @QueryParam("page") int page, @DefaultValue("10") @QueryParam("pagenum") int pageNum) { JSONObject result = new JSONObject(); JSONArray jsonArray = new JSONArray(); result.put("count", 0); result.put("commonlinktypelist", jsonArray); HttpSession session = request.getSession(); User user = (User) session.getAttribute("loginUser"); if (null != user) { PageBounds pb = PageBoundsUtil.PageBoundsOrderExtend("orderId.desc"); pb.setPage(page); pb.setLimit(pageNum); CommonlinkType commonlinkType = new CommonlinkType(String.valueOf(user.getId())); Pager<CommonlinkType> commonLinkPage = commonlinkService.findCommonlinkTypeList(commonlinkType, pb); if (null != commonLinkPage && commonLinkPage.getTotal() > 0) { result.put("count", commonLinkPage.getTotal()); buildCommonlinkTypeListToJSONAarray(commonLinkPage, jsonArray); } } return result; }
/** * 查询分类、公共连接列表 * * @param page 当前页 * @param pageNum 每页显示条数 * @return 分类、公共连接列表 */ @GET @Path("/list/commonlink") @Produces({MediaType.APPLICATION_JSON}) public JSONObject findCommonlinkList( @DefaultValue("1") @QueryParam("page") int page, @DefaultValue("10") @QueryParam("pagenum") int pageNum) { JSONObject result = new JSONObject(); JSONArray jsonArray = new JSONArray(); result.put("count", 0); result.put("result", jsonArray); HttpSession session = request.getSession(); User user = (User) session.getAttribute("loginUser"); if (null != user) { PageBounds pb = PageBoundsUtil.PageBoundsOrderExtend("orderId.desc"); pb.setPage(page); pb.setLimit(pageNum); CommonlinkType commonlinkType = new CommonlinkType(); commonlinkType.setUserId(String.valueOf(user.getId())); // 获取公共连接分类列表 Pager<CommonlinkType> commonLinkTypePage = commonlinkService.findCommonlinkTypeList(commonlinkType, pb); List<String> types = new ArrayList<String>(); if (null != commonLinkTypePage) { result.put("count", commonLinkTypePage.getTotal()); List<CommonlinkType> commonlinkTypes = commonLinkTypePage.getDatas(); // 组装公共连接查询条件(多个分类,主要用作in查询) for (CommonlinkType linkType : commonlinkTypes) { types.add(linkType.getId()); } // 获取指定分类下的所有连接列表 List<Commonlink> commonLinkList = commonlinkService.findCommonlinkList(types, commonlinkType); // {"result": // [{id:"",name:"",userid:"",commonlinks:[{link1},{link2}...]},{id:"",name:"",userid:"",commonlinks:[{link1},{link2}...]}.....]} for (CommonlinkType linkType : commonlinkTypes) { JSONObject jsObj = new JSONObject(); buildCommonlinkTypeJsonObj(jsObj, linkType); JSONArray array = new JSONArray(); for (Commonlink link : commonLinkList) { if (linkType.getId().equals(link.getTypeId())) { JSONObject obj = new JSONObject(); buildCommonlinkJsonObj(obj, link); array.put(obj); } } jsObj.put("commonlinks", array); jsonArray.put(jsObj); } result.put("result", jsonArray); } } return result; }