From aae9a494f83882a004311d3bb95b1eb081f38f02 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 10 Jul 2025 16:13:45 +0800
Subject: [PATCH] refactor(mall): 优化身材数据选择逻辑

---
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java |  144 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 97 insertions(+), 47 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
index 3ddad7e..42e3832 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
@@ -74,6 +74,9 @@
     private final IApiMallMemberWalletService apiMallMemberWalletService;
     private final IMallMoneyFlowService mallMoneyFlowService;
 
+    private final ClothesPatternRemarkMapper clothesPatternRemarkMapper;
+    private final ClothesLocationRemarkMapper clothesLocationRemarkMapper;
+
     @Override
     public FebsResponse myDraft(ApiMyDraftPageDto dto) {
 
@@ -112,30 +115,50 @@
                     record.setStatureName(clothesMemberStature.getName());
                 }
 
-                Long patternId = ObjectUtil.defaultIfNull(record.getPatternId(),0L);
-                List<ClothesTypePattern> clothesTypePatterns = clothesTypePatternMapper.selectList(Wrappers.<ClothesTypePattern>lambdaQuery().eq(ClothesTypePattern::getTypeId, typeId));
-                if (CollUtil.isNotEmpty(clothesTypePatterns)){
-                    Set<Long> patternIds = clothesTypePatterns.stream().map(ClothesTypePattern::getPatternId).collect(Collectors.toSet());
-                    if(CollUtil.isNotEmpty( patternIds) && patternIds.contains(patternId)){
+                BigDecimal totalPatternPrice = BigDecimal.ZERO;
+                List<ClothesPatternRemark> clothesPatternRemarks = clothesPatternRemarkMapper.selectList(
+                        Wrappers.lambdaQuery(ClothesPatternRemark.class)
+                                .eq(ClothesPatternRemark::getSourceId, record.getId())
+                                .eq(ClothesPatternRemark::getType, SocialPatternLocationTypeEnum.DRAFT.getValue())
+                );
+                if(CollUtil.isNotEmpty(clothesPatternRemarks)){
+                    List<ApiClothesPatternInfoVo> vos = new ArrayList<>();
+                    for (ClothesPatternRemark entity : clothesPatternRemarks){
+                        Long patternId = entity.getPatternId();
+                        ApiClothesPatternInfoVo vo = new ApiClothesPatternInfoVo();
+                        vo.setPatternId(patternId);
                         ClothesPattern clothesPattern = clothesPatternMapper.selectById(patternId);
-                        if (ObjectUtil.isNotNull(clothesPattern)){
-                            record.setPatternName(clothesPattern.getName());
-                            record.setPatternPrice(clothesPattern.getPrice());
-                        }
+                        vo.setPatternName(clothesPattern.getName());
+                        vo.setPatternPrice(clothesPattern.getPrice());
+                        vo.setPatternRemark(entity.getRemark());
+                        vos.add(vo);
+
+                        totalPatternPrice = totalPatternPrice.add(clothesPattern.getPrice());
                     }
+                    record.setPatternList(vos);
                 }
 
-                Long locationId = ObjectUtil.defaultIfNull(record.getLocationId(),0L);
-                List<ClothesTypeLocation> clothesTypeLocations = clothesTypeLocationMapper.selectList(Wrappers.<ClothesTypeLocation>lambdaQuery().eq(ClothesTypeLocation::getTypeId, typeId));
-                if (CollUtil.isNotEmpty(clothesTypeLocations)){
-                    Set<Long> locationIds = clothesTypeLocations.stream().map(ClothesTypeLocation::getLocationId).collect(Collectors.toSet());
-                    if(CollUtil.isNotEmpty( locationIds) && locationIds.contains(locationId)){
-                        ClothesLocation clothesLocation = clothesLocationMapper.selectById(locationId);
-                        if (ObjectUtil.isNotNull(clothesLocation)){
-                            record.setLocationName(clothesLocation.getName());
-                            record.setLocationPrice(clothesLocation.getPrice());
-                        }
+                BigDecimal totalLocationPrice = BigDecimal.ZERO;
+                List<ClothesLocationRemark> clothesLocationRemarks = clothesLocationRemarkMapper.selectList(
+                        Wrappers.lambdaQuery(ClothesLocationRemark.class)
+                                .eq(ClothesLocationRemark::getSourceId, record.getId())
+                                .eq(ClothesLocationRemark::getType, SocialPatternLocationTypeEnum.DRAFT.getValue())
+                );
+                if(CollUtil.isNotEmpty(clothesLocationRemarks)){
+                    List<ApiClothesLocationInfoVo> vos = new ArrayList<>();
+                    for (ClothesLocationRemark entity : clothesLocationRemarks){
+                        Long locationId = entity.getLocationId();
+                        ApiClothesLocationInfoVo vo = new ApiClothesLocationInfoVo();
+                        vo.setLocationId(locationId);
+                        ClothesLocation location = clothesLocationMapper.selectById(locationId);
+                        vo.setLocationName(location.getName());
+                        vo.setLocationPrice(location.getPrice());
+                        vo.setLocationRemark(entity.getRemark());
+                        vos.add(vo);
+
+                        totalLocationPrice = totalLocationPrice.add(location.getPrice());
                     }
+                    record.setLocationList(vos);
                 }
 
                 Long artId = ObjectUtil.defaultIfNull(record.getArtId(),0L);
@@ -165,11 +188,11 @@
                 }
 
                 BigDecimal amount =
-                        record.getClothPrice()
-                                .add(record.getLocationPrice())
+                                record.getClothPrice()
+                                .add(totalPatternPrice)
                                 .add(record.getArtPrice())
                                 .add(record.getSizePrice())
-                                .add(record.getPatternPrice()).setScale(2, RoundingMode.DOWN);
+                                .add(totalLocationPrice).setScale(2, RoundingMode.DOWN);
                 record.setAmount(amount);
             }
         }
@@ -192,7 +215,6 @@
             record.setTypeId(typeId);
             record.setTypeName(clothesType.getName());
             record.setTypeImage(clothesType.getImage());
-            record.setPatternRemark(clothesOrderDraft.getPatternRemark());
 
             Long sizeId = ObjectUtil.defaultIfNull(clothesOrderDraft.getSizeId(),0L);
             List<ClothesTypeSize> clothesTypeSizes = clothesTypeSizeMapper.selectList(Wrappers.<ClothesTypeSize>lambdaQuery().eq(ClothesTypeSize::getTypeId, typeId));
@@ -215,32 +237,50 @@
                 record.setStatureName(clothesMemberStature.getName());
             }
 
