| | |
| | | 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; |
| | |
| | | Long userId = comActDiscussDO.getUserId(); |
| | | LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(userId); |
| | | comActDiscussVO.setUserName(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); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-详情 脱敏 |
| | | * |
| | | * @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()); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-分页查询 小程序 |
| | | * |
| | | * @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()); |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 判断discuss状态是否正确 |
| | | * @param comActDiscussVO |
| | | */ |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-详情 小程序 |
| | | * |
| | |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 计算投票占比以及排序 |