From f0bbb626ae8711ced9ddc4c3730893e628a7ec69 Mon Sep 17 00:00:00 2001 From: hxr <1490493387@qq.com> Date: Sun, 31 Mar 2024 23:56:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oms/controller/app/CartController.java | 6 ++-- .../mall/oms/converter/CartConverter.java | 4 +-- .../mall/oms/model/dto/CartItemDto.java | 30 ++++++++++++++++ .../dto/{CartItemDTO.java => CartItemVo.java} | 34 ++++++++----------- .../mall/oms/service/app/CartService.java | 6 ++-- .../oms/service/app/impl/CartServiceImpl.java | 18 +++++----- .../service/app/impl/OrderServiceImpl.java | 6 ++-- .../sms/controller/app/AdvertController.java | 8 ++--- .../mall/sms/converter/AdvertConverter.java | 6 ++-- .../mall/sms/model/entity/SmsAdvert.java | 4 +-- .../vo/{AdBannerVO.java => BannerVO.java} | 6 ++-- .../mall/sms/service/SmsAdvertService.java | 4 +-- .../service/impl/SmsAdvertServiceImpl.java | 26 ++++++-------- 13 files changed, 88 insertions(+), 70 deletions(-) create mode 100644 mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDto.java rename mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/{CartItemDTO.java => CartItemVo.java} (50%) rename mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/{AdBannerVO.java => BannerVO.java} (75%) diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/CartController.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/CartController.java index 0ea455765..f36e02887 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/CartController.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/controller/app/CartController.java @@ -2,7 +2,7 @@ package com.youlai.mall.oms.controller.app; import com.youlai.common.result.Result; import com.youlai.common.security.util.SecurityUtils; -import com.youlai.mall.oms.model.dto.CartItemDTO; +import com.youlai.mall.oms.model.dto.CartItemDto; import com.youlai.mall.oms.service.app.CartService; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; @@ -30,7 +30,7 @@ public class CartController { @Operation(summary = "查询购物车") @GetMapping public Result getCart() { - List result = cartService.listCartItems(SecurityUtils.getMemberId()); + List result = cartService.listCartItems(SecurityUtils.getMemberId()); return Result.success((T) result); } @@ -52,7 +52,7 @@ public class CartController { @PutMapping("/skuId/{skuId}") public Result updateCartItem( @PathVariable Long skuId, - @RequestBody CartItemDTO cartItem + @RequestBody CartItemDto cartItem ) { cartItem.setSkuId(skuId); boolean result = cartService.updateCartItem(cartItem); diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/converter/CartConverter.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/converter/CartConverter.java index 847da7932..715d69dd3 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/converter/CartConverter.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/converter/CartConverter.java @@ -1,7 +1,7 @@ package com.youlai.mall.oms.converter; -import com.youlai.mall.oms.model.dto.CartItemDTO; +import com.youlai.mall.oms.model.dto.CartItemDto; import com.youlai.mall.pms.model.dto.SkuInfoDTO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -19,6 +19,6 @@ public interface CartConverter { @Mappings({ @Mapping(target = "skuId", source = "id"), }) - CartItemDTO sku2CartItem(SkuInfoDTO skuInfo); + CartItemDto sku2CartItem(SkuInfoDTO skuInfo); } \ No newline at end of file diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDto.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDto.java new file mode 100644 index 000000000..682323d1a --- /dev/null +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDto.java @@ -0,0 +1,30 @@ +package com.youlai.mall.oms.model.dto; + +import lombok.Data; + +import java.io.Serializable; +/** + * 购物车商品项 + * + * @author Ray Hao + * @since 0.0.1 + */ +@Data +public class CartItemDto implements Serializable { + + /** + * 商品库存ID + */ + private Long skuId; + + /** + * 商品数量 + */ + private Integer count; + + /** + * 是否选中 + */ + private Boolean checked; + +} diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDTO.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemVo.java similarity index 50% rename from mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDTO.java rename to mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemVo.java index 7d70af96e..b868847f5 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemDTO.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/model/dto/CartItemVo.java @@ -3,12 +3,16 @@ package com.youlai.mall.oms.model.dto; import lombok.Data; import java.io.Serializable; +import java.util.Set; /** - * 购物车商品传输层实体 + * 购物车商品项 + * + * @author Ray Hao + * @since 0.0.1 */ @Data -public class CartItemDTO implements Serializable { +public class CartItemVo implements Serializable { /** * 商品库存ID @@ -16,48 +20,38 @@ public class CartItemDTO implements Serializable { private Long skuId; /** - * 商品库存名称 + * 商品名称 */ - private String skuName; + private String spuName; /** - * 商品编码 + * 规格集合 */ - private String skuSn; + private Set specs; /** * 商品图片 */ - private String picUrl; + private String imageUrl; /** - * 商品数量 + * 加购数量· */ private Integer count; /** - * 加入购物车时价格,因会变动,不能作为订单计算因子,订单提交时需验价 + * 商品价格 */ private Long price; - /** - * 优惠券金额 - */ - private Long coupon; - /** * 是否选中 */ private Boolean checked; /** - * 商品库存数量,页面控制能选择最大数量 + * 商品库存 */ private Integer stock; - /** - * 商品名称 - */ - private String spuName; - } diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/CartService.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/CartService.java index 1f71e4740..9d9ac6ead 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/CartService.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/CartService.java @@ -1,6 +1,6 @@ package com.youlai.mall.oms.service.app; -import com.youlai.mall.oms.model.dto.CartItemDTO; +import com.youlai.mall.oms.model.dto.CartItemDto; import java.util.List; @@ -12,13 +12,13 @@ import java.util.List; */ public interface CartService { - List listCartItems(Long memberId); + List listCartItems(Long memberId); boolean deleteCart(); boolean addCartItem(Long skuId); - boolean updateCartItem(CartItemDTO cartItem); + boolean updateCartItem(CartItemDto cartItem); boolean removeCartItem(Long skuId); diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/CartServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/CartServiceImpl.java index 9018972b8..ddd556b95 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/CartServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/CartServiceImpl.java @@ -5,7 +5,7 @@ import com.youlai.common.security.util.SecurityUtils; import com.youlai.common.web.exception.BizException; import com.youlai.mall.oms.constant.OrderConstants; import com.youlai.mall.oms.converter.CartConverter; -import com.youlai.mall.oms.model.dto.CartItemDTO; +import com.youlai.mall.oms.model.dto.CartItemDto; import com.youlai.mall.oms.service.app.CartService; import com.youlai.mall.pms.api.SkuFeignClient; import com.youlai.mall.pms.model.dto.SkuInfoDTO; @@ -39,10 +39,10 @@ public class CartServiceImpl implements CartService { private final CartConverter cartConverter; @Override - public List listCartItems(Long memberId) { + public List listCartItems(Long memberId) { if (memberId != null) { BoundHashOperations cartHashOperations = getCartHashOperations(memberId); - List cartItems = cartHashOperations.values(); + List cartItems = cartHashOperations.values(); return cartItems; } return Collections.EMPTY_LIST; @@ -64,10 +64,10 @@ public class CartServiceImpl implements CartService { @Override public boolean addCartItem(Long skuId) { Long memberId = SecurityUtils.getMemberId(); - BoundHashOperations cartHashOperations = getCartHashOperations(memberId); + BoundHashOperations cartHashOperations = getCartHashOperations(memberId); String hKey = String.valueOf(skuId); - CartItemDTO cartItem = cartHashOperations.get(hKey); + CartItemDto cartItem = cartHashOperations.get(hKey); if (cartItem != null) { // 购物车已存在该商品,更新商品数量 @@ -90,7 +90,7 @@ public class CartServiceImpl implements CartService { * 更新购物车总商品数量、选中状态 */ @Override - public boolean updateCartItem(CartItemDTO cartItem) { + public boolean updateCartItem(CartItemDto cartItem) { Long memberId; try { memberId = SecurityUtils.getMemberId(); @@ -100,7 +100,7 @@ public class CartServiceImpl implements CartService { BoundHashOperations cartHashOperations = getCartHashOperations(memberId); String hKey = cartItem.getSkuId() + ""; if (cartHashOperations.get(hKey) != null) { - CartItemDTO cacheCartItem = (CartItemDTO) cartHashOperations.get(hKey); + CartItemDto cacheCartItem = (CartItemDto) cartHashOperations.get(hKey); if (cartItem.getChecked() != null) { cacheCartItem.setChecked(cartItem.getChecked()); } @@ -143,7 +143,7 @@ public class CartServiceImpl implements CartService { } BoundHashOperations cartHashOperations = getCartHashOperations(memberId); for (Object value : cartHashOperations.values()) { - CartItemDTO cartItem = (CartItemDTO) value; + CartItemDto cartItem = (CartItemDto) value; cartItem.setChecked(checked); String hKey = cartItem.getSkuId() + ""; cartHashOperations.put(hKey, cartItem); @@ -165,7 +165,7 @@ public class CartServiceImpl implements CartService { } BoundHashOperations cartHashOperations = getCartHashOperations(memberId); for (Object value : cartHashOperations.values()) { - CartItemDTO cartItem = (CartItemDTO) value; + CartItemDto cartItem = (CartItemDto) value; if (cartItem.getChecked()) { cartHashOperations.delete(cartItem.getSkuId() + ""); } diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/OrderServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/OrderServiceImpl.java index f2b8ef52a..4126f06c2 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/OrderServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/app/impl/OrderServiceImpl.java @@ -31,7 +31,7 @@ import com.youlai.mall.oms.enums.OrderStatusEnum; import com.youlai.mall.oms.enums.PaymentMethodEnum; import com.youlai.mall.oms.mapper.OrderMapper; import com.youlai.mall.oms.model.bo.OrderBO; -import com.youlai.mall.oms.model.dto.CartItemDTO; +import com.youlai.mall.oms.model.dto.CartItemDto; import com.youlai.mall.oms.model.dto.OrderItemDTO; import com.youlai.mall.oms.model.entity.OmsOrder; import com.youlai.mall.oms.model.entity.OmsOrderItem; @@ -461,9 +461,9 @@ public class OrderServiceImpl extends ServiceImpl impleme orderItemDTO.setQuantity(1); // 直接购买商品的数量为1 orderItems.add(orderItemDTO); } else { // 购物车结算 - List cartItems = cartService.listCartItems(memberId); + List cartItems = cartService.listCartItems(memberId); orderItems = cartItems.stream() - .filter(CartItemDTO::getChecked) + .filter(CartItemDto::getChecked) .map(cartItem -> { OrderItemDTO orderItemDTO = new OrderItemDTO(); BeanUtil.copyProperties(cartItem, orderItemDTO); diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AdvertController.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AdvertController.java index 50c2d950f..8e4d647fe 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AdvertController.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/controller/app/AdvertController.java @@ -1,7 +1,7 @@ package com.youlai.mall.sms.controller.app; import com.youlai.common.result.Result; -import com.youlai.mall.sms.model.vo.AdBannerVO; +import com.youlai.mall.sms.model.vo.BannerVO; import com.youlai.mall.sms.service.SmsAdvertService; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; @@ -21,10 +21,10 @@ import java.util.List; public class AdvertController { private SmsAdvertService smsAdvertService; - @Operation(summary= "广告横幅列表") + @Operation(summary= "APP首页广告横幅列表") @GetMapping("/banners") - public Result> listAdBanners() { - List list = smsAdvertService.listAdBanners(); + public Result> getBannerList() { + List list = smsAdvertService.getBannerList(); return Result.success(list); } } diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/converter/AdvertConverter.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/converter/AdvertConverter.java index 3270bdc45..54ea69653 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/converter/AdvertConverter.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/converter/AdvertConverter.java @@ -3,7 +3,7 @@ package com.youlai.mall.sms.converter; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.youlai.mall.sms.model.entity.SmsAdvert; -import com.youlai.mall.sms.model.vo.AdBannerVO; +import com.youlai.mall.sms.model.vo.BannerVO; import com.youlai.mall.sms.model.vo.AdvertPageVO; import org.mapstruct.Mapper; @@ -22,7 +22,7 @@ public interface AdvertConverter { Page entity2PageVo(Page po); - AdBannerVO entity2BannerVo(SmsAdvert entity); + BannerVO entity2BannerVo(SmsAdvert entity); - List entity2BannerVo(List entities); + List entity2BannerVo(List entities); } \ No newline at end of file diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/entity/SmsAdvert.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/entity/SmsAdvert.java index 84e5be6ef..b9877d9b2 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/entity/SmsAdvert.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/entity/SmsAdvert.java @@ -16,10 +16,10 @@ public class SmsAdvert extends BaseEntity { private String title; - private String picUrl; + private String imageUrl; @JsonFormat( pattern = "yyyy-MM-dd", timezone = "GMT+8") - private Date beginTime; + private Date startTime; @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date endTime; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/AdBannerVO.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/BannerVO.java similarity index 75% rename from mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/AdBannerVO.java rename to mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/BannerVO.java index 02598351d..1a0556187 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/AdBannerVO.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/model/vo/BannerVO.java @@ -3,15 +3,15 @@ package com.youlai.mall.sms.model.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -@Schema(description = "广告横幅对象") +@Schema(description = "横幅视图对象") @Data -public class AdBannerVO { +public class BannerVO { @Schema(description="广告标题") private String title; @Schema(description="横幅图片URL") - private String picUrl; + private String imageUrl; @Schema(description="跳转URL") private String redirectUrl; diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/SmsAdvertService.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/SmsAdvertService.java index 212bf6c97..c32af1b14 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/SmsAdvertService.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/SmsAdvertService.java @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.mall.sms.model.entity.SmsAdvert; import com.youlai.mall.sms.model.query.AdvertPageQuery; -import com.youlai.mall.sms.model.vo.AdBannerVO; +import com.youlai.mall.sms.model.vo.BannerVO; import com.youlai.mall.sms.model.vo.AdvertPageVO; import java.util.List; @@ -19,5 +19,5 @@ public interface SmsAdvertService extends IService { */ Page getAdvertPage(AdvertPageQuery queryParams); - List listAdBanners(); + List getBannerList(); } diff --git a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsAdvertServiceImpl.java b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsAdvertServiceImpl.java index d5881de90..826191477 100644 --- a/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsAdvertServiceImpl.java +++ b/mall-sms/sms-boot/src/main/java/com/youlai/mall/sms/service/impl/SmsAdvertServiceImpl.java @@ -8,7 +8,7 @@ import com.youlai.mall.sms.converter.AdvertConverter; import com.youlai.mall.sms.model.entity.SmsAdvert; import com.youlai.mall.sms.mapper.SmsAdvertMapper; import com.youlai.mall.sms.model.query.AdvertPageQuery; -import com.youlai.mall.sms.model.vo.AdBannerVO; +import com.youlai.mall.sms.model.vo.BannerVO; import com.youlai.mall.sms.model.vo.AdvertPageVO; import com.youlai.mall.sms.service.SmsAdvertService; import lombok.RequiredArgsConstructor; @@ -19,7 +19,7 @@ import java.util.List; /** * 广告业务实现类 * - * @author haoxr + * @author Ray Hao * @since 2022/5/28 */ @Service @@ -31,33 +31,27 @@ public class SmsAdvertServiceImpl extends ServiceImpl getAdvertPage(AdvertPageQuery queryParams) { - Page entities = this.baseMapper.getAdvertPage(new Page<>(queryParams.getPageNum(), + Page page = this.baseMapper.getAdvertPage(new Page<>(queryParams.getPageNum(), queryParams.getPageSize()), queryParams); - - Page advertVOPage = advertConverter.entity2PageVo(entities); - - return advertVOPage; + return advertConverter.entity2PageVo(page); } /** - * 广告横幅列表对象 - * - * @return + * 获取广告横幅列表 */ @Override - public List listAdBanners() { + public List getBannerList() { List entities = this.list(new LambdaQueryWrapper(). eq(SmsAdvert::getStatus, StatusEnum.ENABLE.getValue()) - .select(SmsAdvert::getTitle, SmsAdvert::getPicUrl, SmsAdvert::getRedirectUrl) + .select(SmsAdvert::getTitle, SmsAdvert::getImageUrl, SmsAdvert::getRedirectUrl) ); - List list = advertConverter.entity2BannerVo(entities); - return list; + return advertConverter.entity2BannerVo(entities); } }