f685280f1a7fb37c6c1e23fd2ed54fa13e856d6b.svn-base 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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.utils.ApiUtil;
  10. import com.yihu.utils.StringUtil;
  11. import com.yihu.wsgw.api.ServiceBus;
  12. @Controller
  13. @RequestMapping("/article")
  14. public class ArticleControl
  15. {
  16. /**
  17. * @Title: queryArticleList
  18. * @Description: 查看订阅文章列表
  19. * @param @param request
  20. * @param @param response
  21. * @param @throws Exception 设定文件
  22. * @return void 返回类型
  23. * @throws
  24. */
  25. @RequestMapping(value = "/queryArticleList")
  26. public void queryArticleList(HttpServletRequest request,
  27. HttpServletResponse response) throws Exception {
  28. try {
  29. response.setContentType("application/json;charset=UTF-8");
  30. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  31. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  32. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  33. if(StringUtil.isEmpty(articleCategoryId)){
  34. response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
  35. return;
  36. }
  37. JSONObject params = new JSONObject();
  38. params.put("pageSize", pageSize);
  39. params.put("pageIndex", pageIndex);
  40. params.put("firstLevelCategoryId", articleCategoryId);
  41. params.put("articleState", "1");//1、正常、2删除 3、草稿
  42. String formResult = ServiceBus.getInstance(
  43. null,
  44. ConfigUtil.getInstance().getAppId()).call(
  45. "JkEdu.Article.getArticalList", params.toString(), false);
  46. JSONObject resultJson = new JSONObject();
  47. JSONObject formResultObj = JSONObject.fromObject(formResult);
  48. int code = formResultObj.getInt("Code");
  49. String msg = formResultObj.getString("Message");
  50. if (code == 10000) {// 成功
  51. int count=formResultObj.getInt("Count");
  52. if(count>0){
  53. JSONArray arrform = formResultObj.getJSONArray("Result");
  54. resultJson.put("Code", 10000);
  55. resultJson.put("Message", msg);
  56. resultJson.put("Result", arrform);
  57. resultJson.put("Count", count);
  58. response.getWriter().write(resultJson.toString());
  59. return ;
  60. }else{
  61. resultJson.put("Code", 10000);
  62. resultJson.put("Message", msg);
  63. resultJson.put("Result", null);
  64. resultJson.put("Count", count);
  65. response.getWriter().write(resultJson.toString());
  66. return ;
  67. }
  68. }
  69. resultJson.put("Code", -10000);
  70. resultJson.put("Message", msg);
  71. resultJson.put("Result", null);
  72. response.getWriter().write(resultJson.toString());
  73. return ;
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取文章列表异常").toString());
  77. return ;
  78. }
  79. }
  80. /**
  81. * @Title: getCollectionArticalList
  82. * @Description: 收藏文章列表
  83. * @param @param request
  84. * @param @param response
  85. * @param @throws Exception 设定文件
  86. * @return void 返回类型
  87. * @throws
  88. */
  89. @RequestMapping(value = "/getCollectionArticalList")
  90. public void getCollectionArticalList(HttpServletRequest request,
  91. HttpServletResponse response) throws Exception {
  92. try {
  93. response.setContentType("application/json;charset=UTF-8");
  94. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  95. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  96. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  97. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  98. String userType = StringUtil.isEmpty(request.getParameter("userType")) ? null : request.getParameter("userType");
  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", userType);
  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. String result = ServiceBus.getInstance(
  179. null,
  180. ConfigUtil.getInstance().getAppId()).call(
  181. "JkEdu.Article.getArticalById", params.toString(), false);
  182. JSONObject formResultObj = JSONObject.fromObject(result);
  183. int code = formResultObj.getInt("Code");
  184. String msg = formResultObj.getString("Message");
  185. JSONObject resultJson = new JSONObject();
  186. if (code == 10000) {// 成功
  187. JSONArray arrform = formResultObj.getJSONArray("Result");
  188. resultJson.put("Code", 10000);
  189. resultJson.put("Message", msg);
  190. resultJson.put("Result", arrform);
  191. resultJson.put("articleId", articleId);
  192. }else{
  193. resultJson.put("Code", code);
  194. resultJson.put("Message", msg);
  195. resultJson.put("Result", null);
  196. resultJson.put("articleId", articleId);
  197. }
  198. response.getWriter().write(resultJson.toString());
  199. return;
  200. } catch (Exception e) {
  201. e.printStackTrace();
  202. response.getWriter().write(ApiUtil.jsonResult(-14444, "取消收藏异常").toString());
  203. return;
  204. }
  205. }
  206. }