Authored by 胡古飞

BUG

... ... @@ -71,26 +71,37 @@ public class ForbidenSortBrandLogicService {
}
private 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);
Map<String, Integer> maxSortMap = new HashMap<>(100);
Map<String, Integer> middleSortMap = new HashMap<>(100);
//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()));
productSortList.stream().filter(sort -> maxSortMap.containsValue(sort.getParentId())).collect(Collectors.toList())
.forEach(sort -> middleSortMap.put(sort.getSortName(), sort.getId()));
// 3�����ļ��ж�ȡ���õ�Ʒ��+Ʒ��
.forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId()));
//4、构造大分类和中分类的对应关系
Map<Integer,Map<String,Integer>> maxSortToMiddleSort = new HashMap<Integer, Map<String,Integer>>();
for (Integer maxSortId : maxSortMap.values()) {
Map<String,Integer> middleSortMap = new HashMap<String, Integer>();
for (ProductSort productSort : productSortList) {
if(productSort.getParentId().equals(maxSortId)){
middleSortMap.put(productSort.getSortName(), productSort.getId());
}
}
maxSortToMiddleSort.put(maxSortId, middleSortMap);
}
//5、读取文件
String filePath = this.getClass().getResource("/").getPath();
List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName);
if (CollectionUtils.isEmpty(records)) {
return new HashMap<Integer, Map<Integer, List<Integer>>>();
}
// 4�����ɽ��
//6、构建数据
Map<Integer, Map<Integer, List<Integer>>> resultMap = new LinkedHashMap<>();
StringBuilder transferResult = new StringBuilder(10000);
for (int i = 1; i < records.size(); i++) {
... ... @@ -107,7 +118,7 @@ public class ForbidenSortBrandLogicService {
logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]);
continue;
}
Integer middleSortId = middleSortMap.get(contents[1]);
Integer middleSortId = maxSortToMiddleSort.get(maxSortId).get(contents[1]);
if (middleSortId == null) {
logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]);
continue;
... ... @@ -131,7 +142,7 @@ public class ForbidenSortBrandLogicService {
transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(brandId).append(LINE_SEPARATOR);
}
// 5��д�����أ����㶨λ
// 7、拼接数据
StringBuilder calResult = new StringBuilder(10000);
for (Map.Entry<Integer, Map<Integer, List<Integer>>> maxSortEntry : resultMap.entrySet()) {
for (Map.Entry<Integer, List<Integer>> middleSortEntry : maxSortEntry.getValue().entrySet()) {
... ... @@ -143,7 +154,7 @@ public class ForbidenSortBrandLogicService {
FileUtils.writeFile("forbidden_cal.txt", calResult.toString());
FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString());
// 6�����ؽ��
// 8、返回结果
return resultMap;
}
... ...