|  |  |  | 
|---|
|  |  |  | 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.service_community.dao.*; | 
|---|
|  |  |  | import com.panzhihua.service_community.model.dos.*; | 
|---|
|  |  |  | import com.panzhihua.common.model.vos.community.SysConfVO; | 
|---|
|  |  |  | import com.panzhihua.common.model.vos.community.screen.work.DiscussListVO; | 
|---|
|  |  |  | 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 org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import com.panzhihua.service_community.service.SysConfService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | 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 新增参数 | 
|---|
|  |  |  | * @return 新增结果 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public R addDiscuss(ComActDiscussDTO comActDiscussDTO) { | 
|---|
|  |  |  | ComActDiscussDO comActDiscussDO=new ComActDiscussDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussDTO,comActDiscussDO); | 
|---|
|  |  |  | ComActVO comActVO=comActDiscussDAO.selectCommunity(comActDiscussDTO.getCommunityId()); | 
|---|
|  |  |  | if (!checkCurrentUserDiscussIdentity(comActDiscussDTO)) { | 
|---|
|  |  |  | return R.fail("权限验证失败,请确认是否有发布权限"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ComActDiscussDO comActDiscussDO = new ComActDiscussDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussDTO, comActDiscussDO); | 
|---|
|  |  |  | 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.intValue()==2) { | 
|---|
|  |  |  | List<String> discussOptions = comActDiscussDTO.getDiscussOptions(); | 
|---|
|  |  |  | List<ComActDiscussOptionDO> comActDiscussOptionDOS=new ArrayList<>(); | 
|---|
|  |  |  | if (insert > 0) { | 
|---|
|  |  |  | //如果是投票,需要把投票的选项存储 | 
|---|
|  |  |  | if (type.equals(2)) { | 
|---|
|  |  |  | Long comActDiscussDO1Id = comActDiscussDO.getId(); | 
|---|
|  |  |  | List<ComActDiscussOptionDTO> discussOptions = comActDiscussDTO.getDiscussOptions(); | 
|---|
|  |  |  | List<ComActDiscussOptionDO> comActDiscussOptionDOS = new ArrayList<>(); | 
|---|
|  |  |  | discussOptions.forEach(s -> { | 
|---|
|  |  |  | ComActDiscussOptionDO comActDiscussOptionDO=new ComActDiscussOptionDO(); | 
|---|
|  |  |  | ComActDiscussOptionDO comActDiscussOptionDO = new ComActDiscussOptionDO(); | 
|---|
|  |  |  | comActDiscussOptionDO.setDiscussId(comActDiscussDO1Id); | 
|---|
|  |  |  | comActDiscussOptionDO.setOptionContent(s); | 
|---|
|  |  |  | comActDiscussOptionDO.setOptionContent(s.getOptionContent()); | 
|---|
|  |  |  | comActDiscussOptionDO.setOptionUrl(s.getOptionUrl()); | 
|---|
|  |  |  | comActDiscussOptionDOS.add(comActDiscussOptionDO); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | comActDiscussOptionService.saveBatch(comActDiscussOptionDOS); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-详情 | 
|---|
|  |  |  | * 小程序用户验证是否拥有发布权限 | 
|---|
|  |  |  | * @param comActDiscussDTO | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!sysAllowedRoles.contains("1")) { | 
|---|
|  |  |  | boolean result = sysAllowedRoles.stream().anyMatch(role -> currentUserRoles.contains(role)); | 
|---|
|  |  |  | if (!result) { | 
|---|
|  |  |  | checkResult = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return checkResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 议事投票-编辑 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 主键 | 
|---|
|  |  |  | * @param comActDiscussDTO 请求参数 | 
|---|
|  |  |  | * @return 编辑结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @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(nowDate); | 
|---|
|  |  |  | 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 discussDetailDTO 请求参数 | 
|---|
|  |  |  | * @return ComActDiscussVO | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R detailDiscuss(Long id) { | 
|---|
|  |  |  | public R detailDiscuss(ComActDiscussDetailDTO discussDetailDTO) { | 
|---|
|  |  |  | Long id = discussDetailDTO.getId(); | 
|---|
|  |  |  | 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 comActDiscussVO = new ComActDiscussVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussDO, comActDiscussVO); | 
|---|
|  |  |  | comActDiscussVO.setSignNum(comActDiscussDO.getFabulousNum()); | 
|---|
|  |  |  | Integer type = comActDiscussVO.getType(); | 
|---|
|  |  |  | if (type.intValue()==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); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | comActDiscussVO.setComActDiscussOptionVOS(comActDiscussOptionVOS); | 
|---|
|  |  |  | if (type.equals(ComActDiscussVO.type.tp)) { | 
|---|
|  |  |  | //查询选项列表 | 
|---|
|  |  |  | List<ComActDiscussOptionVO> comActDiscussOptionList = comActDiscussOptionDAO.getDiscussOptionList(id); | 
|---|
|  |  |  | comActDiscussVO.setComActDiscussOptionVOS(comActDiscussOptionList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long userId = comActDiscussDO.getUserId(); | 
|---|
|  |  |  | LoginUserInfoVO loginUserInfoVO=comActDiscussDAO.selectUserByUserId(userId); | 
|---|
|  |  |  | 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 id 主键 | 
|---|
|  |  |  | * @return 删除结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R deleteDiscuss(Long id) { | 
|---|
|  |  |  | int delete = comActDiscussDAO.deleteById(id); | 
|---|
|  |  |  | if (delete>0) { | 
|---|
|  |  |  | 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 回复结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | Long discussId = comActDiscussCommentDTO.getDiscussId(); | 
|---|
|  |  |  | ComActDiscussDO comActDiscussDO = comActDiscussDAO.selectById(discussId); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(comActDiscussDO)) { | 
|---|
|  |  |  | return R.fail("一起议不存在"); | 
|---|
|  |  |  | return R.fail("议事投票不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO=new ComActDiscussCommentDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussCommentDTO,comActDiscussCommentDO); | 
|---|
|  |  |  | Long userId = comActDiscussCommentDTO.getUserId(); | 
|---|
|  |  |  | Long userId1 = comActDiscussDO.getUserId(); | 
|---|
|  |  |  | if (userId.equals(userId1)) { | 
|---|
|  |  |  | 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 discussUser = comActDiscussDO.getUserId(); | 
|---|
|  |  |  | if (currentUser.equals(discussUser)) { | 
|---|
|  |  |  | comActDiscussCommentDO.setIsAuthor(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int insert = comActDiscussCommentDAO.insert(comActDiscussCommentDO); | 
|---|
|  |  |  | if (insert>0) { | 
|---|
|  |  |  | 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 查询参数 | 
|---|
|  |  |  | * @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 pageComActDiscussDTO 请求参数 | 
|---|
|  |  |  | * @return 议事投票列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R pageDiscussAdmin(PageComActDiscussDTO pageComActDiscussDTO) { | 
|---|
|  |  |  | IPage<ComActDiscussVO> comActDiscussVOIPage=comActDiscussDAO.pageDiscussAdmin(new Page<>(pageComActDiscussDTO.getPageNum(), pageComActDiscussDTO.getPageSize()), pageComActDiscussDTO); | 
|---|
|  |  |  | List<ComActDiscussVO> records = comActDiscussVOIPage.getRecords(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(records)) { | 
|---|
|  |  |  | records.forEach(comActDiscussVO -> { | 
|---|
|  |  |  | 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))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(comActDiscussVOIPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 议事投票-评论-查看 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 主键 | 
|---|
|  |  |  | * @return 详情 ComActDiscussCommentVO | 
|---|
|  |  |  | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(comActDiscussCommentDO)) { | 
|---|
|  |  |  | return R.fail("评论不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ComActDiscussCommentVO comActDiscussCommentVO=new ComActDiscussCommentVO(); | 
|---|
|  |  |  | ComActDiscussCommentVO comActDiscussCommentVO = new ComActDiscussCommentVO(); | 
|---|
|  |  |  | Long parentId = comActDiscussCommentDO.getParentId(); | 
|---|
|  |  |  | if (parentId.intValue()==0) { | 
|---|
|  |  |  | //            一级评论 | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussCommentDO,comActDiscussCommentVO); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | if (parentId.intValue() == 0) { | 
|---|
|  |  |  | // 一级评论 | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussCommentDO, comActDiscussCommentVO); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO1 = comActDiscussCommentDAO.selectById(parentId); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussCommentDO1,comActDiscussCommentVO); | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | Integer count = comActDiscussCommentUserDAO.selectCount(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() | 
|---|
|  |  |  | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, id)); | 
|---|
|  |  |  | comActDiscussCommentVO.setNum(count); | 
|---|
|  |  |  | LoginUserInfoVO loginUserInfoVO=comActDiscussDAO.selectUserByUserId(comActDiscussCommentDO.getUserId()); | 
|---|
|  |  |  | LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(comActDiscussCommentDO.getUserId()); | 
|---|
|  |  |  | comActDiscussCommentVO.setUserName(loginUserInfoVO.getName()); | 
|---|
|  |  |  | comActDiscussCommentVO.setPhone(loginUserInfoVO.getPhone()); | 
|---|
|  |  |  | return R.ok(comActDiscussCommentVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-评论-置顶 | 
|---|
|  |  |  | * 议事投票评论详情 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @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 置顶结果 | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.fail("评论不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long parentId = comActDiscussCommentDO.getParentId(); | 
|---|
|  |  |  | if (parentId.intValue()!=0) { | 
|---|
|  |  |  | if (parentId.intValue() != 0) { | 
|---|
|  |  |  | return R.fail("二级评论不能置顶"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long discussId = comActDiscussCommentDO.getDiscussId(); | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO1=new ComActDiscussCommentDO(); | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO1 = new ComActDiscussCommentDO(); | 
|---|
|  |  |  | comActDiscussCommentDO1.setIsTopping(0); | 
|---|
|  |  |  | comActDiscussCommentDAO.update(comActDiscussCommentDO1,new UpdateWrapper<ComActDiscussCommentDO>().lambda().eq(ComActDiscussCommentDO::getDiscussId,discussId)); | 
|---|
|  |  |  | comActDiscussCommentDAO.update(comActDiscussCommentDO1, | 
|---|
|  |  |  | new UpdateWrapper<ComActDiscussCommentDO>().lambda().eq(ComActDiscussCommentDO::getDiscussId, discussId)); | 
|---|
|  |  |  | comActDiscussCommentDO1.setIsTopping(1); | 
|---|
|  |  |  | comActDiscussCommentDO1.setId(id); | 
|---|
|  |  |  | int update = comActDiscussCommentDAO.updateById(comActDiscussCommentDO1); | 
|---|
|  |  |  | if (update>0) { | 
|---|
|  |  |  | if (update > 0) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-评论-回复 | 
|---|
|  |  |  | * 议事投票-评论-回复 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param comActDiscussCommentDTO 回复内容 | 
|---|
|  |  |  | * @return 回复结果 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO1=new ComActDiscussCommentDO(); | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | 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 分页查询参数 | 
|---|
|  |  |  | * @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 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 分页 | 
|---|
|  |  |  | 
|---|
|  |  |  | Long pageNum = pageComActDiscussDTO.getPageNum(); | 
|---|
|  |  |  | Long pageSize = pageComActDiscussDTO.getPageSize(); | 
|---|
|  |  |  | Long loginUserId = pageComActDiscussDTO.getLoginUserId(); | 
|---|
|  |  |  | if (null==pageNum||0==pageNum) { | 
|---|
|  |  |  | if (null == pageNum || 0 == pageNum) { | 
|---|
|  |  |  | pageNum = 1l; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (null==pageSize||0==pageSize) { | 
|---|
|  |  |  | if (null == pageSize || 0 == pageSize) { | 
|---|
|  |  |  | pageSize = 10l; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | page.setSize(pageSize); | 
|---|
|  |  |  | 
|---|
|  |  |  | records.forEach(comActDiscussVO -> { | 
|---|
|  |  |  | Integer type = comActDiscussVO.getType(); | 
|---|
|  |  |  | Long id = comActDiscussVO.getId(); | 
|---|
|  |  |  | if (type.intValue()==2) { | 
|---|
|  |  |  | List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(new QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, id)); | 
|---|
|  |  |  | List<ComActDiscussOptionVO> comActDiscussOptionVOS=new ArrayList<>(); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //填充投票记录列表 | 
|---|
|  |  |  | List<ComActDiscussOptionUserVO> comActDiscussOptionUserVOList = comActDiscussOptionUserDAO | 
|---|
|  |  |  | .selectVotedRecords(comActDiscussVO.getId()); | 
|---|
|  |  |  | comActDiscussVO.setComActDiscussOptionUserVOList(comActDiscussOptionUserVOList); | 
|---|
|  |  |  | //填充已参与投票人数 | 
|---|
|  |  |  | int votedPersonNum = comActDiscussOptionUserDAO.selectVotedPersonNum(comActDiscussVO.getId()); | 
|---|
|  |  |  | comActDiscussVO.setVotedPersonNum(votedPersonNum); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                判断是否已经投票 | 
|---|
|  |  |  | int haveVote=comActDiscussOptionUserDAO.selectHaveVote(id,loginUserId); | 
|---|
|  |  |  | comActDiscussVO.setHaveVote(haveVote>0?1:0); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(iPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-点赞、取消点赞 | 
|---|
|  |  |  | * 判断discuss状态是否正确 | 
|---|
|  |  |  | * @param comActDiscussVO | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void checkDiscussStatusIsCorrect(ComActDiscussVO comActDiscussVO) { | 
|---|
|  |  |  | //判断discuss状态是否正确 | 
|---|
|  |  |  | if(comActDiscussVO.getEndTime() != null){ | 
|---|
|  |  |  | 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 操作类型 | 
|---|
|  |  |  | * @return 操作结果 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R putDiscussUser(ComActDiscussUserDTO comActDiscussUserDTO) { | 
|---|
|  |  |  | Integer type = comActDiscussUserDTO.getType(); | 
|---|
|  |  |  | int num=0; | 
|---|
|  |  |  | ComActDiscussUserDO comActDiscussUserDO=new ComActDiscussUserDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussUserDTO,comActDiscussUserDO); | 
|---|
|  |  |  | if (type.intValue()==1) { | 
|---|
|  |  |  | num= comActDiscussUserDAO.insert(comActDiscussUserDO); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | num= comActDiscussUserDAO.delete(new QueryWrapper<ComActDiscussUserDO>().lambda().eq(ComActDiscussUserDO::getUserId,comActDiscussUserDTO.getUserId()).eq(ComActDiscussUserDO::getDiscussId,comActDiscussUserDTO.getDiscussId())); | 
|---|
|  |  |  | int num = 0; | 
|---|
|  |  |  | ComActDiscussUserDO comActDiscussUserDO = new ComActDiscussUserDO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussUserDTO, comActDiscussUserDO); | 
|---|
|  |  |  | 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())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (num>0) { | 
|---|
|  |  |  | if (num > 0) { | 
|---|
|  |  |  | //点赞成功 总数+1 || 取消点赞成功 总数-1 | 
|---|
|  |  |  | comActDiscussDAO.incrOrDecrFabulousNumByType(comActDiscussUserDTO.getDiscussId(), isIncr); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-评论-分页查询 小程序 | 
|---|
|  |  |  | * 议事投票-评论-分页查询 小程序 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param pageComActDiscussCommentDTO 分页参数 | 
|---|
|  |  |  | * @return ComActDiscussCommentVO | 
|---|
|  |  |  | 
|---|
|  |  |  | Page page = new Page<>(); | 
|---|
|  |  |  | Long pageNum = pageComActDiscussCommentDTO.getPageNum(); | 
|---|
|  |  |  | Long pageSize = pageComActDiscussCommentDTO.getPageSize(); | 
|---|
|  |  |  | if (null==pageNum||0==pageNum) { | 
|---|
|  |  |  | if (null == pageNum || 0 == pageNum) { | 
|---|
|  |  |  | pageNum = 1l; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (null==pageSize||0==pageSize) { | 
|---|
|  |  |  | if (null == pageSize || 0 == pageSize) { | 
|---|
|  |  |  | pageSize = 10l; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | page.setSize(pageSize); | 
|---|
|  |  |  | page.setCurrent(pageNum); | 
|---|
|  |  |  | IPage<ComActDiscussCommentVO> iPage = comActDiscussDAO.pageDiscussCommentApplets(page, pageComActDiscussCommentDTO); | 
|---|
|  |  |  | IPage<ComActDiscussCommentVO> iPage = | 
|---|
|  |  |  | comActDiscussDAO.pageDiscussCommentApplets(page, pageComActDiscussCommentDTO); | 
|---|
|  |  |  | List<ComActDiscussCommentVO> records = iPage.getRecords(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(records)) { | 
|---|
|  |  |  | records.forEach(comActDiscussCommentVO -> { | 
|---|
|  |  |  | List<ComActDiscussCommentVO> comActDiscussCommentVOList=new ArrayList<>(); | 
|---|
|  |  |  | List<ComActDiscussCommentVO> comActDiscussCommentVOList = new ArrayList<>(); | 
|---|
|  |  |  | Long id = comActDiscussCommentVO.getId(); | 
|---|
|  |  |  | comActDiscussCommentVOList=comActDiscussCommentDAO.selectChilds(id); | 
|---|
|  |  |  | comActDiscussCommentVOList = comActDiscussCommentDAO.selectChilds(id); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(comActDiscussCommentVOList)) { | 
|---|
|  |  |  | List<ComActDiscussCommentVO> comActDiscussCommentVOS=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()); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | List<ComActDiscussCommentVO> collect1 = records.stream() | 
|---|
|  |  |  | .filter(comActDiscussCommentVO2 -> comActDiscussCommentVO2.getId().equals(parentId)) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(collect1)) { | 
|---|
|  |  |  | String userName = collect1.get(0).getUserName(); | 
|---|
|  |  |  | ComActDiscussCommentVO comActDiscussCommentVOFirst = collect1.get(0); | 
|---|
|  |  |  | String userName = comActDiscussCommentVOFirst.getUserName(); | 
|---|
|  |  |  | String userNickName = comActDiscussCommentVOFirst.getUserNickName(); | 
|---|
|  |  |  | comActDiscussCommentVO1.setUserNameBack(userName); | 
|---|
|  |  |  | comActDiscussCommentVO1.setUserNickNameBack(userNickName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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 (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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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 (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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-详情 小程序 | 
|---|
|  |  |  | * 议事投票-详情 小程序 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 主键 | 
|---|
|  |  |  | * @param id          主键 | 
|---|
|  |  |  | * @param loginUserId 登录用户主键 | 
|---|
|  |  |  | * @return ComActDiscussVO | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 comActDiscussVO = new ComActDiscussVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(comActDiscussDO, comActDiscussVO); | 
|---|
|  |  |  | comActDiscussVO.setSignNum(comActDiscussDO.getFabulousNum()); | 
|---|
|  |  |  | Integer type = comActDiscussVO.getType(); | 
|---|
|  |  |  | if (type.intValue()==2) { | 
|---|
|  |  |  | List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(new QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, id)); | 
|---|
|  |  |  | List<ComActDiscussOptionVO> comActDiscussOptionVOS=new ArrayList<>(); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | LoginUserInfoVO loginUserInfoVO = comActDiscussDAO.selectUserByUserId(userId); | 
|---|
|  |  |  | if (loginUserInfoVO != null) { | 
|---|
|  |  |  | comActDiscussVO.setUserName(loginUserInfoVO.getName()); | 
|---|
|  |  |  | comActDiscussVO.setUserNickName(loginUserInfoVO.getNickName()); | 
|---|
|  |  |  | if (StringUtils.isEmpty(loginUserInfoVO.getNickName())) { | 
|---|
|  |  |  | comActDiscussVO.setUserNickName(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); | 
|---|
|  |  |  | if (type1.intValue() > 1) { | 
|---|
|  |  |  | ComActVO comActVO = comActDiscussDAO.selectCommunity(communityId); | 
|---|
|  |  |  | comActDiscussVO.setUserName(comActVO.getName()); | 
|---|
|  |  |  | comActDiscussVO.setUserNickName(comActVO.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ComActDiscussVO comActDiscussVO1=comActDiscussDAO.selectHaveSignAndHaveVote(id,loginUserId); | 
|---|
|  |  |  | comActDiscussVO.setHaveSign(comActDiscussVO1.getHaveSign()); | 
|---|
|  |  |  | comActDiscussVO.setHaveVote(comActDiscussVO1.getHaveVote()); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-投票 | 
|---|
|  |  |  | * 计算投票占比以及排序 | 
|---|
|  |  |  | * @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 投票信息 | 
|---|
|  |  |  | * @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)) { | 
|---|
|  |  |  | return R.fail("选项不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // Long discussId = comActDiscussOptionDO.getDiscussId(); | 
|---|
|  |  |  | // List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(new | 
|---|
|  |  |  | // QueryWrapper<ComActDiscussOptionDO>().lambda().eq(ComActDiscussOptionDO::getDiscussId, discussId)); | 
|---|
|  |  |  | // List<Long> longList=comActDiscussOptionDOS.stream().map(comActDiscussOptionDO1 -> | 
|---|
|  |  |  | // comActDiscussOptionDO1.getId()).collect(Collectors.toList()); | 
|---|
|  |  |  | Long discussId = comActDiscussOptionDO.getDiscussId(); | 
|---|
|  |  |  | List<ComActDiscussOptionDO> comActDiscussOptionDOS = comActDiscussOptionDAO.selectList(new 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).in(ComActDiscussOptionUserDO::getDiscussOptionId, longList)); | 
|---|
|  |  |  | if (integer>0) { | 
|---|
|  |  |  | return R.fail("不要重复投票"); | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 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("票数不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail(); | 
|---|
|  |  |  | List<ComActDiscussOptionUserDO> comActDiscussOptionUserDOList = new ArrayList<>(); | 
|---|
|  |  |  | discussOptionIds.forEach(optionId -> { | 
|---|
|  |  |  | ComActDiscussOptionUserDO comActDiscussOptionUserDO = new ComActDiscussOptionUserDO(); | 
|---|
|  |  |  | comActDiscussOptionUserDO.setUserId(userId); | 
|---|
|  |  |  | comActDiscussOptionUserDO.setDiscussOptionId(optionId); | 
|---|
|  |  |  | comActDiscussOptionUserDO.setDiscussId(discussId); | 
|---|
|  |  |  | comActDiscussOptionUserDAO.insert(comActDiscussOptionUserDO); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 一起议-评论-点赞、取消点赞 | 
|---|
|  |  |  | * 议事投票-评论-点赞、取消点赞 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param comActDiscussCommentUserDTO 评论点赞 | 
|---|
|  |  |  | * @return 点赞结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R putDiscussCommentUser(ComActDiscussCommentUserDTO comActDiscussCommentUserDTO) { | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO = comActDiscussCommentDAO.selectById(comActDiscussCommentUserDTO.getId()); | 
|---|
|  |  |  | ComActDiscussCommentDO comActDiscussCommentDO = | 
|---|
|  |  |  | comActDiscussCommentDAO.selectById(comActDiscussCommentUserDTO.getId()); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(comActDiscussCommentDO)) { | 
|---|
|  |  |  | return R.fail("评论不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer type = comActDiscussCommentUserDTO.getType(); | 
|---|
|  |  |  | int num=0; | 
|---|
|  |  |  | if (type.intValue()==1) { | 
|---|
|  |  |  | ComActDiscussCommentUserDO comActDiscussCommentUserDO=new ComActDiscussCommentUserDO(); | 
|---|
|  |  |  | int num = 0; | 
|---|
|  |  |  | if (type.intValue() == 1) { | 
|---|
|  |  |  | ComActDiscussCommentUserDO comActDiscussCommentUserDO = new ComActDiscussCommentUserDO(); | 
|---|
|  |  |  | comActDiscussCommentUserDO.setUserId(comActDiscussCommentUserDTO.getUserId()); | 
|---|
|  |  |  | comActDiscussCommentUserDO.setDisscussCommentId(comActDiscussCommentUserDTO.getId()); | 
|---|
|  |  |  | num=comActDiscussCommentUserDAO.insert(comActDiscussCommentUserDO); | 
|---|
|  |  |  | num = comActDiscussCommentUserDAO.insert(comActDiscussCommentUserDO); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | num=comActDiscussCommentUserDAO.delete(new QueryWrapper<ComActDiscussCommentUserDO>().lambda().eq(ComActDiscussCommentUserDO::getUserId,comActDiscussCommentUserDTO.getUserId()).eq(ComActDiscussCommentUserDO::getDisscussCommentId,comActDiscussCommentUserDTO.getId())); | 
|---|
|  |  |  | num = comActDiscussCommentUserDAO.delete(new QueryWrapper<ComActDiscussCommentUserDO>().lambda() | 
|---|
|  |  |  | .eq(ComActDiscussCommentUserDO::getUserId, comActDiscussCommentUserDTO.getUserId()) | 
|---|
|  |  |  | .eq(ComActDiscussCommentUserDO::getDisscussCommentId, comActDiscussCommentUserDTO.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (num>0) { | 
|---|
|  |  |  | if (num > 0) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.fail(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 工作大屏-议事投票列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param discussListDTO 请求参数 | 
|---|
|  |  |  | * @return 议事投票列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R getScreenDiscussList(ScreenDiscussListDTO discussListDTO) { | 
|---|
|  |  |  | IPage<DiscussListVO> discussListVOIPage = comActDiscussDAO | 
|---|
|  |  |  | .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())); | 
|---|
|  |  |  | discussListVO.setCommentCount(integer); | 
|---|
|  |  |  | Integer integer1 = comActDiscussUserDAO.selectCount(new QueryWrapper<ComActDiscussUserDO>().lambda() | 
|---|
|  |  |  | .eq(ComActDiscussUserDO::getDiscussId, discussListVO.getId())); | 
|---|
|  |  |  | discussListVO.setFabulousCount(integer1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (discussListVO.getType().equals(ScreenDiscussListDTO.type.tp)) {// 投票 | 
|---|
|  |  |  | List<ComActDiscussOptionVO> discussOptionList = | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | List<String> idList = new ArrayList<>(); | 
|---|
|  |  |  | while (iterator.hasNext()) { | 
|---|
|  |  |  | String next = iterator.next(); | 
|---|
|  |  |  | String key = String.join("_", DISCUSS_VIEW_NUM_PREFIX, next); | 
|---|
|  |  |  | if (stringRedisTemplate.hasKey(key)) { | 
|---|
|  |  |  | idList.add(next); | 
|---|
|  |  |  | viewNumKeys.add(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ValueOperations opsForValue = stringRedisTemplate.opsForValue(); | 
|---|
|  |  |  | List<String> viewNumList = opsForValue.multiGet(viewNumKeys); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //待处理集合,以key-value/discussId-viewNum 存放 | 
|---|
|  |  |  | HashMap<Long, Integer> needDealMap = new HashMap<>(); | 
|---|
|  |  |  | if (nonNull(idList) && !idList.isEmpty()) { | 
|---|
|  |  |  | log.error("一起议id列表:" + idList.toString()); | 
|---|
|  |  |  | log.error("一起议浏览量:" + viewNumList.toString()); | 
|---|
|  |  |  | for (String discussId : idList) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | needDealMap.put(Long.parseLong(discussId), Integer.parseInt(viewNumList.get(0))); | 
|---|
|  |  |  | viewNumList.remove(0); | 
|---|
|  |  |  | } catch (IndexOutOfBoundsException e) { | 
|---|
|  |  |  | log.error("数据异常:" + discussId, e.getMessage()); | 
|---|
|  |  |  | //数据存在异常了,跳过,继续执行正确的 | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|