Authored by 胡古飞

BUG

@@ -71,26 +71,37 @@ public class ForbidenSortBrandLogicService { @@ -71,26 +71,37 @@ public class ForbidenSortBrandLogicService {
71 } 71 }
72 72
73 private Map<Integer, Map<Integer, List<Integer>>> genForbiddenSortBrandMap() { 73 private Map<Integer, Map<Integer, List<Integer>>> genForbiddenSortBrandMap() {
74 - // 1����ȡ���е�Ʒ������ 74 + //1、获取所有的品牌信息
75 Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap(); 75 Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap();
76 76
77 - // 2����ȡ���еĴ������з������� 77 + //2、获取所有的品类信息
78 List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE); 78 List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE);
79 - Map<String, Integer> maxSortMap = new HashMap<>(100);  
80 - Map<String, Integer> middleSortMap = new HashMap<>(100); 79 +
  80 + //3、获取大分类Map
  81 + Map<String,Integer> maxSortMap = new HashMap<String, Integer>();
81 productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList()) 82 productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList())
82 - .forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId()));  
83 - productSortList.stream().filter(sort -> maxSortMap.containsValue(sort.getParentId())).collect(Collectors.toList())  
84 - .forEach(sort -> middleSortMap.put(sort.getSortName(), sort.getId()));  
85 -  
86 - // 3�����ļ��ж�ȡ���õ�Ʒ��+Ʒ�� 83 + .forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId()));
  84 +
  85 + //4、构造大分类和中分类的对应关系
  86 + Map<Integer,Map<String,Integer>> maxSortToMiddleSort = new HashMap<Integer, Map<String,Integer>>();
  87 + for (Integer maxSortId : maxSortMap.values()) {
  88 + Map<String,Integer> middleSortMap = new HashMap<String, Integer>();
  89 + for (ProductSort productSort : productSortList) {
  90 + if(productSort.getParentId().equals(maxSortId)){
  91 + middleSortMap.put(productSort.getSortName(), productSort.getId());
  92 + }
  93 + }
  94 + maxSortToMiddleSort.put(maxSortId, middleSortMap);
  95 + }
  96 +
  97 + //5、读取文件
87 String filePath = this.getClass().getResource("/").getPath(); 98 String filePath = this.getClass().getResource("/").getPath();
88 List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName); 99 List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName);
89 if (CollectionUtils.isEmpty(records)) { 100 if (CollectionUtils.isEmpty(records)) {
90 return new HashMap<Integer, Map<Integer, List<Integer>>>(); 101 return new HashMap<Integer, Map<Integer, List<Integer>>>();
91 } 102 }
92 -  
93 - // 4�����ɽ�� 103 +
  104 + //6、构建数据
94 Map<Integer, Map<Integer, List<Integer>>> resultMap = new LinkedHashMap<>(); 105 Map<Integer, Map<Integer, List<Integer>>> resultMap = new LinkedHashMap<>();
95 StringBuilder transferResult = new StringBuilder(10000); 106 StringBuilder transferResult = new StringBuilder(10000);
96 for (int i = 1; i < records.size(); i++) { 107 for (int i = 1; i < records.size(); i++) {
@@ -107,7 +118,7 @@ public class ForbidenSortBrandLogicService { @@ -107,7 +118,7 @@ public class ForbidenSortBrandLogicService {
107 logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]); 118 logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]);
108 continue; 119 continue;
109 } 120 }
110 - Integer middleSortId = middleSortMap.get(contents[1]); 121 + Integer middleSortId = maxSortToMiddleSort.get(maxSortId).get(contents[1]);
111 if (middleSortId == null) { 122 if (middleSortId == null) {
112 logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]); 123 logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]);
113 continue; 124 continue;
@@ -131,7 +142,7 @@ public class ForbidenSortBrandLogicService { @@ -131,7 +142,7 @@ public class ForbidenSortBrandLogicService {
131 transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(brandId).append(LINE_SEPARATOR); 142 transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(brandId).append(LINE_SEPARATOR);
132 } 143 }
133 144
134 - // 5��д�����أ����㶨λ 145 + // 7、拼接数据
135 StringBuilder calResult = new StringBuilder(10000); 146 StringBuilder calResult = new StringBuilder(10000);
136 for (Map.Entry<Integer, Map<Integer, List<Integer>>> maxSortEntry : resultMap.entrySet()) { 147 for (Map.Entry<Integer, Map<Integer, List<Integer>>> maxSortEntry : resultMap.entrySet()) {
137 for (Map.Entry<Integer, List<Integer>> middleSortEntry : maxSortEntry.getValue().entrySet()) { 148 for (Map.Entry<Integer, List<Integer>> middleSortEntry : maxSortEntry.getValue().entrySet()) {
@@ -143,7 +154,7 @@ public class ForbidenSortBrandLogicService { @@ -143,7 +154,7 @@ public class ForbidenSortBrandLogicService {
143 FileUtils.writeFile("forbidden_cal.txt", calResult.toString()); 154 FileUtils.writeFile("forbidden_cal.txt", calResult.toString());
144 FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString()); 155 FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString());
145 156
146 - // 6�����ؽ�� 157 + // 8、返回结果
147 return resultMap; 158 return resultMap;
148 } 159 }
149 160