完成商品保存和编辑数据回显

pull/2/head
puhui999 2023-05-03 02:31:50 +08:00
parent 70816371e5
commit e163ae8b70
12 changed files with 72 additions and 45 deletions

View File

@ -17,7 +17,7 @@ public enum ProductSpuStatusEnum implements IntArrayValuable {
RECYCLE(-1, "回收站"),
DISABLE(0, "下架"),
ENABLE(1, "上架"),;
ENABLE(1, "上架");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductSpuStatusEnum::getStatus).toArray();

View File

@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueServ
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -81,10 +82,10 @@ public class ProductPropertyController {
return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO)));
}
@GetMapping("/get-value-list")
@PostMapping("/get-value-list")
@Operation(summary = "获得属性项列表")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid ProductPropertyListReqVO listReqVO) {
public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid @RequestBody ProductPropertyListReqVO listReqVO) {
// 查询属性项
List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO);
if (CollUtil.isEmpty(keys)) {

View File

@ -4,12 +4,17 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Schema(description = "管理后台 - 属性项 List Request VO")
@Data
@ToString(callSuper = true)
public class ProductPropertyListReqVO {
@Schema(description = "名称", example = "颜色")
@Schema(description = "属性名称", example = "颜色")
private String name;
@Schema(description = "属性ids", example = "1,2")
private List<Long> propertyIds;
}

View File

@ -7,6 +7,9 @@ import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author HUIHUI
*/
@Schema(description = "管理后台 - 商品 SKU Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ -16,9 +19,6 @@ public class ProductSkuRespVO extends ProductSkuBaseVO {
@Schema(description = "主键", required = true, example = "1024")
private Long id;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "商品属性")
@Data
@AllArgsConstructor
@ -34,11 +34,11 @@ public class ProductSkuRespVO extends ProductSkuBaseVO {
private Long valueId;
@Schema(description = "属性值", example = "1024")
private String value;
private String valueName;
}
/**
*
*/
private List<ProductSkuCreateOrUpdateReqVO.Property> properties;
private List<Property> properties;
}

View File

@ -68,19 +68,7 @@ public class ProductSpuController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<ProductSpuDetailRespVO> getSpuDetail(@RequestParam("id") Long id) {
// 获得商品 SPU
ProductSpuDO spu = productSpuService.getSpu(id);
if (spu == null) {
throw exception(SPU_NOT_EXISTS);
}
// 查询商品 SKU
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuIdAndStatus(spu.getId(), null);
// 查询商品属性
List<ProductPropertyValueDetailRespBO> propertyValues = productPropertyValueService
.getPropertyValueDetailList(ProductSkuConvert.INSTANCE.convertPropertyValueIds(skus));
// 拼接
return success(ProductSpuConvert.INSTANCE.convert03(spu, skus, propertyValues));
return success(productSpuService.getSpuDetail(id));
}
@GetMapping("/get-simple-list")

View File

@ -2,37 +2,26 @@ package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.util.List;
@Schema(description = "管理后台 - 商品 SPU 详细 Response VO") // 包括关联的 SKU 等信息
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuDetailRespVO extends ProductSpuRespVO {
public class ProductSpuDetailRespVO extends ProductSpuBaseVO {
@Schema(description = "商品编号", example = "1")
private Long id;
// ========== SKU 相关字段 =========
/**
* SKU
*/
private List<Sku> skus;
@Schema(description = "管理后台 - 商品 SKU 详细 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public static class Sku extends ProductSkuBaseVO {
/**
*
*/
private List<ProductPropertyValueDetailRespVO> properties;
}
@Schema(description = "SKU 数组", example = "1")
private List<ProductSkuRespVO> skus;
}

View File

@ -43,7 +43,7 @@ public interface ProductSkuConvert {
ProductSkuRespDTO convert02(ProductSkuDO bean);
List<ProductSpuDetailRespVO.Sku> convertList03(List<ProductSkuDO> list);
List<ProductSkuRespVO> convertList03(List<ProductSkuDO> list);
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO;
@ -88,7 +89,7 @@ public interface ProductSpuConvert {
if (CollUtil.isEmpty(properties)) {
continue;
}
ProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
ProductSkuRespVO sku = spuVO.getSkus().get(i);
sku.setProperties(new ArrayList<>(properties.size()));
// 遍历每个 properties设置到 AppSpuDetailRespVO.Sku 中
properties.forEach(property -> {
@ -96,13 +97,13 @@ public interface ProductSpuConvert {
if (propertyValue == null) {
return;
}
sku.getProperties().add(convert04(propertyValue));
//sku.getProperties().add(convert04(propertyValue)); TODO 需要重写
});
}
return spuVO;
}
ProductSpuDetailRespVO convert03(ProductSpuDO spu);
List<ProductSpuDetailRespVO.Sku> convertList04(List<ProductSkuDO> skus);
List<ProductSkuRespVO> convertList04(List<ProductSkuDO> skus);
ProductPropertyValueDetailRespVO convert04(ProductPropertyValueDetailRespBO propertyValue);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.service.property;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO;
@ -92,6 +93,10 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
@Override
public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) {
// 增加使用属性id查询
if (CollUtil.isNotEmpty(listReqVO.getPropertyIds())){
return productPropertyMapper.selectBatchIds(listReqVO.getPropertyIds());
}
return productPropertyMapper.selectList(listReqVO);
}

View File

@ -87,7 +87,7 @@ public interface ProductSkuService {
/**
* SPU SKU
*
* TODO SKUstatus
* @param spuId SPU
* @param status
* @return SKU

View File

@ -98,4 +98,11 @@ public interface ProductSpuService {
*/
void updateSpuStock(Map<Long, Integer> stockIncrCounts);
/**
* spu
*
* @param id id
* @return {@link ProductSpuDetailRespVO}
*/
ProductSpuDetailRespVO getSpuDetail(Long id);
}

View File

@ -4,10 +4,13 @@ import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuDetailRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
@ -15,6 +18,8 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -23,6 +28,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
@ -48,6 +54,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
private ProductBrandService brandService;
@Resource
private ProductCategoryService categoryService;
@Resource
private ProductPropertyValueService productPropertyValueService;
@Override
@Transactional(rollbackFor = Exception.class)
@ -191,4 +199,27 @@ public class ProductSpuServiceImpl implements ProductSpuService {
stockIncrCounts.forEach((id, incCount) -> productSpuMapper.updateStock(id, incCount));
}
@Override
public ProductSpuDetailRespVO getSpuDetail(Long id) {
// 获得商品 SPU
ProductSpuDO spu = getSpu(id);
if (spu == null) {
throw exception(SPU_NOT_EXISTS);
}
ProductSpuDetailRespVO productSpuDetailRespVO = ProductSpuConvert.INSTANCE.convert03(spu);
// 查询商品 SKU
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
if (CollUtil.isNotEmpty(skus)){
List<ProductSkuRespVO> skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus);
// 获取所有的属性值id
Set<Long> valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet());
List<ProductPropertyValueDetailRespBO> valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds);
Map<Long, String> stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName));
// 设置属性值名称
skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId())));
productSpuDetailRespVO.setSkus(skuRespVoS);
}
return productSpuDetailRespVO;
}
}