refactor:商品重构

This commit is contained in:
haoxr 2021-03-11 20:20:04 +08:00
parent f850cf5bcb
commit b9c3af7454
28 changed files with 281 additions and 205 deletions

View File

@ -2,10 +2,10 @@ package com.youlai.mall.oms.service.impl;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.common.web.util.RequestUtils; 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.CartItemBo;
import com.youlai.mall.oms.bo.CartItemCheckBo; 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.CartItemVo;
import com.youlai.mall.oms.pojo.vo.CartVo; import com.youlai.mall.oms.pojo.vo.CartVo;
import com.youlai.mall.oms.service.CartService; import com.youlai.mall.oms.service.CartService;
@ -45,7 +45,7 @@ public class CartServiceImpl implements CartService {
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
private InventoryFeignService inventoryFeignService; private SkuFeignService skuFeignService;
@Override @Override
@ -64,8 +64,8 @@ public class CartServiceImpl implements CartService {
// 添加新商品到购物车 // 添加新商品到购物车
CompletableFuture<Void> skuInfoFuture = CompletableFuture.runAsync(() -> { CompletableFuture<Void> skuInfoFuture = CompletableFuture.runAsync(() -> {
//1远程查询商品详情 //1远程查询商品详情
Result<InventoryDTO> skuInfo = inventoryFeignService.getInventoryById(Long.parseLong(skuId)); Result<SkuDTO> skuInfo = skuFeignService.getInventoryById(Long.parseLong(skuId));
InventoryDTO data = skuInfo.getData(); SkuDTO data = skuInfo.getData();
cartItem.setSkuId(Long.parseLong(skuId)); cartItem.setSkuId(Long.parseLong(skuId));
cartItem.setChecked(true); cartItem.setChecked(true);
cartItem.setSkuName(data.getName()); cartItem.setSkuName(data.getName());

View File

@ -13,7 +13,7 @@ import com.youlai.mall.oms.pojo.OmsOrder;
import com.youlai.mall.oms.pojo.OmsOrderItem; import com.youlai.mall.oms.pojo.OmsOrderItem;
import com.youlai.mall.oms.service.IOmsOrderItemService; import com.youlai.mall.oms.service.IOmsOrderItemService;
import com.youlai.mall.oms.service.IOmsOrderService; 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.api.MemberFeignService;
import com.youlai.mall.ums.pojo.dto.MemberDTO; import com.youlai.mall.ums.pojo.dto.MemberDTO;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
@ -81,12 +81,12 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper, OmsOrder> i
return orderBO; return orderBO;
} }
private InventoryFeignService inventoryFeignService; private SkuFeignService skuFeignService;
@Override @Override
public boolean submit() { public boolean submit() {
log.info("扣减库存----begin"); log.info("扣减库存----begin");
inventoryFeignService.updateStock(1l, -1); skuFeignService.updateStock(1l, -1);
log.info("扣减库存----end"); log.info("扣减库存----end");
log.info("增加积分----begin"); log.info("增加积分----begin");
@ -103,7 +103,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper, OmsOrder> i
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)
public boolean submitWithGlobalTransactional() { public boolean submitWithGlobalTransactional() {
log.info("扣减库存----begin"); log.info("扣减库存----begin");
inventoryFeignService.updateStock(1l, -1); skuFeignService.updateStock(1l, -1);
log.info("扣减库存----end"); log.info("扣减库存----end");
log.info("增加积分----begin"); log.info("增加积分----begin");

View File

@ -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.OrderGoodsService;
import com.youlai.mall.oms.service.OrderRabbitService; import com.youlai.mall.oms.service.OrderRabbitService;
import com.youlai.mall.oms.service.OrderService; 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.InventoryNumDTO; import com.youlai.mall.pms.pojo.dto.InventoryDTO;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -35,7 +35,7 @@ public class OrderRabbitServiceImpl implements OrderRabbitService {
private OrderGoodsService orderGoodsService; private OrderGoodsService orderGoodsService;
private InventoryFeignService inventoryFeignService; private SkuFeignService skuFeignService;
/** /**
* 接收超时订单消息 * 接收超时订单消息
@ -68,13 +68,13 @@ public class OrderRabbitServiceImpl implements OrderRabbitService {
private void unlockInventory(Long orderId) { private void unlockInventory(Long orderId) {
List<OrderGoodsEntity> orderGoods = orderGoodsService.getByOrderId(orderId); List<OrderGoodsEntity> orderGoods = orderGoodsService.getByOrderId(orderId);
List<InventoryNumDTO> items = orderGoods.stream().map(good -> { List<InventoryDTO> items = orderGoods.stream().map(good -> {
InventoryNumDTO item = new InventoryNumDTO(); InventoryDTO item = new InventoryDTO();
item.setInventoryId(good.getSkuId()); item.setInventoryId(good.getSkuId());
item.setNum(good.getSkuQuantity()); item.setNum(good.getSkuQuantity());
return item; return item;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
Result result = inventoryFeignService.unlockInventory(items); Result result = skuFeignService.unlockInventory(items);
if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) { if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
log.error("释放库存异常,商品列表={}", items); log.error("释放库存异常,商品列表={}", items);
throw new BizException("关闭订单失败,释放库存错误"); throw new BizException("关闭订单失败,释放库存错误");

View File

@ -29,9 +29,9 @@ import com.youlai.mall.oms.service.CartService;
import com.youlai.mall.oms.service.OrderGoodsService; import com.youlai.mall.oms.service.OrderGoodsService;
import com.youlai.mall.oms.service.OrderLogsService; import com.youlai.mall.oms.service.OrderLogsService;
import com.youlai.mall.oms.service.OrderService; 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.InventoryDTO;
import com.youlai.mall.pms.pojo.dto.InventoryNumDTO;
import com.youlai.mall.ums.api.MemberFeignService; import com.youlai.mall.ums.api.MemberFeignService;
import com.youlai.mall.ums.pojo.dto.UmsAddressDTO; import com.youlai.mall.ums.pojo.dto.UmsAddressDTO;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
@ -59,7 +59,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> impleme
private CartService cartService; private CartService cartService;
private InventoryFeignService inventoryFeignService; private SkuFeignService skuFeignService;
private MemberFeignService memberFeignService; private MemberFeignService memberFeignService;
@ -96,15 +96,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> impleme
} }
// feign调用商品接口获取商品信息 // feign调用商品接口获取商品信息
Map<Long, InventoryDTO> skuMap = new HashMap<>(items.size()); Map<Long, SkuDTO> skuMap = new HashMap<>(items.size());
List<String> skuIds = items.stream().map(item -> item.getSkuId().toString()).collect(Collectors.toList()); List<String> skuIds = items.stream().map(item -> item.getSkuId().toString()).collect(Collectors.toList());
List<InventoryDTO> skuInfos = inventoryFeignService.listBySkuIds(String.join(",", skuIds)).getData(); List<SkuDTO> skuInfos = skuFeignService.listBySkuIds(String.join(",", skuIds)).getData();
if (!CollectionUtil.isEmpty(skuInfos)) { 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) { for (OrderItemVO item : items) {
InventoryDTO info = skuMap.get(item.getSkuId()); SkuDTO info = skuMap.get(item.getSkuId());
if (info != null) { if (info != null) {
item.setPrice(info.getPrice()); item.setPrice(info.getPrice());
item.setSkuImg(info.getPic()); item.setSkuImg(info.getPic());
@ -288,13 +288,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> impleme
} }
private void lockStock(List<OrderGoodsEntity> orderGoods) { private void lockStock(List<OrderGoodsEntity> orderGoods) {
List<InventoryNumDTO> items = orderGoods.stream().map(good -> { List<InventoryDTO> items = orderGoods.stream().map(good -> {
InventoryNumDTO item = new InventoryNumDTO(); InventoryDTO item = new InventoryDTO();
item.setInventoryId(good.getSkuId()); item.setInventoryId(good.getSkuId());
item.setNum(good.getSkuQuantity()); item.setNum(good.getSkuQuantity());
return item; return item;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
Result result = inventoryFeignService.lockStock(items); Result result = skuFeignService.lockStock(items);
if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) { if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
log.error("锁定库存异常,商品列表={}", items); log.error("锁定库存异常,商品列表={}", items);
throw new BizException("下单失败,锁定库存错误"); throw new BizException("下单失败,锁定库存错误");
@ -363,14 +363,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> impleme
} }
List<String> skuIds = orderGoods.stream().map(vo -> vo.getSkuId().toString()).collect(Collectors.toList()); List<String> skuIds = orderGoods.stream().map(vo -> vo.getSkuId().toString()).collect(Collectors.toList());
Result<List<InventoryDTO>> response = inventoryFeignService.listBySkuIds(String.join(",", skuIds)); Result<List<SkuDTO>> response = skuFeignService.listBySkuIds(String.join(",", skuIds));
List<InventoryDTO> skuInfos = response.getData(); List<SkuDTO> skuInfos = response.getData();
if (skuInfos == null) { if (skuInfos == null) {
return null; return null;
} }
Map<Long, InventoryDTO> skuMap = skuInfos.stream().collect(Collectors.toMap(InventoryDTO::getId, Function.identity(), (o1, o2) -> o2)); Map<Long, SkuDTO> skuMap = skuInfos.stream().collect(Collectors.toMap(SkuDTO::getId, Function.identity(), (o1, o2) -> o2));
for (OrderGoodsEntity good : orderGoods) { for (OrderGoodsEntity good : orderGoods) {
InventoryDTO skuInfo = skuMap.get(good.getSkuId()); SkuDTO skuInfo = skuMap.get(good.getSkuId());
if (skuInfo == null) { if (skuInfo == null) {
throw new BizException("订单商品库存为空"); throw new BizException("订单商品库存为空");
} }

View File

@ -5,7 +5,7 @@ import com.youlai.common.result.ResultCode;
import com.youlai.mall.oms.controller.admin.OrderController; import com.youlai.mall.oms.controller.admin.OrderController;
import com.youlai.mall.oms.pojo.OmsOrder; import com.youlai.mall.oms.pojo.OmsOrder;
import com.youlai.mall.oms.service.IOmsOrderService; 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.api.MemberFeignService;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -56,7 +56,7 @@ public class OrderControllerTest {
@Autowired @Autowired
private InventoryFeignService inventoryFeignService; private SkuFeignService skuFeignService;
@Autowired @Autowired
private MemberFeignService memberFeignService; private MemberFeignService memberFeignService;
@ -69,7 +69,7 @@ public class OrderControllerTest {
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)
public void submitOrder() { public void submitOrder() {
// 扣减库存 // 扣减库存
inventoryFeignService.updateStock(151l, -1); // skuFeignService.lockStock(151l, -1);
// 增加积分 // 增加积分
memberFeignService.updatePoint(1l, 10); memberFeignService.updatePoint(1l, 10);
// 修改订单状态 // 修改订单状态

View File

@ -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<List<InventoryDTO>> listBySkuIds(@PathVariable String ids);
/**
* 获取库存信息
*/
@GetMapping("/api.app/v1/inventories/{id}")
Result<InventoryDTO> getInventoryById(@PathVariable Long id);
/**
* 锁定库存
*/
@PostMapping("/api.app/v1/inventories/batch/_lock")
Result lockStock(@RequestBody List<InventoryNumDTO> list);
/**
* 解锁库存
*/
@PostMapping("/api.app/v1/inventories/batch/_unlock")
Result<Boolean> unlockInventory(@RequestBody List<InventoryNumDTO> list);
}

View File

@ -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<List<SkuDTO>> listBySkuIds(@PathVariable String ids);
/**
* 获取库存信息
*/
@GetMapping("/api.app/v1/skus/{id}")
Result<SkuDTO> getInventoryById(@PathVariable Long id);
/**
* 锁定库存
*/
@PostMapping("/api.app/v1/skus/batch/_lock")
Result lockStock(@RequestBody List<InventoryDTO> list);
/**
* 解锁库存
*/
@PostMapping("/api.app/v1/skus/batch/_unlock")
Result<Boolean> unlockInventory(@RequestBody List<InventoryDTO> list);
}

View File

@ -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.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsAttributeValue; import com.youlai.mall.pms.pojo.domain.PmsAttributeValue;
import com.youlai.mall.pms.pojo.domain.PmsSpecificationValue; 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.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -15,12 +15,12 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class ProductBO { public class ProductBO {
private ProductDTO product; private SpuDTO spu;
private List<PmsAttributeValue> attrs; private List<PmsAttributeValue> attrValues;
private List<PmsSpecificationValue> specs; private List<PmsSpecificationValue> specValues;
private List<PmsSku> skuList; private List<PmsSku> skus;
} }

View File

@ -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.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsAttributeValue; import com.youlai.mall.pms.pojo.domain.PmsAttributeValue;
import com.youlai.mall.pms.pojo.domain.PmsSpecification; 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.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -15,12 +15,12 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class ProductBO { public class ProductBO {
private ProductDTO product; private SpuDTO spu;
private List<PmsAttributeValue> attrs; private List<PmsAttributeValue> attrValues;
private List<PmsSpecification> specs; private List<PmsSpecification> specs;
private List<PmsSku> skuList; private List<PmsSku> skus;
} }

View File

@ -18,5 +18,5 @@ public class PmsSku extends BaseEntity {
private Long price; private Long price;
private Integer inventory; private Integer inventory;
private Integer lockedInventory; private Integer lockedInventory;
private String specValueIds; private String specificationValueIds;
} }

View File

@ -43,7 +43,7 @@ public class PmsSpu extends BaseEntity {
private String brandName; private String brandName;
@TableField(exist = false) @TableField(exist = false)
private List<PmsSku> skuList; private List<PmsSku> skus;
@TableField(exist = false) @TableField(exist = false)
private List<String> picList; private List<String> picList;

View File

@ -1,42 +1,22 @@
package com.youlai.mall.pms.pojo.dto; package com.youlai.mall.pms.pojo.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
/** /**
* @author huawei * @description 库存数量
* @desc * @author haoxr
* @email huawei_code@163.com * @createTime 2021-03-07 15:14
* @date 2021/1/13
*/ */
@Data @Data
@ApiModel
public class InventoryDTO { public class InventoryDTO {
private Long id; @ApiModelProperty("库存ID")
private Long inventoryId;
private String code; @ApiModelProperty("数量")
private Integer num;
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;
} }

View File

@ -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;
}

View File

@ -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;
}

View File

@ -4,7 +4,7 @@ import lombok.Data;
import java.util.List; import java.util.List;
@Data @Data
public class ProductDTO { public class SpuDTO {
private Long id; private Long id;
private String name; private String name;
@ -13,8 +13,8 @@ public class ProductDTO {
private Long originPrice; private Long originPrice;
private Long price; private Long price;
private Integer sales; private Integer sales;
private String picUrl; private String pic;
private List<String> picUrls; private List<String> pics;
private String unit; private String unit;
private String description; private String description;
private String detail; private String detail;

View File

@ -16,7 +16,7 @@ public class CategoryVO {
private Integer level; private Integer level;
private String iconUrl; private String icon;
private Integer sort; private Integer sort;

View File

@ -98,7 +98,7 @@ public class CategoryController {
return Result.success(); return Result.success();
} }
@ApiOperation(value = "修改商品分类", httpMethod = "PATCH") @ApiOperation(value = "修改分类", httpMethod = "PATCH")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory") @ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory")

View File

@ -3,7 +3,7 @@ package com.youlai.mall.pms.controller.admin;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku; 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 com.youlai.mall.pms.service.IPmsSkuService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -25,11 +25,11 @@ public class SkuController {
@ApiOperation(value = "商品库存明细", httpMethod = "GET") @ApiOperation(value = "商品库存明细", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result<InventoryDTO> detail(@PathVariable Long id) { public Result<SkuDTO> detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id); PmsSku sku = iPmsSkuService.getById(id);
InventoryDTO InventoryDTO = new InventoryDTO(); SkuDTO SkuDTO = new SkuDTO();
BeanUtil.copyProperties(sku, InventoryDTO); BeanUtil.copyProperties(sku, SkuDTO);
return Result.success(InventoryDTO); return Result.success(SkuDTO);
} }
@ApiOperation(value = "修改库存", httpMethod = "PUT") @ApiOperation(value = "修改库存", httpMethod = "PUT")

View File

@ -18,10 +18,10 @@ import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品规格") @Api(tags = "【系统管理】商品规格")
@RestController @RestController
@RequestMapping("/api.admin/v1/specifications") @RequestMapping("/api.admin/v1/specs")
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
public class SpecificationController { public class SpecController {
private IPmsSpecificationService iPmsSpecificationService; private IPmsSpecificationService iPmsSpecificationService;

View File

@ -3,8 +3,8 @@ package com.youlai.mall.pms.controller.app;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku; 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.InventoryDTO;
import com.youlai.mall.pms.pojo.dto.InventoryNumDTO;
import com.youlai.mall.pms.service.IPmsSkuService; import com.youlai.mall.pms.service.IPmsSkuService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -15,10 +15,10 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@Api(tags = "【移动端】商品库存") @Api(tags = "【移动端】商品库存")
@RestController("AppInventoryController") @RestController("AppSkuController")
@RequestMapping("/api.app/v1/inventories") @RequestMapping("/api.app/v1/skus")
@AllArgsConstructor @AllArgsConstructor
public class InventoryController { public class SkuController {
private IPmsSkuService iPmsSkuService; private IPmsSkuService iPmsSkuService;
@ -26,11 +26,11 @@ public class InventoryController {
@ApiOperation(value = "商品库存详情", httpMethod = "GET") @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}") @GetMapping("/{id}")
public Result<InventoryDTO> detail(@PathVariable Long id) { public Result<SkuDTO> detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id); PmsSku sku = iPmsSkuService.getById(id);
InventoryDTO InventoryDTO = new InventoryDTO(); SkuDTO SkuDTO = new SkuDTO();
BeanUtil.copyProperties(sku, InventoryDTO); BeanUtil.copyProperties(sku, SkuDTO);
return Result.success(InventoryDTO); return Result.success(SkuDTO);
} }
@ApiOperation("获取商品的库存数量") @ApiOperation("获取商品的库存数量")
@ -45,7 +45,7 @@ public class InventoryController {
@ApiOperation(value = "锁定库存", httpMethod = "PUT") @ApiOperation(value = "锁定库存", httpMethod = "PUT")
@ApiImplicitParam(name = "list", value = "锁定库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @ApiImplicitParam(name = "list", value = "锁定库存", required = true, paramType = "body", dataType = "InventoryNumDTO")
@PostMapping("/batch/_lock") @PostMapping("/batch/_lock")
public Result<Boolean> lockInventory(@RequestBody List<InventoryNumDTO> list) { public Result<Boolean> lockInventory(@RequestBody List<InventoryDTO> list) {
boolean result = iPmsSkuService.lockInventory(list); boolean result = iPmsSkuService.lockInventory(list);
return Result.judge(result); return Result.judge(result);
} }
@ -54,7 +54,7 @@ public class InventoryController {
@ApiOperation(value = "解锁库存", httpMethod = "PUT") @ApiOperation(value = "解锁库存", httpMethod = "PUT")
@ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO") @ApiImplicitParam(name = "list", value = "释放库存", required = true, paramType = "body", dataType = "InventoryNumDTO")
@PostMapping("/batch/_unlock") @PostMapping("/batch/_unlock")
public Result<Boolean> unlockInventory(@RequestBody List<InventoryNumDTO> list) { public Result<Boolean> unlockInventory(@RequestBody List<InventoryDTO> list) {
boolean result = iPmsSkuService.unlockInventory(list); boolean result = iPmsSkuService.unlockInventory(list);
return Result.judge(result); return Result.judge(result);
} }
@ -64,7 +64,7 @@ public class InventoryController {
@ApiImplicitParam(name = "skuIds", value = "库存ID集合字符串英文逗号,分割", required = true, paramType = "param", dataType = "String") @ApiImplicitParam(name = "skuIds", value = "库存ID集合字符串英文逗号,分割", required = true, paramType = "param", dataType = "String")
@GetMapping("/{ids}") @GetMapping("/{ids}")
public Result list(@PathVariable String ids) { public Result list(@PathVariable String ids) {
List<InventoryDTO> list = iPmsSkuService.listBySkuIds(ids); List<SkuDTO> list = iPmsSkuService.listBySkuIds(ids);
return Result.success(list); return Result.success(list);
} }

View File

@ -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.bo.app.ProductBO;
import com.youlai.mall.pms.pojo.domain.PmsSpu; import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.service.IPmsSpuService; import com.youlai.mall.pms.service.IPmsSpuService;
import com.youlai.mall.pms.service.ISpuService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
@ -14,13 +15,15 @@ import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@Api(tags = "【移动端】商品信息") @Api(tags = "【移动端】商品信息")
@RestController("AppProductController") @RestController("AppSpuController")
@RequestMapping("/api.app/v1/products") @RequestMapping("/api.app/v1/spus")
@AllArgsConstructor @AllArgsConstructor
public class ProductController { public class SpuController {
private IPmsSpuService iPmsSpuService; private IPmsSpuService iPmsSpuService;
private ISpuService iSpuService;
@ApiOperation(value = "列表分页", httpMethod = "GET") @ApiOperation(value = "列表分页", httpMethod = "GET")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"), @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
@ -43,10 +46,10 @@ public class ProductController {
} }
@ApiOperation(value = "商品详情", httpMethod = "GET") @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}") @GetMapping("/{id}")
public Result<ProductBO> detail(@PathVariable Long id) { public Result<ProductBO> detail(@PathVariable Long id) {
ProductBO product = iPmsSpuService.getProductByIdForApp(id); ProductBO product = iSpuService.getProductById(id);
return Result.success(product); return Result.success(product);
} }

View File

@ -28,14 +28,14 @@ public interface PmsProductMapper extends BaseMapper<PmsSpu> {
" LEFT JOIN pms_category t2 ON t1.category_id = t2.id " + " LEFT JOIN pms_category t2 ON t1.category_id = t2.id " +
" LEFT JOIN pms_brand t3 ON t1.brand_id = t3.id " + " LEFT JOIN pms_brand t3 ON t1.brand_id = t3.id " +
" WHERE 1=1 " + " WHERE 1=1 " +
" <if test ='product.categoryId !=null and product.categoryId > 0' >" + " <if test ='spu.categoryId !=null and spu.categoryId > 0' >" +
" AND t2.id = #{product.categoryId} " + " AND t2.id = #{spu.categoryId} " +
" </if>" + " </if>" +
" ORDER BY t1.gmt_create DESC" + " ORDER BY t1.gmt_create DESC" +
"</script>") "</script>")
@Results({ @Results({
@Result(id = true, column = "id", property = "id"), @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<PmsSpu> list(Page<PmsSpu> page, PmsSpu product); List<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
} }

View File

@ -2,7 +2,7 @@ package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.domain.PmsSku; 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.Mapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
@ -42,5 +42,5 @@ public interface PmsSkuMapper extends BaseMapper<PmsSku> {
" WHERE t1.id in (#{skuIds})", " WHERE t1.id in (#{skuIds})",
"</script>" "</script>"
}) })
List<InventoryDTO> listBySkuIds(String skuIds); List<SkuDTO> listBySkuIds(String skuIds);
} }

View File

@ -2,8 +2,8 @@ package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.domain.PmsSku; 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.InventoryDTO;
import com.youlai.mall.pms.pojo.dto.InventoryNumDTO;
import java.util.List; import java.util.List;
@ -14,14 +14,14 @@ public interface IPmsSkuService extends IService<PmsSku> {
* @param list * @param list
* @return 库存锁定结果 * @return 库存锁定结果
*/ */
boolean lockInventory(List<InventoryNumDTO> list); boolean lockInventory(List<InventoryDTO> list);
/** /**
* 解锁库存 * 解锁库存
* @param list * @param list
* @return 解锁库存结果 * @return 解锁库存结果
*/ */
boolean unlockInventory(List<InventoryNumDTO> list); boolean unlockInventory(List<InventoryDTO> list);
/** /**
@ -37,5 +37,5 @@ public interface IPmsSkuService extends IService<PmsSku> {
* @param ids * @param ids
* @return * @return
*/ */
List<InventoryDTO> listBySkuIds(String ids); List<SkuDTO> listBySkuIds(String ids);
} }

View File

@ -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<PmsSpu> {
ProductBO getProductById(Long id);
}

View File

@ -8,8 +8,8 @@ import com.youlai.common.web.exception.BizException;
import com.youlai.mall.pms.common.constant.RedisConstants; import com.youlai.mall.pms.common.constant.RedisConstants;
import com.youlai.mall.pms.mapper.PmsSkuMapper; import com.youlai.mall.pms.mapper.PmsSkuMapper;
import com.youlai.mall.pms.pojo.domain.PmsSku; 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.InventoryDTO;
import com.youlai.mall.pms.pojo.dto.InventoryNumDTO;
import com.youlai.mall.pms.service.IPmsSkuService; import com.youlai.mall.pms.service.IPmsSkuService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -29,7 +29,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean lockInventory(List<InventoryNumDTO> inventories) { public boolean lockInventory(List<InventoryDTO> inventories) {
log.info("锁定库存: {}", inventories); log.info("锁定库存: {}", inventories);
inventories.forEach(item -> { inventories.forEach(item -> {
@ -47,7 +47,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
} }
@Override @Override
public boolean unlockInventory(List<InventoryNumDTO> inventories) { public boolean unlockInventory(List<InventoryDTO> inventories) {
log.info("释放库存:{}", inventories); log.info("释放库存:{}", inventories);
inventories.forEach(item -> { inventories.forEach(item -> {
@ -97,7 +97,7 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
} }
@Override @Override
public List<InventoryDTO> listBySkuIds(String ids) { public List<SkuDTO> listBySkuIds(String ids) {
return this.listBySkuIds(ids); return this.listBySkuIds(ids);
} }
} }

View File

@ -7,10 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.mapper.PmsProductMapper;
import com.youlai.mall.pms.pojo.bo.admin.ProductBO;
import com.youlai.mall.pms.pojo.domain.*; 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 com.youlai.mall.pms.service.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -43,23 +43,23 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsProductMapper, PmsSpu> imp
@Override @Override
@Transactional @Transactional
public boolean add(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO) { public boolean add(ProductBO spuBO) {
ProductDTO ProductDTO = spuBO.getProduct(); SpuDTO SpuDTO = spuBO.getSpu();
List<PmsAttributeValue> attrs = spuBO.getAttrs(); List<PmsAttributeValue> attrValues = spuBO.getAttrValues();
List<PmsSpecificationValue> specs = spuBO.getSpecs(); List<PmsSpecificationValue> specs = spuBO.getSpecValues();
List<PmsSku> skuList = spuBO.getSkuList(); List<PmsSku> skuList = spuBO.getSkus();
// spu保存 // spu保存
PmsSpu spu = new PmsSpu(); PmsSpu spu = new PmsSpu();
BeanUtil.copyProperties(ProductDTO, spu); BeanUtil.copyProperties(SpuDTO, spu);
if (ProductDTO.getPicUrls() != null) { if (SpuDTO.getPics() != null) {
String picUrls = JSONUtil.toJsonStr(ProductDTO.getPicUrls()); String picUrls = JSONUtil.toJsonStr(SpuDTO.getPics());
spu.setPics(picUrls); spu.setPics(picUrls);
} }
this.save(spu); this.save(spu);
// 属性保存 // 属性保存
Optional.ofNullable(attrs).ifPresent(list -> { Optional.ofNullable(attrValues).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId())); list.forEach(item -> item.setSpuId(spu.getId()));
iPmsAttributeValueService.saveBatch(list); iPmsAttributeValueService.saveBatch(list);
}); });
@ -82,14 +82,14 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsProductMapper, PmsSpu> imp
@Override @Override
public com.youlai.mall.pms.pojo.bo.admin.ProductBO getBySpuId(Long id) { public com.youlai.mall.pms.pojo.bo.admin.ProductBO getBySpuId(Long id) {
// spu // spu
ProductDTO ProductDTO = new ProductDTO(); SpuDTO spuDTO = new SpuDTO();
PmsSpu spu = this.getById(id); PmsSpu spu = this.getById(id);
BeanUtil.copyProperties(spu, ProductDTO); BeanUtil.copyProperties(spu, spuDTO);
if (StrUtil.isNotBlank(spu.getPics())) { if (StrUtil.isNotBlank(spu.getPics())) {
// spu专辑图片转换处理 json字符串 -> List // spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class);
ProductDTO.setPicUrls(pics); spuDTO.setPics(pics);
} }
// 属性 // 属性
@ -98,33 +98,33 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsProductMapper, PmsSpu> imp
// 规格 // 规格
List<PmsSpecificationValue> specs = iPmsSpecificationValueService.list(new LambdaQueryWrapper<PmsSpecificationValue>().eq(PmsSpecificationValue::getSpuId, id)); List<PmsSpecificationValue> specs = iPmsSpecificationValueService.list(new LambdaQueryWrapper<PmsSpecificationValue>().eq(PmsSpecificationValue::getSpuId, id));
// sku // sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id)); List<PmsSku> skus = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().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; return spuBO;
} }
@Override @Override
public boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO) { public boolean updateById(com.youlai.mall.pms.pojo.bo.admin.ProductBO spuBO) {
ProductDTO ProductDTO = spuBO.getProduct(); SpuDTO SpuDTO = spuBO.getSpu();
List<PmsAttributeValue> attrs = spuBO.getAttrs(); List<PmsAttributeValue> attrValues = spuBO.getAttrValues();
List<PmsSpecificationValue> specs = spuBO.getSpecs(); List<PmsSpecificationValue> specs = spuBO.getSpecValues();
List<PmsSku> skuList = spuBO.getSkuList(); List<PmsSku> skuList = spuBO.getSkus();
// spu保存 // spu保存
PmsSpu spu = new PmsSpu(); PmsSpu spu = new PmsSpu();
BeanUtil.copyProperties(ProductDTO, spu); BeanUtil.copyProperties(SpuDTO, spu);
if (ProductDTO.getPicUrls() != null) { if (SpuDTO.getPics() != null) {
String picUrls = JSONUtil.toJsonStr(ProductDTO.getPicUrls()); String pics = JSONUtil.toJsonStr(SpuDTO.getPics());
spu.setPics(picUrls); spu.setPics(pics);
} }
this.updateById(spu); this.updateById(spu);
// 属性保存 // 属性保存
Optional.ofNullable(attrs).ifPresent(list -> { Optional.ofNullable(attrValues).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId())); list.forEach(item -> item.setSpuId(spu.getId()));
// 删除此次保存删除的 // 删除此次保存删除的
@ -194,15 +194,15 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsProductMapper, PmsSpu> imp
} }
@Override @Override
public ProductBO getProductByIdForApp(Long spuId) { public com.youlai.mall.pms.pojo.bo.app.ProductBO getProductByIdForApp(Long spuId) {
// spu // spu
PmsSpu spu = this.getById(spuId); PmsSpu spu = this.getById(spuId);
ProductDTO ProductDTO = new ProductDTO(); SpuDTO SpuDTO = new SpuDTO();
BeanUtil.copyProperties(spu, ProductDTO); BeanUtil.copyProperties(spu, SpuDTO);
if (StrUtil.isNotBlank(spu.getPics())) { if (StrUtil.isNotBlank(spu.getPics())) {
// spu专辑图片转换处理 json字符串 -> List // spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class);
ProductDTO.setPicUrls(pics); SpuDTO.setPics(pics);
} }
// 属性 // 属性
List<PmsAttributeValue> attrs = iPmsAttributeValueService.list( List<PmsAttributeValue> attrs = iPmsAttributeValueService.list(
@ -216,7 +216,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsProductMapper, PmsSpu> imp
// sku // sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId)); List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().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; return product;
} }
} }

View File

@ -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<PmsProductMapper, PmsSpu> 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<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class);
SpuDTO.setPics(pics);
}
// 属性
List<PmsAttributeValue> attrs = iPmsAttributeValueService.list(
new LambdaQueryWrapper<PmsAttributeValue>(
).eq(PmsAttributeValue::getSpuId, spuId)
);
// 规格
List<PmsSpecification> specs = iPmsSpecificationService.listBySpuId(spuId);
// sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
ProductBO product = new ProductBO(SpuDTO, attrs, specs, skuList);
return product;
}
}