From 3da01b2a6cf247f90aed86fc37d8cb0ab51a4b4c Mon Sep 17 00:00:00 2001
From: yanghui <2536613402@qq.com>
Date: 星期二, 29 十一月 2022 15:58:02 +0800
Subject: [PATCH] #feat .

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActDiscussServiceImpl.java |  419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 404 insertions(+), 15 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActDiscussServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActDiscussServiceImpl.java
index f72e540..b009883 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActDiscussServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActDiscussServiceImpl.java
@@ -17,7 +17,13 @@
 import java.util.stream.Collectors;
 
 import javax.annotation.Resource;
+import javax.validation.constraints.NotEmpty;
 
+import cn.hutool.core.util.DesensitizedUtil;
+import com.panzhihua.common.model.dtos.community.ComActDiscussVoteOptionDTO;
+import com.panzhihua.common.model.dtos.community.DiscussVoteOptionDTO;
+import com.panzhihua.common.model.dtos.community.PageVoteSituationDTO;
+import com.panzhihua.service_community.dao.ComPbMemberDAO;
 import org.springframework.beans.BeanUtils;
 import org.springframework.data.redis.connection.StringRedisConnection;
 import org.springframework.data.redis.core.RedisCallback;
@@ -114,6 +120,8 @@
     private UserService userService;
     @Resource
     private StringRedisTemplate stringRedisTemplate;
+    @Resource
+    private ComPbMemberDAO pbMemberDAO;
 
     /**
      * 议事投票-新增
@@ -163,6 +171,7 @@
                     comActDiscussOptionDO.setDiscussId(comActDiscussDO1Id);
                     comActDiscussOptionDO.setOptionContent(s.getOptionContent());
                     comActDiscussOptionDO.setOptionUrl(s.getOptionUrl());
+                    comActDiscussOptionDO.setNeedReason(s.getNeedReason());
                     comActDiscussOptionDOS.add(comActDiscussOptionDO);
                 });
                 comActDiscussOptionService.saveBatch(comActDiscussOptionDOS);
@@ -317,6 +326,60 @@
             }
         });
         comActDiscussVO.setDiscussCommentList(discussComments.getRecords());
+        String viewNumKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, id.toString());
+        if (stringRedisTemplate.hasKey(viewNumKey)) {
+            ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
+            comActDiscussVO.setViewsNum(Integer.parseInt(opsForValue.get(viewNumKey)));
+        }
+        return R.ok(comActDiscussVO);
+    }
+
+    /**
+     * 议事投票-详情 脱敏
+     *
+     * @param discussDetailDTO 请求参数
+     * @return ComActDiscussVO
+     */
+    @Override
+    public R detailDiscussDesensitize(ComActDiscussDetailDTO discussDetailDTO) {
+        Long id = discussDetailDTO.getId();
+        ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(id);
+        if (ObjectUtils.isEmpty(comActDiscussDO)) {
+            return R.fail("议事投票不存在");
+        }
+        ComActDiscussVO comActDiscussVO = new ComActDiscussVO();
+        BeanUtils.copyProperties(comActDiscussDO, comActDiscussVO);
+        comActDiscussVO.setSignNum(comActDiscussDO.getFabulousNum());
+        Integer type = comActDiscussVO.getType();
+        if (type.equals(ComActDiscussVO.type.tp)) {
+            //查询选项列表
+            List<ComActDiscussOptionVO> comActDiscussOptionList = comActDiscussOptionDAO.getDiscussOptionList(id);
+            comActDiscussVO.setComActDiscussOptionVOS(comActDiscussOptionList);
+        }
+        Long userId = comActDiscussDO.getUserId();
+        LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(userId);
+        comActDiscussVO.setUserName(DesensitizedUtil.chineseName(loginUserInfoVO.getName()));
+        comActDiscussVO.setUserNickName(loginUserInfoVO.getNickName());
+        comActDiscussVO.setImageUrl(loginUserInfoVO.getImageUrl());
+
+        //分页查询评论列表
+        PageComActDiscussCommentDTO pageComActDiscussCommentDTO = new PageComActDiscussCommentDTO();
+        BeanUtils.copyProperties(discussDetailDTO, pageComActDiscussCommentDTO);
+        IPage<ComActDiscussCommentVO> discussComments = comActDiscussDAO.pageDiscussCommentAdmin(new Page<>(pageComActDiscussCommentDTO.getPageNum(), pageComActDiscussCommentDTO.getPageSize()), pageComActDiscussCommentDTO);
+        discussComments.getRecords().forEach(comment -> {
+            if (comment.getReplyNum() > 0) {
+                List<ComActDiscussCommentVO> childList = comActDiscussDAO.getDiscussCommentReplyList(comment.getId());
+                if (!childList.isEmpty()) {
+                    comment.setComActDiscussCommentVOList(childList);
+                }
+            }
+        });
+        comActDiscussVO.setDiscussCommentList(discussComments.getRecords());
+        String viewNumKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, id.toString());
+        if (stringRedisTemplate.hasKey(viewNumKey)) {
+            ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
+            comActDiscussVO.setViewsNum(Integer.parseInt(opsForValue.get(viewNumKey)));
+        }
         return R.ok(comActDiscussVO);
     }
 
