mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
feature(uniapp商品): 商品加载
This commit is contained in:
@ -5,8 +5,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
|
||||
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -19,6 +23,7 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
@ -74,4 +79,14 @@ public class ProductBrandController {
|
||||
return success(ProductBrandConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得品牌列表")
|
||||
@PreAuthorize("@ss.hasPermission('product:brand:query')")
|
||||
public CommonResult<List<ProductBrandRespVO>> getProductCategoryList(@Valid ProductBrandListReqVO listVO) {
|
||||
List<ProductBrandDO> list = brandService.getBrandList(listVO);
|
||||
list.sort(Comparator.comparing(ProductBrandDO::getSort));
|
||||
return success(ProductBrandConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel(value = "管理后台 - 商品品牌分页 Request VO")
|
||||
@Data
|
||||
public class ProductBrandListReqVO {
|
||||
|
||||
@ApiModelProperty(value = "品牌名称", example = "芋道")
|
||||
private String name;
|
||||
|
||||
}
|
@ -40,7 +40,7 @@ public class ProductSkuDO extends BaseDO {
|
||||
private String name;
|
||||
/**
|
||||
* SPU 编号
|
||||
*
|
||||
* <p>
|
||||
* 关联 {@link ProductSpuDO#getId()}
|
||||
*/
|
||||
private Long spuId;
|
||||
@ -71,7 +71,7 @@ public class ProductSkuDO extends BaseDO {
|
||||
private String picUrl;
|
||||
/**
|
||||
* SKU 状态
|
||||
*
|
||||
* <p>
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
@ -100,13 +100,13 @@ public class ProductSkuDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 属性编号
|
||||
*
|
||||
* <p>
|
||||
* 关联 {@link ProductPropertyDO#getId()}
|
||||
*/
|
||||
private Long propertyId;
|
||||
/**
|
||||
* 属性值编号
|
||||
*
|
||||
* <p>
|
||||
* 关联 {@link ProductPropertyValueDO#getId()}
|
||||
*/
|
||||
private Long valueId;
|
||||
|
@ -3,10 +3,14 @@ package cn.iocoder.yudao.module.product.dal.mysql.brand;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandBaseVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandListReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
|
||||
|
||||
@ -18,4 +22,9 @@ public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
|
||||
.orderByDesc(ProductBrandDO::getId));
|
||||
}
|
||||
|
||||
|
||||
default List<ProductBrandDO> selectList(ProductBrandListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<ProductBrandDO>()
|
||||
.likeIfPresent(ProductBrandDO::getName, reqVO.getName()));
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package cn.iocoder.yudao.module.product.service.brand;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@ -55,6 +53,20 @@ public interface ProductBrandService {
|
||||
*/
|
||||
List<ProductBrandDO> getBrandList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得品牌列表
|
||||
* @param listVo 请求参数
|
||||
* @return 品牌列表
|
||||
*/
|
||||
List<ProductBrandDO> getBrandList(ProductBrandListReqVO listVo);
|
||||
|
||||
/**
|
||||
* 验证选择的商品分类是否合法
|
||||
*
|
||||
* @param id 分类编号
|
||||
*/
|
||||
void validateProductBrand(Long id);
|
||||
|
||||
/**
|
||||
* 获得品牌分页
|
||||
*
|
||||
|
@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.module.product.service.brand;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
|
||||
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -16,6 +15,7 @@ import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_CATEGORY_LEVEL;
|
||||
|
||||
/**
|
||||
* 品牌 Service 实现类
|
||||
@ -71,6 +71,18 @@ public class ProductBrandServiceImpl implements ProductBrandService {
|
||||
return brandMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductBrandDO> getBrandList(ProductBrandListReqVO listVo) {
|
||||
return brandMapper.selectList(listVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateProductBrand(Long id) {
|
||||
if(getBrand(id) == null){
|
||||
throw exception(PRODUCT_BRAND_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProductBrandDO> getBrandPage(ProductBrandPageReqVO pageReqVO) {
|
||||
return brandMapper.selectPage(pageReqVO);
|
||||
|
@ -140,7 +140,8 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
||||
|
||||
@Override
|
||||
public List<ProductSkuDO> getSkusBySpuId(Long spuId) {
|
||||
return productSkuMapper.selectBySpuIds(Collections.singletonList(spuId));
|
||||
List<ProductSkuDO> productSkuDOS = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId));
|
||||
return productSkuDOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
|
||||
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum;
|
||||
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.ProductPropertyService;
|
||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||
@ -55,17 +56,19 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
@Resource
|
||||
private ProductPropertyService productPropertyService;
|
||||
|
||||
@Resource
|
||||
private ProductBrandService brandService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long createProductSpu(ProductSpuCreateReqVO createReqVO) {
|
||||
// 校验分类
|
||||
categoryService.validateProductCategory(createReqVO.getCategoryId());
|
||||
// TODO @:校验品牌
|
||||
|
||||
// 校验品牌
|
||||
brandService.validateProductBrand(createReqVO.getBrandId());
|
||||
// 校验SKU
|
||||
List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus();
|
||||
productSkuService.validateProductSkus(skuCreateReqList, createReqVO.getSpecType());
|
||||
|
||||
// 插入 SPU
|
||||
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
|
||||
spu.setMarketPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getMarketPrice));
|
||||
@ -73,7 +76,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
spu.setMinPrice(CollectionUtils.getMinValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice));
|
||||
spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum));
|
||||
ProductSpuMapper.insert(spu);
|
||||
|
||||
// 插入 SKU
|
||||
productSkuService.createProductSkus(skuCreateReqList, spu.getId());
|
||||
// 返回
|
||||
@ -128,27 +130,29 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
spuVO.setSkus(skuReqs);
|
||||
List<ProductSkuRespVO.Property> properties = new ArrayList<>();
|
||||
// 组合 sku 规格属性
|
||||
for (ProductSkuRespVO productSkuRespVO : skuReqs) {
|
||||
properties.addAll(productSkuRespVO.getProperties());
|
||||
}
|
||||
Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
|
||||
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet()));
|
||||
// 装载组装过后的属性
|
||||
List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
|
||||
propertyAndValueList.forEach(p -> {
|
||||
ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO();
|
||||
productPropertyViewRespVO.setPropertyId(p.getId());
|
||||
productPropertyViewRespVO.setName(p.getName());
|
||||
Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>();
|
||||
Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv));
|
||||
propertyMaps.get(p.getId()).forEach(pv -> {
|
||||
ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName());
|
||||
propertyValues.add(tuple2);
|
||||
if(spu.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) {
|
||||
for (ProductSkuRespVO productSkuRespVO : skuReqs) {
|
||||
properties.addAll(productSkuRespVO.getProperties());
|
||||
}
|
||||
Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
|
||||
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet()));
|
||||
// 装载组装过后的属性
|
||||
List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
|
||||
propertyAndValueList.forEach(p -> {
|
||||
ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO();
|
||||
productPropertyViewRespVO.setPropertyId(p.getId());
|
||||
productPropertyViewRespVO.setName(p.getName());
|
||||
Set<ProductPropertyViewRespVO.Tuple2> propertyValues = new HashSet<>();
|
||||
Map<Long, ProductPropertyValueRespVO> propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv));
|
||||
propertyMaps.get(p.getId()).forEach(pv -> {
|
||||
ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName());
|
||||
propertyValues.add(tuple2);
|
||||
});
|
||||
productPropertyViewRespVO.setPropertyValues(propertyValues);
|
||||
productPropertyViews.add(productPropertyViewRespVO);
|
||||
});
|
||||
productPropertyViewRespVO.setPropertyValues(propertyValues);
|
||||
productPropertyViews.add(productPropertyViewRespVO);
|
||||
});
|
||||
spuVO.setProductPropertyViews(productPropertyViews);
|
||||
spuVO.setProductPropertyViews(productPropertyViews);
|
||||
}
|
||||
// 组合分类
|
||||
if (null != spuVO.getCategoryId()) {
|
||||
LinkedList<Long> categoryArray = new LinkedList<>();
|
||||
|
Reference in New Issue
Block a user