diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java index 5dcfac83e..00475c6d7 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/CartServiceImpl.java @@ -2,10 +2,10 @@ package com.youlai.mall.oms.service.impl; import com.youlai.common.result.Result; import com.youlai.common.web.util.RequestUtils; -import com.youlai.mall.pms.api.InventoryFeignService; +import com.youlai.mall.pms.api.SkuFeignService; import com.youlai.mall.oms.bo.CartItemBo; import com.youlai.mall.oms.bo.CartItemCheckBo; -import com.youlai.mall.pms.pojo.dto.InventoryDTO; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.oms.pojo.vo.CartItemVo; import com.youlai.mall.oms.pojo.vo.CartVo; import com.youlai.mall.oms.service.CartService; @@ -45,7 +45,7 @@ public class CartServiceImpl implements CartService { private RedisTemplate redisTemplate; - private InventoryFeignService inventoryFeignService; + private SkuFeignService skuFeignService; @Override @@ -64,8 +64,8 @@ public class CartServiceImpl implements CartService { // 添加新商品到购物车 CompletableFuture skuInfoFuture = CompletableFuture.runAsync(() -> { //1、远程查询商品详情 - Result skuInfo = inventoryFeignService.getInventoryById(Long.parseLong(skuId)); - InventoryDTO data = skuInfo.getData(); + Result skuInfo = skuFeignService.getInventoryById(Long.parseLong(skuId)); + SkuDTO data = skuInfo.getData(); cartItem.setSkuId(Long.parseLong(skuId)); cartItem.setChecked(true); cartItem.setSkuName(data.getName()); diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OmsOrderServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OmsOrderServiceImpl.java index ace5f8488..2aa46df0b 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OmsOrderServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OmsOrderServiceImpl.java @@ -13,7 +13,7 @@ import com.youlai.mall.oms.pojo.OmsOrder; import com.youlai.mall.oms.pojo.OmsOrderItem; import com.youlai.mall.oms.service.IOmsOrderItemService; import com.youlai.mall.oms.service.IOmsOrderService; -import com.youlai.mall.pms.api.InventoryFeignService; +import com.youlai.mall.pms.api.SkuFeignService; import com.youlai.mall.ums.api.MemberFeignService; import com.youlai.mall.ums.pojo.dto.MemberDTO; import io.seata.spring.annotation.GlobalTransactional; @@ -81,12 +81,12 @@ public class OmsOrderServiceImpl extends ServiceImpl i return orderBO; } - private InventoryFeignService inventoryFeignService; + private SkuFeignService skuFeignService; @Override public boolean submit() { log.info("扣减库存----begin"); - inventoryFeignService.updateStock(1l, -1); + skuFeignService.updateStock(1l, -1); log.info("扣减库存----end"); log.info("增加积分----begin"); @@ -103,7 +103,7 @@ public class OmsOrderServiceImpl extends ServiceImpl i @GlobalTransactional(rollbackFor = Exception.class) public boolean submitWithGlobalTransactional() { log.info("扣减库存----begin"); - inventoryFeignService.updateStock(1l, -1); + skuFeignService.updateStock(1l, -1); log.info("扣减库存----end"); log.info("增加积分----begin"); diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderRabbitServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderRabbitServiceImpl.java index 9f210981a..6c92b5f51 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderRabbitServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderRabbitServiceImpl.java @@ -12,8 +12,8 @@ import com.youlai.mall.oms.pojo.entity.OrderGoodsEntity; import com.youlai.mall.oms.service.OrderGoodsService; import com.youlai.mall.oms.service.OrderRabbitService; import com.youlai.mall.oms.service.OrderService; -import com.youlai.mall.pms.api.InventoryFeignService; -import com.youlai.mall.pms.pojo.dto.InventoryNumDTO; +import com.youlai.mall.pms.api.SkuFeignService; +import com.youlai.mall.pms.pojo.dto.InventoryDTO; import io.seata.spring.annotation.GlobalTransactional; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -35,7 +35,7 @@ public class OrderRabbitServiceImpl implements OrderRabbitService { private OrderGoodsService orderGoodsService; - private InventoryFeignService inventoryFeignService; + private SkuFeignService skuFeignService; /** * 接收超时订单消息 @@ -68,13 +68,13 @@ public class OrderRabbitServiceImpl implements OrderRabbitService { private void unlockInventory(Long orderId) { List orderGoods = orderGoodsService.getByOrderId(orderId); - List items = orderGoods.stream().map(good -> { - InventoryNumDTO item = new InventoryNumDTO(); + List items = orderGoods.stream().map(good -> { + InventoryDTO item = new InventoryDTO(); item.setInventoryId(good.getSkuId()); item.setNum(good.getSkuQuantity()); return item; }).collect(Collectors.toList()); - Result result = inventoryFeignService.unlockInventory(items); + Result result = skuFeignService.unlockInventory(items); if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) { log.error("释放库存异常,商品列表={}", items); throw new BizException("关闭订单失败,释放库存错误"); diff --git a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java index 0c646b269..e9356ec54 100644 --- a/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java +++ b/mall-oms/oms-boot/src/main/java/com/youlai/mall/oms/service/impl/OrderServiceImpl.java @@ -29,9 +29,9 @@ import com.youlai.mall.oms.service.CartService; import com.youlai.mall.oms.service.OrderGoodsService; import com.youlai.mall.oms.service.OrderLogsService; import com.youlai.mall.oms.service.OrderService; -import com.youlai.mall.pms.api.InventoryFeignService; +import com.youlai.mall.pms.api.SkuFeignService; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO; -import com.youlai.mall.pms.pojo.dto.InventoryNumDTO; import com.youlai.mall.ums.api.MemberFeignService; import com.youlai.mall.ums.pojo.dto.UmsAddressDTO; import io.seata.spring.annotation.GlobalTransactional; @@ -59,7 +59,7 @@ public class OrderServiceImpl extends ServiceImpl impleme private CartService cartService; - private InventoryFeignService inventoryFeignService; + private SkuFeignService skuFeignService; private MemberFeignService memberFeignService; @@ -96,15 +96,15 @@ public class OrderServiceImpl extends ServiceImpl impleme } // feign调用商品接口,获取商品信息 - Map skuMap = new HashMap<>(items.size()); + Map skuMap = new HashMap<>(items.size()); List skuIds = items.stream().map(item -> item.getSkuId().toString()).collect(Collectors.toList()); - List skuInfos = inventoryFeignService.listBySkuIds(String.join(",", skuIds)).getData(); + List skuInfos = skuFeignService.listBySkuIds(String.join(",", skuIds)).getData(); if (!CollectionUtil.isEmpty(skuInfos)) { - skuMap = skuInfos.stream().collect(Collectors.toMap(InventoryDTO::getId, Function.identity())); + skuMap = skuInfos.stream().collect(Collectors.toMap(SkuDTO::getId, Function.identity())); } for (OrderItemVO item : items) { - InventoryDTO info = skuMap.get(item.getSkuId()); + SkuDTO info = skuMap.get(item.getSkuId()); if (info != null) { item.setPrice(info.getPrice()); item.setSkuImg(info.getPic()); @@ -288,13 +288,13 @@ public class OrderServiceImpl extends ServiceImpl impleme } private void lockStock(List orderGoods) { - List items = orderGoods.stream().map(good -> { - InventoryNumDTO item = new InventoryNumDTO(); + List items = orderGoods.stream().map(good -> { + InventoryDTO item = new InventoryDTO(); item.setInventoryId(good.getSkuId()); item.setNum(good.getSkuQuantity()); return item; }).collect(Collectors.toList()); - Result result = inventoryFeignService.lockStock(items); + Result result = skuFeignService.lockStock(items); if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) { log.error("锁定库存异常,商品列表={}", items); throw new BizException("下单失败,锁定库存错误"); @@ -363,14 +363,14 @@ public class OrderServiceImpl extends ServiceImpl impleme } List skuIds = orderGoods.stream().map(vo -> vo.getSkuId().toString()).collect(Collectors.toList()); - Result> response = inventoryFeignService.listBySkuIds(String.join(",", skuIds)); - List skuInfos = response.getData(); + Result> response = skuFeignService.listBySkuIds(String.join(",", skuIds)); + List skuInfos = response.getData(); if (skuInfos == null) { return null; } - Map skuMap = skuInfos.stream().collect(Collectors.toMap(InventoryDTO::getId, Function.identity(), (o1, o2) -> o2)); + Map skuMap = skuInfos.stream().collect(Collectors.toMap(SkuDTO::getId, Function.identity(), (o1, o2) -> o2)); for (OrderGoodsEntity good : orderGoods) { - InventoryDTO skuInfo = skuMap.get(good.getSkuId()); + SkuDTO skuInfo = skuMap.get(good.getSkuId()); if (skuInfo == null) { throw new BizException("订单商品库存为空"); } diff --git a/mall-oms/oms-boot/src/test/java/com/youlai/mall/oms/controller/OrderControllerTest.java b/mall-oms/oms-boot/src/test/java/com/youlai/mall/oms/controller/OrderControllerTest.java index 63a5b3471..6f4406350 100644 --- a/mall-oms/oms-boot/src/test/java/com/youlai/mall/oms/controller/OrderControllerTest.java +++ b/mall-oms/oms-boot/src/test/java/com/youlai/mall/oms/controller/OrderControllerTest.java @@ -5,7 +5,7 @@ import com.youlai.common.result.ResultCode; import com.youlai.mall.oms.controller.admin.OrderController; import com.youlai.mall.oms.pojo.OmsOrder; import com.youlai.mall.oms.service.IOmsOrderService; -import com.youlai.mall.pms.api.InventoryFeignService; +import com.youlai.mall.pms.api.SkuFeignService; import com.youlai.mall.ums.api.MemberFeignService; import io.seata.spring.annotation.GlobalTransactional; import lombok.extern.slf4j.Slf4j; @@ -56,7 +56,7 @@ public class OrderControllerTest { @Autowired - private InventoryFeignService inventoryFeignService; + private SkuFeignService skuFeignService; @Autowired private MemberFeignService memberFeignService; @@ -69,7 +69,7 @@ public class OrderControllerTest { @GlobalTransactional(rollbackFor = Exception.class) public void submitOrder() { // 扣减库存 - inventoryFeignService.updateStock(151l, -1); + // skuFeignService.lockStock(151l, -1); // 增加积分 memberFeignService.updatePoint(1l, 10); // 修改订单状态 diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/api/InventoryFeignService.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/api/InventoryFeignService.java deleted file mode 100644 index ad46196d3..000000000 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/api/InventoryFeignService.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.youlai.mall.pms.api; - -import com.youlai.common.result.Result; -import com.youlai.mall.pms.pojo.dto.InventoryDTO; -import com.youlai.mall.pms.pojo.dto.InventoryNumDTO; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@FeignClient("mall-pms") -public interface InventoryFeignService { - - /** - * 获取库存列表 - */ - @GetMapping("/api.app/v1/inventories/{ids}") - Result> listBySkuIds(@PathVariable String ids); - - /** - * 获取库存信息 - */ - @GetMapping("/api.app/v1/inventories/{id}") - Result getInventoryById(@PathVariable Long id); - - /** - * 锁定库存 - */ - @PostMapping("/api.app/v1/inventories/batch/_lock") - Result lockStock(@RequestBody List list); - - /** - * 解锁库存 - */ - @PostMapping("/api.app/v1/inventories/batch/_unlock") - Result unlockInventory(@RequestBody List list); - -} diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/api/SkuFeignService.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/api/SkuFeignService.java new file mode 100644 index 000000000..2b1474b2a --- /dev/null +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/api/SkuFeignService.java @@ -0,0 +1,38 @@ +package com.youlai.mall.pms.api; + +import com.youlai.common.result.Result; +import com.youlai.mall.pms.pojo.dto.SkuDTO; +import com.youlai.mall.pms.pojo.dto.InventoryDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@FeignClient("mall-pms") +public interface SkuFeignService { + + /** + * 获取库存列表 + */ + @GetMapping("/api.app/v1/skus/{ids}") + Result> listBySkuIds(@PathVariable String ids); + + /** + * 获取库存信息 + */ + @GetMapping("/api.app/v1/skus/{id}") + Result getInventoryById(@PathVariable Long id); + + /** + * 锁定库存 + */ + @PostMapping("/api.app/v1/skus/batch/_lock") + Result lockStock(@RequestBody List list); + + /** + * 解锁库存 + */ + @PostMapping("/api.app/v1/skus/batch/_unlock") + Result unlockInventory(@RequestBody List list); + +} diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/admin/ProductBO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/admin/ProductBO.java index 35eadb0f0..8f0476c8a 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/admin/ProductBO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/admin/ProductBO.java @@ -3,7 +3,7 @@ package com.youlai.mall.pms.pojo.bo.admin; import com.youlai.mall.pms.pojo.domain.PmsSku; import com.youlai.mall.pms.pojo.domain.PmsAttributeValue; import com.youlai.mall.pms.pojo.domain.PmsSpecificationValue; -import com.youlai.mall.pms.pojo.dto.ProductDTO; +import com.youlai.mall.pms.pojo.dto.SpuDTO; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -15,12 +15,12 @@ import java.util.List; @NoArgsConstructor public class ProductBO { - private ProductDTO product; + private SpuDTO spu; - private List attrs; + private List attrValues; - private List specs; + private List specValues; - private List skuList; + private List skus; } diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/app/ProductBO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/app/ProductBO.java index c20d526ed..4c82f4824 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/app/ProductBO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/bo/app/ProductBO.java @@ -3,7 +3,7 @@ package com.youlai.mall.pms.pojo.bo.app; import com.youlai.mall.pms.pojo.domain.PmsSku; import com.youlai.mall.pms.pojo.domain.PmsAttributeValue; import com.youlai.mall.pms.pojo.domain.PmsSpecification; -import com.youlai.mall.pms.pojo.dto.ProductDTO; +import com.youlai.mall.pms.pojo.dto.SpuDTO; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -15,12 +15,12 @@ import java.util.List; @NoArgsConstructor public class ProductBO { - private ProductDTO product; + private SpuDTO spu; - private List attrs; + private List attrValues; private List specs; - private List skuList; + private List skus; } diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSku.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSku.java index 60c1fe4b3..2c9752c3b 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSku.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSku.java @@ -18,5 +18,5 @@ public class PmsSku extends BaseEntity { private Long price; private Integer inventory; private Integer lockedInventory; - private String specValueIds; + private String specificationValueIds; } diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSpu.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSpu.java index c6a606160..de9f5b734 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSpu.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/domain/PmsSpu.java @@ -43,7 +43,7 @@ public class PmsSpu extends BaseEntity { private String brandName; @TableField(exist = false) - private List skuList; + private List skus; @TableField(exist = false) private List picList; diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryDTO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryDTO.java index 9abd03b75..580cf10f6 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryDTO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryDTO.java @@ -1,42 +1,22 @@ package com.youlai.mall.pms.pojo.dto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** - * @author huawei - * @desc - * @email huawei_code@163.com - * @date 2021/1/13 + * @description 库存数量 + * @author haoxr + * @createTime 2021-03-07 15:14 */ @Data +@ApiModel public class InventoryDTO { - private Long id; + @ApiModelProperty("库存ID") + private Long inventoryId; - private String code; - - private String name; - - private String pic; - - private Long originPrice; - - private Long price; - - private Integer inventory; - - private Long spuId; - - private String productName; - - private String productPic; - - private Long brandId; - - private String brandName; - - private Long categoryId; - - private String categoryName; + @ApiModelProperty("数量") + private Integer num; } diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryNumDTO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryNumDTO.java deleted file mode 100644 index 557d73b2c..000000000 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/InventoryNumDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.youlai.mall.pms.pojo.dto; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -/** - * @description 库存数量 - * @author haoxr - * @createTime 2021-03-07 15:14 - */ -@Data -@ApiModel -public class InventoryNumDTO { - - @ApiModelProperty("库存ID") - private Long inventoryId; - - @ApiModelProperty("数量") - private Integer num; - -} diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/SkuDTO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/SkuDTO.java new file mode 100644 index 000000000..c8b707ad3 --- /dev/null +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/SkuDTO.java @@ -0,0 +1,42 @@ +package com.youlai.mall.pms.pojo.dto; + +import lombok.Data; + +/** + * @author huawei + * @desc + * @email huawei_code@163.com + * @date 2021/1/13 + */ +@Data +public class SkuDTO { + + private Long id; + + private String code; + + private String name; + + private String pic; + + private Long originPrice; + + private Long price; + + private Integer inventory; + + private Long spuId; + + private String productName; + + private String productPic; + + private Long brandId; + + private String brandName; + + private Long categoryId; + + private String categoryName; + +} diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/ProductDTO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/SpuDTO.java similarity index 81% rename from mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/ProductDTO.java rename to mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/SpuDTO.java index bafe1e774..9539d1084 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/ProductDTO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/SpuDTO.java @@ -4,7 +4,7 @@ import lombok.Data; import java.util.List; @Data -public class ProductDTO { +public class SpuDTO { private Long id; private String name; @@ -13,8 +13,8 @@ public class ProductDTO { private Long originPrice; private Long price; private Integer sales; - private String picUrl; - private List picUrls; + private String pic; + private List pics; private String unit; private String description; private String detail; diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/CategoryVO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/CategoryVO.java index 6cf83cd04..65f4688e0 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/CategoryVO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/CategoryVO.java @@ -16,7 +16,7 @@ public class CategoryVO { private Integer level; - private String iconUrl; + private String icon; private Integer sort; diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/CategoryController.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/CategoryController.java index 6f8ffd1b9..ad5f456e1 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/CategoryController.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/CategoryController.java @@ -98,7 +98,7 @@ public class CategoryController { return Result.success(); } - @ApiOperation(value = "修改商品分类", httpMethod = "PATCH") + @ApiOperation(value = "修改分类", httpMethod = "PATCH") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory") diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SkuController.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SkuController.java index 4693078ca..da7180df4 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SkuController.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SkuController.java @@ -3,7 +3,7 @@ package com.youlai.mall.pms.controller.admin; import cn.hutool.core.bean.BeanUtil; import com.youlai.common.result.Result; import com.youlai.mall.pms.pojo.domain.PmsSku; -import com.youlai.mall.pms.pojo.dto.InventoryDTO; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.service.IPmsSkuService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -25,11 +25,11 @@ public class SkuController { @ApiOperation(value = "商品库存明细", httpMethod = "GET") @ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long") @GetMapping("/{id}") - public Result detail(@PathVariable Long id) { + public Result detail(@PathVariable Long id) { PmsSku sku = iPmsSkuService.getById(id); - InventoryDTO InventoryDTO = new InventoryDTO(); - BeanUtil.copyProperties(sku, InventoryDTO); - return Result.success(InventoryDTO); + SkuDTO SkuDTO = new SkuDTO(); + BeanUtil.copyProperties(sku, SkuDTO); + return Result.success(SkuDTO); } @ApiOperation(value = "修改库存", httpMethod = "PUT") diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SpecificationController.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SpecController.java similarity index 97% rename from mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SpecificationController.java rename to mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SpecController.java index c3eda8286..84ab805d3 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SpecificationController.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/admin/SpecController.java @@ -18,10 +18,10 @@ import java.util.stream.Collectors; @Api(tags = "【系统管理】商品规格") @RestController -@RequestMapping("/api.admin/v1/specifications") +@RequestMapping("/api.admin/v1/specs") @Slf4j @AllArgsConstructor -public class SpecificationController { +public class SpecController { private IPmsSpecificationService iPmsSpecificationService; diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/InventoryController.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SkuController.java similarity index 82% rename from mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/InventoryController.java rename to mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SkuController.java index 94d25ebe6..923a2faa3 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/InventoryController.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SkuController.java @@ -3,8 +3,8 @@ package com.youlai.mall.pms.controller.app; import cn.hutool.core.bean.BeanUtil; import com.youlai.common.result.Result; import com.youlai.mall.pms.pojo.domain.PmsSku; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO; -import com.youlai.mall.pms.pojo.dto.InventoryNumDTO; import com.youlai.mall.pms.service.IPmsSkuService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,10 +15,10 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @Api(tags = "【移动端】商品库存") -@RestController("AppInventoryController") -@RequestMapping("/api.app/v1/inventories") +@RestController("AppSkuController") +@RequestMapping("/api.app/v1/skus") @AllArgsConstructor -public class InventoryController { +public class SkuController { private IPmsSkuService iPmsSkuService; @@ -26,11 +26,11 @@ public class InventoryController { @ApiOperation(value = "商品库存详情", httpMethod = "GET") @ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long") @GetMapping("/{id}") - public Result detail(@PathVariable Long id) { + public Result detail(@PathVariable Long id) { PmsSku sku = iPmsSkuService.getById(id); - InventoryDTO InventoryDTO = new InventoryDTO(); - BeanUtil.copyProperties(sku, InventoryDTO); - return Result.success(InventoryDTO); + SkuDTO SkuDTO = new SkuDTO(); + BeanUtil.copyProperties(sku, SkuDTO); + return Result.success(SkuDTO); } @ApiOperation("获取商品的库存数量") @@ -45,7 +45,7 @@ public class InventoryController { @ApiOperation(value = "锁定库存", httpMethod = "PUT") @ApiImplicitParam(name = "list", value = "锁定库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @PostMapping("/batch/_lock") - public Result lockInventory(@RequestBody List list) { + public Result lockInventory(@RequestBody List list) { boolean result = iPmsSkuService.lockInventory(list); return Result.judge(result); } @@ -54,7 +54,7 @@ public class InventoryController { @ApiOperation(value = "解锁库存", httpMethod = "PUT") @ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @PostMapping("/batch/_unlock") - public Result unlockInventory(@RequestBody List list) { + public Result unlockInventory(@RequestBody List list) { boolean result = iPmsSkuService.unlockInventory(list); return Result.judge(result); } @@ -64,7 +64,7 @@ public class InventoryController { @ApiImplicitParam(name = "skuIds", value = "库存ID集合字符串,英文逗号,分割", required = true, paramType = "param", dataType = "String") @GetMapping("/{ids}") public Result list(@PathVariable String ids) { - List list = iPmsSkuService.listBySkuIds(ids); + List list = iPmsSkuService.listBySkuIds(ids); return Result.success(list); } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/ProductController.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SpuController.java similarity index 86% rename from mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/ProductController.java rename to mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SpuController.java index b9042a230..25553b2eb 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/ProductController.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SpuController.java @@ -6,6 +6,7 @@ import com.youlai.common.result.Result; import com.youlai.mall.pms.pojo.bo.app.ProductBO; import com.youlai.mall.pms.pojo.domain.PmsSpu; import com.youlai.mall.pms.service.IPmsSpuService; +import com.youlai.mall.pms.service.ISpuService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -14,13 +15,15 @@ import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; @Api(tags = "【移动端】商品信息") -@RestController("AppProductController") -@RequestMapping("/api.app/v1/products") +@RestController("AppSpuController") +@RequestMapping("/api.app/v1/spus") @AllArgsConstructor -public class ProductController { +public class SpuController { private IPmsSpuService iPmsSpuService; + private ISpuService iSpuService; + @ApiOperation(value = "列表分页", httpMethod = "GET") @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"), @@ -43,10 +46,10 @@ public class ProductController { } @ApiOperation(value = "商品详情", httpMethod = "GET") - @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long") + @ApiImplicitParam(name = "id", value = "商品ID", required = true, paramType = "path", dataType = "Long") @GetMapping("/{id}") public Result detail(@PathVariable Long id) { - ProductBO product = iPmsSpuService.getProductByIdForApp(id); + ProductBO product = iSpuService.getProductById(id); return Result.success(product); } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java index 809444265..e410c332c 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsProductMapper.java @@ -28,14 +28,14 @@ public interface PmsProductMapper extends BaseMapper { " LEFT JOIN pms_category t2 ON t1.category_id = t2.id " + " LEFT JOIN pms_brand t3 ON t1.brand_id = t3.id " + " WHERE 1=1 " + - " " + - " AND t2.id = #{product.categoryId} " + + " " + + " AND t2.id = #{spu.categoryId} " + " " + " ORDER BY t1.gmt_create DESC" + "") @Results({ @Result(id = true, column = "id", property = "id"), - @Result(property = "skuList",column = "id",many = @Many(select="com.youlai.mall.pms.mapper.PmsSkuMapper.listBySpuId")) + @Result(property = "skus",column = "id",many = @Many(select="com.youlai.mall.pms.mapper.PmsSkuMapper.listBySpuId")) }) - List list(Page page, PmsSpu product); + List list(Page page, PmsSpu spu); } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSkuMapper.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSkuMapper.java index 7d0a57ef8..eeac25de2 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSkuMapper.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/mapper/PmsSkuMapper.java @@ -2,7 +2,7 @@ package com.youlai.mall.pms.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.youlai.mall.pms.pojo.domain.PmsSku; -import com.youlai.mall.pms.pojo.dto.InventoryDTO; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @@ -42,5 +42,5 @@ public interface PmsSkuMapper extends BaseMapper { " WHERE t1.id in (#{skuIds})", "" }) - List listBySkuIds(String skuIds); + List listBySkuIds(String skuIds); } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/IPmsSkuService.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/IPmsSkuService.java index 7b4f69626..b07c1d7dc 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/IPmsSkuService.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/IPmsSkuService.java @@ -2,8 +2,8 @@ package com.youlai.mall.pms.service; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.mall.pms.pojo.domain.PmsSku; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO; -import com.youlai.mall.pms.pojo.dto.InventoryNumDTO; import java.util.List; @@ -14,14 +14,14 @@ public interface IPmsSkuService extends IService { * @param list * @return 库存锁定结果 */ - boolean lockInventory(List list); + boolean lockInventory(List list); /** * 解锁库存 * @param list * @return 解锁库存结果 */ - boolean unlockInventory(List list); + boolean unlockInventory(List list); /** @@ -37,5 +37,5 @@ public interface IPmsSkuService extends IService { * @param ids * @return */ - List listBySkuIds(String ids); + List listBySkuIds(String ids); } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/ISpuService.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/ISpuService.java new file mode 100644 index 000000000..81f47f363 --- /dev/null +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/ISpuService.java @@ -0,0 +1,11 @@ +package com.youlai.mall.pms.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.youlai.mall.pms.pojo.bo.app.ProductBO; +import com.youlai.mall.pms.pojo.domain.PmsSpu; + + +public interface ISpuService extends IService { + + ProductBO getProductById(Long id); +} diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java index 2fc6c32b7..20b0720f0 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java @@ -8,8 +8,8 @@ import com.youlai.common.web.exception.BizException; import com.youlai.mall.pms.common.constant.RedisConstants; import com.youlai.mall.pms.mapper.PmsSkuMapper; import com.youlai.mall.pms.pojo.domain.PmsSku; +import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO; -import com.youlai.mall.pms.pojo.dto.InventoryNumDTO; import com.youlai.mall.pms.service.IPmsSkuService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,7 +29,7 @@ public class PmsSkuServiceImpl extends ServiceImpl impleme @Override @Transactional(rollbackFor = Exception.class) - public boolean lockInventory(List inventories) { + public boolean lockInventory(List inventories) { log.info("锁定库存: {}", inventories); inventories.forEach(item -> { @@ -47,7 +47,7 @@ public class PmsSkuServiceImpl extends ServiceImpl impleme } @Override - public boolean unlockInventory(List inventories) { + public boolean unlockInventory(List inventories) { log.info("释放库存:{}", inventories); inventories.forEach(item -> { @@ -97,7 +97,7 @@ public class PmsSkuServiceImpl extends ServiceImpl impleme } @Override - public List listBySkuIds(String ids) { + public List listBySkuIds(String ids) { return this.listBySkuIds(ids); } } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java index 12b43bcf9..cf66515a4 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java @@ -7,10 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.youlai.mall.pms.pojo.bo.app.ProductBO; import com.youlai.mall.pms.mapper.PmsProductMapper; +import com.youlai.mall.pms.pojo.bo.admin.ProductBO; import com.youlai.mall.pms.pojo.domain.*; -import com.youlai.mall.pms.pojo.dto.ProductDTO; +import com.youlai.mall.pms.pojo.dto.SpuDTO; import com.youlai.mall.pms.service.*; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; @@ -43,23 +43,23 @@ public class PmsSpuServiceImpl extends ServiceImpl imp @Override @Transactional - public boolean add(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO) { - ProductDTO ProductDTO = spuBO.getProduct(); - List attrs = spuBO.getAttrs(); - List specs = spuBO.getSpecs(); - List skuList = spuBO.getSkuList(); + public boolean add(ProductBO spuBO) { + SpuDTO SpuDTO = spuBO.getSpu(); + List attrValues = spuBO.getAttrValues(); + List specs = spuBO.getSpecValues(); + List skuList = spuBO.getSkus(); // spu保存 PmsSpu spu = new PmsSpu(); - BeanUtil.copyProperties(ProductDTO, spu); - if (ProductDTO.getPicUrls() != null) { - String picUrls = JSONUtil.toJsonStr(ProductDTO.getPicUrls()); + BeanUtil.copyProperties(SpuDTO, spu); + if (SpuDTO.getPics() != null) { + String picUrls = JSONUtil.toJsonStr(SpuDTO.getPics()); spu.setPics(picUrls); } this.save(spu); // 属性保存 - Optional.ofNullable(attrs).ifPresent(list -> { + Optional.ofNullable(attrValues).ifPresent(list -> { list.forEach(item -> item.setSpuId(spu.getId())); iPmsAttributeValueService.saveBatch(list); }); @@ -82,14 +82,14 @@ public class PmsSpuServiceImpl extends ServiceImpl imp @Override public com.youlai.mall.pms.pojo.bo.admin.ProductBO getBySpuId(Long id) { // spu - ProductDTO ProductDTO = new ProductDTO(); + SpuDTO spuDTO = new SpuDTO(); PmsSpu spu = this.getById(id); - BeanUtil.copyProperties(spu, ProductDTO); + BeanUtil.copyProperties(spu, spuDTO); if (StrUtil.isNotBlank(spu.getPics())) { // spu专辑图片转换处理 json字符串 -> List List pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); - ProductDTO.setPicUrls(pics); + spuDTO.setPics(pics); } // 属性 @@ -98,33 +98,33 @@ public class PmsSpuServiceImpl extends ServiceImpl imp // 规格 List specs = iPmsSpecificationValueService.list(new LambdaQueryWrapper().eq(PmsSpecificationValue::getSpuId, id)); // sku - List skuList = iPmsSkuService.list(new LambdaQueryWrapper().eq(PmsSku::getSpuId, id)); + List skus = iPmsSkuService.list(new LambdaQueryWrapper().eq(PmsSku::getSpuId, id)); // 组合 - com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO = new com.youlai.mall.pms.pojo.bo.admin.ProductBO(ProductDTO, attrs, specs, skuList); + ProductBO spuBO = new ProductBO(spuDTO, attrs, specs, skus); return spuBO; } @Override public boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO) { - ProductDTO ProductDTO = spuBO.getProduct(); + SpuDTO SpuDTO = spuBO.getSpu(); - List attrs = spuBO.getAttrs(); - List specs = spuBO.getSpecs(); - List skuList = spuBO.getSkuList(); + List attrValues = spuBO.getAttrValues(); + List specs = spuBO.getSpecValues(); + List skuList = spuBO.getSkus(); // spu保存 PmsSpu spu = new PmsSpu(); - BeanUtil.copyProperties(ProductDTO, spu); - if (ProductDTO.getPicUrls() != null) { - String picUrls = JSONUtil.toJsonStr(ProductDTO.getPicUrls()); - spu.setPics(picUrls); + BeanUtil.copyProperties(SpuDTO, spu); + if (SpuDTO.getPics() != null) { + String pics = JSONUtil.toJsonStr(SpuDTO.getPics()); + spu.setPics(pics); } this.updateById(spu); // 属性保存 - Optional.ofNullable(attrs).ifPresent(list -> { + Optional.ofNullable(attrValues).ifPresent(list -> { list.forEach(item -> item.setSpuId(spu.getId())); // 删除此次保存删除的 @@ -194,15 +194,15 @@ public class PmsSpuServiceImpl extends ServiceImpl imp } @Override - public ProductBO getProductByIdForApp(Long spuId) { + public com.youlai.mall.pms.pojo.bo.app.ProductBO getProductByIdForApp(Long spuId) { // spu PmsSpu spu = this.getById(spuId); - ProductDTO ProductDTO = new ProductDTO(); - BeanUtil.copyProperties(spu, ProductDTO); + SpuDTO SpuDTO = new SpuDTO(); + BeanUtil.copyProperties(spu, SpuDTO); if (StrUtil.isNotBlank(spu.getPics())) { // spu专辑图片转换处理 json字符串 -> List List pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); - ProductDTO.setPicUrls(pics); + SpuDTO.setPics(pics); } // 属性 List attrs = iPmsAttributeValueService.list( @@ -216,7 +216,7 @@ public class PmsSpuServiceImpl extends ServiceImpl imp // sku List skuList = iPmsSkuService.list(new LambdaQueryWrapper().eq(PmsSku::getSpuId, spuId)); - ProductBO product = new ProductBO(ProductDTO, attrs, specs, skuList); + com.youlai.mall.pms.pojo.bo.app.ProductBO product = new com.youlai.mall.pms.pojo.bo.app.ProductBO(SpuDTO, attrs, specs, skuList); return product; } } diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/SpuServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/SpuServiceImpl.java new file mode 100644 index 000000000..9a801aa3c --- /dev/null +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/SpuServiceImpl.java @@ -0,0 +1,62 @@ +package com.youlai.mall.pms.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.mall.pms.mapper.PmsProductMapper; +import com.youlai.mall.pms.pojo.bo.app.ProductBO; +import com.youlai.mall.pms.pojo.domain.PmsAttributeValue; +import com.youlai.mall.pms.pojo.domain.PmsSku; +import com.youlai.mall.pms.pojo.domain.PmsSpecification; +import com.youlai.mall.pms.pojo.domain.PmsSpu; +import com.youlai.mall.pms.pojo.dto.SpuDTO; +import com.youlai.mall.pms.service.IPmsAttributeValueService; +import com.youlai.mall.pms.service.IPmsSkuService; +import com.youlai.mall.pms.service.IPmsSpecificationService; +import com.youlai.mall.pms.service.ISpuService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author haoxr + * @date 2020-11-06 + */ +@Service +@AllArgsConstructor +public class SpuServiceImpl extends ServiceImpl implements ISpuService { + + private IPmsSkuService iPmsSkuService; + private IPmsAttributeValueService iPmsAttributeValueService; + private IPmsSpecificationService iPmsSpecificationService; + + @Override + public ProductBO getProductById(Long spuId) { + // spu + PmsSpu spu = this.getById(spuId); + SpuDTO SpuDTO = new SpuDTO(); + BeanUtil.copyProperties(spu, SpuDTO); + if (StrUtil.isNotBlank(spu.getPics())) { + // spu专辑图片转换处理 json字符串 -> List + List pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); + SpuDTO.setPics(pics); + } + // 属性 + List attrs = iPmsAttributeValueService.list( + new LambdaQueryWrapper( + ).eq(PmsAttributeValue::getSpuId, spuId) + ); + + // 规格 + List specs = iPmsSpecificationService.listBySpuId(spuId); + + // sku + List skuList = iPmsSkuService.list(new LambdaQueryWrapper().eq(PmsSku::getSpuId, spuId)); + + ProductBO product = new ProductBO(SpuDTO, attrs, specs, skuList); + return product; + } +}