1
|
package com.yoho.search.consumer.service.logic;
|
1
|
package com.yoho.search.consumer.service.logic;
|
2
|
|
2
|
|
3
|
-import java.util.ArrayList;
|
|
|
4
|
-import java.util.HashMap;
|
|
|
5
|
-import java.util.LinkedHashMap;
|
|
|
6
|
-import java.util.List;
|
|
|
7
|
-import java.util.Map;
|
|
|
8
|
-import java.util.stream.Collectors;
|
|
|
9
|
-
|
3
|
+import com.yoho.search.base.utils.FileUtils;
|
|
|
4
|
+import com.yoho.search.consumer.service.base.BrandService;
|
|
|
5
|
+import com.yoho.search.consumer.service.base.ProductSortService;
|
|
|
6
|
+import com.yoho.search.dal.ForbiddenSortBrandMapper;
|
|
|
7
|
+import com.yoho.search.dal.model.Brand;
|
|
|
8
|
+import com.yoho.search.dal.model.ForbiddenSortBrand;
|
|
|
9
|
+import com.yoho.search.dal.model.ProductSort;
|
10
|
import org.apache.commons.collections.CollectionUtils;
|
10
|
import org.apache.commons.collections.CollectionUtils;
|
11
|
import org.apache.commons.lang3.StringUtils;
|
11
|
import org.apache.commons.lang3.StringUtils;
|
12
|
import org.slf4j.Logger;
|
12
|
import org.slf4j.Logger;
|
|
@@ -14,165 +14,205 @@ import org.slf4j.LoggerFactory; |
|
@@ -14,165 +14,205 @@ import org.slf4j.LoggerFactory; |
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.stereotype.Service;
|
15
|
import org.springframework.stereotype.Service;
|
16
|
|
16
|
|
17
|
-import com.yoho.search.base.utils.FileUtils;
|
|
|
18
|
-import com.yoho.search.consumer.service.base.BrandService;
|
|
|
19
|
-import com.yoho.search.consumer.service.base.ProductSortService;
|
|
|
20
|
-import com.yoho.search.dal.model.Brand;
|
|
|
21
|
-import com.yoho.search.dal.model.ProductSort;
|
17
|
+import java.util.*;
|
|
|
18
|
+import java.util.stream.Collectors;
|
22
|
|
19
|
|
23
|
@Service
|
20
|
@Service
|
24
|
public class ForbidenSortBrandLogicService {
|
21
|
public class ForbidenSortBrandLogicService {
|
25
|
|
22
|
|
26
|
- private static final Logger logger = LoggerFactory.getLogger(ForbidenSortBrandLogicService.class);
|
|
|
27
|
-
|
|
|
28
|
- private static final Integer PARENTID_OF_MAXSORT = Integer.valueOf(0);
|
|
|
29
|
- private static final String LINE_SEPARATOR = System.lineSeparator();
|
|
|
30
|
-
|
|
|
31
|
- @Autowired
|
|
|
32
|
- private ProductSortService productSortService;
|
|
|
33
|
- @Autowired
|
|
|
34
|
- private BrandService brandService;
|
|
|
35
|
-
|
|
|
36
|
- private final String forbiddenSortBrandFileName = "inner/forbidden_brands.txt";
|
|
|
37
|
-
|
|
|
38
|
- private Map<Integer, Map<Integer, List<Integer>>> forbiddenSortBrandMap;
|
|
|
39
|
-
|
|
|
40
|
- private void checkAndInit() {
|
|
|
41
|
- if (forbiddenSortBrandMap != null) {
|
|
|
42
|
- return;
|
|
|
43
|
- }
|
|
|
44
|
- synchronized (this) {
|
|
|
45
|
- if (forbiddenSortBrandMap != null) {
|
|
|
46
|
- return;
|
|
|
47
|
- }
|
|
|
48
|
- forbiddenSortBrandMap = genForbiddenSortBrandMap();
|
|
|
49
|
- }
|
|
|
50
|
- }
|
|
|
51
|
-
|
|
|
52
|
- public Map<Integer, Map<Integer, List<Integer>>> getForbiddenSortBrandMap() {
|
|
|
53
|
- checkAndInit();
|
|
|
54
|
- return forbiddenSortBrandMap;
|
|
|
55
|
- }
|
|
|
56
|
-
|
|
|
57
|
- public boolean isForbiddenSortBrand(Integer maxSortId, Integer middleSortId, Integer brandId) {
|
|
|
58
|
- if (maxSortId == null || middleSortId == null || brandId == null) {
|
|
|
59
|
- return false;
|
|
|
60
|
- }
|
|
|
61
|
- checkAndInit();
|
|
|
62
|
- Map<Integer, List<Integer>> middleSortMap = forbiddenSortBrandMap.get(maxSortId);
|
|
|
63
|
- if (middleSortMap == null) {
|
|
|
64
|
- return false;
|
|
|
65
|
- }
|
|
|
66
|
- List<Integer> brandIds = middleSortMap.get(middleSortId);
|
|
|
67
|
- if (brandIds == null) {
|
|
|
68
|
- return false;
|
|
|
69
|
- }
|
|
|
70
|
- return brandIds.contains(brandId);
|
|
|
71
|
- }
|
|
|
72
|
-
|
|
|
73
|
- private Map<Integer, Map<Integer, List<Integer>>> genForbiddenSortBrandMap() {
|
|
|
74
|
- //1、获取所有的品牌信息
|
|
|
75
|
- Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap();
|
|
|
76
|
-
|
|
|
77
|
- //2、获取所有的品类信息
|
|
|
78
|
- List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE);
|
|
|
79
|
-
|
|
|
80
|
- //3、获取大分类Map
|
|
|
81
|
- Map<String,Integer> maxSortMap = new HashMap<String, Integer>();
|
|
|
82
|
- productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList())
|
|
|
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、读取文件
|
|
|
98
|
- String filePath = this.getClass().getResource("/").getPath();
|
|
|
99
|
- List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName);
|
|
|
100
|
- if (CollectionUtils.isEmpty(records)) {
|
|
|
101
|
- return new HashMap<Integer, Map<Integer, List<Integer>>>();
|
|
|
102
|
- }
|
|
|
103
|
-
|
|
|
104
|
- //6、构建数据
|
|
|
105
|
- Map<Integer, Map<Integer, List<Integer>>> resultMap = new LinkedHashMap<>();
|
|
|
106
|
- StringBuilder transferResult = new StringBuilder(10000);
|
|
|
107
|
- for (int i = 1; i < records.size(); i++) {
|
|
|
108
|
- String[] contents = records.get(i).split("\\\t", 3);
|
|
|
109
|
- if (contents == null || contents.length != 3) {
|
|
|
110
|
- contents = records.get(i).split(" ", 3);
|
|
|
111
|
- if (contents == null || contents.length != 3) {
|
|
|
112
|
- logger.warn("Process line [{}] failed.", i);
|
|
|
113
|
- continue;
|
|
|
114
|
- }
|
|
|
115
|
- }
|
|
|
116
|
- Integer maxSortId = maxSortMap.get(contents[0]);
|
|
|
117
|
- if (maxSortId == null) {
|
|
|
118
|
- logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]);
|
|
|
119
|
- continue;
|
|
|
120
|
- }
|
|
|
121
|
- Integer middleSortId = maxSortToMiddleSort.get(maxSortId).get(contents[1]);
|
|
|
122
|
- if (middleSortId == null) {
|
|
|
123
|
- logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]);
|
|
|
124
|
- continue;
|
|
|
125
|
- }
|
|
|
126
|
- Integer brandId = brandNameToIdMap.get(contents[2]);
|
|
|
127
|
- if (brandId == null) {
|
|
|
128
|
- logger.warn("Process line [{}] with brand [{}] failed.", i, contents[2]);
|
|
|
129
|
- continue;
|
|
|
130
|
- }
|
|
|
131
|
- Map<Integer, List<Integer>> innerMap = resultMap.get(maxSortId);
|
|
|
132
|
- if (innerMap == null) {
|
|
|
133
|
- innerMap = new LinkedHashMap<>(1000);
|
|
|
134
|
- resultMap.put(maxSortId, innerMap);
|
|
|
135
|
- }
|
|
|
136
|
- List<Integer> innerBrandIds = innerMap.get(middleSortId);
|
|
|
137
|
- if (innerBrandIds == null) {
|
|
|
138
|
- innerBrandIds = new ArrayList<>(1000);
|
|
|
139
|
- innerMap.put(middleSortId, innerBrandIds);
|
|
|
140
|
- }
|
|
|
141
|
- innerBrandIds.add(brandId);
|
|
|
142
|
- transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(brandId).append(LINE_SEPARATOR);
|
|
|
143
|
- }
|
|
|
144
|
-
|
|
|
145
|
- // 7、拼接数据
|
|
|
146
|
- StringBuilder calResult = new StringBuilder(10000);
|
|
|
147
|
- for (Map.Entry<Integer, Map<Integer, List<Integer>>> maxSortEntry : resultMap.entrySet()) {
|
|
|
148
|
- for (Map.Entry<Integer, List<Integer>> middleSortEntry : maxSortEntry.getValue().entrySet()) {
|
|
|
149
|
- String brandIdList = middleSortEntry.getValue().stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
150
|
- calResult.append(maxSortEntry.getKey()).append("|").append(middleSortEntry.getKey()).append("|").append(brandIdList).append(LINE_SEPARATOR);
|
|
|
151
|
- }
|
|
|
152
|
- }
|
|
|
153
|
- logger.info("[ForbiddenBrandsController][forbidden_cal]" + LINE_SEPARATOR + calResult.toString());
|
|
|
154
|
- FileUtils.writeFile("forbidden_cal.txt", calResult.toString());
|
|
|
155
|
- FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString());
|
|
|
156
|
-
|
|
|
157
|
- // 8、返回结果
|
|
|
158
|
- return resultMap;
|
|
|
159
|
- }
|
|
|
160
|
-
|
|
|
161
|
- private Map<String, Integer> getBrandNameToIdMap() {
|
|
|
162
|
- Map<String, Integer> brandNameToIdMap = new HashMap<String, Integer>();
|
|
|
163
|
- List<Brand> brandList = brandService.getBrandPageLists(0, Integer.MAX_VALUE);
|
|
|
164
|
- brandList.forEach(brand -> {
|
|
|
165
|
- if (StringUtils.isNotEmpty(brand.getBrandName())) {
|
|
|
166
|
- brandNameToIdMap.put(brand.getBrandName(), brand.getId());
|
|
|
167
|
- }
|
|
|
168
|
- if (StringUtils.isNotEmpty(brand.getBrandNameEn())) {
|
|
|
169
|
- brandNameToIdMap.put(brand.getBrandNameEn(), brand.getId());
|
|
|
170
|
- }
|
|
|
171
|
- if (StringUtils.isNotEmpty(brand.getBrandNameCn())) {
|
|
|
172
|
- brandNameToIdMap.put(brand.getBrandNameCn(), brand.getId());
|
|
|
173
|
- }
|
|
|
174
|
- });
|
|
|
175
|
- return brandNameToIdMap;
|
|
|
176
|
- }
|
|
|
177
|
-
|
23
|
+ private static final Logger logger = LoggerFactory.getLogger(ForbidenSortBrandLogicService.class);
|
|
|
24
|
+
|
|
|
25
|
+ private static final Integer PARENTID_OF_MAXSORT = Integer.valueOf(0);
|
|
|
26
|
+ private static final String LINE_SEPARATOR = System.lineSeparator();
|
|
|
27
|
+
|
|
|
28
|
+ @Autowired
|
|
|
29
|
+ private ProductSortService productSortService;
|
|
|
30
|
+ @Autowired
|
|
|
31
|
+ private BrandService brandService;
|
|
|
32
|
+ @Autowired
|
|
|
33
|
+ private ForbiddenSortBrandMapper forbiddenSortBrandMapper;
|
|
|
34
|
+
|
|
|
35
|
+ private final String forbiddenSortBrandFileName = "inner/forbidden_brands.txt";
|
|
|
36
|
+
|
|
|
37
|
+ private Map<Integer, Map<Integer, List<Integer>>> forbiddenSortBrandMap;
|
|
|
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, map) -> {
|
|
|
51
|
+ map.forEach((middleSortId, list) -> {
|
|
|
52
|
+ for (Integer brandId : list) {
|
|
|
53
|
+ ForbiddenSortBrand forbiddenSortBrand = new ForbiddenSortBrand();
|
|
|
54
|
+ forbiddenSortBrand.setMaxSortId(maxSortId);
|
|
|
55
|
+ forbiddenSortBrand.setMiddleSortId(middleSortId);
|
|
|
56
|
+ forbiddenSortBrand.setBrandId(brandId);
|
|
|
57
|
+ long time = System.currentTimeMillis() / 1000L;
|
|
|
58
|
+ forbiddenSortBrand.setCreateTime((int) time);
|
|
|
59
|
+ forbiddenSortBrands.add(forbiddenSortBrand);
|
|
|
60
|
+ }
|
|
|
61
|
+ });
|
|
|
62
|
+ });
|
|
|
63
|
+ forbiddenSortBrandMapper.deleteAll();
|
|
|
64
|
+ long begin = System.currentTimeMillis();
|
|
|
65
|
+ logger.info("deleteAll forbiddenSortBrand success [cost={}]", (System.currentTimeMillis() - begin));
|
|
|
66
|
+ List<List<ForbiddenSortBrand>> result = createList(forbiddenSortBrands, 1000);
|
|
|
67
|
+ logger.info("batch insert forbiddenSortBrand begin");
|
|
|
68
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
69
|
+ forbiddenSortBrandMapper.insertBatch(result.get(i));
|
|
|
70
|
+ logger.info("batch insert forbiddenSortBrand [page={}]of[{}],[cost={}]", i, result.size(),(System.currentTimeMillis() - begin));
|
|
|
71
|
+ }
|
|
|
72
|
+ logger.info("batch insert forbiddenSortBrand success,[cost={}]",(System.currentTimeMillis() - begin));
|
|
|
73
|
+ }
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ public Map<Integer, Map<Integer, List<Integer>>> getForbiddenSortBrandMap() {
|
|
|
77
|
+ checkAndInit();
|
|
|
78
|
+ return forbiddenSortBrandMap;
|
|
|
79
|
+ }
|
|
|
80
|
+
|
|
|
81
|
+ public boolean isForbiddenSortBrand(Integer maxSortId, Integer middleSortId, Integer brandId) {
|
|
|
82
|
+ if (maxSortId == null || middleSortId == null || brandId == null) {
|
|
|
83
|
+ return false;
|
|
|
84
|
+ }
|
|
|
85
|
+ checkAndInit();
|
|
|
86
|
+ Map<Integer, List<Integer>> middleSortMap = forbiddenSortBrandMap.get(maxSortId);
|
|
|
87
|
+ if (middleSortMap == null) {
|
|
|
88
|
+ return false;
|
|
|
89
|
+ }
|
|
|
90
|
+ List<Integer> brandIds = middleSortMap.get(middleSortId);
|
|
|
91
|
+ if (brandIds == null) {
|
|
|
92
|
+ return false;
|
|
|
93
|
+ }
|
|
|
94
|
+ return brandIds.contains(brandId);
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ private Map<Integer, Map<Integer, List<Integer>>> genForbiddenSortBrandMap() {
|
|
|
98
|
+ //1、获取所有的品牌信息
|
|
|
99
|
+ Map<String, Integer> brandNameToIdMap = this.getBrandNameToIdMap();
|
|
|
100
|
+
|
|
|
101
|
+ //2、获取所有的品类信息
|
|
|
102
|
+ List<ProductSort> productSortList = productSortService.getPageLists(0, Integer.MAX_VALUE);
|
|
|
103
|
+
|
|
|
104
|
+ //3、获取大分类Map
|
|
|
105
|
+ Map<String, Integer> maxSortMap = new HashMap<String, Integer>();
|
|
|
106
|
+ productSortList.stream().filter(sort -> PARENTID_OF_MAXSORT.equals(sort.getParentId())).collect(Collectors.toList())
|
|
|
107
|
+ .forEach(sort -> maxSortMap.put(sort.getSortName(), sort.getId()));
|
|
|
108
|
+
|
|
|
109
|
+ //4、构造大分类和中分类的对应关系
|
|
|
110
|
+ Map<Integer, Map<String, Integer>> maxSortToMiddleSort = new HashMap<Integer, Map<String, Integer>>();
|
|
|
111
|
+ for (Integer maxSortId : maxSortMap.values()) {
|
|
|
112
|
+ Map<String, Integer> middleSortMap = new HashMap<String, Integer>();
|
|
|
113
|
+ for (ProductSort productSort : productSortList) {
|
|
|
114
|
+ if (productSort.getParentId().equals(maxSortId)) {
|
|
|
115
|
+ middleSortMap.put(productSort.getSortName(), productSort.getId());
|
|
|
116
|
+ }
|
|
|
117
|
+ }
|
|
|
118
|
+ maxSortToMiddleSort.put(maxSortId, middleSortMap);
|
|
|
119
|
+ }
|
|
|
120
|
+
|
|
|
121
|
+ //5、读取文件
|
|
|
122
|
+ String filePath = this.getClass().getResource("/").getPath();
|
|
|
123
|
+ List<String> records = FileUtils.readFile(filePath + forbiddenSortBrandFileName);
|
|
|
124
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
125
|
+ return new HashMap<Integer, Map<Integer, List<Integer>>>();
|
|
|
126
|
+ }
|
|
|
127
|
+
|
|
|
128
|
+ //6、构建数据
|
|
|
129
|
+ Map<Integer, Map<Integer, List<Integer>>> resultMap = new LinkedHashMap<>();
|
|
|
130
|
+ StringBuilder transferResult = new StringBuilder(10000);
|
|
|
131
|
+ for (int i = 1; i < records.size(); i++) {
|
|
|
132
|
+ String[] contents = records.get(i).split("\\\t", 3);
|
|
|
133
|
+ if (contents == null || contents.length != 3) {
|
|
|
134
|
+ contents = records.get(i).split(" ", 3);
|
|
|
135
|
+ if (contents == null || contents.length != 3) {
|
|
|
136
|
+ logger.warn("Process line [{}] failed.", i);
|
|
|
137
|
+ continue;
|
|
|
138
|
+ }
|
|
|
139
|
+ }
|
|
|
140
|
+ Integer maxSortId = maxSortMap.get(contents[0]);
|
|
|
141
|
+ if (maxSortId == null) {
|
|
|
142
|
+ logger.warn("Process line [{}] with maxSort [{}] failed.", i, contents[0]);
|
|
|
143
|
+ continue;
|
|
|
144
|
+ }
|
|
|
145
|
+ Integer middleSortId = maxSortToMiddleSort.get(maxSortId).get(contents[1]);
|
|
|
146
|
+ if (middleSortId == null) {
|
|
|
147
|
+ logger.warn("Process line [{}] with middleSort [{}] failed.", i, contents[1]);
|
|
|
148
|
+ continue;
|
|
|
149
|
+ }
|
|
|
150
|
+ Integer brandId = brandNameToIdMap.get(contents[2]);
|
|
|
151
|
+ if (brandId == null) {
|
|
|
152
|
+ logger.warn("Process line [{}] with brand [{}] failed.", i, contents[2]);
|
|
|
153
|
+ continue;
|
|
|
154
|
+ }
|
|
|
155
|
+ Map<Integer, List<Integer>> innerMap = resultMap.get(maxSortId);
|
|
|
156
|
+ if (innerMap == null) {
|
|
|
157
|
+ innerMap = new LinkedHashMap<>(1000);
|
|
|
158
|
+ resultMap.put(maxSortId, innerMap);
|
|
|
159
|
+ }
|
|
|
160
|
+ List<Integer> innerBrandIds = innerMap.get(middleSortId);
|
|
|
161
|
+ if (innerBrandIds == null) {
|
|
|
162
|
+ innerBrandIds = new ArrayList<>(1000);
|
|
|
163
|
+ innerMap.put(middleSortId, innerBrandIds);
|
|
|
164
|
+ }
|
|
|
165
|
+ innerBrandIds.add(brandId);
|
|
|
166
|
+ transferResult.append(maxSortId).append("-").append(middleSortId).append("-").append(brandId).append(LINE_SEPARATOR);
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ // 7、拼接数据
|
|
|
170
|
+ StringBuilder calResult = new StringBuilder(10000);
|
|
|
171
|
+ for (Map.Entry<Integer, Map<Integer, List<Integer>>> maxSortEntry : resultMap.entrySet()) {
|
|
|
172
|
+ for (Map.Entry<Integer, List<Integer>> middleSortEntry : maxSortEntry.getValue().entrySet()) {
|
|
|
173
|
+ String brandIdList = middleSortEntry.getValue().stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
174
|
+ calResult.append(maxSortEntry.getKey()).append("|").append(middleSortEntry.getKey()).append("|").append(brandIdList).append(LINE_SEPARATOR);
|
|
|
175
|
+ }
|
|
|
176
|
+ }
|
|
|
177
|
+ logger.info("[ForbiddenBrandsController][forbidden_cal]" + LINE_SEPARATOR + calResult.toString());
|
|
|
178
|
+ FileUtils.writeFile("forbidden_cal.txt", calResult.toString());
|
|
|
179
|
+ FileUtils.writeFile("forbidden_tranfer.txt", transferResult.toString());
|
|
|
180
|
+
|
|
|
181
|
+ // 8、返回结果
|
|
|
182
|
+ return resultMap;
|
|
|
183
|
+ }
|
|
|
184
|
+
|
|
|
185
|
+ private Map<String, Integer> getBrandNameToIdMap() {
|
|
|
186
|
+ Map<String, Integer> brandNameToIdMap = new HashMap<String, Integer>();
|
|
|
187
|
+ List<Brand> brandList = brandService.getBrandPageLists(0, Integer.MAX_VALUE);
|
|
|
188
|
+ brandList.forEach(brand -> {
|
|
|
189
|
+ if (StringUtils.isNotEmpty(brand.getBrandName())) {
|
|
|
190
|
+ brandNameToIdMap.put(brand.getBrandName(), brand.getId());
|
|
|
191
|
+ }
|
|
|
192
|
+ if (StringUtils.isNotEmpty(brand.getBrandNameEn())) {
|
|
|
193
|
+ brandNameToIdMap.put(brand.getBrandNameEn(), brand.getId());
|
|
|
194
|
+ }
|
|
|
195
|
+ if (StringUtils.isNotEmpty(brand.getBrandNameCn())) {
|
|
|
196
|
+ brandNameToIdMap.put(brand.getBrandNameCn(), brand.getId());
|
|
|
197
|
+ }
|
|
|
198
|
+ });
|
|
|
199
|
+ return brandNameToIdMap;
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ public static List<List<ForbiddenSortBrand>> createList(List<ForbiddenSortBrand> target, int size) {
|
|
|
203
|
+ List<List<ForbiddenSortBrand>> listArr = new ArrayList<List<ForbiddenSortBrand>>();
|
|
|
204
|
+ //获取被拆分的数组个数
|
|
|
205
|
+ int arrSize = target.size() % size == 0 ? target.size() / size : target.size() / size + 1;
|
|
|
206
|
+ for (int i = 0; i < arrSize; i++) {
|
|
|
207
|
+ List<ForbiddenSortBrand> sub = new ArrayList<ForbiddenSortBrand>();
|
|
|
208
|
+ //把指定索引数据放入到list中
|
|
|
209
|
+ for (int j = i * size; j <= size * (i + 1) - 1; j++) {
|
|
|
210
|
+ if (j <= target.size() - 1) {
|
|
|
211
|
+ sub.add(target.get(j));
|
|
|
212
|
+ }
|
|
|
213
|
+ }
|
|
|
214
|
+ listArr.add(sub);
|
|
|
215
|
+ }
|
|
|
216
|
+ return listArr;
|
|
|
217
|
+ }
|
178
|
} |
218
|
} |