修改ForbidenSortBrandLogicService的逻辑
Showing
1 changed file
with
227 additions
and
222 deletions
@@ -20,242 +20,247 @@ import java.util.stream.Collectors; | @@ -20,242 +20,247 @@ import java.util.stream.Collectors; | ||
20 | @Service | 20 | @Service |
21 | public class ForbidenSortBrandLogicService { | 21 | public class ForbidenSortBrandLogicService { |
22 | 22 | ||
23 | - private static final Logger logger = LoggerFactory.getLogger(ForbidenSortBrandLogicService.class); | 23 | + private static final Logger logger = LoggerFactory.getLogger(ForbidenSortBrandLogicService.class); |
24 | 24 | ||
25 | - private static final Integer PARENTID_OF_MAXSORT = Integer.valueOf(0); | ||
26 | - private static final String LINE_SEPARATOR = System.lineSeparator(); | 25 | + private static final Integer PARENTID_OF_MAXSORT = Integer.valueOf(0); |
26 | + private static final String LINE_SEPARATOR = System.lineSeparator(); | ||
27 | 27 | ||
28 | - @Autowired | ||
29 | - private ProductSortService productSortService; | ||
30 | - @Autowired | ||
31 | - private BrandService brandService; | ||
32 | - @Autowired | ||
33 | - private ForbiddenSortBrandMapper forbiddenSortBrandMapper; | 28 | + @Autowired |
29 | + private ProductSortService productSortService; | ||
30 | + @Autowired | ||
31 | + private BrandService brandService; | ||
32 | + @Autowired | ||
33 | + private ForbiddenSortBrandMapper forbiddenSortBrandMapper; | ||
34 | 34 | ||
35 | - private final String forbiddenSortBrandFileName = "inner/forbidden_brands.txt"; | 35 | + private final String forbiddenSortBrandFileName = "inner/forbidden_brands.txt"; |
36 | 36 | ||
37 | - private Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> forbiddenSortBrandMap; | 37 | + private Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> forbiddenSortBrandMap; |
38 | 38 | ||
39 | - private void checkAndInit() { | ||
40 | - if (forbiddenSortBrandMap != null) { | ||
41 | - return; | ||
42 | - } | ||
43 | - synchronized (this) { | ||
44 | - if (forbiddenSortBrandMap != null) { | ||
45 | - return; | ||
46 | - } | ||
47 | - forbiddenSortBrandMap = genForbiddenSortBrandMap(); | ||
48 | - //insert to DB | ||
49 | - List<ForbiddenSortBrand> forbiddenSortBrands = new ArrayList<>(); | ||
50 | - forbiddenSortBrandMap.forEach((maxSortId, middleSmallBrandMap) -> { | ||
51 | - middleSmallBrandMap.forEach((middleSortId,smallBrandMap)->{ | ||
52 | - smallBrandMap.forEach((smallSortId, list) -> { | ||
53 | - for (Integer brandId : list) { | ||
54 | - ForbiddenSortBrand forbiddenSortBrand = new ForbiddenSortBrand(); | ||
55 | - forbiddenSortBrand.setMaxSortId(maxSortId); | ||
56 | - forbiddenSortBrand.setMiddleSortId(middleSortId); | ||
57 | - forbiddenSortBrand.setSmallSortId(smallSortId); | ||
58 | - forbiddenSortBrand.setBrandId(brandId); | ||
59 | - long time = System.currentTimeMillis() / 1000L; | ||
60 | - forbiddenSortBrand.setCreateTime((int) time); | ||
61 | - forbiddenSortBrands.add(forbiddenSortBrand); | ||
62 | - } | ||
63 | - }); | ||
64 | - }); | ||
65 | - }); | ||
66 | - forbiddenSortBrandMapper.deleteAll(); | ||
67 | - long begin = System.currentTimeMillis(); | ||
68 | - logger.info("deleteAll forbiddenSortBrand success [cost={}]", (System.currentTimeMillis() - begin)); | ||
69 | - List<List<ForbiddenSortBrand>> result = createList(forbiddenSortBrands, 1000); | ||
70 | - logger.info("batch insert forbiddenSortBrand begin"); | ||
71 | - for (int i = 0; i < result.size(); i++) { | ||
72 | - forbiddenSortBrandMapper.insertBatch(result.get(i)); | ||
73 | - logger.info("batch insert forbiddenSortBrand [page={}]of[{}],[cost={}]", i, result.size(), (System.currentTimeMillis() - begin)); | ||
74 | - } | ||
75 | - logger.info("batch insert forbiddenSortBrand success,[cost={}]", (System.currentTimeMillis() - begin)); | ||
76 | - } | ||
77 | - } | 39 | + private void checkAndInit() { |
40 | + if (forbiddenSortBrandMap != null) { | ||
41 | + return; | ||
42 | + } | ||
43 | + synchronized (this) { | ||
44 | + if (forbiddenSortBrandMap != null) { | ||
45 | + return; | ||
46 | + } | ||
47 | + forbiddenSortBrandMap = genForbiddenSortBrandMap(); | ||
48 | + // insert to DB | ||
49 | + List<ForbiddenSortBrand> forbiddenSortBrands = new ArrayList<>(); | ||
50 | + forbiddenSortBrandMap.forEach((maxSortId, middleSmallBrandMap) -> { | ||
51 | + middleSmallBrandMap.forEach((middleSortId, smallBrandMap) -> { | ||
52 | + smallBrandMap.forEach((smallSortId, list) -> { | ||
53 | + for (Integer brandId : list) { | ||
54 | + ForbiddenSortBrand forbiddenSortBrand = new ForbiddenSortBrand(); | ||
55 | + forbiddenSortBrand.setMaxSortId(maxSortId); | ||
56 | + forbiddenSortBrand.setMiddleSortId(middleSortId); | ||
57 | + forbiddenSortBrand.setSmallSortId(smallSortId); | ||
58 | + forbiddenSortBrand.setBrandId(brandId); | ||
59 | + long time = System.currentTimeMillis() / 1000L; | ||
60 | + forbiddenSortBrand.setCreateTime((int) time); | ||
61 | + forbiddenSortBrands.add(forbiddenSortBrand); | ||
62 | + } | ||
63 | + }); | ||
64 | + }); | ||
65 | + }); | ||
66 | + forbiddenSortBrandMapper.deleteAll(); | ||
67 | + long begin = System.currentTimeMillis(); | ||
68 | + logger.info("deleteAll forbiddenSortBrand success [cost={}]", (System.currentTimeMillis() - begin)); | ||
69 | + List<List<ForbiddenSortBrand>> result = createList(forbiddenSortBrands, 1000); | ||
70 | + logger.info("batch insert forbiddenSortBrand begin"); | ||
71 | + for (int i = 0; i < result.size(); i++) { | ||
72 | + forbiddenSortBrandMapper.insertBatch(result.get(i)); | ||
73 | + logger.info("batch insert forbiddenSortBrand [page={}]of[{}],[cost={}]", i, result.size(), (System.currentTimeMillis() - begin)); | ||
74 | + } | ||
75 | + logger.info("batch insert forbiddenSortBrand success,[cost={}]", (System.currentTimeMillis() - begin)); | ||
76 | + } | ||
77 | + } | ||
78 | 78 | ||
79 | - public Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> getForbiddenSortBrandMap() { | ||
80 | - checkAndInit(); | ||
81 | - return forbiddenSortBrandMap; | ||
82 | - } | 79 | + public Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> getForbiddenSortBrandMap() { |
80 | + checkAndInit(); | ||
81 | + return forbiddenSortBrandMap; | ||
82 | + } | ||
83 | 83 | ||
84 | - public boolean isForbiddenSortBrand(Integer maxSortId, Integer middleSortId,Integer smallSortId, Integer brandId) { | ||
85 | - if (maxSortId == null || middleSortId == null || brandId == null) { | ||
86 | - return false; | ||
87 | - } | ||
88 | - checkAndInit(); | ||
89 | - Map<Integer, Map<Integer, List<Integer>>> middleSortMap = forbiddenSortBrandMap.get(maxSortId); | ||
90 | - if (middleSortMap == null) { | ||
91 | - return false; | ||
92 | - } | ||
93 | - Map<Integer, List<Integer>> smallSortMap = middleSortMap.get(middleSortId); | ||
94 | - if (smallSortMap == null) { | ||
95 | - return false; | ||
96 | - } | ||
97 | - List<Integer> brandIds = smallSortMap.get(smallSortId); | ||
98 | - if (brandIds == null) { | ||
99 | - return false; | ||
100 | - } | ||
101 | - return brandIds.contains(brandId); | ||
102 | - } | 84 | + public boolean isForbiddenSortBrand(Integer maxSortId, Integer middleSortId, Integer smallSortId, Integer brandId) { |
85 | + if (maxSortId == null || middleSortId == null || brandId == null) { | ||
86 | + return false; | ||
87 | + } | ||
88 | + checkAndInit(); | ||
89 | + Map<Integer, Map<Integer, List<Integer>>> middleSortMap = forbiddenSortBrandMap.get(maxSortId); | ||
90 | + if (middleSortMap == null) { | ||
91 | + return false; | ||
92 | + } | ||
93 | + Map<Integer, List<Integer>> smallSortMap = middleSortMap.get(middleSortId); | ||
94 | + if (smallSortMap == null) { | ||
95 | + return false; | ||
96 | + } | ||
97 | + List<Integer> brandIds = smallSortMap.get(smallSortId); | ||
98 | + if (brandIds == null) { | ||
99 | + return false; | ||
100 | + } | ||
101 | + return brandIds.contains(brandId); | ||
102 | + } | ||
103 | 103 | ||
104 | - private Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> genForbiddenSortBrandMap() { | ||
105 | - //1、获取所有的品牌信息 | ||
106 | - Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap(); | 104 | + private Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> genForbiddenSortBrandMap() { |
105 | + // 1、获取所有的品牌信息 | ||
106 | + Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap(); | ||
107 | 107 | ||
108 | - //2、获取所有的品类信息 | ||
109 | - List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE); | 108 | + // 2、获取所有的品类信息 |
109 | + List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE); | ||
110 | 110 | ||
111 | - //3、获取大分类Map | ||
112 | - Map<String, Integer> maxSortMap = new HashMap<String, Integer>(); | ||
113 | - productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList()) | ||
114 | - .forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId())); | 111 | + // 3、获取大分类Map |
112 | + Map<String, Integer> maxSortMap = new HashMap<String, Integer>(); | ||
113 | + productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList()) | ||
114 | + .forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId())); | ||
115 | 115 | ||
116 | - //4、构造大分类和中分类的对应关系 | ||
117 | - Map<Integer, Map<String, Integer>> maxSortToMiddleSort = new HashMap<Integer, Map<String, Integer>>(); | ||
118 | - Map<Integer, Map<String, Integer>> middleSortToSmallSort = new HashMap<>(); | ||
119 | - for (Integer maxSortId : maxSortMap.values()) { | ||
120 | - Map<String, Integer> middleSortMap = new HashMap<String, Integer>(); | ||
121 | - for (ProductSort productSort : productSortList) { | ||
122 | - if (productSort.getParentId().equals(maxSortId)) { | ||
123 | - middleSortMap.put(productSort.getSortName(), productSort.getId()); | ||
124 | - } | ||
125 | - } | ||
126 | - maxSortToMiddleSort.put(maxSortId, middleSortMap); | ||
127 | - //构建中分类个小分类的对应关系 | ||
128 | - Map<String, Integer> smallSortMap = new HashMap<String, Integer>(); | ||
129 | - middleSortMap.forEach((middleSortName, middleSortId) -> { | ||
130 | - for (ProductSort productSort : productSortList) { | ||
131 | - if (productSort.getParentId().equals(middleSortId)) { | ||
132 | - smallSortMap.put(productSort.getSortName(), productSort.getId()); | ||
133 | - } | ||
134 | - } | ||
135 | - middleSortToSmallSort.put(middleSortId, smallSortMap); | ||
136 | - }); | ||
137 | - } | 116 | + // 4、构造大分类和中分类的对应关系 |
117 | + Map<Integer, Map<String, Integer>> maxSortToMiddleSort = new HashMap<Integer, Map<String, Integer>>(); | ||
118 | + Map<Integer, Map<String, Integer>> middleSortToSmallSort = new HashMap<>(); | ||
119 | + Map<Integer, List<Integer>> middleIdToAllSmallSortId = new HashMap<Integer, List<Integer>>(); | ||
138 | 120 | ||
139 | - //5、读取文件 | ||
140 | - String filePath = this.getClass().getResource("/").getPath(); | ||
141 | - List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName); | ||
142 | - if (CollectionUtils.isEmpty(records)) { | ||
143 | - return new HashMap<Integer, Map<Integer, Map<Integer, List<Integer>>>>(); | ||
144 | - } | 121 | + for (Integer maxSortId : maxSortMap.values()) { |
122 | + Map<String, Integer> middleSortMap = new HashMap<String, Integer>(); | ||
123 | + for (ProductSort productSort : productSortList) { | ||
124 | + if (productSort.getParentId().equals(maxSortId)) { | ||
125 | + middleSortMap.put(productSort.getSortName(), productSort.getId()); | ||
126 | + } | ||
127 | + } | ||
128 | + maxSortToMiddleSort.put(maxSortId, middleSortMap); | ||
129 | + // 构建中分类个小分类的对应关系 | ||
130 | + middleSortMap.forEach((middleSortName, middleSortId) -> { | ||
131 | + List<Integer> smallSortIds = new ArrayList<Integer>(); | ||
132 | + Map<String, Integer> smallSortMap = new HashMap<String, Integer>(); | ||
133 | + for (ProductSort productSort : productSortList) { | ||
134 | + if (productSort.getParentId().equals(middleSortId)) { | ||
135 | + smallSortMap.put(productSort.getSortName(), productSort.getId()); | ||
136 | + smallSortIds.add(productSort.getId()); | ||
137 | + } | ||
138 | + } | ||
139 | + middleSortToSmallSort.put(middleSortId, smallSortMap); | ||
140 | + middleIdToAllSmallSortId.put(middleSortId, smallSortIds); | ||
141 | + }); | ||
142 | + } | ||
145 | 143 | ||
146 | - //6、构建数据 | ||
147 | - Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> resultMap = new LinkedHashMap<>(); | ||
148 | - StringBuilder transferResult = new StringBuilder(10000); | ||
149 | - for (int i = 1; i < records.size(); i++) { | ||
150 | - String[] contents = records.get(i).split("\\\t", 4); | ||
151 | - if (contents == null || contents.length != 4) { | ||
152 | - contents = records.get(i).split(" ", 4); | ||
153 | - if (contents == null || contents.length != 4) { | ||
154 | - logger.warn("Process line [{}] failed.", i); | ||
155 | - continue; | ||
156 | - } | ||
157 | - } | ||
158 | - Integer maxSortId = maxSortMap.get(contents[0]); | ||
159 | - if (maxSortId == null) { | ||
160 | - logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]); | ||
161 | - continue; | ||
162 | - } | ||
163 | - Integer middleSortId = maxSortToMiddleSort.get(maxSortId).get(contents[1]); | ||
164 | - if (middleSortId == null) { | ||
165 | - logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]); | ||
166 | - continue; | ||
167 | - } | 144 | + // 5、读取文件 |
145 | + String filePath = this.getClass().getResource("/").getPath(); | ||
146 | + List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName); | ||
147 | + if (CollectionUtils.isEmpty(records)) { | ||
148 | + return new HashMap<Integer, Map<Integer, Map<Integer, List<Integer>>>>(); | ||
149 | + } | ||
168 | 150 | ||
169 | - Integer smallSortId = 0; | ||
170 | - if (contents[2].equals("全部")) { | ||
171 | - } else { | ||
172 | - smallSortId = middleSortToSmallSort.get(middleSortId).get(contents[2]); | ||
173 | - } | 151 | + // 6、构建数据 |
152 | + Map<Integer, Map<Integer, Map<Integer, List<Integer>>>> resultMap = new LinkedHashMap<>(); | ||
153 | + StringBuilder transferResult = new StringBuilder(10000); | ||
154 | + for (int i = 1; i < records.size(); i++) { | ||
155 | + String[] contents = records.get(i).split("\\\t", 4); | ||
156 | + if (contents == null || contents.length != 4) { | ||
157 | + contents = records.get(i).split(" ", 4); | ||
158 | + if (contents == null || contents.length != 4) { | ||
159 | + logger.warn("Process line [{}] failed.", i); | ||
160 | + continue; | ||
161 | + } | ||
162 | + } | ||
163 | + Integer maxSortId = maxSortMap.get(contents[0]); | ||
164 | + if (maxSortId == null) { | ||
165 | + logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]); | ||
166 | + continue; | ||
167 | + } | ||
168 | + Integer middleSortId = maxSortToMiddleSort.get(maxSortId).get(contents[1]); | ||
169 | + if (middleSortId == null) { | ||
170 | + logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]); | ||
171 | + continue; | ||
172 | + } | ||
173 | + List<Integer> smallSortIds = new ArrayList<Integer>(); | ||
174 | + if (contents[2].equals("全部")) { | ||
175 | + smallSortIds = middleIdToAllSmallSortId.get(middleSortId); | ||
176 | + } else { | ||
177 | + Integer smallSortId = middleSortToSmallSort.get(middleSortId).get(contents[2]); | ||
178 | + if (smallSortId != null) { | ||
179 | + smallSortIds.add(smallSortId); | ||
180 | + } | ||
181 | + } | ||
182 | + if (smallSortIds == null || smallSortIds.isEmpty()) { | ||
183 | + logger.warn("Process line [{}] with smallSort [{}] failed.", i, contents[2]); | ||
184 | + continue; | ||
185 | + } | ||
186 | + Integer brandId = brandNameToIdMap.get(contents[3]); | ||
187 | + if (brandId == null) { | ||
188 | + logger.warn("Process line [{}] with brand [{}] failed.", i, contents[3]); | ||
189 | + continue; | ||
190 | + } | ||
191 | + | ||
192 | + Map<Integer, Map<Integer, List<Integer>>> middleSmallBrandMap = resultMap.get(maxSortId); | ||
193 | + if (middleSmallBrandMap == null) { | ||
194 | + middleSmallBrandMap = new LinkedHashMap<>(1000); | ||
195 | + resultMap.put(maxSortId, middleSmallBrandMap); | ||
196 | + } | ||
197 | + Map<Integer, List<Integer>> smallBrandMap = middleSmallBrandMap.get(middleSortId); | ||
198 | + if (smallBrandMap == null) { | ||
199 | + smallBrandMap = new LinkedHashMap<>(1000); | ||
200 | + middleSmallBrandMap.put(middleSortId, smallBrandMap); | ||
201 | + resultMap.put(maxSortId, middleSmallBrandMap); | ||
202 | + } | ||
203 | + for (Integer smallSortId : smallSortIds) { | ||
204 | + List<Integer> innerBrandIds = smallBrandMap.get(smallSortId); | ||
205 | + if (innerBrandIds == null) { | ||
206 | + innerBrandIds = new ArrayList<>(1000); | ||
207 | + smallBrandMap.put(smallSortId, innerBrandIds); | ||
208 | + } | ||
209 | + innerBrandIds.add(brandId); | ||
210 | + transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(smallSortId).append("-").append(brandId).append(LINE_SEPARATOR); | ||
211 | + } | ||
212 | + } | ||
213 | + | ||
214 | + // 7、拼接数据 | ||
215 | + StringBuilder calResult = new StringBuilder(10000); | ||
216 | + resultMap.forEach((maxSortId, middleSmallBrand) -> { | ||
217 | + middleSmallBrand.forEach((middleSortId, smallBrand) -> { | ||
218 | + smallBrand.forEach((smallSortId, brandIdList) -> { | ||
219 | + String brandIdListString = brandIdList.stream().map(String::valueOf).collect(Collectors.joining(",")); | ||
220 | + calResult.append(maxSortId).append("|").append(middleSortId).append("|").append(smallSortId).append("|").append(brandIdListString).append(LINE_SEPARATOR); | ||
221 | + }); | ||
222 | + }); | ||
223 | + }); | ||
224 | + | ||
225 | + logger.info("[ForbiddenBrandsController][forbidden_cal]" + LINE_SEPARATOR + calResult.toString()); | ||
226 | + FileUtils.writeFile("forbidden_cal.txt", calResult.toString()); | ||
227 | + FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString()); | ||
228 | + | ||
229 | + // 8、返回结果 | ||
230 | + return resultMap; | ||
231 | + } | ||
174 | 232 | ||
175 | - if (middleSortId == null) { | ||
176 | - logger.warn("Process line [{}] with smallSort [{}] failed.", i, contents[2]); | ||
177 | - continue; | ||
178 | - } | ||
179 | - Integer brandId = brandNameToIdMap.get(contents[3]); | ||
180 | - if (brandId == null) { | ||
181 | - logger.warn("Process line [{}] with brand [{}] failed.", i, contents[3]); | ||
182 | - continue; | ||
183 | - } | 233 | + private Map<String, Integer> getBrandNameToIdMap() { |
234 | + Map<String, Integer> brandNameToIdMap = new HashMap<String, Integer>(); | ||
235 | + List<Brand> brandList = brandService.getBrandPageLists(0, Integer.MAX_VALUE); | ||
236 | + brandList.forEach(brand -> { | ||
237 | + if (StringUtils.isNotEmpty(brand.getBrandName())) { | ||
238 | + brandNameToIdMap.put(brand.getBrandName(), brand.getId()); | ||
239 | + } | ||
240 | + if (StringUtils.isNotEmpty(brand.getBrandNameEn())) { | ||
241 | + brandNameToIdMap.put(brand.getBrandNameEn(), brand.getId()); | ||
242 | + } | ||
243 | + if (StringUtils.isNotEmpty(brand.getBrandNameCn())) { | ||
244 | + brandNameToIdMap.put(brand.getBrandNameCn(), brand.getId()); | ||
245 | + } | ||
246 | + }); | ||
247 | + return brandNameToIdMap; | ||
248 | + } | ||
184 | 249 | ||
185 | - Map<Integer, Map<Integer, List<Integer>>> middleSmallBrandMap = resultMap.get(maxSortId); | ||
186 | - if (middleSmallBrandMap == null) { | ||
187 | - middleSmallBrandMap = new LinkedHashMap<>(1000); | ||
188 | - resultMap.put(maxSortId, middleSmallBrandMap); | ||
189 | - } | ||
190 | - Map<Integer, List<Integer>> smallBrandMap = middleSmallBrandMap.get(middleSortId); | ||
191 | - if (smallBrandMap == null) { | ||
192 | - smallBrandMap = new LinkedHashMap<>(1000); | ||
193 | - middleSmallBrandMap.put(middleSortId,smallBrandMap); | ||
194 | - resultMap.put(maxSortId, middleSmallBrandMap); | ||
195 | - } | ||
196 | - List<Integer> innerBrandIds = smallBrandMap.get(smallSortId); | ||
197 | - if (innerBrandIds == null) { | ||
198 | - innerBrandIds = new ArrayList<>(1000); | ||
199 | - smallBrandMap.put(smallSortId,innerBrandIds); | ||
200 | - middleSmallBrandMap.put(middleSortId,smallBrandMap); | ||
201 | - resultMap.put(maxSortId, middleSmallBrandMap); | ||
202 | - } | ||
203 | - innerBrandIds.add(brandId); | ||
204 | - | ||
205 | - transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(smallSortId).append("-").append(brandId).append(LINE_SEPARATOR); | ||
206 | - } | ||
207 | - | ||
208 | - // 7、拼接数据 | ||
209 | - StringBuilder calResult = new StringBuilder(10000); | ||
210 | - | ||
211 | - resultMap.forEach((maxSortId,middleSmallBrand)->{ | ||
212 | - middleSmallBrand.forEach((middleSortId,smallBrand)->{ | ||
213 | - smallBrand.forEach((smallSortId,brandIdList)->{ | ||
214 | - String brandIdListString = brandIdList.stream().map(String::valueOf).collect(Collectors.joining(",")); | ||
215 | - calResult.append(maxSortId).append("|").append(middleSortId).append("|").append(smallSortId).append("|").append(brandIdListString).append(LINE_SEPARATOR); | ||
216 | - }); | ||
217 | - }); | ||
218 | - }); | ||
219 | - | ||
220 | - logger.info("[ForbiddenBrandsController][forbidden_cal]" + LINE_SEPARATOR + calResult.toString()); | ||
221 | - FileUtils.writeFile("forbidden_cal.txt", calResult.toString()); | ||
222 | - FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString()); | ||
223 | - | ||
224 | - // 8、返回结果 | ||
225 | - return resultMap; | ||
226 | - } | ||
227 | - | ||
228 | - private Map<String, Integer> getBrandNameToIdMap() { | ||
229 | - Map<String, Integer> brandNameToIdMap = new HashMap<String, Integer>(); | ||
230 | - List<Brand> brandList = brandService.getBrandPageLists(0, Integer.MAX_VALUE); | ||
231 | - brandList.forEach(brand -> { | ||
232 | - if (StringUtils.isNotEmpty(brand.getBrandName())) { | ||
233 | - brandNameToIdMap.put(brand.getBrandName(), brand.getId()); | ||
234 | - } | ||
235 | - if (StringUtils.isNotEmpty(brand.getBrandNameEn())) { | ||
236 | - brandNameToIdMap.put(brand.getBrandNameEn(), brand.getId()); | ||
237 | - } | ||
238 | - if (StringUtils.isNotEmpty(brand.getBrandNameCn())) { | ||
239 | - brandNameToIdMap.put(brand.getBrandNameCn(), brand.getId()); | ||
240 | - } | ||
241 | - }); | ||
242 | - return brandNameToIdMap; | ||
243 | - } | ||
244 | - | ||
245 | - private static List<List<ForbiddenSortBrand>> createList(List<ForbiddenSortBrand> target, int size) { | ||
246 | - List<List<ForbiddenSortBrand>> listArr = new ArrayList<List<ForbiddenSortBrand>>(); | ||
247 | - //获取被拆分的数组个数 | ||
248 | - int arrSize = target.size() % size == 0 ? target.size() / size : target.size() / size + 1; | ||
249 | - for (int i = 0; i < arrSize; i++) { | ||
250 | - List<ForbiddenSortBrand> sub = new ArrayList<ForbiddenSortBrand>(); | ||
251 | - //把指定索引数据放入到list中 | ||
252 | - for (int j = i * size; j <= size * (i + 1) - 1; j++) { | ||
253 | - if (j <= target.size() - 1) { | ||
254 | - sub.add(target.get(j)); | ||
255 | - } | ||
256 | - } | ||
257 | - listArr.add(sub); | ||
258 | - } | ||
259 | - return listArr; | ||
260 | - } | 250 | + private static List<List<ForbiddenSortBrand>> createList(List<ForbiddenSortBrand> target, int size) { |
251 | + List<List<ForbiddenSortBrand>> listArr = new ArrayList<List<ForbiddenSortBrand>>(); | ||
252 | + // 获取被拆分的数组个数 | ||
253 | + int arrSize = target.size() % size == 0 ? target.size() / size : target.size() / size + 1; | ||
254 | + for (int i = 0; i < arrSize; i++) { | ||
255 | + List<ForbiddenSortBrand> sub = new ArrayList<ForbiddenSortBrand>(); | ||
256 | + // 把指定索引数据放入到list中 | ||
257 | + for (int j = i * size; j <= size * (i + 1) - 1; j++) { | ||
258 | + if (j <= target.size() - 1) { | ||
259 | + sub.add(target.get(j)); | ||
260 | + } | ||
261 | + } | ||
262 | + listArr.add(sub); | ||
263 | + } | ||
264 | + return listArr; | ||
265 | + } | ||
261 | } | 266 | } |
-
Please register or login to post a comment