123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- package com.yihu.jkedu.action;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import net.sf.json.JSONObject;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import com.yihu.base.ConfigUtil;
- import com.yihu.utils.ApiUtil;
- import com.yihu.utils.StringUtil;
- import com.yihu.wsgw.api.ServiceBus;
- /**
- * @ClassName: SubscribeControl
- * @Description:订阅大类
- * @author gqb
- * @date 2017-8-30 下午2:40:06
- *
- */
- @Controller
- @RequestMapping("/subscribe")
- public class SubscribeControl
- {
- /**
- * @Title: querySubscribe
- * @Description: 查询全部订阅大类
- * @param @param request
- * @param @param response
- * @param @throws Exception 设定文件
- * @return void 返回类型
- * @throws
- */
- @RequestMapping(value = "/querySubscribe")
- public void querySubscribe(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- try {
- response.setContentType("application/json;charset=UTF-8");
- String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
- if(StringUtil.isEmpty(userId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
- return;
- }
- JSONObject params = new JSONObject();
- params.put("categoryLevel", "1");
- params.put("userId", userId);
- String formResult = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "JkEdu.Category.getCategoryList", params.toString(), false);
- JSONObject resultJson = new JSONObject();
- JSONObject formResultObj = JSONObject.fromObject(formResult);
- int code = formResultObj.getInt("Code");
- String msg = formResultObj.getString("Message");
- if (code == 10000) {// 成功
- JSONObject arrform = formResultObj.getJSONObject("Result");
- if(arrform!=null){
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", arrform);
- response.getWriter().write(resultJson.toString());
- return ;
- }
- }
- resultJson.put("Code", -10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", null);
- response.getWriter().write(resultJson.toString());
- return ;
-
- } catch (Exception e) {
- e.printStackTrace();
- response.getWriter().write(ApiUtil.jsonResult(-14444, "获取全部的订阅异常").toString());
- return ;
- }
- }
- /**
- * @Title: querySubscribeByUserId
- * @Description: 查询用户的订阅大类
- * @param @param request
- * @param @param response
- * @param @throws Exception 设定文件
- * @return void 返回类型
- * @throws
- */
- @RequestMapping(value = "/querySubscribeByUserId")
- public void querySubscribeByUserId(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- try {
- response.setContentType("application/json;charset=UTF-8");
- String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
- if(StringUtil.isEmpty(userId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
- return;
- }
- JSONObject params = new JSONObject();
- params.put("userId", userId);
- params.put("pageIndex", 0);
- params.put("pageSize", 1000);
- String formResult = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "JkEdu.Subscrive.getSubscriveList", params.toString(), false);
- JSONObject resultJson = new JSONObject();
- JSONObject formResultObj = JSONObject.fromObject(formResult);
- int code = formResultObj.getInt("Code");
- String msg = formResultObj.getString("Message");
- if (code == 10000) {// 成功
- JSONObject arrform = formResultObj.getJSONObject("Result");
- if(arrform!=null){
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", arrform);
- response.getWriter().write(resultJson.toString());
- return ;
- }
- }
- resultJson.put("Code", -10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", null);
- response.getWriter().write(resultJson.toString());
- return ;
-
- } catch (Exception e) {
- e.printStackTrace();
- response.getWriter().write(ApiUtil.jsonResult(-14444, "获取用户的订阅异常").toString());
- return ;
- }
- }
- /**
- * @Title: saveSubscribe
- * @Description: 保存用户订阅大类
- * @param @param request
- * @param @param response
- * @param @throws Exception 设定文件
- * @return void 返回类型
- * @throws
- */
- @RequestMapping(value = "/saveSubscribe")
- public void saveSubscribe(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- try {
- response.setContentType("application/json;charset=UTF-8");
- String categoryId = StringUtil.isEmpty(request.getParameter("categoryIds")) ? null : request.getParameter("categoryIds");
- String categoryName = StringUtil.isEmpty(request.getParameter("categoryNames")) ? null : request.getParameter("categoryNames");
- String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
- if(StringUtil.isEmpty(userId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
- return;
- }
- if(StringUtil.isEmpty(categoryId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "请至少选择一个感兴趣的分类").toString());
- return;
- }
- if(StringUtil.isEmpty(categoryName)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "请至少选择一个感兴趣的分类").toString());
- return;
- }
- String cName=null;
- JSONObject userparams = new JSONObject();
- userparams.put("userId", userId);
- String userresult = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "UserMgmt.User.queryUserInfoByID", userparams.toString(), false);
- JSONObject userResultObj = JSONObject.fromObject(userresult);
- int userCode=userResultObj.getInt("Code");
- String usermsg=userResultObj.getString("Message");
- if(userCode ==10000){
- JSONObject arrform = userResultObj.getJSONObject("Result");
- if(null!=arrform && arrform.size()>0){
- cName=arrform.getString("CName");
- if(StringUtil.isEmpty(cName)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
- return;
- }
- }else{
- response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
- return;
- }
- }else{
- response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
- return;
- }
- JSONObject params = new JSONObject();
- params.put("categoryId", categoryId);
- params.put("categoryName", categoryName);
- params.put("userId", userId);
- params.put("cName", cName);
- String result = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "JkEdu.Subscrive.saveSubscrive", params.toString(), false);
- JSONObject formResultObj = JSONObject.fromObject(result);
- int code = formResultObj.getInt("Code");
- String msg = formResultObj.getString("Message");
- JSONObject resultJson = new JSONObject();
- if (code == 10000) {// 成功
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- }else{
- resultJson.put("Code", -10000);
- resultJson.put("Message", msg);
- }
- response.getWriter().write(resultJson.toString());
- return;
-
- } catch (Exception e) {
- e.printStackTrace();
- response.getWriter().write(ApiUtil.jsonResult(-14444, "保存用户的订阅异常").toString());
- return;
- }
- }
- }
|