| | |
| | | String discussIdentityConfig = (String) sysConfValue.getData(); |
| | | if (isBlank(discussIdentityConfig)) { |
| | | checkResult = false; |
| | | } |
| | | List<String> currentUserRoles = new ArrayList<>(); |
| | | List<String> sysAllowedRoles = Arrays.asList(discussIdentityConfig.split(",")); |
| | | LoginUserInfoVO loginUserInfo = comActDiscussDTO.getLoginUserInfo(); |
| | | if (loginUserInfo.getIsPartymember().intValue() == 1) { |
| | | currentUserRoles.add("2"); |
| | | } |
| | | if (loginUserInfo.getIsVolunteer().intValue() == 1) { |
| | | currentUserRoles.add("3"); |
| | | } |
| | | R isTeamResult = userService.checkCurrentUserIsTeam(loginUserInfo.getPhone(), loginUserInfo.getCommunityId()); |
| | | if (R.isOk(isTeamResult) && (Boolean) isTeamResult.getData()) { |
| | | currentUserRoles.add("4"); |
| | | } |
| | | if (currentUserRoles.isEmpty()) { |
| | | checkResult = false; |
| | | } |
| | | boolean result = sysAllowedRoles.stream().anyMatch(role -> currentUserRoles.contains(role)); |
| | | if (!result) { |
| | | checkResult = false; |
| | | } else { |
| | | List<String> currentUserRoles = new ArrayList<>(); |
| | | List<String> sysAllowedRoles = Arrays.asList(discussIdentityConfig.split(",")); |
| | | LoginUserInfoVO loginUserInfo = comActDiscussDTO.getLoginUserInfo(); |
| | | if (loginUserInfo.getIsPartymember() == 1) { |
| | | currentUserRoles.add("2"); |
| | | } |
| | | if (loginUserInfo.getIsVolunteer().intValue() == 1) { |
| | | currentUserRoles.add("3"); |
| | | } |
| | | R isTeamResult = userService.checkCurrentUserIsTeam(loginUserInfo.getPhone(), loginUserInfo.getCommunityId()); |
| | | if (R.isOk(isTeamResult) && (Boolean) isTeamResult.getData()) { |
| | | currentUserRoles.add("4"); |
| | | } |
| | | if (currentUserRoles.isEmpty()) { |
| | | checkResult = false; |
| | | } |
| | | boolean result = sysAllowedRoles.stream().anyMatch(role -> currentUserRoles.contains(role)); |
| | | if (!result) { |
| | | checkResult = false; |
| | | } |
| | | } |
| | | } |
| | | return checkResult; |
| | |
| | | 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 = |
| | |
| | | // 判断选项是否已投票 |
| | | 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); |
| | | } |
| | | } |
| | | //填充投票记录列表 |
| | | List<ComActDiscussOptionUserVO> comActDiscussOptionUserVOList = comActDiscussOptionUserDAO |
| | | .selectVotedRecords(comActDiscussVO.getId()); |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public R addDiscussOptionUser(ComActDiscussOptionUserDTO comActDiscussOptionUserDTO) { |
| | | Long discussOptionId = comActDiscussOptionUserDTO.getDiscussOptionId(); |
| | | List<Long> discussOptionIds = comActDiscussOptionUserDTO.getDiscussOptionIds(); |
| | | Long discussOptionId = discussOptionIds.get(0); |
| | | Long userId = comActDiscussOptionUserDTO.getUserId(); |
| | | ComActDiscussOptionDO comActDiscussOptionDO = comActDiscussOptionDAO.selectById(discussOptionId); |
| | | if (ObjectUtils.isEmpty(comActDiscussOptionDO)) { |
| | |
| | | } |
| | | boolean isRepeat = comActDiscussDO.getIsRepeat().intValue() == 1; |
| | | int usableVoteVotes = comActDiscussDO.getCount().intValue(); |
| | | int currentVoteNum = discussOptionIds.size(); |
| | | if (isRepeat) { |
| | | //可重复投票 |
| | | int votedVotesInToday = comActDiscussOptionUserDAO.selectVotedVotesInToday(discussId, userId); |
| | | if (usableVoteVotes <= votedVotesInToday) { |
| | | return R.fail("当天投票次数已用完"); |
| | | if (usableVoteVotes <= votedVotesInToday || currentVoteNum > usableVoteVotes - votedVotesInToday) { |
| | | return R.fail("票数不足"); |
| | | } |
| | | } else { |
| | | //不可重复投票 |
| | | int alreadyVotedVotes = comActDiscussOptionUserDAO.selectCount( |
| | | new QueryWrapper<ComActDiscussOptionUserDO>().lambda().eq(ComActDiscussOptionUserDO::getUserId, userId) |
| | | .eq(ComActDiscussOptionUserDO::getDiscussId, discussId)); |
| | | if (usableVoteVotes <= alreadyVotedVotes) { |
| | | return R.fail("投票次数已用完"); |
| | | if (usableVoteVotes <= alreadyVotedVotes || currentVoteNum > usableVoteVotes - alreadyVotedVotes) { |
| | | return R.fail("票数不足"); |
| | | } |
| | | } |
| | | ComActDiscussOptionUserDO comActDiscussOptionUserDO = new ComActDiscussOptionUserDO(); |
| | | comActDiscussOptionUserDO.setUserId(userId); |
| | | comActDiscussOptionUserDO.setDiscussOptionId(discussOptionId); |
| | | comActDiscussOptionUserDO.setDiscussId(discussId); |
| | | int insert = comActDiscussOptionUserDAO.insert(comActDiscussOptionUserDO); |
| | | if (insert > 0) { |
| | | List<ComActDiscussOptionUserDO> comActDiscussOptionUserDOList = new ArrayList<>(); |
| | | discussOptionIds.forEach(optionId -> { |
| | | ComActDiscussOptionUserDO comActDiscussOptionUserDO = new ComActDiscussOptionUserDO(); |
| | | comActDiscussOptionUserDO.setUserId(userId); |
| | | comActDiscussOptionUserDO.setDiscussOptionId(optionId); |
| | | comActDiscussOptionUserDO.setDiscussId(discussId); |
| | | comActDiscussOptionUserDOList.add(comActDiscussOptionUserDO); |
| | | }); |
| | | int result = comActDiscussOptionUserDAO.batchInsert(comActDiscussOptionUserDOList); |
| | | if (result > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | |
| | | return R.fail("只能公布或编辑自己发布的主题!"); |
| | | } |
| | | comActDiscussDO.setPublishResult(comActDiscussDTO.getPublishResult()); |
| | | comActDiscussDO.setStatus(4); |
| | | int result = comActDiscussDAO.updateById(comActDiscussDO); |
| | | if (result > 0) { |
| | | return R.ok(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 一起议获取是否有发布权 |
| | | * @param comActDiscussDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getDiscussPermissions(ComActDiscussDTO comActDiscussDTO) { |
| | | return R.ok(checkCurrentUserDiscussIdentity(comActDiscussDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 将redis中浏览量写入表中 |
| | | * @return 执行结果 |
| | | */ |