package com.yihu.jkedu.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.yihu.base.ConfigUtil; import com.yihu.base.Constant; import com.yihu.utils.ApiUtil; import com.yihu.utils.StringUtil; import com.yihu.wsgw.api.ServiceBus; @Controller @RequestMapping("/article") public class ArticleControl { /** * @Title: queryArticleList * @Description: 查看订阅文章列表 * @param @param request * @param @param response * @param @throws Exception 设定文件 * @return void 返回类型 * @throws */ @RequestMapping(value = "/queryArticleList") public void queryArticleList(HttpServletRequest request, HttpServletResponse response) throws Exception { try { response.setContentType("application/json;charset=UTF-8"); String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId"); int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize")); int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex")); if(StringUtil.isEmpty(articleCategoryId)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString()); return; } JSONObject params = new JSONObject(); params.put("pageSize", pageSize); params.put("pageIndex", pageIndex); params.put("firstLevelCategoryId", articleCategoryId); params.put("articleState", "1");//1、正常、2删除 3、草稿 String formResult = ServiceBus.getInstance( null, ConfigUtil.getInstance().getAppId()).call( "JkEdu.Article.getArticalList", params.toString(), false); JSONObject resultJson = new JSONObject(); JSONObject formResultObj = JSONObject.fromObject(formResult); int code = formResultObj.getInt("Code"); String msg = formResultObj.getString("Message"); if (code == 10000) {// 成功 int count=formResultObj.getInt("Count"); if(count>0){ JSONArray arrform = formResultObj.getJSONArray("Result"); resultJson.put("Code", 10000); resultJson.put("Message", msg); resultJson.put("Result", arrform); resultJson.put("Count", count); response.getWriter().write(resultJson.toString()); return ; }else{ resultJson.put("Code", 10000); resultJson.put("Message", msg); resultJson.put("Result", null); resultJson.put("Count", count); response.getWriter().write(resultJson.toString()); return ; } } resultJson.put("Code", -10000); resultJson.put("Message", msg); resultJson.put("Result", null); response.getWriter().write(resultJson.toString()); return ; } catch (Exception e) { e.printStackTrace(); response.getWriter().write(ApiUtil.jsonResult(-14444, "获取文章列表异常").toString()); return ; } } /** * @Title: getCollectionArticalList * @Description: 收藏文章列表 * @param @param request * @param @param response * @param @throws Exception 设定文件 * @return void 返回类型 * @throws */ @RequestMapping(value = "/getCollectionArticalList") public void getCollectionArticalList(HttpServletRequest request, HttpServletResponse response) throws Exception { try { response.setContentType("application/json;charset=UTF-8"); String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId"); String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId"); int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize")); int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex")); if(StringUtil.isEmpty(articleCategoryId)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString()); return; } if(StringUtil.isEmpty(userId)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId参数不能为空").toString()); return; } JSONObject params = new JSONObject(); params.put("pageSize", pageSize); params.put("pageIndex", pageIndex); params.put("userId", userId); params.put("userType", Constant.USERTYPE_RESIDENT); params.put("firstLevelCategoryId", articleCategoryId); params.put("articleState", "1");//1、正常、2删除 3、草稿 String formResult = ServiceBus.getInstance( null, ConfigUtil.getInstance().getAppId()).call( "JkEdu.Article.getCollectionArticalList", params.toString(), false); JSONObject resultJson = new JSONObject(); JSONObject formResultObj = JSONObject.fromObject(formResult); int code = formResultObj.getInt("Code"); String msg = formResultObj.getString("Message"); if (code == 10000) {// 成功 int count=formResultObj.getInt("Count"); if(count>0){ JSONArray arrform = formResultObj.getJSONArray("Result"); resultJson.put("Code", 10000); resultJson.put("Message", msg); resultJson.put("Result", arrform); resultJson.put("Count", count); response.getWriter().write(resultJson.toString()); return ; }else{ resultJson.put("Code", 10000); resultJson.put("Message", msg); resultJson.put("Result", null); resultJson.put("Count", count); response.getWriter().write(resultJson.toString()); return ; } } resultJson.put("Code", -10000); resultJson.put("Message", msg); resultJson.put("Result", null); response.getWriter().write(resultJson.toString()); return ; } catch (Exception e) { e.printStackTrace(); response.getWriter().write(ApiUtil.jsonResult(-14444, "获取收藏文章列表异常").toString()); return ; } } /** * @Title: getArticalById * @Description: 查看文章详情 * @param @param request * @param @param response * @param @throws Exception 设定文件 * @return void 返回类型 * @throws */ @RequestMapping(value = "/getArticalById") public void getArticalById(HttpServletRequest request, HttpServletResponse response) throws Exception { try { response.setContentType("application/json;charset=UTF-8"); String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId"); String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId"); if(StringUtil.isEmpty(articleId)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString()); return; } if(StringUtil.isEmpty(userId)){ response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId").toString()); return; } JSONObject params = new JSONObject(); params.put("articleId", articleId); params.put("userId", userId); String result = ServiceBus.getInstance( null, ConfigUtil.getInstance().getAppId()).call( "JkEdu.Article.getArticalById", params.toString(), false); JSONObject formResultObj = JSONObject.fromObject(result); int code = formResultObj.getInt("Code"); String msg = formResultObj.getString("Message"); JSONObject resultJson = new JSONObject(); if (code == 10000) {// 成功 JSONArray arrform = formResultObj.getJSONArray("Result"); resultJson.put("Code", 10000); resultJson.put("Message", msg); resultJson.put("Result", arrform); resultJson.put("articleId", articleId); }else{ resultJson.put("Code", code); resultJson.put("Message", msg); resultJson.put("Result", null); resultJson.put("articleId", articleId); } response.getWriter().write(resultJson.toString()); return; } catch (Exception e) { e.printStackTrace(); response.getWriter().write(ApiUtil.jsonResult(-14444, "查看文章详情异常").toString()); return; } } }