| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest; |
| | | import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse; |
| | | 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.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.listener.event.IntegralEvent; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.CommentJoinMapper; |
| | | import com.doumee.dao.business.CommentMapper; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.MultifileMapper; |
| | | import com.doumee.dao.business.model.Activity; |
| | | import com.doumee.dao.business.model.Comment; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Multifile; |
| | | import com.doumee.core.wx.WxMiniConfig; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.web.dto.CommentDTO; |
| | | import com.doumee.dao.web.dto.ZanDTO; |
| | | import com.doumee.dao.web.dto.activity.ActivityCommentDTO; |
| | | import com.doumee.dao.web.dto.activity.ActivityReplyCommentDTO; |
| | | import com.doumee.dao.web.request.CommentApplyRequest; |
| | | import com.doumee.service.business.CommentService; |
| | | 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.doumee.service.business.MemberService; |
| | | import com.doumee.service.business.ZanService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Autowired |
| | | private NoticeMapper noticeMapper; |
| | | |
| | | @Autowired |
| | | private ZanService zanService; |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Override |
| | | public Comment apply(CommentApplyRequest comment, Integer memberId) { |
| | | if (StringUtils.isNotBlank(comment.getContent())) { |
| | | try { |
| | | WxMaMsgSecCheckCheckRequest checkRequest = WxMaMsgSecCheckCheckRequest.builder() |
| | | .version("2") |
| | | .scene(3) |
| | | .openid(getMemberOpenId(memberId)) |
| | | .content(comment.getContent()) |
| | | .build(); |
| | | WxMaMsgSecCheckCheckResponse checkResponse = WxMiniConfig.wxMaService.getSecurityService().checkMessage(checkRequest); |
| | | if (checkResponse.getResult() != null && checkResponse.getResult().getSuggest() != null) { |
| | | String suggest = checkResponse.getResult().getSuggest(); |
| | | if ("risky".equalsIgnoreCase(suggest)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "评论内容包含违规信息,请修改后重新发布"); |
| | | } |
| | | } |
| | | } catch (WxErrorException e) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "内容安全检测失败,请稍后重试"); |
| | | } |
| | | } |
| | | |
| | | Comment target = new Comment(); |
| | | target.setCreateDate(new Date()); |
| | | target.setEditDate(new Date()); |
| | |
| | | target.setType(Constants.ZERO); |
| | | |
| | | if (comment.getReplyId() != null){ |
| | | Comment reply = commentMapper.selectById(comment.getReplyId()); |
| | | Comment reply = commentMapper.selectJoinOne(Comment.class,new MPJLambdaWrapper<Comment>() |
| | | .selectAll(Comment.class) |
| | | .selectAs(Member::getNickname,Comment::getReplyMemberNikeName) |
| | | .leftJoin(Member.class,Member::getId,Comment::getMemberId) |
| | | .eq(Comment::getId,comment.getReplyId()) |
| | | ); |
| | | reply = Optional.ofNullable(reply).orElseThrow(() -> new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "回复目标不存在")); |
| | | target.setReplyId(reply.getId()); |
| | | target.setReplyMemberId(reply.getMemberId()); |
| | | target.setCommentId(reply.getId()); |
| | | target.setCommentMemberId(reply.getMemberId()); |
| | | target.setCommentId(Objects.isNull(reply.getCommentId())?reply.getId():reply.getCommentId()); |
| | | target.setType(Constants.ONE); |
| | | } |
| | | target.setCommentMemberId(reply.getMemberId()); |
| | | |
| | | if (comment.getCommentId() != null ){ |
| | | if(!Constants.equalsInteger(memberId,reply.getMemberId())){ |
| | | Member member = memberMapper.selectById(memberId); |
| | | //评论发送用户消息 |
| | | //发送核销通知 |
| | | Notice notice = Notice.getNotice( |
| | | Constants.NoticeType.COMMENT, |
| | | reply.getMemberId(), |
| | | reply.getActivityId() |
| | | ); |
| | | notice.setContent(notice.getContent().replace("{param}",member.getNickname())); |
| | | noticeMapper.insert(notice); |
| | | } |
| | | }else if(comment.getCommentId() != null ){ |
| | | Comment reply = commentMapper.selectById(comment.getCommentId()); |
| | | reply = Optional.ofNullable(reply).orElseThrow(() -> new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "一级评论目标不存在")); |
| | | target.setCommentId(reply.getCommentId()); |
| | |
| | | target.setMemberImgUrl(memberFile + member.getImgurl()); |
| | | } |
| | | } |
| | | IntegralEvent<Comment> integralEvent = new IntegralEvent(this,target, Constants.CoffeeBeanTask.POST_COMMENTS,memberId); |
| | | applicationEventPublisher.publishEvent(integralEvent); |
| | | target.setZanCount(Constants.ZERO); |
| | | target.setZanStatus(Constants.ZERO); |
| | | return target; |
| | |
| | | |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | commentMapper.deleteById(id); |
| | | public void deleteById(Integer id,Integer memberId) { |
| | | Comment comment = commentMapper.selectById(id); |
| | | if(Objects.isNull(comment)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "评论不存在"); |
| | | } |
| | | if(!Constants.equalsInteger(memberId,comment.getMemberId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "非您的评论无权限删除"); |
| | | } |
| | | commentMapper.update(new UpdateWrapper<Comment>().lambda() |
| | | .set(Comment::getIsdeleted,Constants.ONE) |
| | | .eq(Comment::getId,id) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | |
| | | QueryWrapper<Comment> wrapper = new QueryWrapper<>(comment); |
| | | return commentMapper.selectList(wrapper); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageData<Comment> findPage(PageWrap<Comment> pageWrap) { |
| | | IPage<Comment> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | |
| | | queryWrapper.eq(Comment::getType, Constants.ZERO); |
| | | queryWrapper.eq(Comment::getStatus, Constants.ZERO); |
| | | queryWrapper.eq(Comment::getActivityId,pageWrap.getModel().getActivityId()); |
| | | queryWrapper.orderByDesc(Comment::getId); |
| | | queryWrapper.orderByAsc(Comment::getId); |
| | | IPage<ActivityCommentDTO> result = commentJoinMapper.selectJoinPage(page, ActivityCommentDTO.class, queryWrapper); |
| | | |
| | | if (CollectionUtils.isEmpty(result.getRecords())){ |
| | |
| | | MPJLambdaWrapper<Comment> replyWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | replyWrapper.selectAs(Comment::getId,ActivityReplyCommentDTO::getId); |
| | | replyWrapper.selectAs(Comment::getReplyId,ActivityReplyCommentDTO::getReplyId); |
| | | replyWrapper.selectAs(Comment::getIsdeleted,ActivityReplyCommentDTO::getIsdeleted); |
| | | if(Objects.isNull(pageWrap.getModel().getMemberId())){ |
| | | replyWrapper.select(" 0 ",ActivityReplyCommentDTO::getZanStatus); |
| | | }else{ |
| | |
| | | replyWrapper.selectAs(Member::getImgurl,ActivityReplyCommentDTO::getMemberImgUrl); |
| | | replyWrapper.selectCount(Comment::getId,ActivityReplyCommentDTO::getReplyCount); |
| | | replyWrapper.selectMin(Comment::getCreateDate,ActivityReplyCommentDTO::getCreateDate); |
| | | replyWrapper.select("reply.NICKNAME",ActivityReplyCommentDTO::getReplyMemberNikeName); |
| | | replyWrapper.leftJoin(Member.class,Member::getId,Comment::getMemberId); |
| | | replyWrapper.leftJoin("member reply on reply.id = t.REPLY_MEMBER_ID"); |
| | | replyWrapper.eq(Comment::getType, Constants.ONE); |
| | | replyWrapper.eq(Comment::getStatus, Constants.ZERO); |
| | | replyWrapper.in(Comment::getCommentId,commentIds); |
| | |
| | | } |
| | | } |
| | | result.getRecords().forEach(s->{ |
| | | s.setMemberImgUrl(StringUtils.isNotBlank(s.getMemberImgUrl())?memberFile+s.getMemberImgUrl():null); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | s.setMultifileList(multifileList.stream().filter(t -> t.getObjId().equals(s.getId())).collect(Collectors.toList())); |
| | | if(Constants.equalsInteger(s.getIsdeleted(),Constants.ONE)){ |
| | | s.setContent("该评论已被原作者删除"); |
| | | }else{ |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | s.setMultifileList(multifileList.stream().filter(t -> t.getObjId().equals(s.getId())).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | s.setMemberImgUrl(StringUtils.isNotBlank(s.getMemberImgUrl())?memberFile+s.getMemberImgUrl():null); |
| | | ZanDTO object = MapUtils.getObject(count, s.getId()); |
| | | ActivityReplyCommentDTO replyCommentDTO = collect.get(s.getId()); |
| | | if(Objects.nonNull(replyCommentDTO)){ |
| | | ZanDTO replyZan = MapUtils.getObject(count, replyCommentDTO.getId()); |
| | | replyCommentDTO.setZanCount(replyZan != null ? replyZan.getCount() : 0); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | replyCommentDTO.setMultifileList(multifileList.stream().filter(t -> t.getObjId().equals(s.getId())).collect(Collectors.toList())); |
| | | if(Constants.equalsInteger(replyCommentDTO.getIsdeleted(),Constants.ONE)){ |
| | | replyCommentDTO.setContent("该评论已被原作者删除"); |
| | | }else{ |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | replyCommentDTO.setMultifileList(multifileList.stream().filter(t -> t.getObjId().equals(replyCommentDTO.getId())).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | replyCommentDTO.setMemberImgUrl(StringUtils.isNotBlank(replyCommentDTO.getMemberImgUrl())?memberFile+replyCommentDTO.getMemberImgUrl():null); |
| | | s.setActivityReplyCommentDTO(replyCommentDTO); |
| | |
| | | queryWrapper.select(" (select count(1) from zan z where z.OBJ_ID = t.id and z.ISDELETED = 0 and z.OBJ_TYPE = 0) ",ActivityReplyCommentDTO::getZanCount); |
| | | queryWrapper.select("reply.NICKNAME as replyMemberNikeName"); |
| | | queryWrapper.leftJoin(Member.class,Member::getId,Comment::getMemberId); |
| | | queryWrapper.leftJoin("member reply on reply.id = t.REPLY_MEMBER_ID"); |
| | | queryWrapper.leftJoin("member reply on reply.id = t.COMMENT_MEMBER_ID"); |
| | | queryWrapper.eq(Comment::getType, Constants.ONE); |
| | | queryWrapper.eq(Comment::getStatus, Constants.ZERO); |
| | | queryWrapper.eq(Comment::getCommentId,pageWrap.getModel().getCommentId()); |
| | | queryWrapper.orderByAsc(Comment::getId); |
| | | IPage<ActivityReplyCommentDTO> result = commentJoinMapper.selectJoinPage(page, ActivityReplyCommentDTO.class, queryWrapper); |
| | | if (CollectionUtils.isEmpty(result.getRecords())){ |
| | | return PageData.from(result); |
| | |
| | | } |
| | | } |
| | | List<Integer> integerStream = result.getRecords().stream().map(s -> s.getId()).collect(Collectors.toList()); |
| | | |
| | | Map<Integer, ZanDTO> count = zanService.count(integerStream); |
| | | result.getRecords().forEach(s->{ |
| | | s.setMemberImgUrl(StringUtils.isNotBlank(s.getMemberImgUrl())?memberFile+s.getMemberImgUrl():null); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | s.setMultifileList(multifileList.stream().filter(t -> t.getObjId().equals(s.getId())).collect(Collectors.toList())); |
| | | if(Constants.equalsInteger(s.getIsdeleted(),Constants.ONE)){ |
| | | s.setContent("该评论已被原作者删除"); |
| | | }else{ |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | s.setMultifileList(multifileList.stream().filter(t -> t.getObjId().equals(s.getId())).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | s.setMemberImgUrl(StringUtils.isNotBlank(s.getMemberImgUrl())?memberFile+s.getMemberImgUrl():null); |
| | | ZanDTO replyZan = MapUtils.getObject(count, s.getId()); |
| | | s.setZanCount(replyZan != null ? replyZan.getCount() : 0); |
| | | if (pageWrap.getModel().getCommentId().equals(s.getReplyId())){ |
| | | s.setReplyMemberNikeName(null); |
| | | } |
| | | }); |
| | | |
| | | return PageData.from(result); |
| | | } |
| | | |
| | | private String getMemberOpenId(Integer memberId) { |
| | | Member member = memberMapper.selectById(memberId); |
| | | return member != null ? member.getOpenId() : null; |
| | | } |
| | | } |