-            Long patternId = ObjectUtil.defaultIfNull(clothesOrderDraft.getPatternId(),0L);
-            List<ClothesTypePattern> clothesTypePatterns = clothesTypePatternMapper.selectList(Wrappers.<ClothesTypePattern>lambdaQuery().eq(ClothesTypePattern::getTypeId, typeId));
-            if (CollUtil.isNotEmpty(clothesTypePatterns)){
-                Set<Long> patternIds = clothesTypePatterns.stream().map(ClothesTypePattern::getPatternId).collect(Collectors.toSet());
-                if(CollUtil.isNotEmpty( patternIds) && patternIds.contains(patternId)){
+            BigDecimal totalPatternPrice = BigDecimal.ZERO;
+            List<ClothesPatternRemark> clothesPatternRemarks = clothesPatternRemarkMapper.selectList(
+                    Wrappers.lambdaQuery(ClothesPatternRemark.class)
+                            .eq(ClothesPatternRemark::getSourceId, record.getId())
+                            .eq(ClothesPatternRemark::getType, SocialPatternLocationTypeEnum.DRAFT.getValue())
+            );
+            if(CollUtil.isNotEmpty(clothesPatternRemarks)){
+                List<ApiClothesPatternInfoVo> vos = new ArrayList<>();
+                for (ClothesPatternRemark entity : clothesPatternRemarks){
+                    Long patternId = entity.getPatternId();
+                    ApiClothesPatternInfoVo vo = new ApiClothesPatternInfoVo();
+                    vo.setPatternId(patternId);
                     ClothesPattern clothesPattern = clothesPatternMapper.selectById(patternId);
-                    if (ObjectUtil.isNotNull(clothesPattern)){
-                        record.setPatternId(patternId);
-                        record.setPatternName(clothesPattern.getName());
-                        record.setPatternPrice(clothesPattern.getPrice());
-                    }
+                    vo.setPatternName(clothesPattern.getName());
+                    vo.setPatternPrice(clothesPattern.getPrice());
+                    vo.setPatternRemark(entity.getRemark());
+                    vos.add(vo);
+
+                    totalPatternPrice = totalPatternPrice.add(clothesPattern.getPrice());
                 }
+                record.setPatternList(vos);
             }
 
-            Long locationId = ObjectUtil.defaultIfNull(clothesOrderDraft.getLocationId(),0L);
-            List<ClothesTypeLocation> clothesTypeLocations = clothesTypeLocationMapper.selectList(Wrappers.<ClothesTypeLocation>lambdaQuery().eq(ClothesTypeLocation::getTypeId, typeId));
-            if (CollUtil.isNotEmpty(clothesTypeLocations)){
-                Set<Long> locationIds = clothesTypeLocations.stream().map(ClothesTypeLocation::getLocationId).collect(Collectors.toSet());
-                if(CollUtil.isNotEmpty( locationIds) && locationIds.contains(locationId)){
-                    ClothesLocation clothesLocation = clothesLocationMapper.selectById(locationId);
-                    if (ObjectUtil.isNotNull(clothesLocation)){
-                        record.setLocationId(locationId);
-                        record.setLocationName(clothesLocation.getName());
-                        record.setLocationPrice(clothesLocation.getPrice());
-                    }
+            BigDecimal totalLocationPrice = BigDecimal.ZERO;
+            List<ClothesLocationRemark> clothesLocationRemarks = clothesLocationRemarkMapper.selectList(
+                    Wrappers.lambdaQuery(ClothesLocationRemark.class)
+                            .eq(ClothesLocationRemark::getSourceId, record.getId())
+                            .eq(ClothesLocationRemark::getType, SocialPatternLocationTypeEnum.DRAFT.getValue())
+            );
+            if(CollUtil.isNotEmpty(clothesLocationRemarks)){
+                List<ApiClothesLocationInfoVo> vos = new ArrayList<>();
+                for (ClothesLocationRemark entity : clothesLocationRemarks){
+                    Long locationId = entity.getLocationId();
+                    ApiClothesLocationInfoVo vo = new ApiClothesLocationInfoVo();
+                    vo.setLocationId(locationId);
+                    ClothesLocation location = clothesLocationMapper.selectById(locationId);
+                    vo.setLocationName(location.getName());
+                    vo.setLocationPrice(location.getPrice());
+                    vo.setLocationRemark(entity.getRemark());
+                    vos.add(vo);
+
+                    totalLocationPrice = totalLocationPrice.add(location.getPrice());
                 }
+                record.setLocationList(vos);
             }
 
             Long artId = ObjectUtil.defaultIfNull(clothesOrderDraft.getArtId(),0L);
@@ -273,10 +313,10 @@
 
             BigDecimal amount =
                     record.getClothPrice()
-                            .add(record.getLocationPrice())
+                            .add(totalPatternPrice)
                             .add(record.getArtPrice())
                             .add(record.getSizePrice())
-                            .add(record.getPatternPrice()).setScale(2, RoundingMode.DOWN);
+                            .add(totalLocationPrice).setScale(2, RoundingMode.DOWN);
             record.setAmount(amount);
         }
 
@@ -372,6 +412,7 @@
         clothesOrderMapper.insert(orderInfo);
 
         Long orderId = orderInfo.getId();
+
         /**
          * 创建订单子表
          */
@@ -381,15 +422,17 @@
             orderItem.setMemberId(memberId);
             orderItem.setOrderId(orderId);
             orderItem.setType(item.getType());
+            orderItem.setItemCnt(dto.getCnt());
             if (ClothesOrderItemEnum.CLOTH.getCode() == item.getType()) {
                 ClothesCloth cloth = clothesClothMapper.selectById(item.getSkuId());
                 if (ObjectUtil.isNull(cloth)) {
                     throw new FebsException("请选择布料");
                 }
+                orderItem.setItemId(cloth.getId());
                 orderItem.setName(cloth.getName());
                 orderItem.setPrice(cloth.getPrice());
                 orderItem.setItemCnt(item.getCnt());
-                orderItem.setAmount(cloth.getPrice().multiply(new BigDecimal(item.getCnt())).setScale(2, RoundingMode.DOWN));
+                orderItem.setAmount(cloth.getPrice().multiply(new BigDecimal(orderItem.getItemCnt())).setScale(2, RoundingMode.DOWN));
                 clothesOrderItemMapper.insert(orderItem);
 
                 total = total.add(orderItem.getAmount());
@@ -399,6 +442,7 @@
                 if (ObjectUtil.isNull(size)) {
                     throw new FebsException("请选择尺寸");
                 }
+                orderItem.setItemId(size.getId());
                 orderItem.setName(size.getName());
                 orderItem.setPrice(size.getPrice());
                 orderItem.setItemCnt(item.getCnt());
@@ -412,10 +456,12 @@
                 if (ObjectUtil.isNull(location)) {
                     throw new FebsException("请选择图案位置");
                 }
+                orderItem.setItemId(location.getId());
                 orderItem.setName(location.getName());
                 orderItem.setPrice(location.getPrice());
                 orderItem.setItemCnt(item.getCnt());
                 orderItem.setAmount(orderItem.getPrice().multiply(new BigDecimal(orderItem.getItemCnt())).setScale(2, RoundingMode.DOWN));
+                orderItem.setRemark(item.getPatternRemark());
                 clothesOrderItemMapper.insert(orderItem);
 
                 total = total.add(orderItem.getAmount());
@@ -425,10 +471,12 @@
                 if (ObjectUtil.isNull(pattern)) {
                     throw new FebsException("请选择图案");
                 }
+                orderItem.setItemId(pattern.getId());
                 orderItem.setRemark(item.getPatternRemark());
                 orderItem.setName(pattern.getName());
                 orderItem.setPrice(pattern.getPrice());
                 orderItem.setItemCnt(item.getCnt());
+                orderItem.setRemark(item.getPatternRemark());
                 orderItem.setAmount(orderItem.getPrice().multiply(new BigDecimal(orderItem.getItemCnt())).setScale(2, RoundingMode.DOWN));
                 clothesOrderItemMapper.insert(orderItem);
 
@@ -439,6 +487,7 @@
                 if (ObjectUtil.isNull(art)) {
                     throw new FebsException("请选择工艺");
                 }
+                orderItem.setItemId(art.getId());
                 orderItem.setName(art.getName());
                 orderItem.setPrice(art.getPrice());
                 orderItem.setItemCnt(item.getCnt());
@@ -449,6 +498,7 @@
                 continue;
             } else if (ClothesOrderItemEnum.CUSTOMIZE.getCode() == item.getType()) {
                 ClothesMemberStature clothesMemberStature = clothesMemberStatureMapper.selectById(item.getSkuId());
+                orderItem.setItemId(clothesMemberStature.getId());
                 orderItem.setName(clothesMemberStature.getName());
                 orderItem.setPrice(BigDecimal.ZERO);
                 orderItem.setItemCnt(item.getCnt());

--
Gitblit v1.9.1