123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- package com.yihu.jkedu.action;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import net.sf.json.JSONArray;
- 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;
- @Controller
- @RequestMapping("/article")
- public class ArticleControl
- {
- /**
- * @Title: queryArticleList
- * @Description: 查看订阅文章列表
- * @param @param request
- * @param @param response
- * @param @throws Exception 设定文件
- * @return void 返回类型
- * @throws
- */
- @RequestMapping(value = "/queryArticleList")
- public void queryArticleList(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- try {
- response.setContentType("application/json;charset=UTF-8");
- String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
- int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
- int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
- if(StringUtil.isEmpty(articleCategoryId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
- return;
- }
- JSONObject params = new JSONObject();
- params.put("pageSize", pageSize);
- params.put("pageIndex", pageIndex);
- params.put("firstLevelCategoryId", articleCategoryId);
- params.put("articleState", "1");//1、正常、2删除 3、草稿
- String formResult = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "JkEdu.Article.getArticalList", 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) {// 成功
- int count=formResultObj.getInt("Count");
- if(count>0){
- JSONArray arrform = formResultObj.getJSONArray("Result");
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", arrform);
- resultJson.put("Count", count);
- response.getWriter().write(resultJson.toString());
- return ;
- }else{
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", null);
- resultJson.put("Count", count);
- 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: getCollectionArticalList
- * @Description: 收藏文章列表
- * @param @param request
- * @param @param response
- * @param @throws Exception 设定文件
- * @return void 返回类型
- * @throws
- */
- @RequestMapping(value = "/getCollectionArticalList")
- public void getCollectionArticalList(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- try {
- response.setContentType("application/json;charset=UTF-8");
- String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
- String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
- int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
- int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
- String userType = StringUtil.isEmpty(request.getParameter("userType")) ? null : request.getParameter("userType");
- if(StringUtil.isEmpty(articleCategoryId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "articleCategoryId参数不能为空").toString());
- return;
- }
- if(StringUtil.isEmpty(userId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId参数不能为空").toString());
- return;
- }
- JSONObject params = new JSONObject();
- params.put("pageSize", pageSize);
- params.put("pageIndex", pageIndex);
- params.put("userId", userId);
- params.put("userType", userType);
- params.put("firstLevelCategoryId", articleCategoryId);
- params.put("articleState", "1");//1、正常、2删除 3、草稿
- String formResult = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "JkEdu.Article.getCollectionArticalList", 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) {// 成功
- int count=formResultObj.getInt("Count");
- if(count>0){
- JSONArray arrform = formResultObj.getJSONArray("Result");
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", arrform);
- resultJson.put("Count", count);
- response.getWriter().write(resultJson.toString());
- return ;
- }else{
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", null);
- resultJson.put("Count", count);
- 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: getArticalById
- * @Description: 查看文章详情
- * @param @param request
- * @param @param response
- * @param @throws Exception 设定文件
- * @return void 返回类型
- * @throws
- */
- @RequestMapping(value = "/getArticalById")
- public void getArticalById(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- try {
- response.setContentType("application/json;charset=UTF-8");
- String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
- String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
- if(StringUtil.isEmpty(articleId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString());
- return;
- }
- if(StringUtil.isEmpty(userId)){
- response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId").toString());
- return;
- }
- JSONObject params = new JSONObject();
- params.put("articleId", articleId);
- String result = ServiceBus.getInstance(
- null,
- ConfigUtil.getInstance().getAppId()).call(
- "JkEdu.Article.getArticalById", 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) {// 成功
- JSONArray arrform = formResultObj.getJSONArray("Result");
- resultJson.put("Code", 10000);
- resultJson.put("Message", msg);
- resultJson.put("Result", arrform);
- resultJson.put("articleId", articleId);
- }else{
- resultJson.put("Code", code);
- resultJson.put("Message", msg);
- resultJson.put("Result", null);
- resultJson.put("articleId", articleId);
- }
- response.getWriter().write(resultJson.toString());
- return;
- } catch (Exception e) {
- e.printStackTrace();
- response.getWriter().write(ApiUtil.jsonResult(-14444, "取消收藏异常").toString());
- return;
- }
- }
- }
|