商品详情

This commit is contained in:
YunaiV 2019-03-05 23:04:42 +08:00
parent 15a9425396
commit 5af19f9257
5 changed files with 40 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package cn.iocoder.common.framework.util;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -17,4 +18,13 @@ public class StringUtil {
return Arrays.asList(stringArray);
}
public static List<Integer> splitToInt(String toSplit, String delim) {
String[] stringArray = StringUtils.tokenizeToStringArray(toSplit, delim);
List<Integer> array = new ArrayList<>(stringArray.length);
for (String string : stringArray) {
array.add(Integer.valueOf(string));
}
return array;
}
}

View File

@ -121,8 +121,9 @@ public class AdminsProductSpuController {
@GetMapping("/spu/info")
@ApiOperation("商品 SPU 明细")
public CommonResult<AdminsProductSpuDetailVO> info() {
return null;
@ApiImplicitParam(name = "id", value = "SPU 编号", required = true, example = "100")
public CommonResult<AdminsProductSpuDetailVO> info(@RequestParam("id") Integer id) {
return ProductSpuConvert.INSTANCE.convert(productSpuService.getProductSpu(id));
}
private <T> List<T> parseSkus(String skuStr, Class<T> clazz) {

View File

@ -19,7 +19,8 @@ public class ProductSpuController {
// TODO 详情
@GetMapping("/info")
public ProductSpuBO info(@RequestParam("id") Integer id) {
return productSpuService.getProductSpu(id);
// return productSpuService.getProductSpu(id);
return null;
}
// TODO 分页

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
import cn.iocoder.mall.product.api.bo.ProductSpuPageBO;
import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO;
@ -10,8 +9,7 @@ import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO;
public interface ProductSpuService {
// TODO 芋艿需要去改改
ProductSpuBO getProductSpu(Integer id);
CommonResult<ProductSpuDetailBO> getProductSpu(Integer id);
CommonResult<ProductSpuDetailBO> addProductSpu(Integer adminId, ProductSpuAddDTO productSpuAddDTO);

View File

@ -7,7 +7,6 @@ import cn.iocoder.common.framework.util.StringUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductAttrDetailBO;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
import cn.iocoder.mall.product.api.bo.ProductSpuPageBO;
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
@ -43,11 +42,31 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Autowired
private ProductAttrServiceImpl productAttrService;
// @Override
// public ProductSpuBO getProductSpu(Integer id) {
// ProductSpuDO productSpuDO = productSpuMapper.selectById(id);
// // 转换成 BO
// return ProductSpuConvert.INSTANCE.convert(productSpuDO);
// }
@Override
public ProductSpuBO getProductSpu(Integer id) {
ProductSpuDO productSpuDO = productSpuMapper.selectById(id);
// 转换成 BO
return ProductSpuConvert.INSTANCE.convert(productSpuDO);
public CommonResult<ProductSpuDetailBO> getProductSpu(Integer id) {
// 校验商品 spu 存在
ProductSpuDO spu = productSpuMapper.selectById(id);
if (spu == null) {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_SPU_NOT_EXISTS.getCode());
}
// 获得商品 sku 数组
List<ProductSkuDO> skus = productSkuMapper.selectListBySpuIdAndStatus(id, ProductSpuConstants.SKU_STATUS_ENABLE);
// 获得规格
Set<Integer> productAttrValueIds = new HashSet<>();
skus.forEach(sku -> productAttrValueIds.addAll(StringUtil.splitToInt(sku.getAttrs(), ",")));
CommonResult<List<ProductAttrDetailBO>> validAttrResult = productAttrService.validProductAttrAndValue(productAttrValueIds);
if (validAttrResult.isError()) {
return CommonResult.error(validAttrResult);
}
// 返回成功
return CommonResult.success(ProductSpuConvert.INSTANCE.convert2(spu, skus, validAttrResult.getData()));
}
@SuppressWarnings("Duplicates")