4c205e83b65daed5c6de09a03d7dc16872494a52.svn-base 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package com.yihu.jkedu.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import net.sf.json.JSONObject;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import com.yihu.base.ConfigUtil;
  8. import com.yihu.utils.ApiUtil;
  9. import com.yihu.utils.StringUtil;
  10. import com.yihu.wsgw.api.ServiceBus;
  11. /**
  12. * @ClassName: SubscribeControl
  13. * @Description:订阅大类
  14. * @author gqb
  15. * @date 2017-8-30 下午2:40:06
  16. *
  17. */
  18. @Controller
  19. @RequestMapping("/subscribe")
  20. public class SubscribeControl
  21. {
  22. /**
  23. * @Title: querySubscribe
  24. * @Description: 查询全部订阅大类
  25. * @param @param request
  26. * @param @param response
  27. * @param @throws Exception 设定文件
  28. * @return void 返回类型
  29. * @throws
  30. */
  31. @RequestMapping(value = "/querySubscribe")
  32. public void querySubscribe(HttpServletRequest request,
  33. HttpServletResponse response) throws Exception {
  34. try {
  35. response.setContentType("application/json;charset=UTF-8");
  36. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  37. if(StringUtil.isEmpty(userId)){
  38. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  39. return;
  40. }
  41. JSONObject params = new JSONObject();
  42. params.put("categoryLevel", "1");
  43. params.put("userId", userId);
  44. String formResult = ServiceBus.getInstance(
  45. null,
  46. ConfigUtil.getInstance().getAppId()).call(
  47. "JkEdu.Category.getCategoryList", params.toString(), false);
  48. JSONObject resultJson = new JSONObject();
  49. JSONObject formResultObj = JSONObject.fromObject(formResult);
  50. int code = formResultObj.getInt("Code");
  51. String msg = formResultObj.getString("Message");
  52. if (code == 10000) {// 成功
  53. JSONObject arrform = formResultObj.getJSONObject("Result");
  54. if(arrform!=null){
  55. resultJson.put("Code", 10000);
  56. resultJson.put("Message", msg);
  57. resultJson.put("Result", arrform);
  58. response.getWriter().write(resultJson.toString());
  59. return ;
  60. }
  61. }
  62. resultJson.put("Code", -10000);
  63. resultJson.put("Message", msg);
  64. resultJson.put("Result", null);
  65. response.getWriter().write(resultJson.toString());
  66. return ;
  67. } catch (Exception e) {
  68. e.printStackTrace();
  69. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取全部的订阅异常").toString());
  70. return ;
  71. }
  72. }
  73. /**
  74. * @Title: querySubscribeByUserId
  75. * @Description: 查询用户的订阅大类
  76. * @param @param request
  77. * @param @param response
  78. * @param @throws Exception 设定文件
  79. * @return void 返回类型
  80. * @throws
  81. */
  82. @RequestMapping(value = "/querySubscribeByUserId")
  83. public void querySubscribeByUserId(HttpServletRequest request,
  84. HttpServletResponse response) throws Exception {
  85. try {
  86. response.setContentType("application/json;charset=UTF-8");
  87. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  88. if(StringUtil.isEmpty(userId)){
  89. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  90. return;
  91. }
  92. JSONObject params = new JSONObject();
  93. params.put("userId", userId);
  94. params.put("pageIndex", 0);
  95. params.put("pageSize", 1000);
  96. String formResult = ServiceBus.getInstance(
  97. null,
  98. ConfigUtil.getInstance().getAppId()).call(
  99. "JkEdu.Subscrive.getSubscriveList", 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. JSONObject arrform = formResultObj.getJSONObject("Result");
  106. if(arrform!=null){
  107. resultJson.put("Code", 10000);
  108. resultJson.put("Message", msg);
  109. resultJson.put("Result", arrform);
  110. response.getWriter().write(resultJson.toString());
  111. return ;
  112. }
  113. }
  114. resultJson.put("Code", -10000);
  115. resultJson.put("Message", msg);
  116. resultJson.put("Result", null);
  117. response.getWriter().write(resultJson.toString());
  118. return ;
  119. } catch (Exception e) {
  120. e.printStackTrace();
  121. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取用户的订阅异常").toString());
  122. return ;
  123. }
  124. }
  125. /**
  126. * @Title: saveSubscribe
  127. * @Description: 保存用户订阅大类
  128. * @param @param request
  129. * @param @param response
  130. * @param @throws Exception 设定文件
  131. * @return void 返回类型
  132. * @throws
  133. */
  134. @RequestMapping(value = "/saveSubscribe")
  135. public void saveSubscribe(HttpServletRequest request,
  136. HttpServletResponse response) throws Exception {
  137. try {
  138. response.setContentType("application/json;charset=UTF-8");
  139. String categoryId = StringUtil.isEmpty(request.getParameter("categoryIds")) ? null : request.getParameter("categoryIds");
  140. String categoryName = StringUtil.isEmpty(request.getParameter("categoryNames")) ? null : request.getParameter("categoryNames");
  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(categoryId)){
  147. response.getWriter().write(ApiUtil.jsonResult(-10000, "请至少选择一个感兴趣的分类").toString());
  148. return;
  149. }
  150. if(StringUtil.isEmpty(categoryName)){
  151. response.getWriter().write(ApiUtil.jsonResult(-10000, "请至少选择一个感兴趣的分类").toString());
  152. return;
  153. }
  154. String cName=null;
  155. JSONObject userparams = new JSONObject();
  156. userparams.put("userId", userId);
  157. String userresult = ServiceBus.getInstance(
  158. null,
  159. ConfigUtil.getInstance().getAppId()).call(
  160. "UserMgmt.User.queryUserInfoByID", userparams.toString(), false);
  161. JSONObject userResultObj = JSONObject.fromObject(userresult);
  162. int userCode=userResultObj.getInt("Code");
  163. String usermsg=userResultObj.getString("Message");
  164. if(userCode ==10000){
  165. JSONObject arrform = userResultObj.getJSONObject("Result");
  166. if(null!=arrform && arrform.size()>0){
  167. cName=arrform.getString("CName");
  168. if(StringUtil.isEmpty(cName)){
  169. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  170. return;
  171. }
  172. }else{
  173. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  174. return;
  175. }
  176. }else{
  177. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  178. return;
  179. }
  180. JSONObject params = new JSONObject();
  181. params.put("categoryId", categoryId);
  182. params.put("categoryName", categoryName);
  183. params.put("userId", userId);
  184. params.put("cName", cName);
  185. String result = ServiceBus.getInstance(
  186. null,
  187. ConfigUtil.getInstance().getAppId()).call(
  188. "JkEdu.Subscrive.saveSubscrive", params.toString(), false);
  189. JSONObject formResultObj = JSONObject.fromObject(result);
  190. int code = formResultObj.getInt("Code");
  191. String msg = formResultObj.getString("Message");
  192. JSONObject resultJson = new JSONObject();
  193. if (code == 10000) {// 成功
  194. resultJson.put("Code", 10000);
  195. resultJson.put("Message", msg);
  196. }else{
  197. resultJson.put("Code", -10000);
  198. resultJson.put("Message", msg);
  199. }
  200. response.getWriter().write(resultJson.toString());
  201. return;
  202. } catch (Exception e) {
  203. e.printStackTrace();
  204. response.getWriter().write(ApiUtil.jsonResult(-14444, "保存用户的订阅异常").toString());
  205. return;
  206. }
  207. }
  208. }