feature(uniapp商品): 代码调整

pull/2/head
luowenfeng 2022-08-25 17:10:26 +08:00
parent 0bc2ef1d39
commit 4a39f2d9f8
5 changed files with 70 additions and 77 deletions

View File

@ -212,23 +212,28 @@ COMMIT;
-- ----------------------------
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';
`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
@ -241,25 +246,34 @@ COMMIT;
-- ----------------------------
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';
`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,12 +92,12 @@ 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
@ -104,9 +105,9 @@ public class ProductSkuServiceImpl implements ProductSkuService {
.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
},