From f7de67c92de1bd55154c5a2f879e99a1b476750b Mon Sep 17 00:00:00 2001 From: Administrator <15274802129@163.com> Date: Fri, 18 Jul 2025 16:52:34 +0800 Subject: [PATCH] refactor(mall): 调整衣服分类逻辑 --- src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesSocialServiceImpl.java | 125 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 121 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesSocialServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesSocialServiceImpl.java index 6e9ee3b..5751a44 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesSocialServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesSocialServiceImpl.java @@ -27,9 +27,7 @@ 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 @@ -62,11 +60,16 @@ private final ClothesTypeArtMapper clothesTypeArtMapper; private final ClothesLocationRemarkMapper clothesLocationRemarkMapper; private final ClothesPatternRemarkMapper clothesPatternRemarkMapper; + private final ClothesSocialCommentMapper clothesSocialCommentMapper; @Override public FebsResponse allCategory() { List<ApiClothesCategoryInfoVo> vos = new ArrayList<>(); + ApiClothesCategoryInfoVo apiClothesCategoryInfoVo = new ApiClothesCategoryInfoVo(); + apiClothesCategoryInfoVo.setId(0L); + apiClothesCategoryInfoVo.setName("全部"); + vos.add(apiClothesCategoryInfoVo); List<ClothesSocialCategory> list = clothesSocialCategoryMapper.selectList( Wrappers.lambdaQuery(ClothesSocialCategory.class) .select(ClothesSocialCategory::getId, ClothesSocialCategory::getName) @@ -77,6 +80,7 @@ if(CollUtil.isNotEmpty(list)){ vos = buildApiClothesCategoryInfoVo(list, vos); } + return new FebsResponse().success().data(vos); } @@ -114,8 +118,36 @@ // 调用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::getSourceType, SocialSourceTypeEnum.SOCIAL.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) { @@ -130,6 +162,7 @@ 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) @@ -211,6 +244,32 @@ apiSocialMuseVo.setLocationRemarkList(locationRemarkList); } apiSocialMuseVo.setTotalAmount(totalAmount.setScale(2, RoundingMode.DOWN)); + + apiSocialInfoVo.setMuse(apiSocialMuseVo); + + List<ClothesSocialFollow> clothesSocialFollows = clothesSocialFollowMapper.selectList( + Wrappers.lambdaQuery(ClothesSocialFollow.class) + .select(ClothesSocialFollow::getType) + .eq(ClothesSocialFollow::getSourceId, socialId) + .eq(ClothesSocialFollow::getSourceType, SocialSourceTypeEnum.SOCIAL.getValue()) + ); + 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()); + } } } @@ -271,7 +330,7 @@ List<ClothesLocationRemark> clothesLocationRemarks = new ArrayList<>(); List<ClothesPatternRemark> clothesPatternRemarks = new ArrayList<>(); - if(CollUtil.isEmpty(clothesOrderItems)){ + if(CollUtil.isNotEmpty(clothesOrderItems)){ for (ClothesOrderItem item : clothesOrderItems){ if (ClothesOrderItemEnum.CLOTH.getCode() == item.getType()) { ClothesCloth cloth = clothesClothMapper.selectById(item.getItemId()); @@ -405,6 +464,7 @@ if(ObjectUtil.isNotNull(clothesSize)){ record.setSizeId(sizeId); record.setSizeName(clothesSize.getName()); + record.setSizeImage(clothesSize.getImage()); record.setSizePrice(clothesSize.getPrice()); } } @@ -422,6 +482,7 @@ ApiClothesPatternRemarkVo vo = new ApiClothesPatternRemarkVo(); ClothesPattern pattern = clothesPatternMapper.selectById(patternRemark.getPatternId()); vo.setPatternName(pattern.getName()); + vo.setPatternImage(pattern.getImage()); vo.setPatternPrice(pattern.getPrice()); vo.setPatternId(pattern.getId()); vo.setPatternRemark(patternRemark.getRemark()); @@ -446,6 +507,7 @@ ClothesLocation clothesLocation = clothesLocationMapper.selectById(locationRemark.getLocationId()); vo.setLocationName(clothesLocation.getName()); vo.setLocationRemark(locationRemark.getRemark()); + vo.setLocationImage(clothesLocation.getImage()); vo.setLocationPrice(clothesLocation.getPrice()); vo.setLocationId(clothesLocation.getId()); locationRemarkList.add(vo); @@ -463,6 +525,7 @@ ClothesArt clothesArt = clothesArtMapper.selectById(artId); if (ObjectUtil.isNotNull(clothesArt)){ record.setArtId(artId); + record.setArtImage(clothesArt.getImage()); record.setArtName(clothesArt.getName()); record.setArtPrice(clothesArt.getPrice()); } @@ -477,6 +540,7 @@ ClothesCloth clothesCloth = clothesClothMapper.selectById(clothId); if (ObjectUtil.isNotNull(clothesCloth)){ record.setClothId(clothId); + record.setClothImage(clothesCloth.getImage()); record.setClothName(clothesCloth.getName()); record.setClothPrice(clothesCloth.getPrice()); } @@ -496,6 +560,59 @@ 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.getId()); + 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"); -- Gitblit v1.9.1