Commit 5a788af084e6e1f493e908a4f8ab5710432457b7
1 parent
cc71aabd
购物车:简化 cart 表命名
Showing
17 changed files
with
141 additions
and
159 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/TradeCartController.http renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/AppCartController.http
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/TradeCartController.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/AppCartController.java
| ... | ... | @@ -2,11 +2,8 @@ package cn.iocoder.yudao.module.trade.controller.app.cart; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 5 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartAddReqVO; | |
| 6 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | |
| 7 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartResetReqVO; | |
| 8 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartUpdateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.trade.service.cart.TradeCartService; | |
| 5 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.trade.service.cart.CartService; | |
| 10 | 7 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | 8 | import io.swagger.v3.oas.annotations.Parameter; |
| 12 | 9 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -29,30 +26,38 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 29 | 26 | @RequiredArgsConstructor |
| 30 | 27 | @Validated |
| 31 | 28 | @Slf4j |
| 32 | -public class TradeCartController { | |
| 29 | +public class AppCartController { | |
| 33 | 30 | |
| 34 | 31 | @Resource |
| 35 | - private TradeCartService cartService; | |
| 32 | + private CartService cartService; | |
| 36 | 33 | |
| 37 | 34 | @PostMapping("/add") |
| 38 | 35 | @Operation(summary = "添加购物车商品") |
| 39 | 36 | @PreAuthenticated |
| 40 | - public CommonResult<Long> addCart(@Valid @RequestBody AppTradeCartAddReqVO addCountReqVO) { | |
| 37 | + public CommonResult<Long> addCart(@Valid @RequestBody AppCartAddReqVO addCountReqVO) { | |
| 41 | 38 | return success(cartService.addCart(getLoginUserId(), addCountReqVO)); |
| 42 | 39 | } |
| 43 | 40 | |
| 44 | - @PutMapping("/update") | |
| 45 | - @Operation(summary = "更新购物车商品") | |
| 41 | + @PutMapping("/update-count") | |
| 42 | + @Operation(summary = "更新购物车商品数量") | |
| 46 | 43 | @PreAuthenticated |
| 47 | - public CommonResult<Boolean> updateCart(@Valid @RequestBody AppTradeCartUpdateReqVO updateReqVO) { | |
| 48 | - cartService.updateCart(getLoginUserId(), updateReqVO); | |
| 44 | + public CommonResult<Boolean> updateCartCount(@Valid @RequestBody AppCartUpdateCountReqVO updateReqVO) { | |
| 45 | + cartService.updateCartCount(getLoginUserId(), updateReqVO); | |
| 46 | + return success(true); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @PutMapping("/update-selected") | |
| 50 | + @Operation(summary = "更新购物车商品选中") | |
| 51 | + @PreAuthenticated | |
| 52 | + public CommonResult<Boolean> updateCartSelected(@Valid @RequestBody AppCartUpdateSelectedReqVO updateReqVO) { | |
| 53 | + cartService.updateCartSelected(getLoginUserId(), updateReqVO); | |
| 49 | 54 | return success(true); |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | 57 | @PutMapping("/reset") |
| 53 | 58 | @Operation(summary = "重置购物车商品") |
| 54 | 59 | @PreAuthenticated |
| 55 | - public CommonResult<Boolean> resetCart(@Valid @RequestBody AppTradeCartResetReqVO updateReqVO) { | |
| 60 | + public CommonResult<Boolean> resetCart(@Valid @RequestBody AppCartResetReqVO updateReqVO) { | |
| 56 | 61 | cartService.resetCart(getLoginUserId(), updateReqVO); |
| 57 | 62 | return success(true); |
| 58 | 63 | } |
| ... | ... | @@ -83,7 +88,7 @@ public class TradeCartController { |
| 83 | 88 | @GetMapping("/list") |
| 84 | 89 | @Operation(summary = "查询用户的购物车列表") |
| 85 | 90 | @PreAuthenticated |
| 86 | - public CommonResult<AppTradeCartListRespVO> getCartList() { | |
| 91 | + public CommonResult<AppCartListRespVO> getCartList() { | |
| 87 | 92 | return success(cartService.getCartList(getLoginUserId())); |
| 88 | 93 | } |
| 89 | 94 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartAddReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartAddReqVO.java
| ... | ... | @@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull; |
| 7 | 7 | |
| 8 | 8 | @Schema(description = "用户 App - 购物车添加购物项 Request VO") |
| 9 | 9 | @Data |
| 10 | -public class AppTradeCartAddReqVO { | |
| 10 | +public class AppCartAddReqVO { | |
| 11 | 11 | |
| 12 | 12 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED,example = "1024") |
| 13 | 13 | @NotNull(message = "商品 SKU 编号不能为空") |
| ... | ... | @@ -17,8 +17,4 @@ public class AppTradeCartAddReqVO { |
| 17 | 17 | @NotNull(message = "数量不能为空") |
| 18 | 18 | private Integer count; |
| 19 | 19 | |
| 20 | - @Schema(description = "是否添加到购物车", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 21 | - @NotNull(message = "是否添加购物车不能为空") | |
| 22 | - private Boolean addStatus; | |
| 23 | - | |
| 24 | 20 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartDetailRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartDetailRespVO.java
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartListRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartListRespVO.java
| ... | ... | @@ -9,7 +9,7 @@ import java.util.List; |
| 9 | 9 | |
| 10 | 10 | @Schema(description = "用户 App - 用户的购物列表 Response VO") |
| 11 | 11 | @Data |
| 12 | -public class AppTradeCartListRespVO { | |
| 12 | +public class AppCartListRespVO { | |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * 有效的购物项数组 |
| ... | ... | @@ -31,6 +31,9 @@ public class AppTradeCartListRespVO { |
| 31 | 31 | @Schema(description = "商品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 32 | 32 | private Integer count; |
| 33 | 33 | |
| 34 | + @Schema(description = "是否选中", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 35 | + private Boolean selected; | |
| 36 | + | |
| 34 | 37 | /** |
| 35 | 38 | * 商品 SPU |
| 36 | 39 | */ | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartResetReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartResetReqVO.java
| ... | ... | @@ -8,7 +8,7 @@ import javax.validation.constraints.NotNull; |
| 8 | 8 | |
| 9 | 9 | @Schema(description = "用户 App - 购物车重置 Request VO") |
| 10 | 10 | @Data |
| 11 | -public class AppTradeCartResetReqVO { | |
| 11 | +public class AppCartResetReqVO { | |
| 12 | 12 | |
| 13 | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 14 | 14 | @NotNull(message = "编号不能为空") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartUpdateReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartUpdateCountReqVO.java
| ... | ... | @@ -6,9 +6,9 @@ import lombok.Data; |
| 6 | 6 | import javax.validation.constraints.Min; |
| 7 | 7 | import javax.validation.constraints.NotNull; |
| 8 | 8 | |
| 9 | -@Schema(description = "用户 App - 购物车更新 Request VO") | |
| 9 | +@Schema(description = "用户 App - 购物车更新数量 Request VO") | |
| 10 | 10 | @Data |
| 11 | -public class AppTradeCartUpdateReqVO { | |
| 11 | +public class AppCartUpdateCountReqVO { | |
| 12 | 12 | |
| 13 | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 14 | 14 | @NotNull(message = "编号不能为空") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartItemUpdateSelectedReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartUpdateSelectedReqVO.java
| ... | ... | @@ -8,11 +8,11 @@ import java.util.Collection; |
| 8 | 8 | |
| 9 | 9 | @Schema(description = "用户 App - 购物车更新是否选中 Request VO") |
| 10 | 10 | @Data |
| 11 | -public class AppTradeCartItemUpdateSelectedReqVO { | |
| 11 | +public class AppCartUpdateSelectedReqVO { | |
| 12 | 12 | |
| 13 | - @Schema(description = "商品 SKU 编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024,2048") | |
| 14 | - @NotNull(message = "商品 SKU 编号列表不能为空") | |
| 15 | - private Collection<Long> skuIds; | |
| 13 | + @Schema(description = "编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024,2048") | |
| 14 | + @NotNull(message = "编号列表不能为空") | |
| 15 | + private Collection<Long> ids; | |
| 16 | 16 | |
| 17 | 17 | @Schema(description = "是否选中", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 18 | 18 | @NotNull(message = "是否选中不能为空") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/cart/TradeCartConvert.java
| ... | ... | @@ -5,8 +5,8 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 6 | 6 | import cn.iocoder.yudao.module.trade.controller.app.base.sku.AppProductSkuBaseRespVO; |
| 7 | 7 | import cn.iocoder.yudao.module.trade.controller.app.base.spu.AppProductSpuBaseRespVO; |
| 8 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | |
| 9 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 8 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppCartListRespVO; | |
| 9 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 10 | 10 | import org.mapstruct.Mapper; |
| 11 | 11 | import org.mapstruct.factory.Mappers; |
| 12 | 12 | |
| ... | ... | @@ -21,16 +21,16 @@ public interface TradeCartConvert { |
| 21 | 21 | |
| 22 | 22 | TradeCartConvert INSTANCE = Mappers.getMapper(TradeCartConvert.class); |
| 23 | 23 | |
| 24 | - default AppTradeCartListRespVO convertList(List<TradeCartDO> carts, | |
| 25 | - List<ProductSpuRespDTO> spus, List<ProductSkuRespDTO> skus) { | |
| 24 | + default AppCartListRespVO convertList(List<CartDO> carts, | |
| 25 | + List<ProductSpuRespDTO> spus, List<ProductSkuRespDTO> skus) { | |
| 26 | 26 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spus, ProductSpuRespDTO::getId); |
| 27 | 27 | Map<Long, ProductSkuRespDTO> skuMap = convertMap(skus, ProductSkuRespDTO::getId); |
| 28 | 28 | // 遍历,开始转换 |
| 29 | - List<AppTradeCartListRespVO.Cart> validList = new ArrayList<>(carts.size()); | |
| 30 | - List<AppTradeCartListRespVO.Cart> invalidList = new ArrayList<>(); | |
| 29 | + List<AppCartListRespVO.Cart> validList = new ArrayList<>(carts.size()); | |
| 30 | + List<AppCartListRespVO.Cart> invalidList = new ArrayList<>(); | |
| 31 | 31 | carts.forEach(cart -> { |
| 32 | - AppTradeCartListRespVO.Cart cartVO = new AppTradeCartListRespVO.Cart(); | |
| 33 | - cartVO.setId(cart.getId()).setCount(cart.getCount()); | |
| 32 | + AppCartListRespVO.Cart cartVO = new AppCartListRespVO.Cart(); | |
| 33 | + cartVO.setId(cart.getId()).setCount(cart.getCount()).setSelected(cart.getSelected()); | |
| 34 | 34 | ProductSpuRespDTO spu = spuMap.get(cart.getSpuId()); |
| 35 | 35 | ProductSkuRespDTO sku = skuMap.get(cart.getSkuId()); |
| 36 | 36 | cartVO.setSpu(convert(spu)).setSku(convert(sku)); |
| ... | ... | @@ -38,13 +38,14 @@ public interface TradeCartConvert { |
| 38 | 38 | if (spu == null |
| 39 | 39 | || !ProductSpuStatusEnum.isEnable(spu.getStatus()) |
| 40 | 40 | || spu.getStock() <= 0) { |
| 41 | + cartVO.setSelected(false); // 强制设置成不可选中 | |
| 41 | 42 | invalidList.add(cartVO); |
| 42 | 43 | } else { |
| 43 | 44 | // 虽然 SKU 可能也会不存在,但是可以通过购物车重新选择 |
| 44 | 45 | validList.add(cartVO); |
| 45 | 46 | } |
| 46 | 47 | }); |
| 47 | - return new AppTradeCartListRespVO().setValidList(validList).setInvalidList(invalidList); | |
| 48 | + return new AppCartListRespVO().setValidList(validList).setInvalidList(invalidList); | |
| 48 | 49 | } |
| 49 | 50 | AppProductSpuBaseRespVO convert(ProductSpuRespDTO spu); |
| 50 | 51 | AppProductSkuBaseRespVO convert(ProductSkuRespDTO sku); | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| ... | ... | @@ -22,7 +22,7 @@ import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductProp |
| 22 | 22 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; |
| 23 | 23 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; |
| 24 | 24 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; |
| 25 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 25 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 26 | 26 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 27 | 27 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 28 | 28 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| ... | ... | @@ -221,12 +221,12 @@ public interface TradeOrderConvert { |
| 221 | 221 | ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO); |
| 222 | 222 | |
| 223 | 223 | default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, |
| 224 | - List<TradeCartDO> cartList) { | |
| 224 | + List<CartDO> cartList) { | |
| 225 | 225 | TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); |
| 226 | 226 | reqBO.setUserId(userId).setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) |
| 227 | 227 | .setItems(new ArrayList<>(settlementReqVO.getItems().size())); |
| 228 | 228 | // 商品项的构建 |
| 229 | - Map<Long, TradeCartDO> cartMap = convertMap(cartList, TradeCartDO::getId); | |
| 229 | + Map<Long, CartDO> cartMap = convertMap(cartList, CartDO::getId); | |
| 230 | 230 | for (AppTradeOrderSettlementReqVO.Item item : settlementReqVO.getItems()) { |
| 231 | 231 | // 情况一:skuId + count |
| 232 | 232 | if (item.getSkuId() != null) { |
| ... | ... | @@ -235,7 +235,7 @@ public interface TradeOrderConvert { |
| 235 | 235 | continue; |
| 236 | 236 | } |
| 237 | 237 | // 情况二:cartId |
| 238 | - TradeCartDO cart = cartMap.get(item.getCartId()); | |
| 238 | + CartDO cart = cartMap.get(item.getCartId()); | |
| 239 | 239 | if (cart == null) { |
| 240 | 240 | continue; |
| 241 | 241 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/TradeCartDO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/CartDO.java
| ... | ... | @@ -17,7 +17,7 @@ import lombok.experimental.Accessors; |
| 17 | 17 | @Data |
| 18 | 18 | @EqualsAndHashCode(callSuper = true) |
| 19 | 19 | @Accessors(chain = true) |
| 20 | -public class TradeCartDO extends BaseDO { | |
| 20 | +public class CartDO extends BaseDO { | |
| 21 | 21 | |
| 22 | 22 | // ========= 基础字段 BEGIN ========= |
| 23 | 23 | |
| ... | ... | @@ -33,27 +33,7 @@ public class TradeCartDO extends BaseDO { |
| 33 | 33 | */ |
| 34 | 34 | private Long userId; |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * 是否添加到购物车 | |
| 38 | - * | |
| 39 | - * false - 未添加:用户点击【立即购买】 | |
| 40 | - * true - 已添加:用户点击【添加购物车】 | |
| 41 | - * | |
| 42 | - * 为什么要设计这个字段? | |
| 43 | - * 配合 orderStatus 字段,可以知道有多少商品,用户点击了【立即购买】,最终多少【确认下单】 | |
| 44 | - */ | |
| 45 | - private Boolean addStatus; | |
| 46 | - /** | |
| 47 | - * 是否提交订单 | |
| 48 | - * | |
| 49 | - * false - 未下单:立即购买,或者添加到购物车,此时设置为 false | |
| 50 | - * true - 已下单:确认下单,此时设置为 true | |
| 51 | - */ | |
| 52 | - private Boolean orderStatus; | |
| 53 | - | |
| 54 | - // ========= 基础字段 END ========= | |
| 55 | - | |
| 56 | - // ========= 商品信息 BEGIN ========= | |
| 36 | + // ========= 商品信息 ========= | |
| 57 | 37 | |
| 58 | 38 | /** |
| 59 | 39 | * 商品 SPU 编号 |
| ... | ... | @@ -71,16 +51,9 @@ public class TradeCartDO extends BaseDO { |
| 71 | 51 | * 商品购买数量 |
| 72 | 52 | */ |
| 73 | 53 | private Integer count; |
| 74 | - | |
| 75 | - // ========= 商品信息 END ========= | |
| 76 | - | |
| 77 | - // ========= 优惠信息 BEGIN ========= | |
| 78 | - | |
| 79 | - // TODO 芋艿:combination_id 拼团 ID | |
| 80 | - // TODO 芋艿:seckill_id 秒杀产品 ID | |
| 81 | - // TODO 芋艿:bargain_id 砍价 ID | |
| 82 | - // TODO 芋艿:pinkId 团长拼团 ID | |
| 83 | - | |
| 84 | - // ========= 优惠信息 END ========= | |
| 54 | + /** | |
| 55 | + * 是否选中 | |
| 56 | + */ | |
| 57 | + private Boolean selected; | |
| 85 | 58 | |
| 86 | 59 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.order; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; |
| 6 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 6 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 7 | 7 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; |
| 8 | 8 | import com.baomidou.mybatisplus.annotation.TableField; |
| 9 | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
| ... | ... | @@ -46,7 +46,7 @@ public class TradeOrderItemDO extends BaseDO { |
| 46 | 46 | /** |
| 47 | 47 | * 购物车项编号 |
| 48 | 48 | * |
| 49 | - * 关联 {@link TradeCartDO#getId()} | |
| 49 | + * 关联 {@link CartDO#getId()} | |
| 50 | 50 | */ |
| 51 | 51 | private Long cartId; |
| 52 | 52 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/cart/TradeCartMapper.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/cart/CartMapper.java
| ... | ... | @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 7 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 8 | 8 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 9 | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | 10 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -15,19 +15,16 @@ import java.util.Map; |
| 15 | 15 | import java.util.Set; |
| 16 | 16 | |
| 17 | 17 | @Mapper |
| 18 | -public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { | |
| 18 | +public interface CartMapper extends BaseMapperX<CartDO> { | |
| 19 | 19 | |
| 20 | - default TradeCartDO selectByUserIdAndSkuId(Long userId, Long skuId, | |
| 21 | - Boolean addStatus, Boolean orderStatus) { | |
| 22 | - return selectOne(new LambdaQueryWrapper<TradeCartDO>().eq(TradeCartDO::getUserId, userId) | |
| 23 | - .eq(TradeCartDO::getSkuId, skuId) | |
| 24 | - .eq(TradeCartDO::getAddStatus, addStatus) | |
| 25 | - .eq(TradeCartDO::getOrderStatus, orderStatus)); | |
| 20 | + default CartDO selectByUserIdAndSkuId(Long userId, Long skuId) { | |
| 21 | + return selectOne(CartDO::getUserId, userId, | |
| 22 | + CartDO::getSkuId, skuId); | |
| 26 | 23 | } |
| 27 | 24 | |
| 28 | 25 | default Integer selectSumByUserId(Long userId) { |
| 29 | 26 | // SQL sum 查询 |
| 30 | - List<Map<String, Object>> result = selectMaps(new QueryWrapper<TradeCartDO>() | |
| 27 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<CartDO>() | |
| 31 | 28 | .select("SUM(count) AS sumCount") |
| 32 | 29 | .eq("user_id", userId) |
| 33 | 30 | .eq("add_status", true) // 只计算添加到购物车中的 |
| ... | ... | @@ -38,7 +35,7 @@ public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { |
| 38 | 35 | |
| 39 | 36 | default Map<Long, Integer> selectSumMapByUserId(Long userId) { |
| 40 | 37 | // SQL sum 查询 |
| 41 | - List<Map<String, Object>> result = selectMaps(new QueryWrapper<TradeCartDO>() | |
| 38 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<CartDO>() | |
| 42 | 39 | .select("spu_id, SUM(count) AS sumCount") |
| 43 | 40 | .eq("user_id", userId) |
| 44 | 41 | .eq("add_status", true) // 只计算添加到购物车中的 |
| ... | ... | @@ -49,32 +46,32 @@ public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { |
| 49 | 46 | item -> MapUtil.getInt(item, "sumCount")); |
| 50 | 47 | } |
| 51 | 48 | |
| 52 | - default TradeCartDO selectById(Long id, Long userId) { | |
| 53 | - return selectOne(TradeCartDO::getId, id, | |
| 54 | - TradeCartDO::getUserId, userId); | |
| 49 | + default CartDO selectById(Long id, Long userId) { | |
| 50 | + return selectOne(CartDO::getId, id, | |
| 51 | + CartDO::getUserId, userId); | |
| 55 | 52 | } |
| 56 | 53 | |
| 57 | - default List<TradeCartDO> selectListByIds(Collection<Long> ids, Long userId) { | |
| 58 | - return selectList(new LambdaQueryWrapper<TradeCartDO>() | |
| 59 | - .in(TradeCartDO::getId, ids) | |
| 60 | - .eq(TradeCartDO::getUserId, userId)); | |
| 54 | + default List<CartDO> selectListByIds(Collection<Long> ids, Long userId) { | |
| 55 | + return selectList(new LambdaQueryWrapper<CartDO>() | |
| 56 | + .in(CartDO::getId, ids) | |
| 57 | + .eq(CartDO::getUserId, userId)); | |
| 61 | 58 | } |
| 62 | 59 | |
| 63 | - default List<TradeCartDO> selectListByUserId(Long userId, Boolean addStatus, Boolean orderStatus) { | |
| 64 | - return selectList(new LambdaQueryWrapper<TradeCartDO>() | |
| 65 | - .eq(TradeCartDO::getUserId, userId) | |
| 66 | - .eq(TradeCartDO::getAddStatus, addStatus) | |
| 67 | - .eq(TradeCartDO::getOrderStatus, orderStatus)); | |
| 60 | + default List<CartDO> selectListByUserId(Long userId) { | |
| 61 | + return selectList(new LambdaQueryWrapper<CartDO>() | |
| 62 | + .eq(CartDO::getUserId, userId)); | |
| 68 | 63 | } |
| 69 | 64 | |
| 70 | - default void updateByIds(Collection<Long> ids, TradeCartDO updateObject) { | |
| 71 | - update(updateObject, new LambdaQueryWrapper<TradeCartDO>().in(TradeCartDO::getId, ids)); | |
| 65 | + default List<CartDO> selectListByUserId(Long userId, Set<Long> ids) { | |
| 66 | + return selectList(new LambdaQueryWrapper<CartDO>() | |
| 67 | + .eq(CartDO::getUserId, userId) | |
| 68 | + .in(CartDO::getId, ids)); | |
| 72 | 69 | } |
| 73 | 70 | |
| 74 | - default List<TradeCartDO> selectListByUserId(Long userId, Set<Long> ids) { | |
| 75 | - return selectList(new LambdaQueryWrapper<TradeCartDO>() | |
| 76 | - .eq(TradeCartDO::getUserId, userId) | |
| 77 | - .in(TradeCartDO::getId, ids)); | |
| 71 | + default void updateByIds(Collection<Long> ids, Long userId, CartDO updateObj) { | |
| 72 | + update(updateObj, new LambdaQueryWrapper<CartDO>() | |
| 73 | + .in(CartDO::getId, ids) | |
| 74 | + .eq(CartDO::getUserId, userId)); | |
| 78 | 75 | } |
| 79 | 76 | |
| 80 | 77 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartService.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/CartService.java
| 1 | 1 | package cn.iocoder.yudao.module.trade.service.cart; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartAddReqVO; | |
| 4 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | |
| 5 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartResetReqVO; | |
| 6 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 3 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.*; | |
| 4 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 8 | 5 | |
| 9 | 6 | import javax.validation.Valid; |
| 10 | 7 | import java.util.Collection; |
| ... | ... | @@ -17,7 +14,7 @@ import java.util.Set; |
| 17 | 14 | * |
| 18 | 15 | * @author 芋道源码 |
| 19 | 16 | */ |
| 20 | -public interface TradeCartService { | |
| 17 | +public interface CartService { | |
| 21 | 18 | |
| 22 | 19 | /** |
| 23 | 20 | * 添加商品到购物车 |
| ... | ... | @@ -26,7 +23,7 @@ public interface TradeCartService { |
| 26 | 23 | * @param addReqVO 添加信息 |
| 27 | 24 | * @return 购物项的编号 |
| 28 | 25 | */ |
| 29 | - Long addCart(Long userId, @Valid AppTradeCartAddReqVO addReqVO); | |
| 26 | + Long addCart(Long userId, @Valid AppCartAddReqVO addReqVO); | |
| 30 | 27 | |
| 31 | 28 | /** |
| 32 | 29 | * 更新购物车商品数量 |
| ... | ... | @@ -34,7 +31,15 @@ public interface TradeCartService { |
| 34 | 31 | * @param userId 用户编号 |
| 35 | 32 | * @param updateCountReqVO 更新信息 |
| 36 | 33 | */ |
| 37 | - void updateCart(Long userId, AppTradeCartUpdateReqVO updateCountReqVO); | |
| 34 | + void updateCartCount(Long userId, AppCartUpdateCountReqVO updateCountReqVO); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 更新购物车选中状态 | |
| 38 | + * | |
| 39 | + * @param userId 用户编号 | |
| 40 | + * @param updateSelectedReqVO 更新信息 | |
| 41 | + */ | |
| 42 | + void updateCartSelected(Long userId, @Valid AppCartUpdateSelectedReqVO updateSelectedReqVO); | |
| 38 | 43 | |
| 39 | 44 | /** |
| 40 | 45 | * 重置购物车商品 |
| ... | ... | @@ -44,7 +49,7 @@ public interface TradeCartService { |
| 44 | 49 | * @param userId 用户编号 |
| 45 | 50 | * @param updateReqVO 重置信息 |
| 46 | 51 | */ |
| 47 | - void resetCart(Long userId, AppTradeCartResetReqVO updateReqVO); | |
| 52 | + void resetCart(Long userId, AppCartResetReqVO updateReqVO); | |
| 48 | 53 | |
| 49 | 54 | /** |
| 50 | 55 | * 删除购物车商品 |
| ... | ... | @@ -68,7 +73,7 @@ public interface TradeCartService { |
| 68 | 73 | * @param userId 用户编号 |
| 69 | 74 | * @return 购物车列表 |
| 70 | 75 | */ |
| 71 | - AppTradeCartListRespVO getCartList(Long userId); | |
| 76 | + AppCartListRespVO getCartList(Long userId); | |
| 72 | 77 | |
| 73 | 78 | /** |
| 74 | 79 | * 查询用户的购物车列表 |
| ... | ... | @@ -77,7 +82,7 @@ public interface TradeCartService { |
| 77 | 82 | * @param ids 购物项的编号 |
| 78 | 83 | * @return 购物车列表 |
| 79 | 84 | */ |
| 80 | - List<TradeCartDO> getCartList(Long userId, Set<Long> ids); | |
| 85 | + List<CartDO> getCartList(Long userId, Set<Long> ids); | |
| 81 | 86 | |
| 82 | 87 | /** |
| 83 | 88 | * 获得用户的购物车商品 SPU 数量的 Map | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartServiceImpl.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/CartServiceImpl.java
| ... | ... | @@ -5,13 +5,10 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; |
| 5 | 5 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; |
| 6 | 6 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 7 | 7 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 8 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartAddReqVO; | |
| 9 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | |
| 10 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartResetReqVO; | |
| 11 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartUpdateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.*; | |
| 12 | 9 | import cn.iocoder.yudao.module.trade.convert.cart.TradeCartConvert; |
| 13 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 14 | -import cn.iocoder.yudao.module.trade.dal.mysql.cart.TradeCartMapper; | |
| 10 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 11 | +import cn.iocoder.yudao.module.trade.dal.mysql.cart.CartMapper; | |
| 15 | 12 | import org.springframework.stereotype.Service; |
| 16 | 13 | import org.springframework.transaction.annotation.Transactional; |
| 17 | 14 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -29,17 +26,16 @@ import static java.util.Collections.emptyList; |
| 29 | 26 | /** |
| 30 | 27 | * 购物车 Service 实现类 |
| 31 | 28 | * |
| 32 | - * // TODO 芋艿:秒杀、拼团、砍价对购物车的影响 | |
| 33 | - * // TODO 芋艿:未来优化:购物车的价格计算,支持营销信息 | |
| 29 | + * // TODO 芋艿:未来优化:购物车的价格计算,支持营销信息;目前不支持的原因,前端界面需要前端 pr 支持下; | |
| 34 | 30 | * |
| 35 | 31 | * @author 芋道源码 |
| 36 | 32 | */ |
| 37 | 33 | @Service |
| 38 | 34 | @Validated |
| 39 | -public class TradeCartServiceImpl implements TradeCartService { | |
| 35 | +public class CartServiceImpl implements CartService { | |
| 40 | 36 | |
| 41 | 37 | @Resource |
| 42 | - private TradeCartMapper cartMapper; | |
| 38 | + private CartMapper cartMapper; | |
| 43 | 39 | |
| 44 | 40 | @Resource |
| 45 | 41 | private ProductSpuApi productSpuApi; |
| ... | ... | @@ -47,13 +43,11 @@ public class TradeCartServiceImpl implements TradeCartService { |
| 47 | 43 | private ProductSkuApi productSkuApi; |
| 48 | 44 | |
| 49 | 45 | @Override |
| 50 | - public Long addCart(Long userId, AppTradeCartAddReqVO addReqVO) { | |
| 46 | + public Long addCart(Long userId, AppCartAddReqVO addReqVO) { | |
| 51 | 47 | // 查询 TradeCartDO |
| 52 | - TradeCartDO cart = cartMapper.selectByUserIdAndSkuId(userId, addReqVO.getSkuId(), | |
| 53 | - addReqVO.getAddStatus(), false); | |
| 48 | + CartDO cart = cartMapper.selectByUserIdAndSkuId(userId, addReqVO.getSkuId()); | |
| 54 | 49 | // 校验 SKU |
| 55 | - Integer count = cart != null && addReqVO.getAddStatus() ? | |
| 56 | - cart.getCount() + addReqVO.getCount() : addReqVO.getCount(); | |
| 50 | + Integer count = addReqVO.getCount(); | |
| 57 | 51 | ProductSkuRespDTO sku = checkProductSku(addReqVO.getSkuId(), count); |
| 58 | 52 | |
| 59 | 53 | // 情况零:特殊,count 小于等于 0,说明前端项目删除 |
| ... | ... | @@ -63,23 +57,22 @@ public class TradeCartServiceImpl implements TradeCartService { |
| 63 | 57 | if (count <= 0) { |
| 64 | 58 | cartMapper.deleteById(cart.getId()); |
| 65 | 59 | } else { |
| 66 | - cartMapper.updateById(new TradeCartDO().setId(cart.getId()).setCount(count)); | |
| 60 | + cartMapper.updateById(new CartDO().setId(cart.getId()).setCount(count)); | |
| 67 | 61 | } |
| 68 | 62 | return cart.getId(); |
| 69 | 63 | // 情况二:不存在,则进行插入 |
| 70 | 64 | } else { |
| 71 | - cart = new TradeCartDO().setUserId(userId) | |
| 72 | - .setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count) | |
| 73 | - .setAddStatus(addReqVO.getAddStatus()).setOrderStatus(false); | |
| 65 | + cart = new CartDO().setUserId(userId) | |
| 66 | + .setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count); | |
| 74 | 67 | cartMapper.insert(cart); |
| 75 | 68 | } |
| 76 | 69 | return cart.getId(); |
| 77 | 70 | } |
| 78 | 71 | |
| 79 | 72 | @Override |
| 80 | - public void updateCart(Long userId, AppTradeCartUpdateReqVO updateReqVO) { | |
| 73 | + public void updateCartCount(Long userId, AppCartUpdateCountReqVO updateReqVO) { | |
| 81 | 74 | // 校验 TradeCartDO 存在 |
| 82 | - TradeCartDO cart = cartMapper.selectById(updateReqVO.getId(), userId); | |
| 75 | + CartDO cart = cartMapper.selectById(updateReqVO.getId(), userId); | |
| 83 | 76 | if (cart == null) { |
| 84 | 77 | throw exception(CARD_ITEM_NOT_FOUND); |
| 85 | 78 | } |
| ... | ... | @@ -87,29 +80,35 @@ public class TradeCartServiceImpl implements TradeCartService { |
| 87 | 80 | checkProductSku(cart.getSkuId(), updateReqVO.getCount()); |
| 88 | 81 | |
| 89 | 82 | // 更新数量 |
| 90 | - cartMapper.updateById(new TradeCartDO().setId(cart.getId()) | |
| 83 | + cartMapper.updateById(new CartDO().setId(cart.getId()) | |
| 91 | 84 | .setCount(updateReqVO.getCount())); |
| 92 | 85 | } |
| 93 | 86 | |
| 94 | 87 | @Override |
| 88 | + public void updateCartSelected(Long userId, AppCartUpdateSelectedReqVO updateSelectedReqVO) { | |
| 89 | + cartMapper.updateByIds(updateSelectedReqVO.getIds(), userId, | |
| 90 | + new CartDO().setSelected(updateSelectedReqVO.getSelected())); | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 95 | 94 | @Transactional(rollbackFor = Exception.class) |
| 96 | - public void resetCart(Long userId, AppTradeCartResetReqVO resetReqVO) { | |
| 95 | + public void resetCart(Long userId, AppCartResetReqVO resetReqVO) { | |
| 97 | 96 | // 第一步:删除原本的购物项 |
| 98 | - TradeCartDO oldCart = cartMapper.selectById(resetReqVO.getId(), userId); | |
| 97 | + CartDO oldCart = cartMapper.selectById(resetReqVO.getId(), userId); | |
| 99 | 98 | if (oldCart == null) { |
| 100 | 99 | throw exception(CARD_ITEM_NOT_FOUND); |
| 101 | 100 | } |
| 102 | 101 | cartMapper.deleteById(oldCart.getId()); |
| 103 | 102 | |
| 104 | 103 | // 第二步:添加新的购物项 |
| 105 | - TradeCartDO newCart = cartMapper.selectByUserIdAndSkuId(userId, resetReqVO.getSkuId(), | |
| 106 | - true, false); | |
| 104 | + // TODO 芋艿:直接改成 addCart 貌似就行 | |
| 105 | + CartDO newCart = cartMapper.selectByUserIdAndSkuId(userId, resetReqVO.getSkuId()); | |
| 107 | 106 | if (newCart != null) { |
| 108 | - updateCart(userId, new AppTradeCartUpdateReqVO() | |
| 107 | + updateCartCount(userId, new AppCartUpdateCountReqVO() | |
| 109 | 108 | .setId(newCart.getId()).setCount(resetReqVO.getCount())); |
| 110 | 109 | } else { |
| 111 | - addCart(userId, new AppTradeCartAddReqVO().setAddStatus(true) | |
| 112 | - .setSkuId(resetReqVO.getSkuId()).setCount(resetReqVO.getCount())); | |
| 110 | + addCart(userId, new AppCartAddReqVO().setSkuId(resetReqVO.getSkuId()) | |
| 111 | + .setCount(resetReqVO.getCount())); | |
| 113 | 112 | } |
| 114 | 113 | } |
| 115 | 114 | |
| ... | ... | @@ -122,7 +121,7 @@ public class TradeCartServiceImpl implements TradeCartService { |
| 122 | 121 | @Override |
| 123 | 122 | public void deleteCart(Long userId, Collection<Long> ids) { |
| 124 | 123 | // 查询 TradeCartDO 列表 |
| 125 | - List<TradeCartDO> carts = cartMapper.selectListByIds(ids, userId); | |
| 124 | + List<CartDO> carts = cartMapper.selectListByIds(ids, userId); | |
| 126 | 125 | if (CollUtil.isEmpty(carts)) { |
| 127 | 126 | return; |
| 128 | 127 | } |
| ... | ... | @@ -133,30 +132,33 @@ public class TradeCartServiceImpl implements TradeCartService { |
| 133 | 132 | |
| 134 | 133 | @Override |
| 135 | 134 | public Integer getCartCount(Long userId) { |
| 135 | + // TODO 芋艿:需要算上 selected | |
| 136 | 136 | return cartMapper.selectSumByUserId(userId); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | @Override |
| 140 | 140 | public Map<Long, Integer> getCartCountMap(Long userId) { |
| 141 | + // TODO 芋艿:需要算上 selected | |
| 141 | 142 | return cartMapper.selectSumMapByUserId(userId); |
| 142 | 143 | } |
| 143 | 144 | |
| 144 | 145 | @Override |
| 145 | - public AppTradeCartListRespVO getCartList(Long userId) { | |
| 146 | - // 获得购物车的商品,只查询未下单的 | |
| 147 | - List<TradeCartDO> carts = cartMapper.selectListByUserId(userId, true, false); | |
| 148 | - carts.sort(Comparator.comparing(TradeCartDO::getId).reversed()); | |
| 146 | + public AppCartListRespVO getCartList(Long userId) { | |
| 147 | + // 获得购物车的商品 | |
| 148 | + List<CartDO> carts = cartMapper.selectListByUserId(userId); | |
| 149 | + carts.sort(Comparator.comparing(CartDO::getId).reversed()); | |
| 149 | 150 | // 如果未空,则返回空结果 |
| 150 | 151 | if (CollUtil.isEmpty(carts)) { |
| 151 | - return new AppTradeCartListRespVO().setValidList(emptyList()) | |
| 152 | + return new AppCartListRespVO().setValidList(emptyList()) | |
| 152 | 153 | .setInvalidList(emptyList()); |
| 153 | 154 | } |
| 154 | 155 | |
| 155 | 156 | // 查询 SPU、SKU 列表 |
| 156 | - List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(convertSet(carts, TradeCartDO::getSpuId)); | |
| 157 | - List<ProductSkuRespDTO> skus = productSkuApi.getSkuList(convertSet(carts, TradeCartDO::getSkuId)); | |
| 157 | + List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(convertSet(carts, CartDO::getSpuId)); | |
| 158 | + List<ProductSkuRespDTO> skus = productSkuApi.getSkuList(convertSet(carts, CartDO::getSkuId)); | |
| 158 | 159 | |
| 159 | 160 | // 如果 SPU 被删除,则删除购物车对应的商品。延迟删除 |
| 161 | + // 为什么不是 SKU 被删除呢?因为 SKU 被删除时,还可以通过 SPU 选择其它 SKU | |
| 160 | 162 | deleteCartIfSpuDeleted(carts, spus); |
| 161 | 163 | |
| 162 | 164 | // 拼接数据 |
| ... | ... | @@ -164,14 +166,14 @@ public class TradeCartServiceImpl implements TradeCartService { |
| 164 | 166 | } |
| 165 | 167 | |
| 166 | 168 | @Override |
| 167 | - public List<TradeCartDO> getCartList(Long userId, Set<Long> ids) { | |
| 169 | + public List<CartDO> getCartList(Long userId, Set<Long> ids) { | |
| 168 | 170 | if (CollUtil.isEmpty(ids)) { |
| 169 | 171 | return Collections.emptyList(); |
| 170 | 172 | } |
| 171 | 173 | return cartMapper.selectListByUserId(userId, ids); |
| 172 | 174 | } |
| 173 | 175 | |
| 174 | - private void deleteCartIfSpuDeleted(List<TradeCartDO> carts, List<ProductSpuRespDTO> spus) { | |
| 176 | + private void deleteCartIfSpuDeleted(List<CartDO> carts, List<ProductSpuRespDTO> spus) { | |
| 175 | 177 | // 如果 SPU 被删除,则删除购物车对应的商品。延迟删除 |
| 176 | 178 | carts.removeIf(cart -> { |
| 177 | 179 | if (spus.stream().noneMatch(spu -> spu.getId().equals(cart.getSpuId()))) { | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| ... | ... | @@ -43,7 +43,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle |
| 43 | 43 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; |
| 44 | 44 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; |
| 45 | 45 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 46 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | |
| 46 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | |
| 47 | 47 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 48 | 48 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 49 | 49 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| ... | ... | @@ -53,7 +53,7 @@ import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; |
| 53 | 53 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; |
| 54 | 54 | import cn.iocoder.yudao.module.trade.enums.order.*; |
| 55 | 55 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 56 | -import cn.iocoder.yudao.module.trade.service.cart.TradeCartService; | |
| 56 | +import cn.iocoder.yudao.module.trade.service.cart.CartService; | |
| 57 | 57 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; |
| 58 | 58 | import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; |
| 59 | 59 | import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO; |
| ... | ... | @@ -93,7 +93,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 93 | 93 | private TradeOrderItemMapper tradeOrderItemMapper; |
| 94 | 94 | |
| 95 | 95 | @Resource |
| 96 | - private TradeCartService tradeCartService; | |
| 96 | + private CartService tradeCartService; | |
| 97 | 97 | @Resource |
| 98 | 98 | private TradePriceService tradePriceService; |
| 99 | 99 | @Resource |
| ... | ... | @@ -168,7 +168,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 168 | 168 | */ |
| 169 | 169 | private TradePriceCalculateRespBO calculatePrice(Long userId, AppTradeOrderSettlementReqVO settlementReqVO) { |
| 170 | 170 | // 1. 如果来自购物车,则获得购物车的商品 |
| 171 | - List<TradeCartDO> cartList = tradeCartService.getCartList(userId, | |
| 171 | + List<CartDO> cartList = tradeCartService.getCartList(userId, | |
| 172 | 172 | convertSet(settlementReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId)); |
| 173 | 173 | |
| 174 | 174 | // 2. 计算价格 | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
| ... | ... | @@ -168,7 +168,7 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 168 | 168 | |
| 169 | 169 | @Override |
| 170 | 170 | public boolean isPasswordMatch(String rawPassword, String encodedPassword) { |
| 171 | - if (true) { | |
| 171 | + if(true) { | |
| 172 | 172 | return true; |
| 173 | 173 | } |
| 174 | 174 | return passwordEncoder.matches(rawPassword, encodedPassword); | ... | ... |