ContentAction.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package net.mingsoft.cms.action.web;
  2. import io.swagger.annotations.Api;
  3. import io.swagger.annotations.ApiImplicitParam;
  4. import io.swagger.annotations.ApiImplicitParams;
  5. import io.swagger.annotations.ApiOperation;
  6. import net.mingsoft.base.entity.BaseEntity;
  7. import net.mingsoft.base.entity.ResultData;
  8. import net.mingsoft.basic.bean.EUListBean;
  9. import net.mingsoft.basic.util.BasicUtil;
  10. import net.mingsoft.basic.util.StringUtil;
  11. import net.mingsoft.cms.biz.IContentBiz;
  12. import net.mingsoft.cms.entity.ContentEntity;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Controller;
  15. import org.springframework.ui.ModelMap;
  16. import org.springframework.validation.BindingResult;
  17. import org.springframework.web.bind.annotation.GetMapping;
  18. import org.springframework.web.bind.annotation.ModelAttribute;
  19. import org.springframework.web.bind.annotation.PathVariable;
  20. import org.springframework.web.bind.annotation.PostMapping;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.ResponseBody;
  24. import springfox.documentation.annotations.ApiIgnore;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;
  27. import java.util.List;
  28. /**
  29. * 文章管理控制层
  30. * @author 铭飞开发团队
  31. * 创建日期:2019-11-28 15:12:32<br/>
  32. * 历史修订:<br/>
  33. */
  34. @Api(value = "文章接口")
  35. @Controller("WebcmsContentAction")
  36. @RequestMapping("/cms/content")
  37. public class ContentAction extends net.mingsoft.cms.action.BaseAction{
  38. /**
  39. * 注入文章业务层
  40. */
  41. @Autowired
  42. private IContentBiz contentBiz;
  43. /**
  44. * 返回主界面index
  45. */
  46. @GetMapping("/index")
  47. public String index(HttpServletResponse response,HttpServletRequest request){
  48. return "/cms/content/index";
  49. }
  50. /**
  51. * 查询文章列表
  52. * @param content 文章实体
  53. */
  54. @ApiOperation(value = "查询文章列表接口")
  55. @ApiImplicitParams({
  56. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
  57. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  58. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  59. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  60. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  61. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  62. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =false,paramType="query"),
  63. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  64. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  65. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  66. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  67. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  68. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  69. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  70. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  71. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  72. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  73. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  74. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  75. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  76. })
  77. @RequestMapping("/list")
  78. @ResponseBody
  79. public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
  80. BasicUtil.startPage();
  81. List contentList = contentBiz.query(content);
  82. return ResultData.build().success(new EUListBean(contentList,(int)BasicUtil.endPage(contentList).getTotal()));
  83. }
  84. /**
  85. * 返回编辑界面content_form
  86. */
  87. @GetMapping("/form")
  88. public String form(@ModelAttribute ContentEntity content,HttpServletResponse response,HttpServletRequest request,ModelMap model){
  89. if(content.getId()!=null){
  90. BaseEntity contentEntity = contentBiz.getEntity(Integer.parseInt(content.getId()));
  91. model.addAttribute("contentEntity",contentEntity);
  92. }
  93. return "/cms/content/form";
  94. }
  95. /**
  96. * 获取文章
  97. * @param content 文章实体
  98. */
  99. @ApiOperation(value = "获取文章列表接口")
  100. @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
  101. @GetMapping("/get")
  102. @ResponseBody
  103. public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
  104. if(content.getId()==null) {
  105. return ResultData.build().error();
  106. }
  107. ContentEntity _content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
  108. return ResultData.build().success(_content);
  109. }
  110. @ApiOperation(value = "保存文章列表接口")
  111. @ApiImplicitParams({
  112. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
  113. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  114. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  115. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  116. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  117. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  118. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =true,paramType="query"),
  119. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  120. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  121. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  122. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  123. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  124. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  125. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  126. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  127. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  128. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  129. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  130. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  131. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  132. })
  133. /**
  134. * 保存文章
  135. * @param content 文章实体
  136. */
  137. @PostMapping("/save")
  138. @ResponseBody
  139. public ResultData save(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response, HttpServletRequest request) {
  140. //验证文章标题的值是否合法
  141. if(StringUtil.isBlank(content.getContentTitle())){
  142. return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));
  143. }
  144. if(!StringUtil.checkLength(content.getContentTitle()+"", 0, 200)){
  145. return ResultData.build().error(getResString("err.length", this.getResString("content.title"), "0", "200"));
  146. }
  147. if(!StringUtil.checkLength(content.getContentAuthor()+"", 0, 200)){
  148. return ResultData.build().error(getResString("err.length", this.getResString("content.author"), "0", "200"));
  149. }
  150. if(!StringUtil.checkLength(content.getContentSource()+"", 0, 200)){
  151. return ResultData.build().error(getResString("err.length", this.getResString("content.source"), "0", "200"));
  152. }
  153. //验证发布时间的值是否合法
  154. if(StringUtil.isBlank(content.getContentDatetime())){
  155. return ResultData.build().error(getResString("err.empty", this.getResString("content.datetime")));
  156. }
  157. if(!StringUtil.checkLength(content.getContentUrl()+"", 0, 200)){
  158. return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
  159. }
  160. contentBiz.saveEntity(content);
  161. return ResultData.build().success(content);
  162. }
  163. /**
  164. * @param contents 文章实体
  165. */
  166. @ApiOperation(value = "批量删除文章列表接口")
  167. @PostMapping("/delete")
  168. @ResponseBody
  169. public ResultData delete(@RequestBody List<ContentEntity> contents,HttpServletResponse response, HttpServletRequest request) {
  170. int[] ids = new int[contents.size()];
  171. for(int i = 0;i<contents.size();i++){
  172. ids[i] =Integer.parseInt(contents.get(i).getId()) ;
  173. }
  174. contentBiz.delete(ids);
  175. return ResultData.build().success();
  176. }
  177. /**
  178. * 更新文章列表
  179. * @param content 文章实体
  180. */
  181. @ApiOperation(value = "更新文章列表接口")
  182. @ApiImplicitParams({
  183. @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"),
  184. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
  185. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  186. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  187. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  188. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  189. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  190. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =true,paramType="query"),
  191. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  192. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  193. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  194. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  195. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  196. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  197. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  198. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  199. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  200. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  201. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  202. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  203. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  204. })
  205. @PostMapping("/update")
  206. @ResponseBody
  207. public ResultData update(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response,
  208. HttpServletRequest request) {
  209. //验证文章标题的值是否合法
  210. if(StringUtil.isBlank(content.getContentTitle())){
  211. return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));
  212. }
  213. if(!StringUtil.checkLength(content.getContentTitle()+"", 0, 200)){
  214. return ResultData.build().error(getResString("err.length", this.getResString("content.title"), "0", "200"));
  215. }
  216. if(!StringUtil.checkLength(content.getContentAuthor()+"", 0, 200)){
  217. return ResultData.build().error(getResString("err.length", this.getResString("content.author"), "0", "200"));
  218. }
  219. if(!StringUtil.checkLength(content.getContentSource()+"", 0, 200)){
  220. return ResultData.build().error(getResString("err.length", this.getResString("content.source"), "0", "200"));
  221. }
  222. //验证发布时间的值是否合法
  223. if(StringUtil.isBlank(content.getContentDatetime())){
  224. return ResultData.build().error(getResString("err.empty", this.getResString("content.datetime")));
  225. }
  226. if(!StringUtil.checkLength(content.getContentUrl()+"", 0, 200)){
  227. return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
  228. }
  229. contentBiz.updateEntity(content);
  230. return ResultData.build().success(content);
  231. }
  232. @ApiOperation(value = "查看文章点击数")
  233. @ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
  234. @GetMapping(value = "/{contentId}/hit")
  235. @ResponseBody
  236. public void hit(@PathVariable @ApiIgnore int contentId, HttpServletRequest request, HttpServletResponse response){
  237. if(contentId<=0){
  238. this.outString(response, "document.write(0)");
  239. return;
  240. }
  241. ContentEntity content = (ContentEntity)contentBiz.getEntity(contentId);
  242. if(content == null){
  243. this.outString(response, "document.write(0)");
  244. return;
  245. }
  246. if(content.getAppId() == null || content.getAppId() != BasicUtil.getAppId()){
  247. this.outString(response, "document.write(0)");
  248. return;
  249. }
  250. this.outString(response, "document.write(" + content.getContentHit() + ")");
  251. return;
  252. }
  253. }