feature(uniapp商品): 代码调整

This commit is contained in:
luowenfeng 2022-08-25 17:10:26 +08:00
parent 0bc2ef1d39
commit 4a39f2d9f8
5 changed files with 70 additions and 77 deletions

View File

@ -211,24 +211,29 @@ COMMIT;
-- Table structure for product_sku
-- ----------------------------
DROP TABLE IF EXISTS `product_sku`;
CREATE TABLE `product_sku` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`spu_id` bigint NOT NULL COMMENT 'spu编号',
`properties` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]',
`price` int NOT NULL DEFAULT -1 COMMENT '销售价格单位',
`original_price` int NOT NULL DEFAULT -1 COMMENT '原价 单位 ',
`cost_price` int NOT NULL DEFAULT -1 COMMENT '成本价单位 ',
`bar_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '条形码',
`pic_url` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '图片地址',
`status` tinyint NULL DEFAULT NULL COMMENT '状态 0-正常 1-禁用',
`create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品sku';
CREATE TABLE `product_sku` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`spu_id` bigint NOT NULL COMMENT 'spu编号',
`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
`name` varchar(128) DEFAULT NULL COMMENT '商品 SKU 名字',
`properties` varchar(128) DEFAULT NULL COMMENT '规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]',
`price` int NOT NULL DEFAULT '-1' COMMENT '销售价格单位',
`market_price` int DEFAULT NULL COMMENT '市场价',
`cost_price` int NOT NULL DEFAULT '-1' COMMENT '成本价单位 ',
`pic_url` varchar(128) NOT NULL COMMENT '图片地址',
`stock` int DEFAULT NULL COMMENT '库存',
`warn_stock` int DEFAULT NULL COMMENT '预警库存',
`volume` double DEFAULT NULL COMMENT '商品体积',
`weight` double DEFAULT NULL COMMENT '商品重量',
`bar_code` varchar(64) DEFAULT NULL COMMENT '条形码',
`status` tinyint DEFAULT NULL COMMENT '状态 0-正常 1-禁用',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`creator` varchar(64) DEFAULT NULL COMMENT '创建人',
`updater` double(64,0) DEFAULT NULL COMMENT '更新人',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB COMMENT='商品sku';
-- ----------------------------
-- Records of product_sku
@ -240,26 +245,35 @@ COMMIT;
-- Table structure for product_spu
-- ----------------------------
DROP TABLE IF EXISTS `product_spu`;
CREATE TABLE `product_spu` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品名称',
`sell_point` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '卖点',
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '描述',
`category_id` bigint NOT NULL COMMENT '分类id',
`pic_urls` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '商品主图地址\n *\n * 数组以逗号分隔\n 最多上传15张',
`sort` int NOT NULL DEFAULT 0 COMMENT '排序字段',
`like_count` int NULL DEFAULT NULL COMMENT '点赞初始人数',
`price` int NULL DEFAULT NULL COMMENT '价格 单位使用',
`quantity` int NULL DEFAULT NULL COMMENT '库存数量',
`status` bit(1) NULL DEFAULT NULL COMMENT '上下架状态 0 上架开启 1 下架禁用',
`create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品spu';
CREATE TABLE `product_spu` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
`brand_id` int DEFAULT NULL COMMENT '商品品牌编号',
`category_id` bigint NOT NULL COMMENT '分类id',
`spec_type` int NOT NULL COMMENT '规格类型0 单规格 1 多规格',
`code` varchar(128) DEFAULT NULL COMMENT '商品编码',
`name` varchar(128) NOT NULL COMMENT '商品名称',
`sell_point` varchar(128) DEFAULT NULL COMMENT '卖点',
`description` text COMMENT '描述',
`pic_urls` varchar(1024) DEFAULT '' COMMENT '商品轮播图地址\n 数组以逗号分隔\n 最多上传15张',
`video_url` varchar(128) DEFAULT NULL COMMENT '商品视频',
`market_price` int DEFAULT NULL COMMENT '市场价单位使用',
`min_price` int DEFAULT NULL COMMENT '最小价格单位使用',
`max_price` int DEFAULT NULL COMMENT '最大价格单位使用',
`total_stock` int NOT NULL DEFAULT '0' COMMENT '总库存',
`show_stock` int DEFAULT '0' COMMENT '是否展示库存',
`sales_count` int DEFAULT '0' COMMENT '商品销量',
`virtual_sales_count` int DEFAULT '0' COMMENT '虚拟销量',
`click_count` int DEFAULT '0' COMMENT '商品点击量',
`status` bit(1) DEFAULT NULL COMMENT '上下架状态 0 上架开启 1 下架禁用-1 回收',
`sort` int NOT NULL DEFAULT '0' COMMENT '排序字段',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`creator` varchar(64) DEFAULT NULL COMMENT '创建人',
`updater` varchar(64) DEFAULT NULL COMMENT '更新人',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB COMMENT='商品spu';
-- ----------------------------
-- Records of product_spu
@ -299,26 +313,3 @@ INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `
INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2028, 'Banner更新', 'market:banner:update', 3, 3, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0');
INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2029, 'Banner删除', 'market:banner:delete', 3, 4, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0');
alter table product_spu add `code` varchar(128) COMMENT '商品编码';
alter table product_spu add total_stock int COMMENT '总库存';
alter table product_spu add warn_stock int COMMENT '预警预存';
alter table product_spu add show_stock int COMMENT '是否展示库存';
alter table product_spu add sales_count int COMMENT '商品销量';
alter table product_spu add virtual_sales_count int COMMENT '虚拟销量';
alter table product_spu add click_count int COMMENT '商品点击量';
alter table product_spu add banner_url varchar(128) COMMENT '主图地址';
alter table product_spu add spec_type int COMMENT '规格类型';
alter table product_spu add brand_id int COMMENT '商品品牌编号';
alter table product_spu add video_url varchar(128) COMMENT '商品视频';
alter table product_spu add min_price int COMMENT '最小价格单位使用';
alter table product_spu add max_price int COMMENT '最大价格单位使用';
alter table product_spu add market_price int COMMENT '市场价单位使用';
alter table product_sku add `name` varchar(128) COMMENT '商品 SKU 名字';
alter table product_sku add `stock` int COMMENT '库存';
alter table product_sku add `weight` double COMMENT '商品重量';
alter table product_sku add `volume` double COMMENT '商品体积';
alter table product_sku DROP `original_price`;

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReq
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collections;
import java.util.List;
/**
@ -38,6 +39,10 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
.inIfPresent(ProductSkuDO::getSpuId, spuIds));
}
default List<ProductSkuDO> selectBySpuId(Long spuIds) {
return selectBySpuIds(Collections.singletonList(spuIds));
}
default void deleteBySpuId(Long spuId) {
// TODO @franky直接 delete(new XXX) 即可更简洁一些
LambdaQueryWrapperX<ProductSkuDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<ProductSkuDO>()

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.service.sku;
import cn.hutool.core.collection.CollectionUtil;
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.property.vo.ProductPropertyRespVO;
@ -91,22 +92,22 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override
public void validateProductSkus(List<ProductSkuCreateOrUpdateReqVO> list, Integer specType) {
// 多规格才需校验
if(specType.equals(ProductSpuSpecTypeEnum.DISABLE.getType())){
if (specType.equals(ProductSpuSpecTypeEnum.DISABLE.getType())) {
List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList());
// 1校验规格属性存在
List<Long> propertyIds = CollectionUtils.convertList(skuPropertyList, ProductSkuBaseVO.Property::getPropertyId);
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds);
if (propertyAndValueList.size() == propertyIds.size()){
if (propertyAndValueList.size() == propertyIds.size()) {
throw exception(PROPERTY_NOT_EXISTS);
}
// 2. 校验一个 Sku 没有重复的规格校验方式是遍历每个 Sku 看看是否有重复的规格 attrId
List<ProductPropertyValueRespVO> collect = propertyAndValueList.stream()
.flatMap(v -> Optional.of(v.getPropertyValueList())
.flatMap(v -> Optional.of(v.getPropertyValueList())
.orElse(new ArrayList<>()).stream()).collect(Collectors.toList());
Map<Long, ProductPropertyValueRespVO> propertyValueRespVOMap = CollectionUtils.convertMap(collect, ProductPropertyValueRespVO::getId);
list.forEach(v->{
list.forEach(v -> {
Set<Long> keys = v.getProperties().stream().map(k -> propertyValueRespVOMap.get(k.getValueId()).getPropertyId()).collect(Collectors.toSet());
if(keys.size() != v.getProperties().size()){
if (keys.size() != v.getProperties().size()) {
throw exception(ErrorCodeConstants.SKU_PROPERTIES_DUPLICATED);
}
});
@ -133,7 +134,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
public void createProductSkus(List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList, Long spuId) {
// 批量插入 SKU
List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList);
skuDOList.forEach(v->v.setSpuId(spuId));
skuDOList.forEach(v -> v.setSpuId(spuId));
productSkuMapper.insertBatch(skuDOList);
}
@ -156,10 +157,8 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Transactional
public void updateProductSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) {
// 查询 spu 下已经存在的 sku 的集合
// TODO @luowenfengselectListBySpuId 搞个
List<ProductSkuDO> existsSkus = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId));
// TODO @franky使用 CollUtils 即可
Map<Long, ProductSkuDO> existsSkuMap = existsSkus.stream().collect(Collectors.toMap(ProductSkuDO::getId, p -> p));
List<ProductSkuDO> existsSkus = productSkuMapper.selectBySpuId(spuId);
Map<Long, ProductSkuDO> existsSkuMap = CollectionUtils.convertMap(existsSkus, ProductSkuDO::getId);
// 拆分三个集合新插入的需要更新的需要删除的
List<ProductSkuDO> insertSkus = new ArrayList<>();
@ -170,8 +169,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus);
allUpdateSkus.forEach(p -> {
if (p.getId() != null) {
// TODO @luowenfengcontains
if (existsSkuMap.get(p.getId()) != null) {
if (existsSkuMap.containsKey(p.getId())) {
updateSkus.add(p);
return;
}
@ -182,8 +180,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
insertSkus.add(p);
});
// TODO @luowenfeng使用 CollUtil.isNotEmpty 判断
if (insertSkus.size() > 0) {
if (CollectionUtil.isNotEmpty(insertSkus)) {
productSkuMapper.insertBatch(insertSkus);
}
if (updateSkus.size() > 0) {

View File

@ -60,7 +60,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
public Long createProductSpu(ProductSpuCreateReqVO createReqVO) {
// 校验分类
categoryService.validateProductCategory(createReqVO.getCategoryId());
// TODO @luowenfeng校验品牌
// TODO @校验品牌
// 校验SKU
List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus();

View File

@ -50,7 +50,7 @@
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "",
"appid" : "wx48d7c38b46f2e81c",
"setting" : {
"urlCheck" : false
},