ContentAction.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package net.mingsoft.cms.action.web;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import io.swagger.annotations.Api;
  4. import io.swagger.annotations.ApiImplicitParam;
  5. import io.swagger.annotations.ApiImplicitParams;
  6. import io.swagger.annotations.ApiOperation;
  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.cms.biz.IContentBiz;
  11. import net.mingsoft.cms.biz.IHistoryLogBiz;
  12. import net.mingsoft.cms.entity.ContentEntity;
  13. import net.mingsoft.cms.entity.HistoryLogEntity;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.ui.ModelMap;
  17. import org.springframework.validation.BindingResult;
  18. import org.springframework.web.bind.annotation.GetMapping;
  19. import org.springframework.web.bind.annotation.ModelAttribute;
  20. import org.springframework.web.bind.annotation.PathVariable;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.ResponseBody;
  23. import springfox.documentation.annotations.ApiIgnore;
  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.util.Date;
  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. @Autowired
  44. private IHistoryLogBiz historyLogBiz;
  45. /**
  46. * 查询文章列表
  47. * @param content 文章实体
  48. */
  49. @ApiOperation(value = "查询文章列表接口")
  50. @ApiImplicitParams({
  51. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
  52. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  53. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  54. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  55. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  56. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  57. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =false,paramType="query"),
  58. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  59. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  60. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  61. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  62. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  63. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  64. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  65. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  66. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  67. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  68. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  69. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  70. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  71. })
  72. @RequestMapping("/list")
  73. @ResponseBody
  74. public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
  75. BasicUtil.startPage();
  76. List contentList = contentBiz.query(content);
  77. return ResultData.build().success(new EUListBean(contentList,(int)BasicUtil.endPage(contentList).getTotal()));
  78. }
  79. /**
  80. * 获取文章
  81. * @param content 文章实体
  82. */
  83. @ApiOperation(value = "获取文章列表接口")
  84. @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
  85. @GetMapping("/get")
  86. @ResponseBody
  87. public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
  88. if(content.getId()==null) {
  89. return ResultData.build().error();
  90. }
  91. ContentEntity _content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
  92. return ResultData.build().success(_content);
  93. }
  94. @ApiOperation(value = "查看文章点击数")
  95. @ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
  96. @GetMapping(value = "/{contentId}/hit")
  97. @ResponseBody
  98. public String hit(@PathVariable @ApiIgnore int contentId, HttpServletRequest request, HttpServletResponse response){
  99. if(contentId<=0){
  100. return "document.write(0)";
  101. }
  102. //获取ip
  103. String ip = BasicUtil.getIp();
  104. //获取端口(移动/web..)
  105. boolean isMobileDevice = BasicUtil.isMobileDevice();
  106. ContentEntity content = (ContentEntity)contentBiz.getEntity(contentId);
  107. if(content == null){
  108. return "document.write(0)";
  109. }
  110. //浏览数+1
  111. if(ObjectUtil.isNotEmpty(content.getContentHit())){
  112. content.setContentHit(content.getContentHit()+1);
  113. }else {
  114. content.setContentHit(1);
  115. }
  116. contentBiz.updateEntity(content);
  117. // cms_history 增加相应记录
  118. HistoryLogEntity entity = new HistoryLogEntity();
  119. entity.setHlIsMobile(isMobileDevice);
  120. entity.setHlIp(ip);
  121. entity.setContentId(content.getId());
  122. entity.setCreateDate(new Date());
  123. historyLogBiz.saveEntity(entity);
  124. if(content.getAppId() == null || content.getAppId() != BasicUtil.getAppId()){
  125. return "document.write(0)";
  126. }
  127. return "document.write(" + content.getContentHit() + ")";
  128. }
  129. }