5d87f90f3a9855d3c54b43ece983a279e42ce012.svn-base 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. /**
  13. * @ClassName: SubscribeControl
  14. * @Description:订阅大类
  15. * @author gqb
  16. * @date 2017-8-30 下午2:40:06
  17. *
  18. */
  19. @Controller
  20. @RequestMapping("/subscribe")
  21. public class SubscribeControl
  22. {
  23. /**
  24. * @Title: querySubscribe
  25. * @Description: 查询全部订阅大类(接口未提供)
  26. * @param @param request
  27. * @param @param response
  28. * @param @throws Exception 设定文件
  29. * @return void 返回类型
  30. * @throws
  31. */
  32. @RequestMapping(value = "/querySubscribe")
  33. public void querySubscribe(HttpServletRequest request,
  34. HttpServletResponse response) throws Exception {
  35. try {
  36. response.setContentType("application/json;charset=UTF-8");
  37. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  38. if(StringUtil.isEmpty(userId)){
  39. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  40. return;
  41. }
  42. JSONObject params = new JSONObject();
  43. params.put("categoryLevel", "1");
  44. params.put("userId", userId);
  45. String formResult = ServiceBus.getInstance(
  46. null,
  47. ConfigUtil.getInstance().getAppId()).call(
  48. "JkEdu.Category.getCategoryList", params.toString(), false);
  49. JSONObject resultJson = new JSONObject();
  50. JSONObject formResultObj = JSONObject.fromObject(formResult);
  51. int code = formResultObj.getInt("Code");
  52. String msg = formResultObj.getString("Message");
  53. if (code == 10000) {// 成功
  54. JSONObject arrform = formResultObj.getJSONObject("Result");
  55. if(arrform!=null){
  56. resultJson.put("Code", 10000);
  57. resultJson.put("Message", msg);
  58. resultJson.put("Result", arrform);
  59. response.getWriter().write(resultJson.toString());
  60. return ;
  61. }
  62. }
  63. resultJson.put("Code", -10000);
  64. resultJson.put("Message", msg);
  65. resultJson.put("Result", null);
  66. response.getWriter().write(resultJson.toString());
  67. return ;
  68. } catch (Exception e) {
  69. e.printStackTrace();
  70. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取全部的订阅异常").toString());
  71. return ;
  72. }
  73. }
  74. /**
  75. * @Title: querySubscribeByUserId
  76. * @Description: 查询用户的订阅大类
  77. * @param @param request
  78. * @param @param response
  79. * @param @throws Exception 设定文件
  80. * @return void 返回类型
  81. * @throws
  82. */
  83. @RequestMapping(value = "/querySubscribeByUserId")
  84. public void querySubscribeByUserId(HttpServletRequest request,
  85. HttpServletResponse response) throws Exception {
  86. try {
  87. response.setContentType("application/json;charset=UTF-8");
  88. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  89. if(StringUtil.isEmpty(userId)){
  90. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  91. return;
  92. }
  93. JSONObject params = new JSONObject();
  94. params.put("userId", userId);
  95. params.put("pageIndex", 0);
  96. params.put("pageSize", 1000);
  97. String formResult = ServiceBus.getInstance(
  98. null,
  99. ConfigUtil.getInstance().getAppId()).call(
  100. "JkEdu.Subscrive.getSubscriveList", params.toString(), false);
  101. JSONObject resultJson = new JSONObject();
  102. JSONObject formResultObj = JSONObject.fromObject(formResult);
  103. int code = formResultObj.getInt("Code");
  104. String msg = formResultObj.getString("Message");
  105. if (code == 10000) {// 成功
  106. JSONObject arrform = formResultObj.getJSONObject("Result");
  107. if(arrform!=null){
  108. resultJson.put("Code", 10000);
  109. resultJson.put("Message", msg);
  110. resultJson.put("Result", arrform);
  111. response.getWriter().write(resultJson.toString());
  112. return ;
  113. }
  114. }
  115. resultJson.put("Code", -10000);
  116. resultJson.put("Message", msg);
  117. resultJson.put("Result", null);
  118. response.getWriter().write(resultJson.toString());
  119. return ;
  120. } catch (Exception e) {
  121. e.printStackTrace();
  122. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取用户的订阅异常").toString());
  123. return ;
  124. }
  125. }
  126. /**
  127. * @Title: saveSubscribe
  128. * @Description: 保存用户订阅大类
  129. * @param @param request
  130. * @param @param response
  131. * @param @throws Exception 设定文件
  132. * @return void 返回类型
  133. * @throws
  134. */
  135. @RequestMapping(value = "/saveSubscribe")
  136. public void saveSubscribe(HttpServletRequest request,
  137. HttpServletResponse response) throws Exception {
  138. try {
  139. response.setContentType("application/json;charset=UTF-8");
  140. String categoryId = StringUtil.isEmpty(request.getParameter("categoryIds")) ? null : request.getParameter("categoryIds");
  141. String categoryName = StringUtil.isEmpty(request.getParameter("categoryNames")) ? null : request.getParameter("categoryNames");
  142. String cName = StringUtil.isEmpty(request.getParameter("cname")) ? null : request.getParameter("cname");
  143. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  144. if(StringUtil.isEmpty(userId)){
  145. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户UserId不能为空").toString());
  146. return;
  147. }
  148. if(StringUtil.isEmpty(cName)){
  149. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户CName不能为空").toString());
  150. return;
  151. }
  152. if(StringUtil.isEmpty(categoryId)){
  153. response.getWriter().write(ApiUtil.jsonResult(-10000, "请至少选择一个感兴趣的分类").toString());
  154. return;
  155. }
  156. if(StringUtil.isEmpty(categoryName)){
  157. response.getWriter().write(ApiUtil.jsonResult(-10000, "请至少选择一个感兴趣的分类").toString());
  158. return;
  159. }
  160. JSONObject params = new JSONObject();
  161. params.put("categoryId", categoryId);
  162. params.put("categoryName", categoryName);
  163. params.put("userId", userId);
  164. params.put("cName", cName);
  165. String result = ServiceBus.getInstance(
  166. null,
  167. ConfigUtil.getInstance().getAppId()).call(
  168. "JkEdu.Subscrive.saveSubscrive", params.toString(), false);
  169. JSONObject formResultObj = JSONObject.fromObject(result);
  170. int code = formResultObj.getInt("Code");
  171. String msg = formResultObj.getString("Message");
  172. JSONObject resultJson = new JSONObject();
  173. if (code == 10000) {// 成功
  174. resultJson.put("Code", 10000);
  175. resultJson.put("Message", msg);
  176. }else{
  177. resultJson.put("Code", code);
  178. resultJson.put("Message", msg);
  179. }
  180. response.getWriter().write(resultJson.toString());
  181. return;
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. response.getWriter().write(ApiUtil.jsonResult(-14444, "保存用户的订阅异常").toString());
  185. return;
  186. }
  187. }
  188. }