puhanshu
2021-09-18 f0d44c4bf251611e80cbb736b85e7768ad88eb4a
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActDiscussServiceImpl.java
@@ -597,9 +597,12 @@
        IPage<ComActDiscussVO> iPage = comActDiscussDAO.pageDiscussApplets(page, pageComActDiscussDTO);
        List<ComActDiscussVO> records = iPage.getRecords();
        if (!ObjectUtils.isEmpty(records)) {
            List<String> viewNumKeys = new ArrayList<>();
            records.forEach(comActDiscussVO -> {
                Integer type = comActDiscussVO.getType();
                Long id = comActDiscussVO.getId();
                String viewNumKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, id.toString());
                viewNumKeys.add(viewNumKey);
                if (type.equals(2)) {
                    List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(
                            new QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, id));
@@ -663,6 +666,17 @@
                    comActDiscussVO.setHaveVote(haveVote > 0 ? 1 : 0);
                }
            });
            ValueOperations opsForValue = stringRedisTemplate.opsForValue();
            List<String> viewNumList = opsForValue.multiGet(viewNumKeys);
            for (ComActDiscussVO discussVO : records) {
                try {
                    discussVO.setViewsNum(Integer.parseInt(viewNumList.get(0)));
                    viewNumList.remove(0);
                } catch (IndexOutOfBoundsException e) {
                    //数据存在异常了,跳过,继续执行正确的
                    continue;
                }
            }
        }
        return R.ok(iPage);
    }
@@ -889,7 +903,10 @@
            comActDiscussVO.setHaveSign(comActDiscussVO1.getHaveSign());
            comActDiscussVO.setHaveVote(comActDiscussVO1.getHaveVote());
        }
        String viewNumKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, id.toString());
        ValueOperations opsForValue = stringRedisTemplate.opsForValue();
        int viewNum = Integer.parseInt((String) opsForValue.get(viewNumKey));
        comActDiscussVO.setViewsNum(viewNum);
        return R.ok(comActDiscussVO);
    }