@@ -409,7 +472,7 @@
                 }
             });
         }
-        return R.ok();
+        return R.ok(comActDiscussVOIPage);
     }
 
     /**
@@ -610,6 +673,12 @@
         }
         page.setSize(pageSize);
         page.setCurrent(pageNum);
+        pageComActDiscussDTO.setIsPbMember(0);
+        pageComActDiscussDTO.setIsVolunteer(0);
+        if (nonNull(loginUserId)) {
+            pageComActDiscussDTO.setIsPbMember(pbMemberDAO.checkIsPbMember(loginUserId) > 0 ? 1 : 0);
+            pageComActDiscussDTO.setIsVolunteer(pbMemberDAO.checkIsVolunteer(loginUserId) > 0 ? 1 : 0);
+        }
         IPage<ComActDiscussVO> iPage = comActDiscussDAO.pageDiscussApplets(page, pageComActDiscussDTO);
         List<ComActDiscussVO> records = iPage.getRecords();
         if (!ObjectUtils.isEmpty(records)) {
@@ -661,6 +730,111 @@
                             comActDiscussVO.setRemainingVotes(remainingVotes >= 0 ? remainingVotes : 0);
                         }
                     }
+                    //填充投票记录列表
+                    List<ComActDiscussOptionUserVO> comActDiscussOptionUserVOList = comActDiscussOptionUserDAO
+                            .selectVotedRecords(comActDiscussVO.getId());
+                    comActDiscussVO.setComActDiscussOptionUserVOList(comActDiscussOptionUserVOList);
+                    //填充已参与投票人数
+                    int votedPersonNum = comActDiscussOptionUserDAO.selectVotedPersonNum(comActDiscussVO.getId());
+                    comActDiscussVO.setVotedPersonNum(votedPersonNum);
+                }
+
+                if (loginUserId != null) {
+                    Integer integer = comActDiscussUserDAO.selectCount(new QueryWrapper<ComActDiscussUserDO>().lambda()
+                            .eq(ComActDiscussUserDO::getDiscussId, comActDiscussVO.getId())
+                            .eq(ComActDiscussUserDO::getUserId, loginUserId));
+                    if (integer > 0) {
+                        comActDiscussVO.setHaveSign(1);
+                    } else {
+                        comActDiscussVO.setHaveSign(0);
+                    }
+                    // 判断是否已经投票
+                    int haveVote = comActDiscussOptionUserDAO.selectHaveVote(id, loginUserId);
+                    comActDiscussVO.setHaveVote(haveVote > 0 ? 1 : 0);
+                }
+            });
+        }
+        return R.ok(iPage);
+    }
+
+    /**
+     * 议事投票-分页查询 小程序
+     *
+     * @param pageComActDiscussDTO 查询参数
+     * @return ComActDiscussVO 分页
+     */
+    @Override
+    public R pageDiscussAppletsDesensitize(PageComActDiscussDTO pageComActDiscussDTO) {
+        Page page = new Page<>();
+        Long pageNum = pageComActDiscussDTO.getPageNum();
+        Long pageSize = pageComActDiscussDTO.getPageSize();
+        Long loginUserId = pageComActDiscussDTO.getLoginUserId();
+        if (null == pageNum || 0 == pageNum) {
+            pageNum = 1l;
+        }
+        if (null == pageSize || 0 == pageSize) {
+            pageSize = 10l;
+        }
+        page.setSize(pageSize);
+        page.setCurrent(pageNum);
+        pageComActDiscussDTO.setIsPbMember(0);
+        pageComActDiscussDTO.setIsVolunteer(0);
+        if (nonNull(loginUserId)) {
+            pageComActDiscussDTO.setIsPbMember(pbMemberDAO.checkIsPbMember(loginUserId) > 0 ? 1 : 0);
+            pageComActDiscussDTO.setIsVolunteer(pbMemberDAO.checkIsVolunteer(loginUserId) > 0 ? 1 : 0);
+        }
+        IPage<ComActDiscussVO> iPage = comActDiscussDAO.pageDiscussApplets(page, pageComActDiscussDTO);
+        List<ComActDiscussVO> records = iPage.getRecords();
+        if (!ObjectUtils.isEmpty(records)) {
+            records.forEach(comActDiscussVO -> {
+                Integer type = comActDiscussVO.getType();
+                Long id = comActDiscussVO.getId();
+                String viewNumKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, id.toString());
+                if (stringRedisTemplate.hasKey(viewNumKey)) {
+                    ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
+                    comActDiscussVO.setViewsNum(Integer.parseInt(opsForValue.get(viewNumKey)));
+                }
+                if (type.equals(2)) {
+                    List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(
+                            new QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, id));
+                    List<ComActDiscussOptionVO> comActDiscussOptionVOS = new ArrayList<>();
+                    List<Integer> votes = new ArrayList<>();
+                    comActDiscussOptionDOS.forEach(comActDiscussOptionDO -> {
+                        Long discussOptionDOId = comActDiscussOptionDO.getId();
+                        Integer selectCount =
+                                comActDiscussOptionUserDAO.selectCount(new QueryWrapper<ComActDiscussOptionUserDO>()
+                                        .lambda().eq(ComActDiscussOptionUserDO::getDiscussOptionId, discussOptionDOId));
+                        ComActDiscussOptionVO comActDiscussOptionVO = new ComActDiscussOptionVO();
+                        BeanUtils.copyProperties(comActDiscussOptionDO, comActDiscussOptionVO);
+                        comActDiscussOptionVO.setNum(selectCount);
+
+                        if (loginUserId != null) {
+                            // 判断选项是否已投票
+                            int haveVote =
+                                    comActDiscussOptionUserDAO.selectHaveVotes(comActDiscussOptionDO.getId(), loginUserId);
+                            votes.add(haveVote);
+                            comActDiscussOptionVO.setHaveVote(haveVote > 0 ? 1 : 0);
+                        }
+                        comActDiscussOptionVOS.add(comActDiscussOptionVO);
+                    });
+                    fillThePercentAndSort(comActDiscussOptionVOS);
+                    checkDiscussStatusIsCorrect(comActDiscussVO);
+                    comActDiscussVO.setComActDiscussOptionVOS(comActDiscussOptionVOS);
+                    //填充剩余可投票数
+                    if (loginUserId != null && !loginUserId.equals(0L)) {
+                        if (comActDiscussVO.getIsRepeat().intValue() == 1) {
+                            //可重复投票
+                            int votedVotesInToday = comActDiscussOptionUserDAO.selectVotedVotesInToday(id, loginUserId);
+                            int remainingVotes = comActDiscussVO.getCount().intValue() - votedVotesInToday;
+                            comActDiscussVO.setRemainingVotes(remainingVotes >= 0 ? remainingVotes : 0);
+                        } else {
+                            //不可重复投票
+                            int alreadyVotedVotes = votes.stream().mapToInt(Integer::intValue).sum();
+                            int remainingVotes = comActDiscussVO.getCount().intValue() - alreadyVotedVotes;
+                            comActDiscussVO.setRemainingVotes(remainingVotes >= 0 ? remainingVotes : 0);
+                        }
+                    }
+                    comActDiscussVO.setUserName(DesensitizedUtil.chineseName(comActDiscussVO.getUserName()));
                     //填充投票记录列表
                     List<ComActDiscussOptionUserVO> comActDiscussOptionUserVOList = comActDiscussOptionUserDAO
                             .selectVotedRecords(comActDiscussVO.getId());
@@ -824,6 +998,104 @@
         return R.ok(iPage);
     }
 
+ /**
+     * 议事投票-评论-分页查询 小程序
+     *
+     * @param pageComActDiscussCommentDTO 分页参数
+     * @return ComActDiscussCommentVO
+     */
+    @Override
+    public R pageDiscussCommentAppletsDesensitize(PageComActDiscussCommentDTO pageComActDiscussCommentDTO) {
+        Page page = new Page<>();
+        Long pageNum = pageComActDiscussCommentDTO.getPageNum();
+        Long pageSize = pageComActDiscussCommentDTO.getPageSize();
+        if (null == pageNum || 0 == pageNum) {
+            pageNum = 1l;
+        }
+        if (null == pageSize || 0 == pageSize) {
+            pageSize = 10l;
+        }
+        page.setSize(pageSize);
+        page.setCurrent(pageNum);
+        IPage<ComActDiscussCommentVO> iPage =
+                comActDiscussDAO.pageDiscussCommentApplets(page, pageComActDiscussCommentDTO);
+        List<ComActDiscussCommentVO> records = iPage.getRecords();
+        if (!ObjectUtils.isEmpty(records)) {
+            records.forEach(comActDiscussCommentVO -> {
+                List<ComActDiscussCommentVO> comActDiscussCommentVOList = new ArrayList<>();
+                Long id = comActDiscussCommentVO.getId();
+                comActDiscussCommentVO.setPhone(DesensitizedUtil.mobilePhone(comActDiscussCommentVO.getPhone()));
+                comActDiscussCommentVO.setUserName(DesensitizedUtil.chineseName(comActDiscussCommentVO.getUserName()));
+                comActDiscussCommentVO.setUserNameBack(DesensitizedUtil.chineseName(comActDiscussCommentVO.getUserNameBack()));
+                comActDiscussCommentVOList = comActDiscussCommentDAO.selectChilds(id);
+                if (!ObjectUtils.isEmpty(comActDiscussCommentVOList)) {
+                    List<ComActDiscussCommentVO> comActDiscussCommentVOS = comActDiscussCommentVOList;
+                    comActDiscussCommentVOList.forEach(comActDiscussCommentVO1 -> {
+                        Long parentId = comActDiscussCommentVO1.getParentId();
+                        List<ComActDiscussCommentVO> collect = comActDiscussCommentVOS.stream()
+                                .filter(comActDiscussCommentVO2 -> comActDiscussCommentVO2.getId().equals(parentId))
+                                .collect(Collectors.toList());
+                        if (!ObjectUtils.isEmpty(collect)) {
+                            String userName = collect.get(0).getUserName();
+                            String userNickName = collect.get(0).getUserNickName();
+                            comActDiscussCommentVO1.setUserNameBack(userName);
+                            comActDiscussCommentVO1.setUserNickNameBack(userNickName);
+                        }
+                        List<ComActDiscussCommentVO> collect1 = records.stream()
+                                .filter(comActDiscussCommentVO2 -> comActDiscussCommentVO2.getId().equals(parentId))
+                                .collect(Collectors.toList());
+                        if (!ObjectUtils.isEmpty(collect1)) {
+                            ComActDiscussCommentVO comActDiscussCommentVOFirst = collect1.get(0);
+                            String userName = comActDiscussCommentVOFirst.getUserName();
+                            String userNickName = comActDiscussCommentVOFirst.getUserNickName();
+                            comActDiscussCommentVO1.setUserNameBack(userName);
+                            comActDiscussCommentVO1.setUserNickNameBack(userNickName);
+                        }
+                        comActDiscussCommentVO1.setPhone(DesensitizedUtil.mobilePhone(comActDiscussCommentVO1.getPhone()));
+                        comActDiscussCommentVO1.setUserName(DesensitizedUtil.chineseName(comActDiscussCommentVO1.getUserName()));
+                        comActDiscussCommentVO1.setUserNameBack(DesensitizedUtil.chineseName(comActDiscussCommentVO1.getUserNameBack()));
+                        if (pageComActDiscussCommentDTO.getLoginUserId() != null
+                                && !pageComActDiscussCommentDTO.getLoginUserId().equals(0L)) {
+                            Integer integer = comActDiscussCommentUserDAO
+                                    .selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda()
+                                            .eq(ComActDiscussCommentUserDO::getDisscussCommentId,
+                                                    comActDiscussCommentVO1.getId())
+                                            .eq(ComActDiscussCommentUserDO::getUserId,
+                                                    pageComActDiscussCommentDTO.getLoginUserId()));
+                            if (integer > 0) {
+                                comActDiscussCommentVO1.setHaveSign(1);
+                            } else {
+                                comActDiscussCommentVO1.setHaveSign(0);
+                            }
+                        }
+//                        if(StringUtils.isEmpty(comActDiscussCommentVO1.getUserNickNameBack())){
+//                            comActDiscussCommentVO1.setUserNickNameBack("社区管理员");
+//                        }
+                    });
+                    comActDiscussCommentVO.setComActDiscussCommentVOList(comActDiscussCommentVOList);
+                }
+                if (pageComActDiscussCommentDTO.getLoginUserId() != null
+                        && !pageComActDiscussCommentDTO.getLoginUserId().equals(0L)) {
+                    Integer integer =
+                            comActDiscussCommentUserDAO.selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda()
+                                    .eq(ComActDiscussCommentUserDO::getDisscussCommentId, comActDiscussCommentVO.getId())
+                                    .eq(ComActDiscussCommentUserDO::getUserId, pageComActDiscussCommentDTO.getLoginUserId()));
+                    if (integer > 0) {
+                        comActDiscussCommentVO.setHaveSign(1);
+                    } else {
+                        comActDiscussCommentVO.setHaveSign(0);
+                    }
+                }
+
+                // 判断当前评论是否是社区管理员评论
+                if (!comActDiscussCommentVO.getUserType().equals(1)) {
+                    comActDiscussCommentVO.setUserNickName("社区管理员");
+                }
+            });
+        }
+        return R.ok(iPage);
+    }
+
     /**
      * 议事投票-详情 小程序
      *
@@ -920,6 +1192,102 @@
         }
         return R.ok(comActDiscussVO);
     }
+    /**
+     * 议事投票-详情 小程序 脱敏
+     *
+     * @param id          主键
+     * @param loginUserId 登录用户主键
+     * @return ComActDiscussVO
+     */
+    @Override
+    public R detailDiscussAppletsDesensitize(Long id, Long loginUserId) {
+        ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(id);
+        if (ObjectUtils.isEmpty(comActDiscussDO)) {
+            return R.fail("议事投票不存在");
+        }
+        ComActDiscussVO comActDiscussVO = new ComActDiscussVO();
+        BeanUtils.copyProperties(comActDiscussDO, comActDiscussVO);
+        comActDiscussVO.setSignNum(comActDiscussDO.getFabulousNum());
+        Integer type = comActDiscussVO.getType();
+        if (type.equals(2)) {
+            List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(
+                    new QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, id));
+            List<ComActDiscussOptionVO> comActDiscussOptionVOS = new ArrayList<>();
+            ArrayList<Integer> votes = new ArrayList<>();
+            comActDiscussOptionDOS.forEach(comActDiscussOptionDO -> {
+                Long discussOptionDOId = comActDiscussOptionDO.getId();
+                Integer selectCount =
+                        comActDiscussOptionUserDAO.selectCount(new QueryWrapper<ComActDiscussOptionUserDO>().lambda()
+                                .eq(ComActDiscussOptionUserDO::getDiscussOptionId, discussOptionDOId));
+                ComActDiscussOptionVO comActDiscussOptionVO = new ComActDiscussOptionVO();
+                BeanUtils.copyProperties(comActDiscussOptionDO, comActDiscussOptionVO);
+                comActDiscussOptionVO.setNum(selectCount);
+                if (loginUserId != null && !loginUserId.equals(0L)) {
+                    // 判断选项是否已投票
+                    int haveVote =
+                            comActDiscussOptionUserDAO.selectHaveVotes(comActDiscussOptionDO.getId(), loginUserId);
+                    votes.add(haveVote);
+                    comActDiscussOptionVO.setHaveVote(haveVote > 0 ? 1 : 0);
+                }
+                comActDiscussOptionVOS.add(comActDiscussOptionVO);
+            });
+            fillThePercentAndSort(comActDiscussOptionVOS);
+            comActDiscussVO.setComActDiscussOptionVOS(comActDiscussOptionVOS);
+            //填充剩余可投票数
+            if (loginUserId != null && !loginUserId.equals(0L)) {
+                if (comActDiscussVO.getIsRepeat().intValue() == 1) {
+                    //可重复投票
+                    int votedVotesInToday = comActDiscussOptionUserDAO.selectVotedVotesInToday(id, loginUserId);
+                    int remainingVotes = comActDiscussVO.getCount().intValue() - votedVotesInToday;
+                    comActDiscussVO.setRemainingVotes(remainingVotes >= 0 ? remainingVotes : 0);
+                } else {
+                    //不可重复投票
+                    int alreadyVotedVotes = votes.stream().mapToInt(Integer::intValue).sum();
+                    int remainingVotes = comActDiscussVO.getCount().intValue() - alreadyVotedVotes;
+                    comActDiscussVO.setRemainingVotes(remainingVotes >= 0 ? remainingVotes : 0);
+                }
+            }
+            checkDiscussStatusIsCorrect(comActDiscussVO);
+            //填充投票记录列表
+            List<ComActDiscussOptionUserVO> comActDiscussOptionUserVOList = comActDiscussOptionUserDAO
+                    .selectVotedRecords(comActDiscussVO.getId());
+            comActDiscussVO.setComActDiscussOptionUserVOList(comActDiscussOptionUserVOList);
+            //填充已参与投票人数
+            int votedPersonNum = comActDiscussOptionUserDAO.selectVotedPersonNum(comActDiscussVO.getId());
+            comActDiscussVO.setVotedPersonNum(votedPersonNum);
+        }
+        Long userId = comActDiscussDO.getUserId();
+        LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(userId);
+        if (loginUserInfoVO != null) {
+            comActDiscussVO.setUserName(DesensitizedUtil.chineseName(loginUserInfoVO.getName()));
+            if (StringUtils.isEmpty(loginUserInfoVO.getNickName())) {
+                comActDiscussVO.setUserNickName(DesensitizedUtil.chineseName(loginUserInfoVO.getName()));
+            } else {
+                comActDiscussVO.setUserNickName(loginUserInfoVO.getNickName());
+            }
+            comActDiscussVO.setImageUrl(loginUserInfoVO.getImageUrl());
+            comActDiscussVO.setUserType(loginUserInfoVO.getType());
+        }
+        Long communityId = comActDiscussDO.getCommunityId();
+        Integer type1 = loginUserInfoVO.getType();
+        if (type1.intValue() > 1) {
+            ComActVO comActVO = comActDiscussDAO.selectCommunity(communityId);
+            comActDiscussVO.setUserName(comActVO.getName());
+            comActDiscussVO.setUserNickName(comActVO.getName());
+        }
+        if (loginUserId != null && !loginUserId.equals(0L)) {
+            ComActDiscussVO comActDiscussVO1 = comActDiscussDAO.selectHaveSignAndHaveVote(id, loginUserId);
+            comActDiscussVO.setHaveSign(comActDiscussVO1.getHaveSign());
+            comActDiscussVO.setHaveVote(comActDiscussVO1.getHaveVote());
+        }
+        String viewNumKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, id.toString());
+        if (stringRedisTemplate.hasKey(viewNumKey)) {
+            ValueOperations opsForValue = stringRedisTemplate.opsForValue();
+            int viewNum = Integer.parseInt((String) opsForValue.get(viewNumKey));
+            comActDiscussVO.setViewsNum(viewNum);
+        }
+        return R.ok(comActDiscussVO);
+    }
 
     /**
      * 计算投票占比以及排序
@@ -944,14 +1312,14 @@
     /**
      * 议事投票-投票
      *
-     * @param comActDiscussOptionUserDTO 投票信息
+     * @param discussVoteOptionDTO 投票信息
      * @return 投票结果
      */
     @Override
