mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	feature(管理后台): 商品列表
This commit is contained in:
		| @@ -1,6 +1,5 @@ | |||||||
| package cn.iocoder.yudao.module.product.service.category; | package cn.iocoder.yudao.module.product.service.category; | ||||||
|  |  | ||||||
| import cn.hutool.core.util.ObjectUtil; |  | ||||||
| import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; | ||||||
| @@ -93,33 +92,20 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void validateCategoryLevel(Long id) { |     public void validateCategoryLevel(Long id) { | ||||||
|         Integer level = getProductCategoryLevel(id, 1); |         Long parentId = id; | ||||||
|         if (level < 3){ |         for (int i = 0; i < 3; i++) { | ||||||
|  |             if (Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)) { | ||||||
|                 throw exception(CATEGORY_LEVEL_ERROR); |                 throw exception(CATEGORY_LEVEL_ERROR); | ||||||
|             } |             } | ||||||
|     } |             ProductCategoryDO category = productCategoryMapper.selectById(parentId); | ||||||
|  |  | ||||||
|     // TODO @Luowenfeng:建议使用 for 循环,避免递归 |  | ||||||
|     /** |  | ||||||
|      * 获得商品分类的级别 |  | ||||||
|      * |  | ||||||
|      * @param id 商品分类的编号 |  | ||||||
|      * @return 级别 |  | ||||||
|      */ |  | ||||||
|     private Integer getProductCategoryLevel(Long id, int level){ |  | ||||||
|         ProductCategoryDO category = productCategoryMapper.selectById(id); |  | ||||||
|             if (category == null) { |             if (category == null) { | ||||||
|                 throw exception(CATEGORY_NOT_EXISTS); |                 throw exception(CATEGORY_NOT_EXISTS); | ||||||
|             } |             } | ||||||
|         // TODO Luowenfeng:去掉是否开启,它不影响级别哈 |             parentId = category.getParentId(); | ||||||
|         if (ObjectUtil.notEqual(category.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { |  | ||||||
|             throw exception(CATEGORY_DISABLED); |  | ||||||
|         } |         } | ||||||
|         // TODO Luowenfeng:不使用 0 直接比较哈,使用枚举 |         if (!Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)) { | ||||||
|         if (category.getParentId() == 0) { |             throw exception(CATEGORY_LEVEL_ERROR); | ||||||
|             return level; |  | ||||||
|         } |         } | ||||||
|         return getProductCategoryLevel(category.getParentId(), ++level); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -144,36 +144,52 @@ public class ProductSkuServiceImpl implements ProductSkuService { | |||||||
|     public void updateProductSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) { |     public void updateProductSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) { | ||||||
|         // 查询 SPU 下已经存在的 SKU 的集合 |         // 查询 SPU 下已经存在的 SKU 的集合 | ||||||
|         List<ProductSkuDO> existsSkus = productSkuMapper.selectListBySpuId(spuId); |         List<ProductSkuDO> existsSkus = productSkuMapper.selectListBySpuId(spuId); | ||||||
|         Map<Long, ProductSkuDO> existsSkuMap = CollectionUtils.convertMap(existsSkus, ProductSkuDO::getId); |  | ||||||
|  |         Map<String, Long> existsSkuMap = existsSkus.stream() | ||||||
|  |                 .map(v -> { | ||||||
|  |                     String collect = v.getProperties() == null? "null": v.getProperties() | ||||||
|  |                             .stream() | ||||||
|  |                             .map(m -> String.valueOf(m.getValueId())) | ||||||
|  |                             .collect(Collectors.joining()); | ||||||
|  |                     return String.join("-", collect, String.valueOf(v.getId())); | ||||||
|  |                 }) | ||||||
|  |                 .collect(Collectors.toMap(v -> v.split("-")[0], v -> Long.valueOf(v.split("-")[1]))); | ||||||
|  |  | ||||||
|  |  | ||||||
|         // 拆分三个集合,新插入的、需要更新的、需要删除的 |         // 拆分三个集合,新插入的、需要更新的、需要删除的 | ||||||
|         List<ProductSkuDO> insertSkus = new ArrayList<>(); |         List<ProductSkuDO> insertSkus = new ArrayList<>(); | ||||||
|         List<ProductSkuDO> updateSkus = new ArrayList<>(); // TODO Luowenfeng:使用 Long 即可 |         List<ProductSkuDO> updateSkus = new ArrayList<>(); | ||||||
|         List<ProductSkuDO> deleteSkus = new ArrayList<>(); |         List<Long> deleteSkus = new ArrayList<>(); | ||||||
|  |  | ||||||
|         // TODO @Luowenfeng:是不是基于规格匹配会比较好。可以参考下 onemall 的 ProductSpuServiceImpl 的 updateProductSpu 逻辑 |  | ||||||
|         List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus); |         List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus); | ||||||
|         allUpdateSkus.forEach(p -> { |         allUpdateSkus.forEach(p -> { | ||||||
|             if (p.getId() != null) { |             String propertiesKey = p.getProperties() == null? "null": p.getProperties().stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining()); | ||||||
|                 if (existsSkuMap.containsKey(p.getId())) { |             // 1、找得到的,进行更新 | ||||||
|  |             if (existsSkuMap.containsKey(propertiesKey)) { | ||||||
|                 updateSkus.add(p); |                 updateSkus.add(p); | ||||||
|  |                 existsSkuMap.remove(propertiesKey); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|                 deleteSkus.add(p); |             // 2、找不到,进行插入 | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             p.setSpuId(spuId); |             p.setSpuId(spuId); | ||||||
|             insertSkus.add(p); |             insertSkus.add(p); | ||||||
|         }); |         }); | ||||||
|  |         // 3、多余的,删除 | ||||||
|  |         if(!existsSkuMap.isEmpty()){ | ||||||
|  |             deleteSkus = new ArrayList<>(existsSkuMap.values()); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if (CollectionUtil.isNotEmpty(insertSkus)) { |         // 4、执行修改 Sku | ||||||
|  |         if (!insertSkus.isEmpty()) { | ||||||
|             productSkuMapper.insertBatch(insertSkus); |             productSkuMapper.insertBatch(insertSkus); | ||||||
|         } |         } | ||||||
|         if (updateSkus.size() > 0) { |         if (!updateSkus.isEmpty()) { | ||||||
|             updateSkus.forEach(p -> productSkuMapper.updateById(p)); |             updateSkus.forEach(p -> productSkuMapper.updateById(p)); | ||||||
|         } |         } | ||||||
|         if (deleteSkus.size() > 0) { |         if (!deleteSkus.isEmpty()) { | ||||||
|             productSkuMapper.deleteBatchIds(deleteSkus.stream().map(ProductSkuDO::getId).collect(Collectors.toList())); |             productSkuMapper.deleteBatchIds(deleteSkus); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -361,7 +361,7 @@ export default { | |||||||
|         if (!valid) { |         if (!valid) { | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|         let rates = this.ratesForm.rates; |         let rates = JSON.parse(JSON.stringify(this.ratesForm.rates)); | ||||||
|  |  | ||||||
|         // 价格元转分 |         // 价格元转分 | ||||||
|         rates.forEach(r => { |         rates.forEach(r => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 luowenfeng
					luowenfeng