diff --git a/script/笔记/MySQL/all_tables_backup.zip b/script/笔记/MySQL/all_tables_backup.zip index 9ec23c0979..8b986a507a 100644 Binary files a/script/笔记/MySQL/all_tables_backup.zip and b/script/笔记/MySQL/all_tables_backup.zip differ diff --git a/script/笔记/商品分类/商品分类.zip b/script/笔记/商品分类/商品分类.zip new file mode 100644 index 0000000000..367ae72581 Binary files /dev/null and b/script/笔记/商品分类/商品分类.zip differ diff --git a/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java b/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java index d2343e81a1..763cf9fd68 100644 --- a/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java +++ b/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/controller/admin/category/ProductCategoryController.java @@ -71,5 +71,12 @@ public class ProductCategoryController { list.sort(Comparator.comparing(ProductCategoryDO::getSort)); return success(BeanUtils.toBean(list, ProductCategoryRespVO.class)); } + @GetMapping("/init") + @Operation(summary = "获得商品分类列表") + @PreAuthorize("@ss.hasPermission('product:category:query')") + public CommonResult initCategoryList() { + categoryService.initCategory(); + return success(true); + } } diff --git a/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java b/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java index 73a93fa279..6f2e32c0ed 100644 --- a/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java +++ b/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java @@ -30,6 +30,12 @@ public interface ProductCategoryService { */ void updateCategory(@Valid ProductCategorySaveReqVO updateReqVO); + /** + * 构造商品分类 + * + */ + void initCategory(); + /** * 删除商品分类 * diff --git a/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java b/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java index 42db6d94eb..9c9c132b42 100644 --- a/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java @@ -14,10 +14,10 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL; @@ -63,6 +63,75 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { productCategoryMapper.updateById(updateObj); } + @Override + public void initCategory() { + List firstCateNames = new ArrayList<>(); + Map firstCateNamesIds = new HashMap<>(); + List secondCateNames = new ArrayList<>(); + Map secondCateNamesIds = new HashMap<>(); + Map secondCateNamesIndexs = new HashMap<>(); + Map thirdCateIndexs = new HashMap<>(); + try { + BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\D\\Desktop\\商品分类.txt")); + String line; + String firstCateName = ""; + String highlight = ""; + String secondCateName = ""; + String thirdCateName = ""; + while ((line = reader.readLine()) != null) { + if (line.contains("firstCateName")) { + firstCateName = line.split(":")[1].replace("\"", "").replace(",", ""); + if (!firstCateNames.contains(firstCateName) && !firstCateName.contains("天猫榜单") && !firstCateName.contains("热卖频道")) { + ProductCategoryDO category = new ProductCategoryDO(); + category.setName(firstCateName); + category.setParentId(0L); + category.setSort(firstCateNames.size() + 1); + productCategoryMapper.insert(category); + firstCateNamesIds.put(firstCateName, category.getId()); + firstCateNames.add(firstCateName); + secondCateNamesIndexs.put(firstCateName, 1); + } + } + if (line.contains("highlight")) { + highlight = line.split(":")[1].replace("\"", "").replace(",", ""); + } + if (line.contains("secondCateName")) { + secondCateName = line.split(":")[1].replace("\"", "").replace(",", ""); + + if (!secondCateNames.contains(secondCateName) && !secondCateName.contains("天猫榜单") && !secondCateName.contains("热卖频道")) { + int sort = secondCateNamesIndexs.get(firstCateName) + 1; + secondCateNamesIndexs.put(firstCateName, sort + 1); + ProductCategoryDO category = new ProductCategoryDO(); + category.setName(secondCateName); + category.setParentId(firstCateNamesIds.get(firstCateName)); + category.setSort(sort + 1); + productCategoryMapper.insert(category); + secondCateNamesIds.put(firstCateName + "_" + secondCateName, category.getId()); + secondCateNames.add(secondCateName); + + thirdCateIndexs.put(firstCateName + "_" + secondCateName, 1); + System.out.println(",secondCateName:" + secondCateName); + } + } + if (line.contains("thirdCateName") && !highlight.contains("true") && !secondCateName.contains("天猫榜单") && !secondCateName.contains("热卖频道")) { + thirdCateName = line.split(":")[1].replace("\"", "").replace(",", ""); + System.out.println("firstCateName:" + firstCateName + ",secondCateName:" + secondCateName + ",thirdCateName:" + thirdCateName); + int sort = thirdCateIndexs.get(firstCateName + "_" + secondCateName) + 1; + thirdCateIndexs.put(firstCateName + "_" + secondCateName, sort + 1); + + ProductCategoryDO category = new ProductCategoryDO(); + category.setName(thirdCateName); + category.setParentId(secondCateNamesIds.get(firstCateName + "_" + secondCateName)); + category.setSort(sort + 1); + productCategoryMapper.insert(category); + } + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override public void deleteCategory(Long id) { // 校验分类是否存在