12eb92afe45ab2d0e10b11bdd27adb5421bad9a2.svn-base 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package com.yihu.jkedu.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import net.sf.json.JSONArray;
  5. import net.sf.json.JSONObject;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import com.yihu.base.ConfigUtil;
  9. import com.yihu.base.Constant;
  10. import com.yihu.utils.ApiUtil;
  11. import com.yihu.utils.StringUtil;
  12. import com.yihu.wsgw.api.ServiceBus;
  13. @Controller
  14. @RequestMapping("/article")
  15. public class ArticleControl
  16. {
  17. /**
  18. * @Title: queryArticleList
  19. * @Description: 查看订阅文章列表
  20. * @param @param request
  21. * @param @param response
  22. * @param @throws Exception 设定文件
  23. * @return void 返回类型
  24. * @throws
  25. */
  26. @RequestMapping(value = "/queryArticleList")
  27. public void queryArticleList(HttpServletRequest request,
  28. HttpServletResponse response) throws Exception {
  29. try {
  30. response.setContentType("application/json;charset=UTF-8");
  31. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  32. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  33. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  34. if(StringUtil.isEmpty(articleCategoryId)){
  35. response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
  36. return;
  37. }
  38. JSONObject params = new JSONObject();
  39. params.put("pageSize", pageSize);
  40. params.put("pageIndex", pageIndex);
  41. params.put("firstLevelCategoryId", articleCategoryId);
  42. params.put("articleState", "1");//1、正常、2删除 3、草稿
  43. String formResult = ServiceBus.getInstance(
  44. null,
  45. ConfigUtil.getInstance().getAppId()).call(
  46. "JkEdu.Article.getArticalList", params.toString(), false);
  47. JSONObject resultJson = new JSONObject();
  48. JSONObject formResultObj = JSONObject.fromObject(formResult);
  49. int code = formResultObj.getInt("Code");
  50. String msg = formResultObj.getString("Message");
  51. if (code == 10000) {// 成功
  52. int count=formResultObj.getInt("Count");
  53. if(count>0){
  54. JSONArray arrform = formResultObj.getJSONArray("Result");
  55. resultJson.put("Code", 10000);
  56. resultJson.put("Message", msg);
  57. resultJson.put("Result", arrform);
  58. resultJson.put("Count", count);
  59. response.getWriter().write(resultJson.toString());
  60. return ;
  61. }else{
  62. resultJson.put("Code", 10000);
  63. resultJson.put("Message", msg);
  64. resultJson.put("Result", null);
  65. resultJson.put("Count", count);
  66. response.getWriter().write(resultJson.toString());
  67. return ;
  68. }
  69. }
  70. resultJson.put("Code", -10000);
  71. resultJson.put("Message", msg);
  72. resultJson.put("Result", null);
  73. response.getWriter().write(resultJson.toString());
  74. return ;
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取文章列表异常").toString());
  78. return ;
  79. }
  80. }
  81. /**
  82. * @Title: getCollectionArticalList
  83. * @Description: 收藏文章列表
  84. * @param @param request
  85. * @param @param response
  86. * @param @throws Exception 设定文件
  87. * @return void 返回类型
  88. * @throws
  89. */
  90. @RequestMapping(value = "/getCollectionArticalList")
  91. public void getCollectionArticalList(HttpServletRequest request,
  92. HttpServletResponse response) throws Exception {
  93. try {
  94. response.setContentType("application/json;charset=UTF-8");
  95. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  96. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  97. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  98. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  99. if(StringUtil.isEmpty(articleCategoryId)){
  100. response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
  101. return;
  102. }
  103. if(StringUtil.isEmpty(userId)){
  104. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId参数不能为空").toString());
  105. return;
  106. }
  107. JSONObject params = new JSONObject();
  108. params.put("pageSize", pageSize);
  109. params.put("pageIndex", pageIndex);
  110. params.put("userId", userId);
  111. params.put("userType", Constant.USERTYPE_RESIDENT);
  112. params.put("firstLevelCategoryId", articleCategoryId);
  113. params.put("articleState", "1");//1、正常、2删除 3、草稿
  114. String formResult = ServiceBus.getInstance(
  115. null,
  116. ConfigUtil.getInstance().getAppId()).call(
  117. "JkEdu.Article.getCollectionArticalList", params.toString(), false);
  118. JSONObject resultJson = new JSONObject();
  119. JSONObject formResultObj = JSONObject.fromObject(formResult);
  120. int code = formResultObj.getInt("Code");
  121. String msg = formResultObj.getString("Message");
  122. if (code == 10000) {// 成功
  123. int count=formResultObj.getInt("Count");
  124. if(count>0){
  125. JSONArray arrform = formResultObj.getJSONArray("Result");
  126. resultJson.put("Code", 10000);
  127. resultJson.put("Message", msg);
  128. resultJson.put("Result", arrform);
  129. resultJson.put("Count", count);
  130. response.getWriter().write(resultJson.toString());
  131. return ;
  132. }else{
  133. resultJson.put("Code", 10000);
  134. resultJson.put("Message", msg);
  135. resultJson.put("Result", null);
  136. resultJson.put("Count", count);
  137. response.getWriter().write(resultJson.toString());
  138. return ;
  139. }
  140. }
  141. resultJson.put("Code", -10000);
  142. resultJson.put("Message", msg);
  143. resultJson.put("Result", null);
  144. response.getWriter().write(resultJson.toString());
  145. return ;
  146. } catch (Exception e) {
  147. e.printStackTrace();
  148. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取收藏文章列表异常").toString());
  149. return ;
  150. }
  151. }
  152. /**
  153. * @Title: getArticalById
  154. * @Description: 查看文章详情
  155. * @param @param request
  156. * @param @param response
  157. * @param @throws Exception 设定文件
  158. * @return void 返回类型
  159. * @throws
  160. */
  161. @RequestMapping(value = "/getArticalById")
  162. public void getArticalById(HttpServletRequest request,
  163. HttpServletResponse response) throws Exception {
  164. try {
  165. response.setContentType("application/json;charset=UTF-8");
  166. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  167. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  168. if(StringUtil.isEmpty(articleId)){
  169. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString());
  170. return;
  171. }
  172. if(StringUtil.isEmpty(userId)){
  173. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId").toString());
  174. return;
  175. }
  176. JSONObject params = new JSONObject();
  177. params.put("articleId", articleId);
  178. params.put("userId", userId);
  179. String result = ServiceBus.getInstance(
  180. null,
  181. ConfigUtil.getInstance().getAppId()).call(
  182. "JkEdu.Article.getArticalById", params.toString(), false);
  183. JSONObject formResultObj = JSONObject.fromObject(result);
  184. int code = formResultObj.getInt("Code");
  185. String msg = formResultObj.getString("Message");
  186. JSONObject resultJson = new JSONObject();
  187. if (code == 10000) {// 成功
  188. JSONArray arrform = formResultObj.getJSONArray("Result");
  189. resultJson.put("Code", 10000);
  190. resultJson.put("Message", msg);
  191. resultJson.put("Result", arrform);
  192. resultJson.put("articleId", articleId);
  193. }else{
  194. resultJson.put("Code", code);
  195. resultJson.put("Message", msg);
  196. resultJson.put("Result", null);
  197. resultJson.put("articleId", articleId);
  198. }
  199. response.getWriter().write(resultJson.toString());
  200. return;
  201. } catch (Exception e) {
  202. e.printStackTrace();
  203. response.getWriter().write(ApiUtil.jsonResult(-14444, "查看文章详情异常").toString());
  204. return;
  205. }
  206. }
  207. }