Commit 91240351ed55fdf89a9b2e6c49f7b0274a98143a

Authored by puhui999
1 parent 5c3a9604

【代码优化】商城: 完成代码评审 TODO

yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java
... ... @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.product.api.spu.dto;
3 3 import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
4 4 import lombok.Data;
5 5  
  6 +import java.util.List;
  7 +
6 8 /**
7 9 * 商品 SPU 信息 Response DTO
8 10 *
... ... @@ -69,6 +71,13 @@ public class ProductSpuRespDTO {
69 71 // ========== 物流相关字段 =========
70 72  
71 73 /**
  74 + * 配送方式数组
  75 + *
  76 + * 对应 DeliveryTypeEnum 枚举
  77 + */
  78 + private List<Integer> deliveryTypes;
  79 +
  80 + /**
72 81 * 物流配置模板编号
73 82 *
74 83 * 对应 TradeDeliveryExpressTemplateDO 的 id 编号
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java
... ... @@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil;
6 6 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
7 7 import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
8 8 import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
  9 +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
  10 +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
9 11 import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO;
10 12 import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO;
11 13 import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum;
... ... @@ -17,18 +19,19 @@ import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplate
17 19 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
18 20 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
19 21 import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO.OrderItem;
  22 +import jakarta.annotation.Resource;
20 23 import lombok.extern.slf4j.Slf4j;
21 24 import org.springframework.core.annotation.Order;
22 25 import org.springframework.stereotype.Component;
23 26  
24   -import jakarta.annotation.Resource;
25 27 import java.util.List;
26 28 import java.util.Map;
27 29 import java.util.Set;
28 30  
29 31 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
30 32 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
31   -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
  33 +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PICK_UP_STORE_NOT_EXISTS;
  34 +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND;
32 35  
33 36 /**
34 37 * 运费的 {@link TradePriceCalculator} 实现类
... ... @@ -49,13 +52,20 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
49 52 private DeliveryExpressTemplateService deliveryExpressTemplateService;
50 53 @Resource
51 54 private TradeConfigService tradeConfigService;
  55 + @Resource
  56 + private ProductSpuApi productSpuApi;
52 57  
53 58 @Override
54 59 public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
55 60 if (param.getDeliveryType() == null) {
56 61 return;
57 62 }
58   - // TODO @puhui999:需要校验,是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈
  63 + // 校验是不是存在商品不能门店自提,或者不能快递发货的情况。就是说,配送方式不匹配哈
  64 + List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(convertSet(result.getItems(), OrderItem::getSpuId));
  65 + if (anyMatch(spuList, item -> !item.getDeliveryTypes().contains(param.getDeliveryType()))) {
  66 + return;
  67 + }
  68 +
59 69 if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) {
60 70 calculateByPickUp(param);
61 71 } else if (DeliveryTypeEnum.EXPRESS.getType().equals(param.getDeliveryType())) {
... ... @@ -124,7 +134,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
124 134 Map<Long, List<OrderItem>> template2ItemMap = convertMultiMap(selectedSkus, OrderItem::getDeliveryTemplateId);
125 135 // 依次计算快递运费
126 136 for (Map.Entry<Long, List<OrderItem>> entry : template2ItemMap.entrySet()) {
127   - Long templateId = entry.getKey();
  137 + Long templateId = entry.getKey();
128 138 List<OrderItem> orderItems = entry.getValue();
129 139 DeliveryExpressTemplateRespBO templateBO = expressTemplateMap.get(templateId);
130 140 if (templateBO == null) {
... ... @@ -144,8 +154,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
144 154 /**
145 155 * 按配送方式来计算运费
146 156 *
147   - * @param orderItems SKU 商品项目
148   - * @param chargeMode 配送计费方式
  157 + * @param orderItems SKU 商品项目
  158 + * @param chargeMode 配送计费方式
149 159 * @param templateCharge 快递运费配置
150 160 */
151 161 private void calculateExpressFeeByChargeMode(List<OrderItem> orderItems, Integer chargeMode,
... ...
yudao-module-member/yudao-module-member-biz/pom.xml
... ... @@ -33,12 +33,6 @@
33 33 <artifactId>yudao-module-infra-api</artifactId>
34 34 <version>${revision}</version>
35 35 </dependency>
36   - <!-- TODO @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。 -->
37   - <dependency>
38   - <groupId>cn.iocoder.boot</groupId>
39   - <artifactId>yudao-module-pay-api</artifactId>
40   - <version>${revision}</version>
41   - </dependency>
42 36  
43 37 <!-- 业务组件 -->
44 38 <dependency>
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java
... ... @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.member.controller.admin.user;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7 6 import cn.iocoder.yudao.module.member.controller.admin.user.vo.*;
8 7 import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert;
9 8 import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO;
... ... @@ -16,8 +15,6 @@ import cn.iocoder.yudao.module.member.service.level.MemberLevelService;
16 15 import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService;
17 16 import cn.iocoder.yudao.module.member.service.tag.MemberTagService;
18 17 import cn.iocoder.yudao.module.member.service.user.MemberUserService;
19   -import cn.iocoder.yudao.module.pay.api.wallet.PayWalletApi;
20   -import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO;
21 18 import io.swagger.v3.oas.annotations.Operation;
22 19 import io.swagger.v3.oas.annotations.Parameter;
23 20 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -53,8 +50,6 @@ public class MemberUserController {
53 50 private MemberGroupService memberGroupService;
54 51 @Resource
55 52 private MemberPointRecordService memberPointRecordService;
56   - @Resource
57   - private PayWalletApi payWalletApi;
58 53  
59 54 @PutMapping("/update")
60 55 @Operation(summary = "更新会员用户")
... ... @@ -81,15 +76,6 @@ public class MemberUserController {
81 76 return success(true);
82 77 }
83 78  
84   - @PutMapping("/update-balance")
85   - @Operation(summary = "更新会员用户余额")
86   - @PreAuthorize("@ss.hasPermission('member:user:update-balance')")
87   - public CommonResult<Boolean> updateUserBalance(@Valid @RequestBody MemberUserUpdateBalanceReqVO updateReqVO) {
88   - payWalletApi.updateBalance(BeanUtils.toBean(updateReqVO, PayWalletUpdateBalanceReqDTO.class)
89   - .setUserId(updateReqVO.getId()));
90   - return success(true);
91   - }
92   -
93 79 @GetMapping("/get")
94 80 @Operation(summary = "获得会员用户")
95 81 @Parameter(name = "id", description = "编号", required = true, example = "1024")
... ...
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java deleted
1   -package cn.iocoder.yudao.module.pay.api.wallet;
2   -
3   -import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO;
4   -
5   -// TODO @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。
6   -/**
7   - * 会员钱包 API 接口
8   - *
9   - * @author HUIHUI
10   - */
11   -public interface PayWalletApi {
12   -
13   - /**
14   - * 更新钱包余额
15   - *
16   - * @param reqDTO 请求
17   - */
18   - void updateBalance(PayWalletUpdateBalanceReqDTO reqDTO);
19   -
20   -}
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/PayWalletUpdateBalanceReqDTO.java deleted
1   -package cn.iocoder.yudao.module.pay.api.wallet.dto;
2   -
3   -import jakarta.validation.constraints.NotNull;
4   -import lombok.Data;
5   -
6   -// TODO @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。
7   -/**
8   - * 钱包余额更新 Request DTO
9   - *
10   - * @author HUIHUI
11   - */
12   -@Data
13   -public class PayWalletUpdateBalanceReqDTO {
14   -
15   - @NotNull(message = "用户编号不能为空")
16   - private Long userId;
17   -
18   - /**
19   - * 变动余额,正数为增加,负数为减少
20   - */
21   - @NotNull(message = "变动余额不能为空")
22   - private Integer balance;
23   -
24   -}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java deleted
1   -package cn.iocoder.yudao.module.pay.api.wallet;
2   -
3   -import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO;
4   -import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
5   -import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
6   -import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
7   -import jakarta.annotation.Resource;
8   -import lombok.extern.slf4j.Slf4j;
9   -import org.springframework.stereotype.Service;
10   -import org.springframework.validation.annotation.Validated;
11   -
12   -import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
13   -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
14   -import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
15   -
16   -// @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。
17   -/**
18   - * 会员钱包 API 实现类
19   - *
20   - * @author HUIHUI
21   - */
22   -@Service
23   -@Validated
24   -@Slf4j
25   -public class PayWalletApiImpl implements PayWalletApi {
26   -
27   - @Resource
28   - private PayWalletService payWalletService;
29   -
30   - @Override
31   - public void updateBalance(PayWalletUpdateBalanceReqDTO reqDTO) {
32   - // 获得用户钱包
33   - PayWalletDO wallet = payWalletService.getOrCreateWallet(reqDTO.getUserId(), MEMBER.getValue());
34   - if (wallet == null) {
35   - log.error("[updateBalance],reqDTO({}) 用户钱包不存在.", reqDTO);
36   - throw exception(WALLET_NOT_FOUND);
37   - }
38   -
39   - // 更新钱包余额
40   - payWalletService.addWalletBalance(wallet.getId(), String.valueOf(reqDTO.getUserId()),
41   - PayWalletBizTypeEnum.UPDATE_BALANCE, reqDTO.getBalance());
42   - }
43   -
44   -}
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletController.java
... ... @@ -4,9 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
6 6 import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
  7 +import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUpdateBalanceReqVO;
7 8 import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUserReqVO;
8 9 import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert;
9 10 import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
  11 +import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
10 12 import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
11 13 import io.swagger.v3.oas.annotations.Operation;
12 14 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -15,12 +17,12 @@ import jakarta.validation.Valid;
15 17 import lombok.extern.slf4j.Slf4j;
16 18 import org.springframework.security.access.prepost.PreAuthorize;
17 19 import org.springframework.validation.annotation.Validated;
18   -import org.springframework.web.bind.annotation.GetMapping;
19   -import org.springframework.web.bind.annotation.RequestMapping;
20   -import org.springframework.web.bind.annotation.RestController;
  20 +import org.springframework.web.bind.annotation.*;
21 21  
22 22 import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
  23 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
23 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  25 +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
24 26  
25 27 @Tag(name = "管理后台 - 用户钱包")
26 28 @RestController
... ... @@ -48,6 +50,21 @@ public class PayWalletController {
48 50 return success(PayWalletConvert.INSTANCE.convertPage(pageResult));
49 51 }
50 52  
51   - // TODO @puhui999:修改钱包余额,权限标识,记得加下噢
  53 + @PutMapping("/update-balance")
  54 + @Operation(summary = "更新会员用户余额")
  55 + @PreAuthorize("@ss.hasPermission('pay:wallet:update-balance')")
  56 + public CommonResult<Boolean> updateWalletBalance(@Valid @RequestBody PayWalletUpdateBalanceReqVO updateReqVO) {
  57 + // 获得用户钱包
  58 + PayWalletDO wallet = payWalletService.getOrCreateWallet(updateReqVO.getUserId(), MEMBER.getValue());
  59 + if (wallet == null) {
  60 + log.error("[updateWalletBalance],updateReqVO({}) 用户钱包不存在.", updateReqVO);
  61 + throw exception(WALLET_NOT_FOUND);
  62 + }
  63 +
  64 + // 更新钱包余额
  65 + payWalletService.addWalletBalance(wallet.getId(), String.valueOf(updateReqVO.getUserId()),
  66 + PayWalletBizTypeEnum.UPDATE_BALANCE, updateReqVO.getBalance());
  67 + return success(true);
  68 + }
52 69  
53 70 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateBalanceReqVO.java renamed to yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/vo/wallet/PayWalletUpdateBalanceReqVO.java
1   -package cn.iocoder.yudao.module.member.controller.admin.user.vo;
  1 +package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import jakarta.validation.constraints.NotNull;
5 5 import lombok.Data;
6   -import lombok.ToString;
7 6  
8   -@Schema(description = "管理后台 - 用户修改余额 Request VO")
  7 +@Schema(description = "管理后台 - 修改钱包余额 Request VO")
9 8 @Data
10   -@ToString(callSuper = true)
11   -public class MemberUserUpdateBalanceReqVO {
  9 +public class PayWalletUpdateBalanceReqVO {
12 10  
13 11 @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23788")
14 12 @NotNull(message = "用户编号不能为空")
15   - private Long id;
  13 + private Long userId;
16 14  
17 15 @Schema(description = "变动余额,正数为增加,负数为减少", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
18 16 @NotNull(message = "变动余额不能为空")
... ...