9afd23354d05a346ee7beb30c28fa07ed54dc599.svn-base 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. @RequestMapping(value = "/queryArticleList")
  17. public void queryArticleList(HttpServletRequest request,
  18. HttpServletResponse response) throws Exception {
  19. try {
  20. response.setContentType("application/json;charset=UTF-8");
  21. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  22. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  23. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  24. if(StringUtil.isEmpty(articleCategoryId)){
  25. response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
  26. return;
  27. }
  28. JSONObject params = new JSONObject();
  29. params.put("pageSize", pageSize);
  30. params.put("pageIndex", pageIndex);
  31. params.put("firstLevelCategoryId", articleCategoryId);
  32. params.put("articleState", "1");//1、正常、2删除 3、草稿
  33. String formResult = ServiceBus.getInstance(
  34. null,
  35. ConfigUtil.getInstance().getAppId()).call(
  36. "JkEdu.Article.getArticalList", params.toString(), false);
  37. JSONObject resultJson = new JSONObject();
  38. JSONObject formResultObj = JSONObject.fromObject(formResult);
  39. int code = formResultObj.getInt("Code");
  40. String msg = formResultObj.getString("Message");
  41. if (code == 10000) {// 成功
  42. int count=formResultObj.getInt("Count");
  43. if(count>0){
  44. JSONArray arrform = formResultObj.getJSONArray("Result");
  45. resultJson.put("Code", 10000);
  46. resultJson.put("Message", msg);
  47. resultJson.put("Result", arrform);
  48. resultJson.put("Count", count);
  49. response.getWriter().write(resultJson.toString());
  50. return ;
  51. }else{
  52. resultJson.put("Code", 10000);
  53. resultJson.put("Message", msg);
  54. resultJson.put("Result", null);
  55. resultJson.put("Count", count);
  56. response.getWriter().write(resultJson.toString());
  57. return ;
  58. }
  59. }
  60. resultJson.put("Code", -10000);
  61. resultJson.put("Message", msg);
  62. resultJson.put("Result", null);
  63. response.getWriter().write(resultJson.toString());
  64. return ;
  65. } catch (Exception e) {
  66. e.printStackTrace();
  67. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取文章列表异常").toString());
  68. return ;
  69. }
  70. }
  71. @RequestMapping(value = "/queryCollectionArticalList")
  72. public void getCollectionArticalList(HttpServletRequest request,
  73. HttpServletResponse response) throws Exception {
  74. try {
  75. response.setContentType("application/json;charset=UTF-8");
  76. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  77. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  78. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  79. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  80. String userType = StringUtil.isEmpty(request.getParameter("userType")) ? null : request.getParameter("userType");
  81. if(StringUtil.isEmpty(articleCategoryId)){
  82. response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
  83. return;
  84. }
  85. if(StringUtil.isEmpty(userId)){
  86. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId参数不能为空").toString());
  87. return;
  88. }
  89. JSONObject params = new JSONObject();
  90. params.put("pageSize", pageSize);
  91. params.put("pageIndex", pageIndex);
  92. params.put("userId", userId);
  93. params.put("userType", userType);
  94. params.put("firstLevelCategoryId", articleCategoryId);
  95. params.put("articleState", "1");//1、正常、2删除 3、草稿
  96. String formResult = ServiceBus.getInstance(
  97. null,
  98. ConfigUtil.getInstance().getAppId()).call(
  99. "JkEdu.Article.getCollectionArticalList", params.toString(), false);
  100. JSONObject resultJson = new JSONObject();
  101. JSONObject formResultObj = JSONObject.fromObject(formResult);
  102. int code = formResultObj.getInt("Code");
  103. String msg = formResultObj.getString("Message");
  104. if (code == 10000) {// 成功
  105. int count=formResultObj.getInt("Count");
  106. if(count>0){
  107. JSONArray arrform = formResultObj.getJSONArray("Result");
  108. resultJson.put("Code", 10000);
  109. resultJson.put("Message", msg);
  110. resultJson.put("Result", arrform);
  111. resultJson.put("Count", count);
  112. response.getWriter().write(resultJson.toString());
  113. return ;
  114. }else{
  115. resultJson.put("Code", 10000);
  116. resultJson.put("Message", msg);
  117. resultJson.put("Result", null);
  118. resultJson.put("Count", count);
  119. response.getWriter().write(resultJson.toString());
  120. return ;
  121. }
  122. }
  123. resultJson.put("Code", -10000);
  124. resultJson.put("Message", msg);
  125. resultJson.put("Result", null);
  126. response.getWriter().write(resultJson.toString());
  127. return ;
  128. } catch (Exception e) {
  129. e.printStackTrace();
  130. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取收藏文章列表异常").toString());
  131. return ;
  132. }
  133. }
  134. @RequestMapping(value = "/cancelArticle")
  135. public void cancelArticle(HttpServletRequest request,
  136. HttpServletResponse response) throws Exception {
  137. try {
  138. response.setContentType("application/json;charset=UTF-8");
  139. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  140. String userType = StringUtil.isEmpty(request.getParameter("userType")) ? null : request.getParameter("userType");
  141. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  142. if(StringUtil.isEmpty(userId)){
  143. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  144. return;
  145. }
  146. if(StringUtil.isEmpty(articleId)){
  147. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString());
  148. return;
  149. }
  150. if(StringUtil.isEmpty(userType)){
  151. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章userType不能为空").toString());
  152. return;
  153. }
  154. JSONObject params = new JSONObject();
  155. params.put("articleId", articleId);
  156. params.put("userType", userType);
  157. params.put("userId", userId);
  158. String result = ServiceBus.getInstance(
  159. null,
  160. ConfigUtil.getInstance().getAppId()).call(
  161. "JkEdu.Behavior.cancelArticleCollection", params.toString(), false);
  162. JSONObject formResultObj = JSONObject.fromObject(result);
  163. int code = formResultObj.getInt("Code");
  164. String msg = formResultObj.getString("Message");
  165. JSONObject resultJson = new JSONObject();
  166. if (code == 10000) {// 成功
  167. resultJson.put("Code", 10000);
  168. resultJson.put("Message", msg);
  169. resultJson.put("articleId", articleId);
  170. }else{
  171. resultJson.put("Code", code);
  172. resultJson.put("Message", msg);
  173. resultJson.put("articleId", articleId);
  174. }
  175. response.getWriter().write(resultJson.toString());
  176. return;
  177. } catch (Exception e) {
  178. e.printStackTrace();
  179. response.getWriter().write(ApiUtil.jsonResult(-14444, "取消收藏异常").toString());
  180. return;
  181. }
  182. }
  183. }