/** * 根据分类id,查询当前分类下的公共连接列表 * * @param typeid 分类id * @param page 当前页 * @param pageNum 每页显示条数 * @return 当前分类下的公共连接列表 */ @GET @Path("/list/commonlink/{typeid}") @Produces({MediaType.APPLICATION_JSON}) public JSONObject findCommonlinkListByTypeId( @PathParam("typeid") String typeid, @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("commonlinklist", 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); Commonlink commonlink = new Commonlink(); commonlink.setUserId(String.valueOf(user.getId())); commonlink.setTypeId(typeid); // 获取公共连接分类列表 Pager<Commonlink> commonLinkPage = commonlinkService.findCommonlinkListByTypeId(commonlink, pb); if (null != commonLinkPage && commonLinkPage.getTotal() > 0) { result.put("count", commonLinkPage.getTotal()); buildCommonlinkListToJSONAarray(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; }
private void buildJSONObjectToCommonlinkType(CommonlinkType commonlinkType, JSONObject jsonObj) throws UnsupportedEncodingException { HttpSession session = request.getSession(); User user = (User) session.getAttribute("loginUser"); commonlinkType.setId(Utils.getUuid()); commonlinkType.setName(URLDecoder.decode(jsonObj.optString("name"), "UTF-8")); commonlinkType.setUserId(null != user ? String.valueOf(user.getId()) : ""); commonlinkType.setCreateDate(DataUtil.date2Str(new Date())); commonlinkType.setLastmodifyDate(DataUtil.date2Str(new Date())); }
private void buildJSONObjectToCommonlink(Commonlink commonlink, JSONObject jsonObj) throws UnsupportedEncodingException { HttpSession session = request.getSession(); User user = (User) session.getAttribute("loginUser"); // 添加和修改的uuid使用方式 commonlink.setId( StringUtils.isNotEmpty(jsonObj.optString("id")) ? jsonObj.optString("id") : Utils.getUuid()); commonlink.setName(URLDecoder.decode(jsonObj.optString("name"), "UTF-8")); commonlink.setUrl(URLDecoder.decode(jsonObj.optString("url"), "UTF-8")); commonlink.setUserId(null != user ? String.valueOf(user.getId()) : ""); commonlink.setNewWin(jsonObj.optInt("newwin")); commonlink.setCreateDate(DataUtil.date2Str(new Date())); commonlink.setLastmodifyDate(DataUtil.date2Str(new Date())); commonlink.setPosition(jsonObj.optInt("position")); commonlink.setTypeId(jsonObj.optString("typeid")); }
/** * 删除公共连接分类 * * @param id 分类id * @return 0:失败 1:成功 */ @DELETE @Path("/delete/commonlinktype/{id}") @Produces({MediaType.APPLICATION_JSON}) public JSONObject deleteCommonlinkType(@PathParam("id") String id) { HttpSession session = request.getSession(); User user = (User) session.getAttribute("loginUser"); JSONObject result = new JSONObject(); result.put("result", 0); if (null != user) { String userId = String.valueOf(user.getId()); CommonlinkType commonlinkType = new CommonlinkType(id, userId); boolean success = commonlinkService.deleteCommonlinkType(commonlinkType); if (success) { result.put("result", 1); return result; } } return result; }
/** * 更新公共链接分类 * * @param jsonObj 公共连接分类json数据 * @return 0:失败 1:成功 */ @POST @Path("/update/commonlinktype") @Produces({MediaType.APPLICATION_JSON}) public JSONObject updateCommonlinkType(JSONObject jsonObj) { HttpSession session = request.getSession(); User user = (User) session.getAttribute("loginUser"); JSONObject result = new JSONObject(); result.put("result", 0); if (null != jsonObj && null != user) { String id = jsonObj.optString("id"); String userId = String.valueOf(user.getId()); String name = jsonObj.optString("name"); CommonlinkType commonlinkType = new CommonlinkType(id, name, userId, DataUtil.date2Str(new Date())); boolean success = commonlinkService.updateCommonlinkType(commonlinkType); if (success) { result.put("result", 1); return result; } } return result; }