|
@@ -21,9 +21,13 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.connection.ConnectionUtils;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -38,6 +42,9 @@ public class NewsController extends BaseController<News> {
|
|
|
@Autowired
|
|
|
NewsServiceImpl newsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public BaseService getBaseService() {
|
|
@@ -49,7 +56,7 @@ public class NewsController extends BaseController<News> {
|
|
|
return "业务--新闻表";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "新闻列表(后台)")
|
|
|
+ @ApiOperation(value = "新闻列表(有分页,后台)")
|
|
|
@ApiImplicitParam(name = "queryData", value = "查询条件")
|
|
|
@PostMapping("findAllNews")
|
|
|
public JsonPageResult findAllNews(@RequestBody QueryData queryData) {
|
|
@@ -94,11 +101,33 @@ public class NewsController extends BaseController<News> {
|
|
|
}
|
|
|
|
|
|
@ApiOperation("前台新闻详情")
|
|
|
- @GetMapping("findByIdPcNews/{newsId}")
|
|
|
- public JsonResult getAllList(@PathVariable("newsId") String newsId) {
|
|
|
+ @GetMapping("findByIdPcNews")
|
|
|
+ public JsonResult getAllList(@RequestParam("newsId") String newsId,
|
|
|
+ HttpSession httpSession) {
|
|
|
JsonResult<News> newsJsonResult = this.get(newsId);
|
|
|
// 统计浏览数量
|
|
|
- newsService.countViews(queryLoginUser(),newsId);
|
|
|
+ // TODO: 2022/11/25 后续取登录员工信息
|
|
|
+ String loginUserId = "1001";
|
|
|
+ List<String> newsIdAttr = (List<String>) httpSession.getServletContext().getAttribute(loginUserId);
|
|
|
+ if (newsIdAttr == null){
|
|
|
+ List<String> initNewsIds = new ArrayList<>();
|
|
|
+ initNewsIds.add(newsId);
|
|
|
+ httpSession.getServletContext().setAttribute(loginUserId,initNewsIds);
|
|
|
+ }
|
|
|
+ if (newsIdAttr != null || !newsIdAttr.contains(newsId)){
|
|
|
+ newsIdAttr.add(newsId);
|
|
|
+ httpSession.getServletContext().setAttribute(loginUserId,newsIdAttr);
|
|
|
+ }
|
|
|
+ newsIdAttr.forEach(e -> {
|
|
|
+ if (redisTemplate.hasKey(e)){
|
|
|
+ // 获取该新闻浏览数量
|
|
|
+ Integer views = (Integer) redisTemplate.opsForValue().get(e);
|
|
|
+ redisTemplate.opsForValue().set(e,++views);
|
|
|
+ } else {
|
|
|
+ Integer views = newsJsonResult.getData().getViews();
|
|
|
+ redisTemplate.opsForValue().set(e,++views);
|
|
|
+ }
|
|
|
+ });
|
|
|
return newsJsonResult;
|
|
|
}
|
|
|
|