-    public R addDiscussOptionUser(ComActDiscussOptionUserDTO comActDiscussOptionUserDTO) {
-        List<Long> discussOptionIds = comActDiscussOptionUserDTO.getDiscussOptionIds();
-        Long discussOptionId = discussOptionIds.get(0);
-        Long userId = comActDiscussOptionUserDTO.getUserId();
+    public R addDiscussOptionUser(DiscussVoteOptionDTO discussVoteOptionDTO) {
+        List<ComActDiscussVoteOptionDTO> options = discussVoteOptionDTO.getOptions();
+        Long discussOptionId = options.get(0).getId();
+        Long userId = discussVoteOptionDTO.getUserId();
         ComActDiscussOptionDO comActDiscussOptionDO = comActDiscussOptionDAO.selectById(discussOptionId);
         if (ObjectUtils.isEmpty(comActDiscussOptionDO)) {
             return R.fail("选项不存在");
@@ -968,7 +1336,7 @@
         }
         boolean isRepeat = comActDiscussDO.getIsRepeat().intValue() == 1;
         int usableVoteVotes = comActDiscussDO.getCount().intValue();
-        int currentVoteNum = discussOptionIds.size();
+        int currentVoteNum = options.size();
         if (isRepeat) {
             //可重复投票
             int votedVotesInToday = comActDiscussOptionUserDAO.selectVotedVotesInToday(discussId, userId);
@@ -985,18 +1353,16 @@
             }
         }
         List<ComActDiscussOptionUserDO> comActDiscussOptionUserDOList = new ArrayList<>();
-        discussOptionIds.forEach(optionId -> {
+        options.forEach(option -> {
             ComActDiscussOptionUserDO comActDiscussOptionUserDO = new ComActDiscussOptionUserDO();
             comActDiscussOptionUserDO.setUserId(userId);
-            comActDiscussOptionUserDO.setDiscussOptionId(optionId);
+            comActDiscussOptionUserDO.setDiscussOptionId(option.getId());
             comActDiscussOptionUserDO.setDiscussId(discussId);
-            comActDiscussOptionUserDOList.add(comActDiscussOptionUserDO);
+            comActDiscussOptionUserDO.setSignUrl(option.getSignUrl());
+            comActDiscussOptionUserDO.setReason(option.getReason());
+            comActDiscussOptionUserDAO.insert(comActDiscussOptionUserDO);
         });
-        int result = comActDiscussOptionUserDAO.batchInsert(comActDiscussOptionUserDOList);
-        if (result > 0) {
-            return R.ok();
-        }
-        return R.fail();
+        return R.ok();
     }
 
     /**
@@ -1296,6 +1662,29 @@
     }
 
     /**
+     * 投票情况-分页查询
+     * @param pageVoteSituationDTO
+     * @return
+     */
+    @Override
+    public R pageVoteSituation(PageVoteSituationDTO pageVoteSituationDTO) {
+        Page page = new Page<>();
+        page.setCurrent(pageVoteSituationDTO.getPageNum());
+        page.setSize(pageVoteSituationDTO.getPageSize());
+        return R.ok(comActDiscussOptionUserDAO.pageVoteSituation(page, pageVoteSituationDTO));
+    }
+
+    /**
+     * 投票情况详情
+     * @param optionUserId
+     * @return
+     */
+    @Override
+    public R detailVoteSituation(Long optionUserId) {
+        return R.ok(comActDiscussOptionUserDAO.detailVoteSituation(optionUserId));
+    }
+
+    /**
      * 将redis中浏览量写入表中
      * @return 执行结果
      */

--
Gitblit v1.7.1