ArticleAction.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /**
  2. The MIT License (MIT) * Copyright (c) 2016 铭飞科技(mingsoft.net)
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. * this software and associated documentation files (the "Software"), to deal in
  5. * the Software without restriction, including without limitation the rights to
  6. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  7. * the Software, and to permit persons to whom the Software is furnished to do so,
  8. * subject to the following conditions:
  9. * The above copyright notice and this permission notice shall be included in all
  10. * copies or substantial portions of the Software.
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  13. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  14. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  15. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. */
  18. package net.mingsoft.cms.action.web;
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Controller;
  28. import org.springframework.web.bind.annotation.GetMapping;
  29. import org.springframework.web.bind.annotation.ModelAttribute;
  30. import org.springframework.web.bind.annotation.PathVariable;
  31. import org.springframework.web.bind.annotation.RequestMapping;
  32. import org.springframework.web.bind.annotation.RequestMethod;
  33. import org.springframework.web.bind.annotation.ResponseBody;
  34. import com.alibaba.fastjson.JSONArray;
  35. import com.alibaba.fastjson.JSONObject;
  36. import io.swagger.annotations.ApiOperation;
  37. import net.mingsoft.base.filter.DateValueFilter;
  38. import net.mingsoft.basic.action.BaseAction;
  39. import net.mingsoft.basic.bean.ListBean;
  40. import net.mingsoft.basic.biz.IColumnBiz;
  41. import net.mingsoft.basic.entity.ColumnEntity;
  42. import net.mingsoft.basic.util.BasicUtil;
  43. import net.mingsoft.cms.biz.IArticleBiz;
  44. import net.mingsoft.cms.entity.ArticleEntity;
  45. import net.mingsoft.mdiy.biz.IContentModelBiz;
  46. import net.mingsoft.mdiy.biz.IContentModelFieldBiz;
  47. import net.mingsoft.mdiy.entity.ContentModelEntity;
  48. import springfox.documentation.annotations.ApiIgnore;
  49. /**
  50. *
  51. * @ClassName: ArticleAction
  52. * @Description:TODO 前段文章控制,如果标签不能满足可以使用这个控制来满足用户的查询文章需求,主要是通过ajax返回json数据格式
  53. * @author: 铭飞开发团队
  54. * @date: 2018年1月31日 下午2:52:44
  55. *
  56. * @Copyright: 2018 www.mingsoft.net Inc. All rights reserved.
  57. */
  58. @Controller("jsonApiArticle")
  59. @RequestMapping("/mcms/article")
  60. public class ArticleAction extends BaseAction {
  61. /**
  62. * 文章管理业务处理层
  63. */
  64. @Autowired
  65. private IArticleBiz articleBiz;
  66. /**
  67. * 栏目管理业务处理层
  68. */
  69. @Autowired
  70. private IColumnBiz columnBiz;
  71. /**
  72. * 内容模型管理业务处理层
  73. */
  74. @Autowired
  75. private IContentModelBiz contentModelBiz;
  76. /**
  77. * 自定义字段管理业务处理层
  78. */
  79. @Autowired
  80. private IContentModelFieldBiz fieldBiz;
  81. /**
  82. * 文章信息
  83. *
  84. * @param basicId
  85. * 文章编号
  86. * <dt><span class="strong">返回</span></dt><br/>
  87. * {"basicCategoryId":分类编号,basicTitle
  88. * :"标题",basicDescription:"描述",basicThumbnails:"缩略图",
  89. * basicDateTime:"发布时间",basicUpdateTime:"更新时间","basicHit":点击数,
  90. * "basicId":编号 articleContent:"文章内容","basicSort":排序,[自定义模型字段]}
  91. */
  92. @GetMapping("/{basicId}/detail")
  93. @ResponseBody
  94. public void detail(@PathVariable int basicId, HttpServletRequest request, HttpServletResponse response) {
  95. ArticleEntity article = articleBiz.getById(basicId);
  96. if (article == null) {
  97. this.outJson(response, "");
  98. return;
  99. }
  100. // 获取文章栏目id获取栏目实体
  101. ColumnEntity column = (ColumnEntity) columnBiz.getEntity(article.getBasicCategoryId());
  102. ContentModelEntity contentModel = (ContentModelEntity) contentModelBiz
  103. .getEntity(column.getColumnContentModelId());
  104. // 判断内容模型的值
  105. if (contentModel != null) {
  106. Map where = new HashMap();
  107. // 压入basicId字段的值
  108. where.put("basicId", basicId);
  109. // 遍历所有的字段实体,得到字段名列表信息
  110. List<String> listFieldName = new ArrayList<String>();
  111. listFieldName.add("basicId");
  112. // 查询新增字段的信息
  113. List fieldLists = fieldBiz.queryBySQL(contentModel.getCmTableName(), listFieldName, where);
  114. if (fieldLists.size() > 0) {
  115. Map map = (Map) fieldLists.get(0);
  116. article.setExtendsFields(map);
  117. }
  118. }
  119. this.outJson(response, JSONObject.toJSONStringWithDateFormat(article, "yyyy-MM-dd hh:mm:ss"));
  120. }
  121. /**
  122. * 文章列表信息
  123. *
  124. * @param pageSize
  125. * 一页显示数量
  126. * @param pageNum
  127. * 当前页码
  128. * @param basicCategoryId
  129. * 分类编号
  130. * <dt><span class="strong">返回</span></dt><br/>
  131. * {"list":"[{
  132. * "basicTitle":"标题",
  133. * "basicDescription":"描述",
  134. * "basicThumbnails":"缩略图",
  135. * "basicDateTime":"发布时间",
  136. * "basicUpdateTime":"更新时间",
  137. * "basicHit":点击数,
  138. * "basicId":编号,
  139. * "articleContent":文章内容,
  140. * "articleAuthor":文章作者
  141. * "articleType":文章属性,
  142. * "articleSource":文章的来源,
  143. * "articleUrl":文章跳转链接地址,
  144. * "articleKeyword":文章关键字,
  145. * "articleCategoryId":文章所属的分类Id,
  146. * "articleTypeLinkURL":文章分类url地址,主要是用户生成html使用,
  147. * "order":"排序方式",
  148. * "orderBy":"排序字段
  149. * }],
  150. * "page":{"endRow": 2, 当前页面最后一个元素在数据库中的行号
  151. * "firstPage": 1, 第一页页码
  152. * "hasNextPage": true存在下一页false不存在,
  153. * "hasPreviousPage": true存在上一页false不存在,
  154. * "isFirstPage": true是第一页false不是第一页,
  155. * "isLastPage": true是最后一页false不是最后一页,
  156. * "lastPage": 最后一页的页码,
  157. * "navigatePages": 导航数量,实现 1...5.6.7....10效果,
  158. * "navigatepageNums": []导航页码集合,
  159. * "nextPage": 下一页,
  160. * "pageNum": 当前页码,
  161. * "pageSize": 一页显示数量,
  162. * "pages": 总页数,
  163. * "prePage": 上一页,
  164. * "size": 总记录,
  165. * "startRow":当前页面第一个元素在数据库中的行号,
  166. * "total":总记录数量
  167. * }
  168. */
  169. @RequestMapping(value = "/list",method= RequestMethod.GET)
  170. @ApiOperation(value="文章列表信息")
  171. @ResponseBody
  172. public void list(@ModelAttribute @ApiIgnore ArticleEntity article, HttpServletRequest request, HttpServletResponse response) {
  173. int appId = BasicUtil.getAppId();
  174. int[] ids = null;
  175. if (article.getBasicCategoryId()>0) {
  176. ids = new int[]{article.getBasicCategoryId()};
  177. }
  178. //默认为desc排序
  179. boolean isOrder = true;
  180. if(!StringUtils.isBlank(article.getOrder())){
  181. String basicOrder = article.getOrder();
  182. if(basicOrder.equalsIgnoreCase("asc")){
  183. isOrder = false;
  184. }
  185. }
  186. BasicUtil.startPage();
  187. List<ArticleEntity> list = articleBiz.query(appId, ids, null, null, article.getOrderBy(), isOrder, null, null, article);
  188. for(ArticleEntity _article : list){
  189. // 获取文章栏目id获取栏目实体
  190. ColumnEntity column = (ColumnEntity) columnBiz.getEntity(_article.getBasicCategoryId());
  191. ContentModelEntity contentModel = (ContentModelEntity) contentModelBiz
  192. .getEntity(column.getColumnContentModelId());
  193. // 判断内容模型的值
  194. if (contentModel != null) {
  195. Map where = new HashMap();
  196. // 压入basicId字段的值
  197. where.put("basicId", _article.getBasicId());
  198. // 遍历所有的字段实体,得到字段名列表信息
  199. List<String> listFieldName = new ArrayList<String>();
  200. listFieldName.add("basicId");
  201. // 查询新增字段的信息
  202. List fieldLists = fieldBiz.queryBySQL(contentModel.getCmTableName(), listFieldName, where);
  203. if (fieldLists.size() > 0) {
  204. Map map = (Map) fieldLists.get(0);
  205. _article.setExtendsFields(map);
  206. }
  207. }
  208. }
  209. this.outJson(response, JSONArray.toJSONString(new ListBean(list, BasicUtil.endPage(list)),new DateValueFilter("yyyy-MM-dd HH:mm:ss")));
  210. }
  211. }