...
|
...
|
@@ -45,10 +45,10 @@ public class ForbidenSortBrandLogicService { |
|
|
return;
|
|
|
}
|
|
|
forbiddenSortBrandMap = genForbiddenSortBrandMap();
|
|
|
//insert to DB
|
|
|
// insert to DB
|
|
|
List<ForbiddenSortBrand> forbiddenSortBrands = new ArrayList<>();
|
|
|
forbiddenSortBrandMap.forEach((maxSortId, middleSmallBrandMap) -> {
|
|
|
middleSmallBrandMap.forEach((middleSortId,smallBrandMap)->{
|
|
|
middleSmallBrandMap.forEach((middleSortId, smallBrandMap) -> {
|
|
|
smallBrandMap.forEach((smallSortId, list) -> {
|
|
|
for (Integer brandId : list) {
|
|
|
ForbiddenSortBrand forbiddenSortBrand = new ForbiddenSortBrand();
|
...
|
...
|
@@ -81,7 +81,7 @@ public class ForbidenSortBrandLogicService { |
|
|
return forbiddenSortBrandMap;
|
|
|
}
|
|
|
|
|
|
public boolean isForbiddenSortBrand(Integer maxSortId, Integer middleSortId,Integer smallSortId, Integer brandId) {
|
|
|
public boolean isForbiddenSortBrand(Integer maxSortId, Integer middleSortId, Integer smallSortId, Integer brandId) {
|
|
|
if (maxSortId == null || middleSortId == null || brandId == null) {
|
|
|
return false;
|
|
|
}
|
...
|
...
|
@@ -102,20 +102,22 @@ public class ForbidenSortBrandLogicService { |
|
|
}
|
|
|
|
|
|
private Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> genForbiddenSortBrandMap() {
|
|
|
//1、获取所有的品牌信息
|
|
|
// 1、获取所有的品牌信息
|
|
|
Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap();
|
|
|
|
|
|
//2、获取所有的品类信息
|
|
|
// 2、获取所有的品类信息
|
|
|
List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE);
|
|
|
|
|
|
//3、获取大分类Map
|
|
|
// 3、获取大分类Map
|
|
|
Map<String, Integer> maxSortMap = new HashMap<String, Integer>();
|
|
|
productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList())
|
|
|
.forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId()));
|
|
|
|
|
|
//4、构造大分类和中分类的对应关系
|
|
|
// 4、构造大分类和中分类的对应关系
|
|
|
Map<Integer, Map<String, Integer>> maxSortToMiddleSort = new HashMap<Integer, Map<String, Integer>>();
|
|
|
Map<Integer, Map<String, Integer>> middleSortToSmallSort = new HashMap<>();
|
|
|
Map<Integer, List<Integer>> middleIdToAllSmallSortId = new HashMap<Integer, List<Integer>>();
|
|
|
|
|
|
for (Integer maxSortId : maxSortMap.values()) {
|
|
|
Map<String, Integer> middleSortMap = new HashMap<String, Integer>();
|
|
|
for (ProductSort productSort : productSortList) {
|
...
|
...
|
@@ -124,26 +126,29 @@ public class ForbidenSortBrandLogicService { |
|
|
}
|
|
|
}
|
|
|
maxSortToMiddleSort.put(maxSortId, middleSortMap);
|
|
|
//构建中分类个小分类的对应关系
|
|
|
Map<String, Integer> smallSortMap = new HashMap<String, Integer>();
|
|
|
// 构建中分类个小分类的对应关系
|
|
|
middleSortMap.forEach((middleSortName, middleSortId) -> {
|
|
|
List<Integer> smallSortIds = new ArrayList<Integer>();
|
|
|
Map<String, Integer> smallSortMap = new HashMap<String, Integer>();
|
|
|
for (ProductSort productSort : productSortList) {
|
|
|
if (productSort.getParentId().equals(middleSortId)) {
|
|
|
smallSortMap.put(productSort.getSortName(), productSort.getId());
|
|
|
smallSortIds.add(productSort.getId());
|
|
|
}
|
|
|
}
|
|
|
middleSortToSmallSort.put(middleSortId, smallSortMap);
|
|
|
middleIdToAllSmallSortId.put(middleSortId, smallSortIds);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//5、读取文件
|
|
|
// 5、读取文件
|
|
|
String filePath = this.getClass().getResource("/").getPath();
|
|
|
List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName);
|
|
|
if (CollectionUtils.isEmpty(records)) {
|
|
|
return new HashMap<Integer, Map<Integer, Map<Integer, List<Integer>>>>();
|
|
|
}
|
|
|
|
|
|
//6、构建数据
|
|
|
// 6、构建数据
|
|
|
Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> resultMap = new LinkedHashMap<>();
|
|
|
StringBuilder transferResult = new StringBuilder(10000);
|
|
|
for (int i = 1; i < records.size(); i++) {
|
...
|
...
|
@@ -165,14 +170,16 @@ public class ForbidenSortBrandLogicService { |
|
|
logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
Integer smallSortId = 0;
|
|
|
List<Integer> smallSortIds = new ArrayList<Integer>();
|
|
|
if (contents[2].equals("全部")) {
|
|
|
smallSortIds = middleIdToAllSmallSortId.get(middleSortId);
|
|
|
} else {
|
|
|
smallSortId = middleSortToSmallSort.get(middleSortId).get(contents[2]);
|
|
|
Integer smallSortId = middleSortToSmallSort.get(middleSortId).get(contents[2]);
|
|
|
if (smallSortId != null) {
|
|
|
smallSortIds.add(smallSortId);
|
|
|
}
|
|
|
|
|
|
if (middleSortId == null) {
|
|
|
}
|
|
|
if (smallSortIds == null || smallSortIds.isEmpty()) {
|
|
|
logger.warn("Process line [{}] with smallSort [{}] failed.", i, contents[2]);
|
|
|
continue;
|
|
|
}
|
...
|
...
|
@@ -190,27 +197,25 @@ public class ForbidenSortBrandLogicService { |
|
|
Map<Integer, List<Integer>> smallBrandMap = middleSmallBrandMap.get(middleSortId);
|
|
|
if (smallBrandMap == null) {
|
|
|
smallBrandMap = new LinkedHashMap<>(1000);
|
|
|
middleSmallBrandMap.put(middleSortId,smallBrandMap);
|
|
|
middleSmallBrandMap.put(middleSortId, smallBrandMap);
|
|
|
resultMap.put(maxSortId, middleSmallBrandMap);
|
|
|
}
|
|
|
for (Integer smallSortId : smallSortIds) {
|
|
|
List<Integer> innerBrandIds = smallBrandMap.get(smallSortId);
|
|
|
if (innerBrandIds == null) {
|
|
|
innerBrandIds = new ArrayList<>(1000);
|
|
|
smallBrandMap.put(smallSortId,innerBrandIds);
|
|
|
middleSmallBrandMap.put(middleSortId,smallBrandMap);
|
|
|
resultMap.put(maxSortId, middleSmallBrandMap);
|
|
|
smallBrandMap.put(smallSortId, innerBrandIds);
|
|
|
}
|
|
|
innerBrandIds.add(brandId);
|
|
|
|
|
|
transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(smallSortId).append("-").append(brandId).append(LINE_SEPARATOR);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 7、拼接数据
|
|
|
StringBuilder calResult = new StringBuilder(10000);
|
|
|
|
|
|
resultMap.forEach((maxSortId,middleSmallBrand)->{
|
|
|
middleSmallBrand.forEach((middleSortId,smallBrand)->{
|
|
|
smallBrand.forEach((smallSortId,brandIdList)->{
|
|
|
resultMap.forEach((maxSortId, middleSmallBrand) -> {
|
|
|
middleSmallBrand.forEach((middleSortId, smallBrand) -> {
|
|
|
smallBrand.forEach((smallSortId, brandIdList) -> {
|
|
|
String brandIdListString = brandIdList.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
calResult.append(maxSortId).append("|").append(middleSortId).append("|").append(smallSortId).append("|").append(brandIdListString).append(LINE_SEPARATOR);
|
|
|
});
|
...
|
...
|
@@ -244,11 +249,11 @@ public class ForbidenSortBrandLogicService { |
|
|
|
|
|
private static List<List<ForbiddenSortBrand>> createList(List<ForbiddenSortBrand> target, int size) {
|
|
|
List<List<ForbiddenSortBrand>> listArr = new ArrayList<List<ForbiddenSortBrand>>();
|
|
|
//获取被拆分的数组个数
|
|
|
// 获取被拆分的数组个数
|
|
|
int arrSize = target.size() % size == 0 ? target.size() / size : target.size() / size + 1;
|
|
|
for (int i = 0; i < arrSize; i++) {
|
|
|
List<ForbiddenSortBrand> sub = new ArrayList<ForbiddenSortBrand>();
|
|
|
//把指定索引数据放入到list中
|
|
|
// 把指定索引数据放入到list中
|
|
|
for (int j = i * size; j <= size * (i + 1) - 1; j++) {
|
|
|
if (j <= target.size() - 1) {
|
|
|
sub.add(target.get(j));
|
...
|
...
|
|