1
|
package com.yohoufo.product.service.impl;
|
1
|
package com.yohoufo.product.service.impl;
|
2
|
|
2
|
|
3
|
import java.math.BigDecimal;
|
3
|
import java.math.BigDecimal;
|
4
|
-import java.util.*;
|
4
|
+import java.util.ArrayList;
|
|
|
5
|
+import java.util.Arrays;
|
|
|
6
|
+import java.util.Collection;
|
|
|
7
|
+import java.util.Collections;
|
|
|
8
|
+import java.util.Comparator;
|
|
|
9
|
+import java.util.HashMap;
|
|
|
10
|
+import java.util.List;
|
|
|
11
|
+import java.util.Map;
|
5
|
import java.util.Map.Entry;
|
12
|
import java.util.Map.Entry;
|
|
|
13
|
+import java.util.Objects;
|
|
|
14
|
+import java.util.UUID;
|
6
|
import java.util.function.BinaryOperator;
|
15
|
import java.util.function.BinaryOperator;
|
7
|
import java.util.function.Function;
|
16
|
import java.util.function.Function;
|
8
|
import java.util.stream.Collectors;
|
17
|
import java.util.stream.Collectors;
|
9
|
|
18
|
|
10
|
-import com.alibaba.fastjson.JSON;
|
|
|
11
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
12
|
-import com.yoho.tools.common.beans.ApiResponse;
|
|
|
13
|
-import com.yohobuy.ufo.model.GoodsBO;
|
|
|
14
|
-import com.yohobuy.ufo.model.GoodsImageBO;
|
|
|
15
|
-import com.yohobuy.ufo.model.GoodsSize;
|
|
|
16
|
-import com.yohobuy.ufo.model.ProductInfo;
|
|
|
17
|
-import com.yohobuy.ufo.model.request.StoragePriceBo;
|
|
|
18
|
-import com.yohobuy.ufo.model.response.ProductDetailResp;
|
|
|
19
|
-import com.yohobuy.ufo.model.response.StorageInfoResp;
|
|
|
20
|
-import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
21
|
-import com.yohoufo.common.helper.ImageUrlAssist;
|
|
|
22
|
-import com.yohoufo.dal.product.*;
|
|
|
23
|
-import com.yohoufo.dal.product.model.*;
|
|
|
24
|
-import com.yohoufo.product.model.*;
|
|
|
25
|
-import com.yohoufo.product.response.*;
|
|
|
26
|
import org.apache.commons.lang.ArrayUtils;
|
19
|
import org.apache.commons.lang.ArrayUtils;
|
27
|
import org.apache.commons.lang3.StringUtils;
|
20
|
import org.apache.commons.lang3.StringUtils;
|
28
|
import org.apache.commons.lang3.tuple.Pair;
|
21
|
import org.apache.commons.lang3.tuple.Pair;
|
|
@@ -32,14 +25,74 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
@@ -32,14 +25,74 @@ import org.springframework.beans.factory.annotation.Autowired; |
32
|
import org.springframework.stereotype.Service;
|
25
|
import org.springframework.stereotype.Service;
|
33
|
import org.springframework.util.CollectionUtils;
|
26
|
import org.springframework.util.CollectionUtils;
|
34
|
|
27
|
|
|
|
28
|
+import com.alibaba.fastjson.JSONArray;
|
35
|
import com.alibaba.fastjson.JSONObject;
|
29
|
import com.alibaba.fastjson.JSONObject;
|
36
|
import com.google.common.collect.Lists;
|
30
|
import com.google.common.collect.Lists;
|
37
|
import com.yoho.core.common.helpers.ImagesHelper;
|
31
|
import com.yoho.core.common.helpers.ImagesHelper;
|
|
|
32
|
+import com.yoho.core.config.ConfigReader;
|
38
|
import com.yoho.core.dal.datasource.annotation.Database;
|
33
|
import com.yoho.core.dal.datasource.annotation.Database;
|
39
|
import com.yoho.error.exception.ServiceException;
|
34
|
import com.yoho.error.exception.ServiceException;
|
|
|
35
|
+import com.yoho.tools.common.beans.ApiResponse;
|
|
|
36
|
+import com.yohobuy.ufo.model.GoodsBO;
|
|
|
37
|
+import com.yohobuy.ufo.model.GoodsImageBO;
|
|
|
38
|
+import com.yohobuy.ufo.model.GoodsSize;
|
|
|
39
|
+import com.yohobuy.ufo.model.ProductInfo;
|
|
|
40
|
+import com.yohobuy.ufo.model.request.StoragePriceBo;
|
|
|
41
|
+import com.yohobuy.ufo.model.response.ProductDetailResp;
|
|
|
42
|
+import com.yohobuy.ufo.model.response.StorageDataResp;
|
|
|
43
|
+import com.yohobuy.ufo.model.response.StorageInfoResp;
|
|
|
44
|
+import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
45
|
+import com.yohoufo.common.helper.ImageUrlAssist;
|
40
|
import com.yohoufo.common.utils.DateUtil;
|
46
|
import com.yohoufo.common.utils.DateUtil;
|
41
|
import com.yohoufo.common.utils.UfoStringUtils;
|
47
|
import com.yohoufo.common.utils.UfoStringUtils;
|
42
|
-import com.yohobuy.ufo.model.response.StorageDataResp;
|
48
|
+import com.yohoufo.dal.product.BrandMapper;
|
|
|
49
|
+import com.yohoufo.dal.product.BrandSeriesMapper;
|
|
|
50
|
+import com.yohoufo.dal.product.GoodsImagesMapper;
|
|
|
51
|
+import com.yohoufo.dal.product.GoodsMapper;
|
|
|
52
|
+import com.yohoufo.dal.product.PriceTrendDayMapper;
|
|
|
53
|
+import com.yohoufo.dal.product.PriceTrendMonthMapper;
|
|
|
54
|
+import com.yohoufo.dal.product.ProductLimitSaleMapper;
|
|
|
55
|
+import com.yohoufo.dal.product.ProductMapper;
|
|
|
56
|
+import com.yohoufo.dal.product.ProductSalesMapper;
|
|
|
57
|
+import com.yohoufo.dal.product.ProductSortMapper;
|
|
|
58
|
+import com.yohoufo.dal.product.SaleCategoryMapper;
|
|
|
59
|
+import com.yohoufo.dal.product.SecondhandFlawMapper;
|
|
|
60
|
+import com.yohoufo.dal.product.SecondhandImagesMapper;
|
|
|
61
|
+import com.yohoufo.dal.product.SecondhandInfoMapper;
|
|
|
62
|
+import com.yohoufo.dal.product.SizeAddRecordMapper;
|
|
|
63
|
+import com.yohoufo.dal.product.SizeMapper;
|
|
|
64
|
+import com.yohoufo.dal.product.StorageMapper;
|
|
|
65
|
+import com.yohoufo.dal.product.StoragePriceMapper;
|
|
|
66
|
+import com.yohoufo.dal.product.model.Brand;
|
|
|
67
|
+import com.yohoufo.dal.product.model.BrandSeries;
|
|
|
68
|
+import com.yohoufo.dal.product.model.Goods;
|
|
|
69
|
+import com.yohoufo.dal.product.model.GoodsImages;
|
|
|
70
|
+import com.yohoufo.dal.product.model.PriceTrendModel;
|
|
|
71
|
+import com.yohoufo.dal.product.model.Product;
|
|
|
72
|
+import com.yohoufo.dal.product.model.ProductLimitSale;
|
|
|
73
|
+import com.yohoufo.dal.product.model.ProductSales;
|
|
|
74
|
+import com.yohoufo.dal.product.model.ProductSort;
|
|
|
75
|
+import com.yohoufo.dal.product.model.SaleCategory;
|
|
|
76
|
+import com.yohoufo.dal.product.model.SecondhandFlaw;
|
|
|
77
|
+import com.yohoufo.dal.product.model.SecondhandImages;
|
|
|
78
|
+import com.yohoufo.dal.product.model.SecondhandInfo;
|
|
|
79
|
+import com.yohoufo.dal.product.model.Size;
|
|
|
80
|
+import com.yohoufo.dal.product.model.SizeAddRecord;
|
|
|
81
|
+import com.yohoufo.dal.product.model.Storage;
|
|
|
82
|
+import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
83
|
+import com.yohoufo.product.model.PriceTrendBO;
|
|
|
84
|
+import com.yohoufo.product.model.ProductSeriesTemplate;
|
|
|
85
|
+import com.yohoufo.product.model.ProductSortTemplate;
|
|
|
86
|
+import com.yohoufo.product.model.SkupDetailForScreenInfo;
|
|
|
87
|
+import com.yohoufo.product.model.SkupInfo;
|
|
|
88
|
+import com.yohoufo.product.model.SkusBO;
|
|
|
89
|
+import com.yohoufo.product.response.ProductSeriesTemplateResp;
|
|
|
90
|
+import com.yohoufo.product.response.ProductSimpleResp;
|
|
|
91
|
+import com.yohoufo.product.response.ProductSortTemplateResp;
|
|
|
92
|
+import com.yohoufo.product.response.SaleCategoryBo;
|
|
|
93
|
+import com.yohoufo.product.response.SecondHandProductResp;
|
|
|
94
|
+import com.yohoufo.product.response.SkupDetailForScreenResp;
|
|
|
95
|
+import com.yohoufo.product.response.StorageLeastPriceResp;
|
43
|
import com.yohoufo.product.service.ProductSearchService;
|
96
|
import com.yohoufo.product.service.ProductSearchService;
|
44
|
import com.yohoufo.product.service.ProductService;
|
97
|
import com.yohoufo.product.service.ProductService;
|
45
|
|
98
|
|
|
@@ -80,9 +133,6 @@ public class ProductServiceImpl implements ProductService { |
|
@@ -80,9 +133,6 @@ public class ProductServiceImpl implements ProductService { |
80
|
private ProductSearchService productSearchService;
|
133
|
private ProductSearchService productSearchService;
|
81
|
|
134
|
|
82
|
@Autowired
|
135
|
@Autowired
|
83
|
- private PriceTrendSixtyDayMapper priceTrendSixtyDayMapper;
|
|
|
84
|
-
|
|
|
85
|
- @Autowired
|
|
|
86
|
private PriceTrendMonthMapper priceTrendMonthMapper;
|
136
|
private PriceTrendMonthMapper priceTrendMonthMapper;
|
87
|
|
137
|
|
88
|
@Autowired
|
138
|
@Autowired
|
|
@@ -109,6 +159,15 @@ public class ProductServiceImpl implements ProductService { |
|
@@ -109,6 +159,15 @@ public class ProductServiceImpl implements ProductService { |
109
|
@Autowired
|
159
|
@Autowired
|
110
|
private UfoServiceCaller ufoServiceCaller;
|
160
|
private UfoServiceCaller ufoServiceCaller;
|
111
|
|
161
|
|
|
|
162
|
+ @Autowired
|
|
|
163
|
+ private ProductSortMapper productSortMapper;
|
|
|
164
|
+
|
|
|
165
|
+ @Autowired
|
|
|
166
|
+ private ConfigReader configReader;
|
|
|
167
|
+
|
|
|
168
|
+ @Autowired
|
|
|
169
|
+ private SizeAddRecordMapper sizeAddRecordMapper;
|
|
|
170
|
+
|
112
|
@Override
|
171
|
@Override
|
113
|
public ProductDetailResp queryProductDetailById(Integer productId) {
|
172
|
public ProductDetailResp queryProductDetailById(Integer productId) {
|
114
|
ProductDetailResp productDetailResp = new ProductDetailResp();
|
173
|
ProductDetailResp productDetailResp = new ProductDetailResp();
|
|
@@ -151,6 +210,11 @@ public class ProductServiceImpl implements ProductService { |
|
@@ -151,6 +210,11 @@ public class ProductServiceImpl implements ProductService { |
151
|
productInfo.setSecondHandLeastPrice(secondHandLeastPrice);
|
210
|
productInfo.setSecondHandLeastPrice(secondHandLeastPrice);
|
152
|
}
|
211
|
}
|
153
|
goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy));
|
212
|
goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy));
|
|
|
213
|
+ List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsBOList);
|
|
|
214
|
+ if(!CollectionUtils.isEmpty(otherAddSizeList)) {
|
|
|
215
|
+ goodsBO.setCanAddSize(true);
|
|
|
216
|
+ goodsBO.setOtherSizeList(otherAddSizeList);
|
|
|
217
|
+ }
|
154
|
}
|
218
|
}
|
155
|
}
|
219
|
}
|
156
|
productInfo.setGoodsList(goodsBOList);
|
220
|
productInfo.setGoodsList(goodsBOList);
|
|
@@ -160,6 +224,76 @@ public class ProductServiceImpl implements ProductService { |
|
@@ -160,6 +224,76 @@ public class ProductServiceImpl implements ProductService { |
160
|
return productDetailResp;
|
224
|
return productDetailResp;
|
161
|
}
|
225
|
}
|
162
|
|
226
|
|
|
|
227
|
+ private List<JSONObject> getOtherSizeList(Integer maxSortId, Integer midSortId, List<GoodsBO> goodsBOList) {
|
|
|
228
|
+ List<JSONObject> result = Lists.newArrayList();
|
|
|
229
|
+ String configMaxSortIds = configReader.getString("ufo.product.addSizeSortId", "");
|
|
|
230
|
+ if(StringUtils.isEmpty(configMaxSortIds)) {
|
|
|
231
|
+ return result;
|
|
|
232
|
+ }
|
|
|
233
|
+
|
|
|
234
|
+ List<Integer> configSortList = Lists.newArrayList();
|
|
|
235
|
+ String[] configSortArr = configMaxSortIds.split(",");
|
|
|
236
|
+ for(int i=0; i<configSortArr.length; i++) {
|
|
|
237
|
+ configSortList.add(Integer.parseInt(configSortArr[i]));
|
|
|
238
|
+ }
|
|
|
239
|
+
|
|
|
240
|
+ //如果没有配置这个品类,则不可以添加尺码
|
|
|
241
|
+ if(!configSortList.contains(maxSortId)) {
|
|
|
242
|
+ return result;
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ List<Size> sizeList = getAllSizeBySortId(midSortId);
|
|
|
246
|
+ if(CollectionUtils.isEmpty(sizeList)) {
|
|
|
247
|
+ return result;
|
|
|
248
|
+ }
|
|
|
249
|
+
|
|
|
250
|
+ List<Integer> sizeIdList = sizeList.stream().map(Size::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
251
|
+ if(!CollectionUtils.isEmpty(goodsBOList)) {
|
|
|
252
|
+ List<GoodsSize> goodsSizes = goodsBOList.get(0).getSizeList();
|
|
|
253
|
+ if(!CollectionUtils.isEmpty(goodsSizes)) {
|
|
|
254
|
+ List<Integer> goodsSizeIdList = goodsSizes.stream().map(GoodsSize::getSizeId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
255
|
+ sizeIdList.removeAll(goodsSizeIdList);
|
|
|
256
|
+ }
|
|
|
257
|
+ }
|
|
|
258
|
+
|
|
|
259
|
+ if(CollectionUtils.isEmpty(sizeIdList)) {
|
|
|
260
|
+ return result;
|
|
|
261
|
+ }
|
|
|
262
|
+
|
|
|
263
|
+ Map<Integer, Size> sizeMap = sizeList.stream().collect(Collectors.toMap(Size::getId, s->s));
|
|
|
264
|
+ List<Size> resultSizeList = Lists.newArrayList();
|
|
|
265
|
+
|
|
|
266
|
+ //排序
|
|
|
267
|
+ for(Integer sizeId : sizeIdList) {
|
|
|
268
|
+ resultSizeList.add(sizeMap.get(sizeId));
|
|
|
269
|
+ }
|
|
|
270
|
+ resultSizeList.sort(Comparator.comparing(Size::getOrderBy));
|
|
|
271
|
+
|
|
|
272
|
+ JSONObject jsonObject;
|
|
|
273
|
+ for(Size item : resultSizeList) {
|
|
|
274
|
+ jsonObject = new JSONObject();
|
|
|
275
|
+ jsonObject.put("id", item.getId());
|
|
|
276
|
+ jsonObject.put("text", item.getSizeName());
|
|
|
277
|
+ result.add(jsonObject);
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ return result;
|
|
|
281
|
+ }
|
|
|
282
|
+
|
|
|
283
|
+ private List<Size> getAllSizeBySortId(Integer sortId) {
|
|
|
284
|
+ ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);
|
|
|
285
|
+ List<Size> sizes = Lists.newArrayList();
|
|
|
286
|
+ if (sort != null) {
|
|
|
287
|
+ List<Integer> idList = new ArrayList<>();
|
|
|
288
|
+ idList.add(sortId);
|
|
|
289
|
+ if (sort.getParentId() != null && sort.getParentId() > 0) {
|
|
|
290
|
+ idList.add(sort.getParentId());
|
|
|
291
|
+ }
|
|
|
292
|
+ sizes = sizeMapper.selectAllSizeBySortIdList(idList);
|
|
|
293
|
+ }
|
|
|
294
|
+ return sizes;
|
|
|
295
|
+ }
|
|
|
296
|
+
|
163
|
@Override
|
297
|
@Override
|
164
|
public StorageLeastPriceResp queryStorageLeastPrice(Integer storageId) {
|
298
|
public StorageLeastPriceResp queryStorageLeastPrice(Integer storageId) {
|
165
|
StoragePrice storagePrice = storagePriceMapper.selectLeastPrice(storageId);
|
299
|
StoragePrice storagePrice = storagePriceMapper.selectLeastPrice(storageId);
|
|
@@ -1476,6 +1610,45 @@ public class ProductServiceImpl implements ProductService { |
|
@@ -1476,6 +1610,45 @@ public class ProductServiceImpl implements ProductService { |
1476
|
return productDetailResp;
|
1610
|
return productDetailResp;
|
1477
|
}
|
1611
|
}
|
1478
|
|
1612
|
|
|
|
1613
|
+ public int addSizeForGoods(Integer productId, Integer goodsId, String sizeIds, Integer applyUid) {
|
|
|
1614
|
+ Product product = productMapper.selectByPrimaryKey(productId);
|
|
|
1615
|
+ if(null == product) {
|
|
|
1616
|
+ throw new ServiceException(400, "productId不存在");
|
|
|
1617
|
+ }
|
|
|
1618
|
+
|
|
|
1619
|
+ Goods goods = goodsMapper.selectByPrimaryKey(goodsId);
|
|
|
1620
|
+ if(null == goods || !goods.getProductId().equals(productId)) {
|
|
|
1621
|
+ throw new ServiceException(400, "goodsId不存在");
|
|
|
1622
|
+ }
|
|
|
1623
|
+
|
|
|
1624
|
+ //校验sizetId
|
|
|
1625
|
+ String[] sizeIdArr = sizeIds.split(",");
|
|
|
1626
|
+ List<SizeAddRecord> recordList = Lists.newArrayList();
|
|
|
1627
|
+
|
|
|
1628
|
+ //goodsId现对应的尺码
|
|
|
1629
|
+ List<Storage> storageList = storageMapper.selectByGoodsId(goodsId);
|
|
|
1630
|
+ List<Integer> existSizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
|
|
|
1631
|
+ List<Size> sizeList = sizeMapper.selectByIds(existSizeIdList);
|
|
|
1632
|
+ Map<Integer, String> sizeIdNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
|
|
|
1633
|
+ for(int i=0; i<sizeIdArr.length; i++) {
|
|
|
1634
|
+ Integer sizeId = Integer.parseInt(sizeIdArr[i]);
|
|
|
1635
|
+ if(existSizeIdList.contains(sizeId)) {
|
|
|
1636
|
+ throw new ServiceException(400, "尺码" + sizeIdNameMap.get(sizeId) + "已存在,不需要添加,请重新选择");
|
|
|
1637
|
+ }
|
|
|
1638
|
+
|
|
|
1639
|
+ SizeAddRecord record = new SizeAddRecord();
|
|
|
1640
|
+ record.setProductId(productId);
|
|
|
1641
|
+ record.setGoodsId(goodsId);
|
|
|
1642
|
+ record.setSizeId(sizeId);
|
|
|
1643
|
+ record.setApplyUid(applyUid);
|
|
|
1644
|
+ record.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
1645
|
+ recordList.add(record);
|
|
|
1646
|
+ }
|
|
|
1647
|
+
|
|
|
1648
|
+ //添加尺码审核记录
|
|
|
1649
|
+ return sizeAddRecordMapper.insertBatch(recordList);
|
|
|
1650
|
+ }
|
|
|
1651
|
+
|
1479
|
private String getGoodsDeafultImage(Integer goodsId) {
|
1652
|
private String getGoodsDeafultImage(Integer goodsId) {
|
1480
|
List<GoodsImages> goodsImages = goodsImagesMapper.selectByGoodsId(goodsId);
|
1653
|
List<GoodsImages> goodsImages = goodsImagesMapper.selectByGoodsId(goodsId);
|
1481
|
String defaultYImage = null;
|
1654
|
String defaultYImage = null;
|