| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | private final ClothesTypeArtMapper clothesTypeArtMapper; |
| | | private final ClothesLocationRemarkMapper clothesLocationRemarkMapper; |
| | | private final ClothesPatternRemarkMapper clothesPatternRemarkMapper; |
| | | private final ClothesSocialCommentMapper clothesSocialCommentMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | // 调用Mapper方法获取活动分页数据 |
| | | Page<ApiAllSocialVo> voPage = clothesSocialMapper.selectPageInSocial(page, dto); |
| | | |
| | | List<ApiAllSocialVo> vos = voPage.getRecords(); |
| | | if (CollUtil.isNotEmpty(vos)) { |
| | | Set<Long> socialIds = vos.stream() |
| | | .map(ApiAllSocialVo::getId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | if (CollUtil.isNotEmpty(socialIds)) { |
| | | List<ClothesSocialFollow> clothesSocialFollows = clothesSocialFollowMapper.selectList( |
| | | Wrappers.lambdaQuery(ClothesSocialFollow.class) |
| | | .select(ClothesSocialFollow::getId, ClothesSocialFollow::getSourceId) |
| | | .in(ClothesSocialFollow::getSourceId, socialIds) |
| | | .eq(ClothesSocialFollow::getType, SocialTypeEnum.LIKE.getValue()) |
| | | ); |
| | | |
| | | Map<Long, Long> likeCountBySocialIdMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(clothesSocialFollows)) { |
| | | likeCountBySocialIdMap = clothesSocialFollows.stream() |
| | | .collect(Collectors.groupingBy(ClothesSocialFollow::getSourceId, Collectors.counting())); |
| | | } |
| | | |
| | | for (ApiAllSocialVo item : vos){ |
| | | item.setLikeCnt(likeCountBySocialIdMap.getOrDefault(item.getId(), 0L).intValue()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return new FebsResponse().success().data(voPage); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public FebsResponse socialInfo(ApiSocialInfoDto dto) { |
| | |
| | | apiSocialInfoVo.setName(clothesSocial.getName()); |
| | | apiSocialInfoVo.setContent(clothesSocial.getContent()); |
| | | apiSocialInfoVo.setCreatedTime(clothesSocial.getCreatedTime()); |
| | | apiSocialInfoVo.setCommentState(clothesSocial.getCommentState()); |
| | | |
| | | List<ClothesSocialFile> clothesSocialFiles = clothesSocialFileMapper.selectList( |
| | | Wrappers.lambdaQuery(ClothesSocialFile.class) |
| | |
| | | apiSocialMuseVo.setLocationRemarkList(locationRemarkList); |
| | | } |
| | | apiSocialMuseVo.setTotalAmount(totalAmount.setScale(2, RoundingMode.DOWN)); |
| | | |
| | | List<ClothesSocialFollow> clothesSocialFollows = clothesSocialFollowMapper.selectList( |
| | | Wrappers.lambdaQuery(ClothesSocialFollow.class) |
| | | .select(ClothesSocialFollow::getType) |
| | | .eq(ClothesSocialFollow::getSourceId, socialId) |
| | | ); |
| | | if (CollUtil.isNotEmpty(clothesSocialFollows)){ |
| | | |
| | | Map<Integer, Long> collect = clothesSocialFollows.stream() |
| | | .collect(Collectors.groupingBy(ClothesSocialFollow::getType, Collectors.counting())); |
| | | apiSocialInfoVo.setLikeCnt(collect.getOrDefault(SocialTypeEnum.LIKE.getValue(), 0L).intValue()); |
| | | apiSocialInfoVo.setCollectCnt(collect.getOrDefault(SocialTypeEnum.COLLECT.getValue(), 0L).intValue()); |
| | | } |
| | | |
| | | List<ClothesSocialComment> clothesSocialComments = clothesSocialCommentMapper.selectList( |
| | | Wrappers.lambdaQuery(ClothesSocialComment.class) |
| | | .eq(ClothesSocialComment::getSocialId, socialId) |
| | | .eq(ClothesSocialComment::getShowState, ClothesEnum.UP.getCode()) |
| | | .isNull(ClothesSocialComment::getParentId) |
| | | ); |
| | | if (CollUtil.isNotEmpty(clothesSocialComments)){ |
| | | apiSocialInfoVo.setCommentCnt(clothesSocialComments.size()); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return new FebsResponse().success().data(record); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse comment(ApiClothesSocialCommentDto dto) { |
| | | |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | Long socialId = dto.getSocialId(); |
| | | Long commentId = dto.getCommentId(); |
| | | ClothesSocial clothesSocial = clothesSocialMapper.selectById(socialId); |
| | | if (ObjectUtil.isNull(clothesSocial)){ |
| | | return new FebsResponse().fail().message("社区不存在"); |
| | | } |
| | | if (ClothesEnum.DOWN.getCode() == clothesSocial.getCommentState()){ |
| | | return new FebsResponse().fail().message("禁止评论"); |
| | | } |
| | | ClothesSocialComment entity = new ClothesSocialComment(); |
| | | entity.setMemberId(memberId); |
| | | entity.setSocialId(socialId); |
| | | entity.setComment(dto.getComment()); |
| | | ClothesSocialComment clothesSocialComment = clothesSocialCommentMapper.selectById(commentId); |
| | | if(ObjectUtil.isNotNull(clothesSocialComment)){ |
| | | entity.setParentId(clothesSocialComment.getParentId()); |
| | | entity.setCommentId(clothesSocialComment.getId()); |
| | | } |
| | | clothesSocialCommentMapper.insert(entity); |
| | | |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse allComment(ApiAllCommentDto dto) { |
| | | // 创建分页对象,传入当前页和每页大小 |
| | | Page<ApiAllCommentVo> page = new Page<>(dto.getPageNow(), dto.getPageSize()); |
| | | // 调用Mapper方法获取活动分页数据 |
| | | Page<ApiAllCommentVo> voPage = clothesSocialCommentMapper.selectPageInComment(page, dto); |
| | | List<ApiAllCommentVo> records = voPage.getRecords(); |
| | | if (CollUtil.isNotEmpty(records)){ |
| | | Set<Long> collect = records.stream().map(ApiAllCommentVo::getCommentId).collect(Collectors.toSet()); |
| | | List<ClothesSocialComment> clothesSocialComments = clothesSocialCommentMapper.selectList( |
| | | Wrappers.lambdaQuery(ClothesSocialComment.class) |
| | | .select(ClothesSocialComment::getParentId) |
| | | .in(ClothesSocialComment::getParentId, collect) |
| | | .eq(ClothesSocialComment::getShowState, ClothesEnum.UP.getCode()) |
| | | ); |
| | | if (CollUtil.isNotEmpty(clothesSocialComments)){ |
| | | Map<Long, Long> collect1 = clothesSocialComments.stream() |
| | | .collect(Collectors.groupingBy(ClothesSocialComment::getParentId, Collectors.counting())); |
| | | for (ApiAllCommentVo vo : records){ |
| | | vo.setCommentCnt(collect1.getOrDefault(vo.getCommentId(), 0L).intValue()); |
| | | } |
| | | } |
| | | } |
| | | return new FebsResponse().success().data(voPage); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.putByPath("text", "123"); |