商品分类
This commit is contained in:
parent
af4c5b0ef8
commit
25955e95ba
Binary file not shown.
Binary file not shown.
|
@ -71,5 +71,12 @@ public class ProductCategoryController {
|
||||||
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
|
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
|
||||||
return success(BeanUtils.toBean(list, ProductCategoryRespVO.class));
|
return success(BeanUtils.toBean(list, ProductCategoryRespVO.class));
|
||||||
}
|
}
|
||||||
|
@GetMapping("/init")
|
||||||
|
@Operation(summary = "获得商品分类列表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('product:category:query')")
|
||||||
|
public CommonResult<Boolean> initCategoryList() {
|
||||||
|
categoryService.initCategory();
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,12 @@ public interface ProductCategoryService {
|
||||||
*/
|
*/
|
||||||
void updateCategory(@Valid ProductCategorySaveReqVO updateReqVO);
|
void updateCategory(@Valid ProductCategorySaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造商品分类
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void initCategory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除商品分类
|
* 删除商品分类
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,10 +14,10 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Collection;
|
import java.io.BufferedReader;
|
||||||
import java.util.List;
|
import java.io.FileReader;
|
||||||
import java.util.Map;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.*;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
|
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);
|
productCategoryMapper.updateById(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initCategory() {
|
||||||
|
List<String> firstCateNames = new ArrayList<>();
|
||||||
|
Map<String, Long> firstCateNamesIds = new HashMap<>();
|
||||||
|
List<String> secondCateNames = new ArrayList<>();
|
||||||
|
Map<String, Long> secondCateNamesIds = new HashMap<>();
|
||||||
|
Map<String, Integer> secondCateNamesIndexs = new HashMap<>();
|
||||||
|
Map<String, Integer> 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
|
@Override
|
||||||
public void deleteCategory(Long id) {
|
public void deleteCategory(Long id) {
|
||||||
// 校验分类是否存在
|
// 校验分类是否存在
|
||||||
|
|
Loading…
Reference in New Issue