文章浏览统计功能以及各个列表回显统计数量的值。

master
rong.liu 2 years ago
parent 114b46cd5f
commit 1444047b94
  1. 11
      src/main/java/com/huoran/iasf/controller/SysContentController.java
  2. 4
      src/main/java/com/huoran/iasf/mapper/xml/SysContentMapper.xml
  3. 4
      src/main/java/com/huoran/iasf/service/SysContentService.java
  4. 28
      src/main/java/com/huoran/iasf/service/impl/SysContentServiceImpl.java

@ -16,6 +16,7 @@ import io.swagger.annotations.*;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -49,8 +50,9 @@ public class SysContentController {
public SysContentFileService fileService; public SysContentFileService fileService;
@PostMapping("/pagingQuery") @PostMapping("/pagingQuery")
@ApiOperation(value = "分页查询", response = PageContentRespVO.class) @ApiOperation(value = "分页查询文章列表", response = PageContentRespVO.class)
public R pagingQuery(@RequestBody @Valid @ApiParam(name = "分页查询参数", value = "传入json格式", required = true) PageContentReqVO sysContent) { public R pagingQuery(@RequestBody @Valid @ApiParam(name = "分页查询参数", value = "传入json格式", required = true) PageContentReqVO sysContent) {
return service.articlePaginationList(sysContent); return service.articlePaginationList(sysContent);
} }
@ -150,5 +152,12 @@ public class SysContentController {
return ret ? R.success() : R.fail("禁用/启用失败"); return ret ? R.success() : R.fail("禁用/启用失败");
} }
@PostMapping("/articlePreview")
@ApiOperation(value = "增加文章浏览量(点击一次算一次)", response = SysContent.class)
public R articlePreview(@ApiParam(name = "contentId", value = "文章id", required = true) @RequestParam Integer contentId) {
return R.success(service.statisticsOfPageViews(contentId));
}
} }

@ -88,11 +88,11 @@
</if> </if>
<if test="req.convokeType == 2"> <if test="req.convokeType == 1">
and unix_timestamp(activity_start_time) <![CDATA[ >= ]]> unix_timestamp(NOW()) and unix_timestamp(activity_start_time) <![CDATA[ >= ]]> unix_timestamp(NOW())
</if> </if>
<if test="req.convokeType == 1"> <if test="req.convokeType == 2">
and unix_timestamp(activity_start_time) <![CDATA[ <= ]]> unix_timestamp(NOW()) and unix_timestamp(activity_start_time) <![CDATA[ <= ]]> unix_timestamp(NOW())
</if> </if>

@ -24,4 +24,8 @@ public interface SysContentService extends IService<SysContent> {
R publishedEnabledArticles(); R publishedEnabledArticles();
R getTheFullArticleByColumn(String ids); R getTheFullArticleByColumn(String ids);
//统计浏览
Integer statisticsOfPageViews(Integer id);
} }

@ -1,6 +1,7 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -12,6 +13,7 @@ import com.huoran.iasf.service.SysContentService;
import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO; import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO;
import com.huoran.iasf.vo.req.PageContentReqVO; import com.huoran.iasf.vo.req.PageContentReqVO;
import com.huoran.iasf.vo.resp.PageContentRespVO; import com.huoran.iasf.vo.resp.PageContentRespVO;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -28,6 +30,9 @@ public class SysContentServiceImpl extends ServiceImpl<SysContentMapper, SysCont
@Autowired @Autowired
private SysContentMapper mapper; private SysContentMapper mapper;
@Autowired
private StringRedisTemplate redisTemplate;
@Override @Override
public boolean checkIfTheTitleIsRepeat(ContentHeavyTitleReqVO content) { public boolean checkIfTheTitleIsRepeat(ContentHeavyTitleReqVO content) {
//只对已发布的标题判重 //只对已发布的标题判重
@ -58,9 +63,6 @@ public class SysContentServiceImpl extends ServiceImpl<SysContentMapper, SysCont
@Override @Override
public R newlyPublishedArticles(PageContentReqVO reqVO) { public R newlyPublishedArticles(PageContentReqVO reqVO) {
/* QueryWrapper<SysContent> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("site_id", reqVO.getSiteId());
queryWrapper.eq("is_release", Constant.ARTICLE_PUBLISHED).orderByDesc("create_time");*/
Page<PageContentRespVO> page = new Page<PageContentRespVO>(reqVO.getPageNum(), reqVO.getPageSize()); Page<PageContentRespVO> page = new Page<PageContentRespVO>(reqVO.getPageNum(), reqVO.getPageSize());
IPage<PageContentRespVO> pageList = baseMapper.getPublishedArticles(page, reqVO); IPage<PageContentRespVO> pageList = baseMapper.getPublishedArticles(page, reqVO);
return R.success(pageList); return R.success(pageList);
@ -73,7 +75,6 @@ public class SysContentServiceImpl extends ServiceImpl<SysContentMapper, SysCont
queryWrapper.eq("is_release", Constant.ARTICLE_PUBLISHED); queryWrapper.eq("is_release", Constant.ARTICLE_PUBLISHED);
queryWrapper.eq("template_status", Constant.TEMPLATE_STATUS_ENABLED); queryWrapper.eq("template_status", Constant.TEMPLATE_STATUS_ENABLED);
List<SysContent> sysContentList = mapper.selectList(queryWrapper); List<SysContent> sysContentList = mapper.selectList(queryWrapper);
return R.success(sysContentList); return R.success(sysContentList);
} }
@ -83,7 +84,26 @@ public class SysContentServiceImpl extends ServiceImpl<SysContentMapper, SysCont
return R.success(mapper.useTheColumnToGetTagsForTheFullArticle(ids)); return R.success(mapper.useTheColumnToGetTagsForTheFullArticle(ids));
} }
@Override
public Integer statisticsOfPageViews(Integer id) {
String key = "preview:contentId:" + id;
//查看缓存是否有数据
String returnValue = redisTemplate.opsForValue().get(key);
if (returnValue == null) {
returnValue = "0";
}
returnValue = Integer.valueOf(returnValue) + 1 + "";
//保存到缓存中
redisTemplate.opsForValue().set(key, returnValue + "");
SysContent sysContent = new SysContent();
sysContent.setId(id);
sysContent.setTotalBrowsing(Integer.valueOf(returnValue));
mapper.updateById(sysContent);
return Integer.valueOf(returnValue);
}
} }

Loading…
Cancel
Save