ContentAction.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * The MIT License (MIT)
  3. * Copyright (c) 2012-2022 铭软科技(mingsoft.net)
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. * The above copyright notice and this permission notice shall be included in all
  11. * copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. */
  19. package net.mingsoft.cms.action.web;
  20. import cn.hutool.core.util.ObjectUtil;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiImplicitParam;
  23. import io.swagger.annotations.ApiImplicitParams;
  24. import io.swagger.annotations.ApiOperation;
  25. import net.mingsoft.base.entity.ResultData;
  26. import net.mingsoft.basic.bean.EUListBean;
  27. import net.mingsoft.basic.util.BasicUtil;
  28. import net.mingsoft.cms.bean.ContentBean;
  29. import net.mingsoft.cms.biz.IContentBiz;
  30. import net.mingsoft.cms.biz.IHistoryLogBiz;
  31. import net.mingsoft.cms.entity.ContentEntity;
  32. import net.mingsoft.cms.entity.HistoryLogEntity;
  33. import org.apache.commons.lang3.StringUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.stereotype.Controller;
  36. import org.springframework.web.bind.annotation.*;
  37. import springfox.documentation.annotations.ApiIgnore;
  38. import java.util.Date;
  39. import java.util.List;
  40. /**
  41. * 文章管理控制层
  42. * @author 铭飞开发团队
  43. * 创建日期:2019-11-28 15:12:32<br/>
  44. * 历史修订:<br/>
  45. */
  46. @Api(tags={"前端-内容模块接口"})
  47. @Controller("WebcmsContentAction")
  48. @RequestMapping("/cms/content")
  49. public class ContentAction extends net.mingsoft.cms.action.BaseAction{
  50. /**
  51. * 注入文章业务层
  52. */
  53. @Autowired
  54. private IContentBiz contentBiz;
  55. @Autowired
  56. private IHistoryLogBiz historyLogBiz;
  57. /**
  58. * 查询文章列表接口
  59. * @param content 文章
  60. * @return
  61. */
  62. @ApiOperation(value = "查询文章列表接口")
  63. @ApiImplicitParams({
  64. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
  65. @ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"),
  66. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  67. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  68. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  69. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  70. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =false,paramType="query"),
  71. })
  72. @PostMapping("/list")
  73. @ResponseBody
  74. public ResultData list(@ModelAttribute @ApiIgnore ContentBean content) {
  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. * @return
  83. */
  84. @ApiOperation(value = "获取文章列表接口")
  85. @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
  86. @GetMapping("/get")
  87. @ResponseBody
  88. public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content){
  89. if(content.getId()==null) {
  90. return ResultData.build().error();
  91. }
  92. ContentEntity _content = (ContentEntity)contentBiz.getById(content.getId());;
  93. return ResultData.build().success(_content);
  94. }
  95. /**
  96. * 查看文章点击数
  97. * @param contentId 文章编号
  98. * @return
  99. */
  100. @ApiOperation(value = "查看文章点击数")
  101. @ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
  102. @GetMapping(value = "/{contentId}/hit")
  103. @ResponseBody
  104. public String hit(@PathVariable @ApiIgnore String contentId) {
  105. if(StringUtils.isEmpty(contentId)){
  106. return "document.write(0)";
  107. }
  108. //获取ip
  109. String ip = BasicUtil.getIp();
  110. //获取端口(移动/web..)
  111. boolean isMobileDevice = BasicUtil.isMobileDevice();
  112. ContentEntity content = contentBiz.getById(contentId);
  113. if(content == null){
  114. return "document.write(0)";
  115. }
  116. //浏览数+1
  117. if(ObjectUtil.isNotEmpty(content.getContentHit())){
  118. content.setContentHit(content.getContentHit()+1);
  119. }else {
  120. content.setContentHit(1);
  121. }
  122. contentBiz.updateById(content);
  123. // cms_history 增加相应记录
  124. HistoryLogEntity entity = new HistoryLogEntity();
  125. entity.setHlIsMobile(isMobileDevice);
  126. entity.setHlIp(ip);
  127. entity.setContentId(content.getId());
  128. entity.setCreateDate(new Date());
  129. historyLogBiz.saveEntity(entity);
  130. return "document.write(" + content.getContentHit() + ")";
  131. }
  132. }