| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | import static org.apache.commons.lang3.StringUtils.isBlank; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.redis.connection.StringRedisConnection; |
| | | import org.springframework.data.redis.core.RedisCallback; |
| | | import org.springframework.data.redis.core.SetOperations; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.panzhihua.common.model.dtos.community.*; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.exceptions.ServiceException; |
| | | import com.panzhihua.common.model.dtos.community.ComActDiscussCommentDTO; |
| | | import com.panzhihua.common.model.dtos.community.ComActDiscussCommentUserDTO; |
| | | import com.panzhihua.common.model.dtos.community.ComActDiscussDTO; |
| | | import com.panzhihua.common.model.dtos.community.ComActDiscussOptionDTO; |
| | | import com.panzhihua.common.model.dtos.community.ComActDiscussOptionUserDTO; |
| | | import com.panzhihua.common.model.dtos.community.ComActDiscussUserDTO; |
| | | import com.panzhihua.common.model.dtos.community.PageComActDiscussCommentDTO; |
| | | import com.panzhihua.common.model.dtos.community.PageComActDiscussDTO; |
| | | import com.panzhihua.common.model.dtos.community.bigscreen.work.ScreenDiscussListDTO; |
| | | import com.panzhihua.common.model.dtos.community.discuss.ComActDiscussDetailDTO; |
| | | import com.panzhihua.common.model.dtos.community.discuss.ComActDiscussPublishResultDTO; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComActDiscussCommentVO; |
| | | import com.panzhihua.common.model.vos.community.ComActDiscussOptionUserVO; |
| | | import com.panzhihua.common.model.vos.community.ComActDiscussOptionVO; |
| | | import com.panzhihua.common.model.vos.community.ComActDiscussVO; |
| | | import com.panzhihua.common.model.vos.community.ComActVO; |
| | | import com.panzhihua.common.model.vos.community.SysConfVO; |
| | | import com.panzhihua.common.model.vos.community.screen.work.DiscussListVO; |
| | | import com.panzhihua.service_community.dao.*; |
| | | import com.panzhihua.service_community.model.dos.*; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import com.panzhihua.service_community.dao.ComActDiscussCommentDAO; |
| | | import com.panzhihua.service_community.dao.ComActDiscussCommentUserDAO; |
| | | import com.panzhihua.service_community.dao.ComActDiscussDAO; |
| | | import com.panzhihua.service_community.dao.ComActDiscussOptionDAO; |
| | | import com.panzhihua.service_community.dao.ComActDiscussOptionUserDAO; |
| | | import com.panzhihua.service_community.dao.ComActDiscussUserDAO; |
| | | import com.panzhihua.service_community.dao.SysConfMapper; |
| | | import com.panzhihua.service_community.model.dos.ComActDiscussCommentDO; |
| | | import com.panzhihua.service_community.model.dos.ComActDiscussCommentUserDO; |
| | | import com.panzhihua.service_community.model.dos.ComActDiscussDO; |
| | | import com.panzhihua.service_community.model.dos.ComActDiscussOptionDO; |
| | | import com.panzhihua.service_community.model.dos.ComActDiscussOptionUserDO; |
| | | import com.panzhihua.service_community.model.dos.ComActDiscussUserDO; |
| | | import com.panzhihua.service_community.model.dos.SysConfDO; |
| | | import com.panzhihua.service_community.service.ComActDiscussOptionService; |
| | | import com.panzhihua.service_community.service.ComActDiscussService; |
| | | import com.panzhihua.service_community.service.SysConfService; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @program: springcloud_k8s_panzhihuazhihuishequ |
| | | * @description: 一起议 |
| | | * @description: 议事投票 |
| | | * @author: huang.hongfa weixin hhf9596 qq 959656820 |
| | | * @create: 2021-01-22 14:51 |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | public class ComActDiscussServiceImpl implements ComActDiscussService { |
| | | |
| | | private static final String DISCUSS_VIEW_NUM_PREFIX = "DISCUSS_VIEW_NUM"; |
| | | private static final String INCR_VIEW_DISCUSS_IDS_KEY = "INCR_VIEW_DISCUSS_IDS"; |
| | | private static final long DISCUSS_EXPIRE_TIME = 2678400L; |
| | | |
| | | @Resource |
| | | private ComActDiscussCommentDAO comActDiscussCommentDAO; |
| | | @Resource |
| | |
| | | private ComActDiscussCommentUserDAO comActDiscussCommentUserDAO; |
| | | @Resource |
| | | private ComActDiscussOptionService comActDiscussOptionService; |
| | | @Resource |
| | | private SysConfMapper sysConfDao; |
| | | @Resource |
| | | private SysConfService sysConfService; |
| | | @Resource |
| | | private UserService userService; |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | |
| | | /** |
| | | * 一起议-新增 |
| | | * 议事投票-新增 |
| | | * |
| | | * @param comActDiscussDTO |
| | | * 新增参数 |
| | | * @param comActDiscussDTO 新增参数 |
| | | * @return 新增结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R addDiscuss(ComActDiscussDTO comActDiscussDTO) { |
| | | if (!checkCurrentUserDiscussIdentity(comActDiscussDTO)) { |
| | | return R.fail("权限验证失败,请确认是否有发布权限"); |
| | | } |
| | | ComActDiscussDO comActDiscussDO = new ComActDiscussDO(); |
| | | BeanUtils.copyProperties(comActDiscussDTO, comActDiscussDO); |
| | | ComActVO comActVO = comActDiscussDAO.selectCommunity(comActDiscussDTO.getCommunityId()); |
| | | Integer type = comActDiscussDTO.getType(); |
| | | Date nowDate = new Date(); |
| | | if (type.equals(ComActDiscussDO.type.tp)) {//判断是投票,需要转义时间 |
| | | Date startTime = DateUtils.stringToDate(comActDiscussDTO.getStartTime(), DateUtils.ymdhms_format); |
| | | Date endTime = DateUtils.stringToDate(comActDiscussDTO.getEndTime(), DateUtils.ymdhms_format); |
| | | comActDiscussDO.setStartTime(startTime); |
| | | comActDiscussDO.setEndTime(endTime); |
| | | comActDiscussDO.setStatus(ComActDiscussDO.status.wks); |
| | | //根据时间判断状态是否开始 |
| | | if (startTime != null && startTime.getTime() <= nowDate.getTime()) { |
| | | comActDiscussDO.setStatus(ComActDiscussDO.status.jxz); |
| | | comActDiscussDO.setReleaseAt(nowDate); |
| | | } |
| | | } else { |
| | | comActDiscussDO.setStatus(ComActDiscussDO.status.yfb); |
| | | } |
| | | String address = comActDiscussDO.getAddress(); |
| | | if (ObjectUtils.isEmpty(address)) { |
| | | //查询社区地址 |
| | | ComActVO comActVO = comActDiscussDAO.selectCommunity(comActDiscussDTO.getCommunityId()); |
| | | comActDiscussDO.setAddress(comActVO.getAddress()); |
| | | } |
| | | int insert = comActDiscussDAO.insert(comActDiscussDO); |
| | | if (insert > 0) { |
| | | ComActDiscussDO comActDiscussDO1 = comActDiscussDAO.selectOne(new QueryWrapper<ComActDiscussDO>().lambda() |
| | | .eq(ComActDiscussDO::getDiscussSubject, comActDiscussDTO.getDiscussSubject()) |
| | | .eq(ComActDiscussDO::getUserId, comActDiscussDTO.getUserId()) |
| | | .last(" order by create_at desc limit 1 ")); |
| | | Long comActDiscussDO1Id = comActDiscussDO1.getId(); |
| | | Integer type = comActDiscussDTO.getType(); |
| | | //如果是投票,需要把投票的选项存储 |
| | | if (type.equals(2)) { |
| | | Long comActDiscussDO1Id = comActDiscussDO.getId(); |
| | | List<ComActDiscussOptionDTO> discussOptions = comActDiscussDTO.getDiscussOptions(); |
| | | List<ComActDiscussOptionDO> comActDiscussOptionDOS = new ArrayList<>(); |
| | | discussOptions.forEach(s -> { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 一起议-详情 |
| | | * |
| | | * @param id |
| | | * 主键 |
| | | * @return ComActDiscussVO |
| | | * 小程序用户验证是否拥有发布权限 |
| | | * @param comActDiscussDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R detailDiscuss(Long id) { |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(id); |
| | | if (ObjectUtils.isEmpty(comActDiscussDO)) { |
| | | return R.fail("一起议不存在"); |
| | | private boolean checkCurrentUserDiscussIdentity(ComActDiscussDTO comActDiscussDTO) { |
| | | //小程序用户验证是否拥有发布权限 |
| | | boolean checkResult = true; |
| | | Boolean isApplets = comActDiscussDTO.getIsApplets(); |
| | | if (nonNull(isApplets) && isApplets) { |
| | | String discussIdentityPrefix = "DISCUSS_IDENTITY_"; |
| | | Long communityId = comActDiscussDTO.getCommunityId(); |
| | | R sysConfValue = sysConfService.getSysConfValue(discussIdentityPrefix + communityId, communityId); |
| | | String discussIdentityConfig = (String) sysConfValue.getData(); |
| | | if (isBlank(discussIdentityConfig)) { |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | ComActDiscussVO comActDiscussVO = new ComActDiscussVO(); |
| | | BeanUtils.copyProperties(comActDiscussDO, comActDiscussVO); |
| | | Integer integer = comActDiscussCommentDAO.selectCount( |
| | | new QueryWrapper<ComActDiscussCommentDO>().lambda().eq(ComActDiscussCommentDO::getDiscussId, id)); |
| | | comActDiscussVO.setCommentNum(integer); |
| | | Integer integer1 = comActDiscussUserDAO |
| | | .selectCount(new QueryWrapper<ComActDiscussUserDO>().lambda().eq(ComActDiscussUserDO::getDiscussId, id)); |
| | | comActDiscussVO.setSignNum(integer1); |
| | | 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<>(); |
| | | 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); |
| | | comActDiscussOptionVOS.add(comActDiscussOptionVO); |
| | | }); |
| | | comActDiscussOptionVOS.sort(Comparator.comparing(ComActDiscussOptionVO::getNum).reversed()); |
| | | comActDiscussVO.setComActDiscussOptionVOS(comActDiscussOptionVOS); |
| | | } |
| | | Long userId = comActDiscussDO.getUserId(); |
| | | LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(userId); |
| | | comActDiscussVO.setUserName(loginUserInfoVO.getName()); |
| | | |
| | | return R.ok(comActDiscussVO); |
| | | return checkResult; |
| | | } |
| | | |
| | | /** |
| | | * 一起议-删除 |
| | | * 议事投票-编辑 |
| | | * |
| | | * @param id |
| | | * 主键 |
| | | * @return 删除结果 |
| | | * @param comActDiscussDTO 请求参数 |
| | | * @return 编辑结果 |
| | | */ |
| | | @Override |
| | | public R deleteDiscuss(Long id) { |
| | | int delete = comActDiscussDAO.deleteById(id); |
| | | if (delete > 0) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R editDiscuss(ComActDiscussDTO comActDiscussDTO) { |
| | | Long comActDiscussDO1Id = comActDiscussDTO.getId(); |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(comActDiscussDO1Id); |
| | | if (ObjectUtils.isEmpty(comActDiscussDO)) { |
| | | return R.fail("议事投票不存在"); |
| | | } |
| | | if (!comActDiscussDO.getStatus().equals(ComActDiscussDO.status.wks) && !comActDiscussDO.getStatus().equals(ComActDiscussDO.status.yfb)) { |
| | | return R.fail("该状态不可修改"); |
| | | } |
| | | Integer type = comActDiscussDO.getType(); |
| | | Integer isRepeat = comActDiscussDO.getIsRepeat(); |
| | | BeanUtils.copyProperties(comActDiscussDTO, comActDiscussDO); |
| | | comActDiscussDO.setType(type); |
| | | comActDiscussDO.setIsRepeat(isRepeat); |
| | | Date nowDate = new Date(); |
| | | if (type.equals(ComActDiscussDO.type.tp)) {//判断是投票,需要转义时间 |
| | | Date startTime = DateUtils.stringToDate(comActDiscussDTO.getStartTime(), DateUtils.ymdhms_format); |
| | | Date endTime = DateUtils.stringToDate(comActDiscussDTO.getEndTime(), DateUtils.ymdhms_format); |
| | | comActDiscussDO.setStartTime(startTime); |
| | | comActDiscussDO.setEndTime(endTime); |
| | | comActDiscussDO.setStatus(ComActDiscussDO.status.wks); |
| | | //根据时间判断状态是否开始 |
| | | if (startTime != null && startTime.getTime() <= nowDate.getTime()) { |
| | | comActDiscussDO.setStatus(ComActDiscussDO.status.jxz); |
| | | comActDiscussDO.setReleaseAt(nowDate); |
| | | } |
| | | } else { |
| | | comActDiscussDO.setStatus(ComActDiscussDO.status.yfb); |
| | | } |
| | | comActDiscussDO.setUpdateAt(new Date()); |
| | | int insert = comActDiscussDAO.updateById(comActDiscussDO); |
| | | if (insert > 0) { |
| | | //如果是投票,需要把投票的选项存储 |
| | | if (type.equals(2)) { |
| | | comActDiscussOptionService.remove(new QueryWrapper<ComActDiscussOptionDO>().lambda() |
| | | .eq(ComActDiscussOptionDO::getDiscussId, comActDiscussDO1Id)); |
| | | List<ComActDiscussOptionDO> comActDiscussOptionDOS = new ArrayList<>(); |
| | | comActDiscussDTO.getDiscussOptions().forEach(s -> { |
| | | ComActDiscussOptionDO comActDiscussOptionDO = new ComActDiscussOptionDO(); |
| | | comActDiscussOptionDO.setDiscussId(comActDiscussDO1Id); |
| | | comActDiscussOptionDO.setOptionContent(s.getOptionContent()); |
| | | comActDiscussOptionDO.setOptionUrl(s.getOptionUrl()); |
| | | comActDiscussOptionDOS.add(comActDiscussOptionDO); |
| | | }); |
| | | comActDiscussOptionService.saveBatch(comActDiscussOptionDOS); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-回复 |
| | | * 议事投票-详情 |
| | | * |
| | | * @param comActDiscussCommentDTO |
| | | * 评论内容 |
| | | * @param discussDetailDTO 请求参数 |
| | | * @return ComActDiscussVO |
| | | */ |
| | | @Override |
| | | public R detailDiscuss(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(loginUserInfoVO.getName()); |
| | | comActDiscussVO.setUserNickName(loginUserInfoVO.getNickName()); |
| | | |
| | | //分页查询评论列表 |
| | | 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()); |
| | | return R.ok(comActDiscussVO); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-删除 |
| | | * |
| | | * @param id 主键 |
| | | * @return 删除结果 |
| | | */ |
| | | @Override |
| | | public R deleteDiscuss(Long id) { |
| | | ComActDiscussDO comActDiscussDO = new ComActDiscussDO(); |
| | | comActDiscussDO.setId(id); |
| | | comActDiscussDO.setIsDel(ComActDiscussDO.isOk.yes); |
| | | if (comActDiscussDAO.updateById(comActDiscussDO) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-回复 |
| | | * |
| | | * @param comActDiscussCommentDTO 评论内容 |
| | | * @return 回复结果 |
| | | */ |
| | | @Override |
| | |
| | | Long discussId = comActDiscussCommentDTO.getDiscussId(); |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(discussId); |
| | | if (ObjectUtils.isEmpty(comActDiscussDO)) { |
| | | return R.fail("一起议不存在"); |
| | | return R.fail("议事投票不存在"); |
| | | } |
| | | Long currentUser = comActDiscussCommentDTO.getUserId(); |
| | | //判断当前用户是否参与过评论 |
| | | int currentUserCommentCount = comActDiscussCommentDAO.selectCount(new QueryWrapper<ComActDiscussCommentDO>() |
| | | .lambda().eq(ComActDiscussCommentDO::getDiscussId, discussId).eq(ComActDiscussCommentDO::getUserId, currentUser)); |
| | | |
| | | ComActDiscussCommentDO comActDiscussCommentDO = new ComActDiscussCommentDO(); |
| | | BeanUtils.copyProperties(comActDiscussCommentDTO, comActDiscussCommentDO); |
| | | Long userId = comActDiscussCommentDTO.getUserId(); |
| | | Long userId1 = comActDiscussDO.getUserId(); |
| | | if (userId.equals(userId1)) { |
| | | Long discussUser = comActDiscussDO.getUserId(); |
| | | if (currentUser.equals(discussUser)) { |
| | | comActDiscussCommentDO.setIsAuthor(1); |
| | | } |
| | | int insert = comActDiscussCommentDAO.insert(comActDiscussCommentDO); |
| | | if (insert > 0) { |
| | | // comActDiscussDAO.addCommentCount(discussId, 1); |
| | | //评论成功,评论总数+1 |
| | | //若首次参与评论,参与讨论人数+1 |
| | | if (currentUserCommentCount > 0) { |
| | | comActDiscussDAO.incrCommentAndJoinNumById(discussId, false); |
| | | } else { |
| | | comActDiscussDAO.incrCommentAndJoinNumById(discussId, true); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-分页查询 |
| | | * 议事投票-分页查询 |
| | | * |
| | | * @param pageComActDiscussDTO |
| | | * 查询参数 |
| | | * @param pageComActDiscussDTO 查询参数 |
| | | * @return ComActDiscussVO |
| | | */ |
| | | @Override |
| | | public R pageDiscuss(PageComActDiscussDTO pageComActDiscussDTO) { |
| | | Page page = new Page<>(); |
| | | Long pageNum = pageComActDiscussDTO.getPageNum(); |
| | | Long pageSize = pageComActDiscussDTO.getPageSize(); |
| | | if (null == pageNum || 0 == pageNum) { |
| | | pageNum = 1l; |
| | | } |
| | | if (null == pageSize || 0 == pageSize) { |
| | | pageSize = 10l; |
| | | } |
| | | page.setSize(pageSize); |
| | | page.setCurrent(pageNum); |
| | | IPage<ComActDiscussVO> iPage = comActDiscussDAO.pageDiscuss(page, pageComActDiscussDTO); |
| | | IPage<ComActDiscussVO> iPage = comActDiscussDAO.pageDiscuss(new Page<>(pageComActDiscussDTO.getPageNum(), pageComActDiscussDTO.getPageSize()), pageComActDiscussDTO); |
| | | return R.ok(iPage); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 一起议-评论-查看 |
| | | * 议事投票-后台分页查询 |
| | | * |
| | | * @param id |
| | | * 主键 |
| | | * @param pageComActDiscussDTO 请求参数 |
| | | * @return 议事投票列表 |
| | | */ |
| | | @Override |
| | | public R pageDiscussAdmin(PageComActDiscussDTO pageComActDiscussDTO) { |
| | | return R.ok(comActDiscussDAO.pageDiscussAdmin(new Page<>(pageComActDiscussDTO.getPageNum(), pageComActDiscussDTO.getPageSize()), pageComActDiscussDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-评论-查看 |
| | | * |
| | | * @param id 主键 |
| | | * @return 详情 ComActDiscussCommentVO |
| | | */ |
| | | @Override |
| | |
| | | comActDiscussCommentVO.setParentId(parentId); |
| | | } |
| | | Integer count = comActDiscussCommentUserDAO.selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, id)); |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, id)); |
| | | comActDiscussCommentVO.setNum(count); |
| | | LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(comActDiscussCommentDO.getUserId()); |
| | | comActDiscussCommentVO.setUserName(loginUserInfoVO.getName()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 一起议-评论-置顶 |
| | | * 议事投票评论详情 |
| | | * |
| | | * @param id |
| | | * 主键 |
| | | * @param pageComActDiscussCommentDTO 请求参数 |
| | | * @return 议事投票详情 |
| | | */ |
| | | @Override |
| | | public R detailDiscussCommentAdmin(PageComActDiscussCommentDTO pageComActDiscussCommentDTO) { |
| | | Long id = pageComActDiscussCommentDTO.getId(); |
| | | ComActDiscussCommentDO comActDiscussCommentDO = comActDiscussCommentDAO.selectById(id); |
| | | if (ObjectUtils.isEmpty(comActDiscussCommentDO)) { |
| | | return R.fail("评论不存在"); |
| | | } |
| | | ComActDiscussCommentVO comActDiscussCommentVO = new ComActDiscussCommentVO(); |
| | | Long parentId = comActDiscussCommentDO.getParentId(); |
| | | if (parentId.intValue() == 0) { |
| | | // 一级评论 |
| | | BeanUtils.copyProperties(comActDiscussCommentDO, comActDiscussCommentVO); |
| | | } else { |
| | | ComActDiscussCommentDO comActDiscussCommentDO1 = comActDiscussCommentDAO.selectById(parentId); |
| | | BeanUtils.copyProperties(comActDiscussCommentDO1, comActDiscussCommentVO); |
| | | comActDiscussCommentVO.setCommentBack(comActDiscussCommentDO.getComment()); |
| | | comActDiscussCommentVO.setTimeBack(comActDiscussCommentDO.getCreateAt()); |
| | | comActDiscussCommentVO.setParentId(parentId); |
| | | } |
| | | Integer count = comActDiscussCommentUserDAO.selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, id)); |
| | | comActDiscussCommentVO.setNum(count); |
| | | LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(comActDiscussCommentDO.getUserId()); |
| | | comActDiscussCommentVO.setUserName(loginUserInfoVO.getName()); |
| | | comActDiscussCommentVO.setPhone(loginUserInfoVO.getPhone()); |
| | | comActDiscussCommentVO.setImageUrl(loginUserInfoVO.getImageUrl()); |
| | | |
| | | //查询该评论下所有回复内容 |
| | | IPage<ComActDiscussCommentVO> discussCommentList = comActDiscussCommentDAO.getDiscussCommentList(new Page(pageComActDiscussCommentDTO.getPageNum(), pageComActDiscussCommentDTO.getPageSize()), pageComActDiscussCommentDTO.getId()); |
| | | if (!discussCommentList.getRecords().isEmpty()) { |
| | | comActDiscussCommentVO.setComActDiscussCommentVOList(discussCommentList.getRecords()); |
| | | } |
| | | return R.ok(comActDiscussCommentVO); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-评论-置顶 |
| | | * |
| | | * @param id 主键 |
| | | * @return 置顶结果 |
| | | */ |
| | | @Override |
| | |
| | | ComActDiscussCommentDO comActDiscussCommentDO1 = new ComActDiscussCommentDO(); |
| | | comActDiscussCommentDO1.setIsTopping(0); |
| | | comActDiscussCommentDAO.update(comActDiscussCommentDO1, |
| | | new UpdateWrapper<ComActDiscussCommentDO>().lambda().eq(ComActDiscussCommentDO::getDiscussId, discussId)); |
| | | new UpdateWrapper<ComActDiscussCommentDO>().lambda().eq(ComActDiscussCommentDO::getDiscussId, discussId)); |
| | | comActDiscussCommentDO1.setIsTopping(1); |
| | | comActDiscussCommentDO1.setId(id); |
| | | int update = comActDiscussCommentDAO.updateById(comActDiscussCommentDO1); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 一起议-评论-回复 |
| | | * 议事投票-评论-回复 |
| | | * |
| | | * @param comActDiscussCommentDTO |
| | | * 回复内容 |
| | | * @param comActDiscussCommentDTO 回复内容 |
| | | * @return 回复结果 |
| | | */ |
| | | @Override |
| | |
| | | Long discussId = comActDiscussCommentDO.getDiscussId(); |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(discussId); |
| | | if (ObjectUtils.isEmpty(comActDiscussDO)) { |
| | | return R.fail("一起议不存在"); |
| | | return R.fail("议事投票不存在"); |
| | | } |
| | | Long userId = comActDiscussDO.getUserId(); |
| | | Long userId1 = comActDiscussCommentDTO.getUserId(); |
| | | Long parentId = comActDiscussCommentDO.getParentId(); |
| | | if (parentId.intValue() != 0) { |
| | | return R.fail("二级评论不能回复"); |
| | | } |
| | | Long currentUser = comActDiscussCommentDTO.getUserId(); |
| | | //判断当前用户是否参与过评论/回复 |
| | | int currentUserCommentCount = comActDiscussCommentDAO.selectCount(new QueryWrapper<ComActDiscussCommentDO>() |
| | | .lambda().eq(ComActDiscussCommentDO::getDiscussId, discussId).eq(ComActDiscussCommentDO::getUserId, currentUser)); |
| | | Long discussUser = comActDiscussDO.getUserId(); |
| | | ComActDiscussCommentDO comActDiscussCommentDO1 = new ComActDiscussCommentDO(); |
| | | comActDiscussCommentDO1.setDiscussId(discussId); |
| | | comActDiscussCommentDO1.setComment(comActDiscussCommentDTO.getComment()); |
| | | comActDiscussCommentDO1.setUserId(comActDiscussCommentDTO.getUserId()); |
| | | comActDiscussCommentDO1.setParentId(id); |
| | | if (userId.equals(userId1)) { |
| | | if (discussUser.equals(currentUser)) { |
| | | comActDiscussCommentDO1.setIsAuthor(1); |
| | | } |
| | | int insert = comActDiscussCommentDAO.insert(comActDiscussCommentDO1); |
| | | if (insert > 0) { |
| | | // comActDiscussDAO.addCommentCount(discussId, 1); |
| | | //回复成功,评论总数+1 |
| | | //若首次参与评论,参与讨论人数+1 |
| | | if (currentUserCommentCount > 0) { |
| | | comActDiscussDAO.incrCommentAndJoinNumById(discussId, false); |
| | | } else { |
| | | comActDiscussDAO.incrCommentAndJoinNumById(discussId, true); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-评论-分页查询 |
| | | * 议事投票-评论-分页查询 |
| | | * |
| | | * @param pageComActDiscussCommentDTO |
| | | * 分页查询参数 |
| | | * @param pageComActDiscussCommentDTO 分页查询参数 |
| | | * @return ComActDiscussCommentVO |
| | | */ |
| | | @Override |
| | | public R pageDiscussComment(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.pageDiscussComment(page, pageComActDiscussCommentDTO); |
| | | IPage<ComActDiscussCommentVO> iPage = comActDiscussDAO.pageDiscussComment(new Page<>(pageComActDiscussCommentDTO.getPageNum(), pageComActDiscussCommentDTO.getPageSize()), pageComActDiscussCommentDTO); |
| | | return R.ok(iPage); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-分页查询 小程序 |
| | | * 议事投票-评论-后台分页查询 |
| | | * |
| | | * @param pageComActDiscussDTO |
| | | * 查询参数 |
| | | * @param pageComActDiscussCommentDTO 分页查询参数 |
| | | * @return ComActDiscussCommentVO |
| | | */ |
| | | @Override |
| | | public R pageDiscussCommentAdmin(PageComActDiscussCommentDTO pageComActDiscussCommentDTO) { |
| | | IPage<ComActDiscussCommentVO> iPage = comActDiscussDAO.pageDiscussCommentAdmin(new Page<>(pageComActDiscussCommentDTO.getPageNum(), pageComActDiscussCommentDTO.getPageSize()), pageComActDiscussCommentDTO); |
| | | return R.ok(iPage); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-分页查询 小程序 |
| | | * |
| | | * @param pageComActDiscussDTO 查询参数 |
| | | * @return ComActDiscussVO 分页 |
| | | */ |
| | | @Override |
| | |
| | | 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)); |
| | | 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)); |
| | | 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); |
| | | comActDiscussOptionUserDAO.selectHaveVotes(comActDiscussOptionDO.getId(), loginUserId); |
| | | votes.add(haveVote); |
| | | comActDiscussOptionVO.setHaveVote(haveVote > 0 ? 1 : 0); |
| | | } |
| | | comActDiscussOptionVOS.add(comActDiscussOptionVO); |
| | | }); |
| | | comActDiscussOptionVOS.sort(Comparator.comparing(ComActDiscussOptionVO::getNum).reversed()); |
| | | 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.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)); |
| | | .eq(ComActDiscussUserDO::getDiscussId, comActDiscussVO.getId()) |
| | | .eq(ComActDiscussUserDO::getUserId, loginUserId)); |
| | | if (integer > 0) { |
| | | comActDiscussVO.setHaveSign(1); |
| | | } else { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 一起议-点赞、取消点赞 |
| | | * 判断discuss状态是否正确 |
| | | * @param comActDiscussVO |
| | | */ |
| | | private void checkDiscussStatusIsCorrect(ComActDiscussVO comActDiscussVO) { |
| | | //判断discuss状态是否正确 |
| | | boolean isIncorrectStatus = comActDiscussVO.getEndTime().before(new Date()) && |
| | | (comActDiscussVO.getStatus().intValue() == 1 || comActDiscussVO.getStatus().intValue() == 2); |
| | | if (isIncorrectStatus) { |
| | | comActDiscussVO.setStatus(3); |
| | | comActDiscussDAO.updateStatusById(comActDiscussVO.getId(), 3); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-点赞、取消点赞 |
| | | * |
| | | * @param comActDiscussUserDTO |
| | | * 操作类型 |
| | | * @param comActDiscussUserDTO 操作类型 |
| | | * @return 操作结果 |
| | | */ |
| | | @Override |
| | |
| | | int num = 0; |
| | | ComActDiscussUserDO comActDiscussUserDO = new ComActDiscussUserDO(); |
| | | BeanUtils.copyProperties(comActDiscussUserDTO, comActDiscussUserDO); |
| | | if (type.intValue() == 1) { |
| | | boolean isIncr = type.intValue() == 1; |
| | | if (isIncr) { |
| | | num = comActDiscussUserDAO.insert(comActDiscussUserDO); |
| | | } else { |
| | | num = comActDiscussUserDAO.delete(new QueryWrapper<ComActDiscussUserDO>().lambda() |
| | | .eq(ComActDiscussUserDO::getUserId, comActDiscussUserDTO.getUserId()) |
| | | .eq(ComActDiscussUserDO::getDiscussId, comActDiscussUserDTO.getDiscussId())); |
| | | .eq(ComActDiscussUserDO::getUserId, comActDiscussUserDTO.getUserId()) |
| | | .eq(ComActDiscussUserDO::getDiscussId, comActDiscussUserDTO.getDiscussId())); |
| | | } |
| | | if (num > 0) { |
| | | //点赞成功 总数+1 || 取消点赞成功 总数-1 |
| | | comActDiscussDAO.incrOrDecrFabulousNumByType(comActDiscussUserDTO.getDiscussId(), isIncr); |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-评论-分页查询 小程序 |
| | | * 议事投票-评论-分页查询 小程序 |
| | | * |
| | | * @param pageComActDiscussCommentDTO |
| | | * 分页参数 |
| | | * @param pageComActDiscussCommentDTO 分页参数 |
| | | * @return ComActDiscussCommentVO |
| | | */ |
| | | @Override |
| | |
| | | page.setSize(pageSize); |
| | | page.setCurrent(pageNum); |
| | | IPage<ComActDiscussCommentVO> iPage = |
| | | comActDiscussDAO.pageDiscussCommentApplets(page, pageComActDiscussCommentDTO); |
| | | comActDiscussDAO.pageDiscussCommentApplets(page, pageComActDiscussCommentDTO); |
| | | List<ComActDiscussCommentVO> records = iPage.getRecords(); |
| | | if (!ObjectUtils.isEmpty(records)) { |
| | | records.forEach(comActDiscussCommentVO -> { |
| | |
| | | comActDiscussCommentVOList.forEach(comActDiscussCommentVO1 -> { |
| | | Long parentId = comActDiscussCommentVO1.getParentId(); |
| | | List<ComActDiscussCommentVO> collect = comActDiscussCommentVOS.stream() |
| | | .filter(comActDiscussCommentVO2 -> comActDiscussCommentVO2.getId().equals(parentId)) |
| | | .collect(Collectors.toList()); |
| | | .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.setUserNickNameBack(userNickName); |
| | | } |
| | | List<ComActDiscussCommentVO> collect1 = records.stream() |
| | | .filter(comActDiscussCommentVO2 -> comActDiscussCommentVO2.getId().equals(parentId)) |
| | | .collect(Collectors.toList()); |
| | | .filter(comActDiscussCommentVO2 -> comActDiscussCommentVO2.getId().equals(parentId)) |
| | | .collect(Collectors.toList()); |
| | | if (!ObjectUtils.isEmpty(collect1)) { |
| | | ComActDiscussCommentVO comActDiscussCommentVOFirst = collect1.get(0); |
| | | String userName = comActDiscussCommentVOFirst.getUserName(); |
| | |
| | | comActDiscussCommentVO1.setUserNickNameBack(userNickName); |
| | | } |
| | | if (pageComActDiscussCommentDTO.getLoginUserId() != null |
| | | && !pageComActDiscussCommentDTO.getLoginUserId().equals(0L)) { |
| | | && !pageComActDiscussCommentDTO.getLoginUserId().equals(0L)) { |
| | | Integer integer = comActDiscussCommentUserDAO |
| | | .selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, |
| | | comActDiscussCommentVO1.getId()) |
| | | .eq(ComActDiscussCommentUserDO::getUserId, |
| | | pageComActDiscussCommentDTO.getLoginUserId())); |
| | | .selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, |
| | | comActDiscussCommentVO1.getId()) |
| | | .eq(ComActDiscussCommentUserDO::getUserId, |
| | | pageComActDiscussCommentDTO.getLoginUserId())); |
| | | if (integer > 0) { |
| | | comActDiscussCommentVO1.setHaveSign(1); |
| | | } else { |
| | |
| | | comActDiscussCommentVO.setComActDiscussCommentVOList(comActDiscussCommentVOList); |
| | | } |
| | | if (pageComActDiscussCommentDTO.getLoginUserId() != null |
| | | && !pageComActDiscussCommentDTO.getLoginUserId().equals(0L)) { |
| | | && !pageComActDiscussCommentDTO.getLoginUserId().equals(0L)) { |
| | | Integer integer = |
| | | comActDiscussCommentUserDAO.selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, comActDiscussCommentVO.getId()) |
| | | .eq(ComActDiscussCommentUserDO::getUserId, pageComActDiscussCommentDTO.getLoginUserId())); |
| | | comActDiscussCommentUserDAO.selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, comActDiscussCommentVO.getId()) |
| | | .eq(ComActDiscussCommentUserDO::getUserId, pageComActDiscussCommentDTO.getLoginUserId())); |
| | | if (integer > 0) { |
| | | comActDiscussCommentVO.setHaveSign(1); |
| | | } else { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 一起议-详情 小程序 |
| | | * 议事投票-详情 小程序 |
| | | * |
| | | * @param id |
| | | * 主键 |
| | | * @param loginUserId |
| | | * 登录用户主键 |
| | | * @param id 主键 |
| | | * @param loginUserId 登录用户主键 |
| | | * @return ComActDiscussVO |
| | | */ |
| | | @Override |
| | | public R detailDiscussApplets(Long id, Long loginUserId) { |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(id); |
| | | if (ObjectUtils.isEmpty(comActDiscussDO)) { |
| | | return R.fail("一起议不存在"); |
| | | return R.fail("议事投票不存在"); |
| | | } |
| | | ComActDiscussVO comActDiscussVO = new ComActDiscussVO(); |
| | | BeanUtils.copyProperties(comActDiscussDO, comActDiscussVO); |
| | | Integer integer = comActDiscussCommentDAO.selectCount( |
| | | new QueryWrapper<ComActDiscussCommentDO>().lambda().eq(ComActDiscussCommentDO::getDiscussId, id)); |
| | | comActDiscussVO.setCommentNum(integer); |
| | | Integer integer1 = comActDiscussUserDAO |
| | | .selectCount(new QueryWrapper<ComActDiscussUserDO>().lambda().eq(ComActDiscussUserDO::getDiscussId, id)); |
| | | comActDiscussVO.setSignNum(integer1); |
| | | 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)); |
| | | 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)); |
| | | 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); |
| | | comActDiscussOptionUserDAO.selectHaveVotes(comActDiscussOptionDO.getId(), loginUserId); |
| | | votes.add(haveVote); |
| | | comActDiscussOptionVO.setHaveVote(haveVote > 0 ? 1 : 0); |
| | | } |
| | | comActDiscussOptionVOS.add(comActDiscussOptionVO); |
| | | }); |
| | | comActDiscussOptionVOS.sort(Comparator.comparing(ComActDiscussOptionVO::getNum).reversed()); |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-投票 |
| | | * 计算投票占比以及排序 |
| | | * @param comActDiscussOptionVOS |
| | | */ |
| | | private void fillThePercentAndSort(List<ComActDiscussOptionVO> comActDiscussOptionVOS) { |
| | | //填充总票数 |
| | | int allSum = comActDiscussOptionVOS.stream().mapToInt(ComActDiscussOptionVO::getNum).sum(); |
| | | comActDiscussOptionVOS.forEach(option -> { |
| | | if (allSum == 0) { |
| | | option.setPercent(new BigDecimal(0)); |
| | | } else { |
| | | //占比 |
| | | BigDecimal percent = BigDecimal.valueOf(option.getNum()).divide(BigDecimal.valueOf(allSum), 2, RoundingMode.HALF_UP) |
| | | .multiply(BigDecimal.valueOf(100)).setScale(0); |
| | | option.setPercent(percent); |
| | | } |
| | | }); |
| | | comActDiscussOptionVOS.sort(Comparator.comparing(ComActDiscussOptionVO::getNum).reversed()); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-投票 |
| | | * |
| | | * @param comActDiscussOptionUserDTO |
| | | * 投票信息 |
| | | * @param comActDiscussOptionUserDTO 投票信息 |
| | | * @return 投票结果 |
| | | */ |
| | | @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)) { |
| | |
| | | // QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, discussId)); |
| | | // List<Long> longList=comActDiscussOptionDOS.stream().map(comActDiscussOptionDO1 -> |
| | | // comActDiscussOptionDO1.getId()).collect(Collectors.toList()); |
| | | Integer integer = comActDiscussOptionUserDAO.selectCount( |
| | | new QueryWrapper<ComActDiscussOptionUserDO>().lambda().eq(ComActDiscussOptionUserDO::getUserId, userId) |
| | | .eq(ComActDiscussOptionUserDO::getDiscussOptionId, discussOptionId)); |
| | | if (integer > 0) { |
| | | return R.fail("不要重复投票"); |
| | | Long discussId = comActDiscussOptionDO.getDiscussId(); |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(comActDiscussOptionDO.getDiscussId()); |
| | | if (isNull(comActDiscussOptionDO)) { |
| | | return R.fail("投票主题不存在"); |
| | | } |
| | | ComActDiscussOptionUserDO comActDiscussOptionUserDO = new ComActDiscussOptionUserDO(); |
| | | comActDiscussOptionUserDO.setUserId(userId); |
| | | comActDiscussOptionUserDO.setDiscussOptionId(discussOptionId); |
| | | int insert = comActDiscussOptionUserDAO.insert(comActDiscussOptionUserDO); |
| | | if (insert > 0) { |
| | | 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 || 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 || currentVoteNum > usableVoteVotes - alreadyVotedVotes) { |
| | | return R.fail("票数不足"); |
| | | } |
| | | } |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 一起议-评论-点赞、取消点赞 |
| | | * 议事投票-评论-点赞、取消点赞 |
| | | * |
| | | * @param comActDiscussCommentUserDTO |
| | | * 评论点赞 |
| | | * @param comActDiscussCommentUserDTO 评论点赞 |
| | | * @return 点赞结果 |
| | | */ |
| | | @Override |
| | | public R putDiscussCommentUser(ComActDiscussCommentUserDTO comActDiscussCommentUserDTO) { |
| | | ComActDiscussCommentDO comActDiscussCommentDO = |
| | | comActDiscussCommentDAO.selectById(comActDiscussCommentUserDTO.getId()); |
| | | comActDiscussCommentDAO.selectById(comActDiscussCommentUserDTO.getId()); |
| | | if (ObjectUtils.isEmpty(comActDiscussCommentDO)) { |
| | | return R.fail("评论不存在"); |
| | | } |
| | |
| | | num = comActDiscussCommentUserDAO.insert(comActDiscussCommentUserDO); |
| | | } else { |
| | | num = comActDiscussCommentUserDAO.delete(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() |
| | | .eq(ComActDiscussCommentUserDO::getUserId, comActDiscussCommentUserDTO.getUserId()) |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, comActDiscussCommentUserDTO.getId())); |
| | | .eq(ComActDiscussCommentUserDO::getUserId, comActDiscussCommentUserDTO.getUserId()) |
| | | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, comActDiscussCommentUserDTO.getId())); |
| | | } |
| | | if (num > 0) { |
| | | return R.ok(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 工作大屏-一起议列表 |
| | | * 工作大屏-议事投票列表 |
| | | * |
| | | * @param discussListDTO |
| | | * 请求参数 |
| | | * @return 一起议列表 |
| | | * @param discussListDTO 请求参数 |
| | | * @return 议事投票列表 |
| | | */ |
| | | @Override |
| | | public R getScreenDiscussList(ScreenDiscussListDTO discussListDTO) { |
| | | IPage<DiscussListVO> discussListVOIPage = comActDiscussDAO |
| | | .getScreenDiscussList(new Page(discussListDTO.getPageNum(), discussListDTO.getPageSize()), discussListDTO); |
| | | .getScreenDiscussList(new Page(discussListDTO.getPageNum(), discussListDTO.getPageSize()), discussListDTO); |
| | | if (!discussListVOIPage.getRecords().isEmpty()) { |
| | | discussListVOIPage.getRecords().forEach(discussListVO -> { |
| | | // 查询评论数量和点赞数量 |
| | | Integer integer = comActDiscussCommentDAO.selectCount(new QueryWrapper<ComActDiscussCommentDO>() |
| | | .lambda().eq(ComActDiscussCommentDO::getDiscussId, discussListVO.getId())); |
| | | .lambda().eq(ComActDiscussCommentDO::getDiscussId, discussListVO.getId())); |
| | | discussListVO.setCommentCount(integer); |
| | | Integer integer1 = comActDiscussUserDAO.selectCount(new QueryWrapper<ComActDiscussUserDO>().lambda() |
| | | .eq(ComActDiscussUserDO::getDiscussId, discussListVO.getId())); |
| | | .eq(ComActDiscussUserDO::getDiscussId, discussListVO.getId())); |
| | | discussListVO.setFabulousCount(integer1); |
| | | |
| | | if (discussListVO.getType().equals(ScreenDiscussListDTO.type.tp)) {// 投票 |
| | | List<ComActDiscussOptionVO> discussOptionList = |
| | | comActDiscussDAO.getScreenDiscussOptionList(discussListVO.getId()); |
| | | comActDiscussDAO.getScreenDiscussOptionList(discussListVO.getId()); |
| | | if (!discussOptionList.isEmpty()) { |
| | | discussListVO.setDiscussOptionList(discussOptionList); |
| | | } |
| | |
| | | } |
| | | return R.ok(discussListVOIPage); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票后台公布结果 |
| | | * |
| | | * @param publishResultDTO 请求参数 |
| | | * @return 公布结果 |
| | | */ |
| | | @Override |
| | | public R publishResultAdmin(ComActDiscussPublishResultDTO publishResultDTO) { |
| | | ComActDiscussDO discussDO = comActDiscussDAO.selectById(publishResultDTO.getId()); |
| | | if (discussDO == null) { |
| | | return R.fail("议事投票记录不存在"); |
| | | } |
| | | Date nowDate = new Date(); |
| | | if (publishResultDTO.getType().equals(ComActDiscussPublishResultDTO.type.add)) { |
| | | if (!discussDO.getStatus().equals(ComActDiscussDO.status.dgb)) { |
| | | return R.fail("该议事投票不是待公布状态,不可公布结果操作"); |
| | | } |
| | | discussDO.setStatus(ComActDiscussDO.status.ygb); |
| | | } |
| | | discussDO.setPublishAt(nowDate); |
| | | discussDO.setPublishResult(publishResultDTO.getResult()); |
| | | discussDO.setUpdateAt(nowDate); |
| | | discussDO.setPublishBy(publishResultDTO.getUserId()); |
| | | if (comActDiscussDAO.updateById(discussDO) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票-评论/回复删除 |
| | | * |
| | | * @param id 评论/回复id |
| | | * @return 删除结果 |
| | | */ |
| | | @Override |
| | | public R deleteDiscussCommentAdmin(Long id) { |
| | | ComActDiscussCommentDO discussCommentDO = comActDiscussCommentDAO.selectById(id); |
| | | if (discussCommentDO == null) { |
| | | return R.fail("未查询到该记录"); |
| | | } |
| | | if (discussCommentDO.getIsDel().equals(ComActDiscussCommentDO.isDelete.yes)) { |
| | | return R.fail("该记录已被删除"); |
| | | } |
| | | discussCommentDO.setIsDel(ComActDiscussCommentDO.isDelete.yes); |
| | | if (comActDiscussCommentDAO.updateById(discussCommentDO) > 0) { |
| | | ComActDiscussDO discussDO = comActDiscussDAO.selectById(discussCommentDO.getDiscussId()); |
| | | if (discussDO != null) { |
| | | if (discussDO.getCommentNum() > 0) { |
| | | if (discussCommentDO.getParentId().equals(0L)) { |
| | | Integer count = comActDiscussCommentDAO.selectCount(new QueryWrapper<ComActDiscussCommentDO>().lambda() |
| | | .eq(ComActDiscussCommentDO::getParentId, id).eq(ComActDiscussCommentDO::getIsDel, ComActDiscussCommentDO.isDelete.no)); |
| | | if (count != null && count > 0 && discussDO.getCommentNum() > count) { |
| | | discussDO.setCommentNum(discussDO.getCommentNum() - count); |
| | | } else { |
| | | discussDO.setCommentNum(discussDO.getCommentNum() - 1); |
| | | } |
| | | comActDiscussDAO.updateById(discussDO); |
| | | } else { |
| | | discussDO.setCommentNum(discussDO.getCommentNum() - 1); |
| | | comActDiscussDAO.updateById(discussDO); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询评论下回复列表 |
| | | * |
| | | * @param discussDetailDTO 请求参数 |
| | | * @return 回复列表 |
| | | */ |
| | | @Override |
| | | public R discussCommentReplyAdmin(ComActDiscussDetailDTO discussDetailDTO) { |
| | | return R.ok(comActDiscussCommentDAO.getDiscussCommentList(new Page(discussDetailDTO.getPageNum(), discussDetailDTO.getPageSize()), discussDetailDTO.getId())); |
| | | } |
| | | |
| | | /** |
| | | * 查询社区可发布议事投票权限配置 |
| | | * |
| | | * @param communityId 社区id |
| | | * @return 社区可发布议事投票权限配置 |
| | | */ |
| | | @Override |
| | | public R discussJurisdictionGet(Long communityId, Long userId) { |
| | | List<SysConfDO> confDOList = sysConfDao.selectList(new LambdaQueryWrapper<SysConfDO>() |
| | | .eq(SysConfDO::getCommunityId, communityId) |
| | | .eq(SysConfDO::getCode,Constants.DISCUSS_IDENTITY_KEY + communityId) |
| | | .orderByDesc(SysConfDO::getCreateAt)); |
| | | if (confDOList == null || confDOList.size() == 0) { |
| | | SysConfDO sysConfDO = new SysConfDO(); |
| | | sysConfDO.setCode(Constants.DISCUSS_IDENTITY_KEY + communityId); |
| | | sysConfDO.setName("社区议事投票小程序身份验证参数"); |
| | | sysConfDO.setValue("");// 社区议事投票小程序身份验证参数(1.全部 2.党员 3.志愿者 4.社区工作人员) |
| | | sysConfDO.setDescription("社区议事投票小程序身份验证参数(1.全部 2.党员 3.志愿者 4.社区工作人员)"); |
| | | sysConfDO.setCommunityId(communityId); |
| | | sysConfDO.setCreateBy(userId); |
| | | int inserted = sysConfDao.insert(sysConfDO); |
| | | if (inserted != 1) { |
| | | throw new ServiceException("添加社区议事投票小程序身份验证参数失败"); |
| | | } |
| | | confDOList = sysConfDao.selectList(new LambdaQueryWrapper<SysConfDO>() |
| | | .eq(SysConfDO::getCommunityId, communityId) |
| | | .orderByDesc(SysConfDO::getCreateAt)); |
| | | } |
| | | if (confDOList != null && confDOList.size() > 0) { |
| | | SysConfDO latest = confDOList.get(0); |
| | | SysConfVO sysConfVO = new SysConfVO(); |
| | | BeanUtils.copyProperties(latest, sysConfVO); |
| | | return R.ok(sysConfVO.getValue()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 设置当前社区议事投票小程序身份验证参数(1.全部 2.党员 3.志愿者 4.社区工作人员) |
| | | * |
| | | * @param communityId 社区id |
| | | * @param value 需要设置的参数值 |
| | | * @return 设置结果 |
| | | */ |
| | | @Override |
| | | public R discussJurisdictionSet(Long communityId, String value) { |
| | | List<SysConfDO> authConf = |
| | | sysConfDao.selectList(new LambdaQueryWrapper<SysConfDO>().eq(SysConfDO::getCommunityId, communityId) |
| | | .eq(SysConfDO::getCode, Constants.DISCUSS_IDENTITY_KEY + communityId).orderByDesc(SysConfDO::getCreateAt)); |
| | | if (authConf != null && authConf.size() > 0) { |
| | | SysConfDO first = authConf.get(0); |
| | | first.setValue(value); |
| | | int updated = sysConfDao.updateById(first); |
| | | if (updated == 1) { |
| | | return R.ok(); |
| | | } |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 议事投票检测状态定时任务 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public R timedTaskDiscussInspectStatus() { |
| | | Date nowDate = new Date(); |
| | | //查询已过开始时间未开始投票列表 |
| | | List<ComActDiscussDO> wksDiscussList = comActDiscussDAO.selectList(new QueryWrapper<ComActDiscussDO>().lambda() |
| | | .eq(ComActDiscussDO::getType, ComActDiscussDO.type.tp).eq(ComActDiscussDO::getIsDel, ComActDiscussDO.isOk.no) |
| | | .eq(ComActDiscussDO::getStatus,ComActDiscussDO.status.wks).le(ComActDiscussDO::getStartTime, nowDate)); |
| | | wksDiscussList.forEach(wksDiscuss -> { |
| | | wksDiscuss.setStatus(ComActDiscussDO.status.jxz); |
| | | wksDiscuss.setUpdateAt(nowDate); |
| | | wksDiscuss.setReleaseAt(nowDate); |
| | | comActDiscussDAO.updateById(wksDiscuss); |
| | | }); |
| | | |
| | | //查询已过结束时间未结束的投票列表 |
| | | List<ComActDiscussDO> jxzDiscussList = comActDiscussDAO.selectList(new QueryWrapper<ComActDiscussDO>().lambda() |
| | | .eq(ComActDiscussDO::getType, ComActDiscussDO.type.tp).eq(ComActDiscussDO::getIsDel, ComActDiscussDO.isOk.no) |
| | | .eq(ComActDiscussDO::getStatus,ComActDiscussDO.status.jxz).le(ComActDiscussDO::getEndTime, nowDate)); |
| | | jxzDiscussList.forEach(jxzDiscuss -> { |
| | | jxzDiscuss.setStatus(ComActDiscussDO.status.dgb); |
| | | jxzDiscuss.setUpdateAt(nowDate); |
| | | comActDiscussDAO.updateById(jxzDiscuss); |
| | | }); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 一起议增加浏览量 |
| | | * @param discussId 一起议主键id |
| | | */ |
| | | @Override |
| | | public void increaseViewNum(Long discussId) { |
| | | String incrKey = String.join("_", DISCUSS_VIEW_NUM_PREFIX, discussId.toString()); |
| | | Boolean isExist = stringRedisTemplate.hasKey(incrKey); |
| | | ValueOperations opsForValue = stringRedisTemplate.opsForValue(); |
| | | if (isExist) { |
| | | opsForValue.increment(incrKey); |
| | | } else { |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(discussId); |
| | | if (nonNull(comActDiscussDO)) { |
| | | stringRedisTemplate.executePipelined((RedisCallback<Object>) redisConnection -> { |
| | | StringRedisConnection stringRedisConnection = (StringRedisConnection) redisConnection; |
| | | Integer nowViewNum = Math.addExact(comActDiscussDO.getViewsNum().intValue(), 1); |
| | | stringRedisConnection.set(incrKey, nowViewNum.toString()); |
| | | stringRedisConnection.expire(incrKey, DISCUSS_EXPIRE_TIME); |
| | | stringRedisConnection.sAdd(INCR_VIEW_DISCUSS_IDS_KEY, discussId.toString()); |
| | | stringRedisConnection.expire(INCR_VIEW_DISCUSS_IDS_KEY, DISCUSS_EXPIRE_TIME); |
| | | return null; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 公布/编辑一起议投票结果 |
| | | * @param comActDiscussDTO |
| | | * @return 请求结果 |
| | | */ |
| | | @Override |
| | | public R editDiscussResult(ComActDiscussDTO comActDiscussDTO) { |
| | | if (isNull(comActDiscussDTO.getId()) || isNull(comActDiscussDTO.getPublishResult())) { |
| | | return R.fail("缺少参数!"); |
| | | } |
| | | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(comActDiscussDTO.getId()); |
| | | if (isNull(comActDiscussDO)) { |
| | | return R.fail("当前一起议主题不存在!"); |
| | | } |
| | | if (!comActDiscussDTO.getUserId().equals(comActDiscussDO.getUserId())) { |
| | | return R.fail("只能公布或编辑自己发布的主题!"); |
| | | } |
| | | comActDiscussDO.setPublishResult(comActDiscussDTO.getPublishResult()); |
| | | comActDiscussDO.setStatus(4); |
| | | int result = comActDiscussDAO.updateById(comActDiscussDO); |
| | | if (result > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("网络错误,请重试!"); |
| | | } |
| | | |
| | | /** |
| | | * 一起议获取是否有发布权 |
| | | * @param comActDiscussDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getDiscussPermissions(ComActDiscussDTO comActDiscussDTO) { |
| | | return R.ok(checkCurrentUserDiscussIdentity(comActDiscussDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 将redis中浏览量写入表中 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public R writeDiscussViewNumToTable() { |
| | | try { |
| | | if (stringRedisTemplate.hasKey(INCR_VIEW_DISCUSS_IDS_KEY)) { |
| | | SetOperations opsForSet = stringRedisTemplate.opsForSet(); |
| | | Set<String> needWriteDiscussIdSet = opsForSet.members(INCR_VIEW_DISCUSS_IDS_KEY); |
| | | |
| | | //组装viewNum key |
| | | List<String> viewNumKeys = new ArrayList<>(); |
| | | Iterator<String> iterator = needWriteDiscussIdSet.iterator(); |
| | | while (iterator.hasNext()) { |
| | | viewNumKeys.add(String.join("_", DISCUSS_VIEW_NUM_PREFIX, iterator.next())); |
| | | } |
| | | |
| | | ValueOperations opsForValue = stringRedisTemplate.opsForValue(); |
| | | List<String> viewNumList = opsForValue.multiGet(viewNumKeys); |
| | | |
| | | //待处理集合,以key-value/discussId-viewNum 存放 |
| | | HashMap<Long, Integer> needDealMap = new HashMap<>(); |
| | | for (String discussId : needWriteDiscussIdSet) { |
| | | try { |
| | | needDealMap.put(Long.parseLong(discussId), Integer.parseInt(viewNumList.get(0))); |
| | | viewNumList.remove(0); |
| | | } catch (IndexOutOfBoundsException e) { |
| | | //数据存在异常了,跳过,继续执行正确的 |
| | | continue; |
| | | } |
| | | } |
| | | int result = comActDiscussDAO.batchUpdateViewNum(needDealMap); |
| | | if (result <= 0) { |
| | | return R.fail("处理失败"); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("写入浏览量失败【{}】", e.getMessage()); |
| | | return R.fail("处理失败"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |