|
|
package com.yohoufo.product.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.Objects;
|
|
|
import java.util.UUID;
|
|
|
import java.util.function.BinaryOperator;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.GoodsBO;
|
|
|
import com.yohobuy.ufo.model.GoodsImageBO;
|
|
|
import com.yohobuy.ufo.model.GoodsSize;
|
|
|
import com.yohobuy.ufo.model.ProductInfo;
|
|
|
import com.yohobuy.ufo.model.request.StoragePriceBo;
|
|
|
import com.yohobuy.ufo.model.response.ProductDetailResp;
|
|
|
import com.yohobuy.ufo.model.response.StorageInfoResp;
|
|
|
import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
import com.yohoufo.common.helper.ImageUrlAssist;
|
|
|
import com.yohoufo.dal.product.*;
|
|
|
import com.yohoufo.dal.product.model.*;
|
|
|
import com.yohoufo.product.model.*;
|
|
|
import com.yohoufo.product.response.*;
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
...
|
...
|
@@ -32,14 +25,74 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.common.helpers.ImagesHelper;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.dal.datasource.annotation.Database;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.GoodsBO;
|
|
|
import com.yohobuy.ufo.model.GoodsImageBO;
|
|
|
import com.yohobuy.ufo.model.GoodsSize;
|
|
|
import com.yohobuy.ufo.model.ProductInfo;
|
|
|
import com.yohobuy.ufo.model.request.StoragePriceBo;
|
|
|
import com.yohobuy.ufo.model.response.ProductDetailResp;
|
|
|
import com.yohobuy.ufo.model.response.StorageDataResp;
|
|
|
import com.yohobuy.ufo.model.response.StorageInfoResp;
|
|
|
import com.yohoufo.common.caller.UfoServiceCaller;
|
|
|
import com.yohoufo.common.helper.ImageUrlAssist;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.common.utils.UfoStringUtils;
|
|
|
import com.yohobuy.ufo.model.response.StorageDataResp;
|
|
|
import com.yohoufo.dal.product.BrandMapper;
|
|
|
import com.yohoufo.dal.product.BrandSeriesMapper;
|
|
|
import com.yohoufo.dal.product.GoodsImagesMapper;
|
|
|
import com.yohoufo.dal.product.GoodsMapper;
|
|
|
import com.yohoufo.dal.product.PriceTrendDayMapper;
|
|
|
import com.yohoufo.dal.product.PriceTrendMonthMapper;
|
|
|
import com.yohoufo.dal.product.ProductLimitSaleMapper;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
|
|
import com.yohoufo.dal.product.ProductSalesMapper;
|
|
|
import com.yohoufo.dal.product.ProductSortMapper;
|
|
|
import com.yohoufo.dal.product.SaleCategoryMapper;
|
|
|
import com.yohoufo.dal.product.SecondhandFlawMapper;
|
|
|
import com.yohoufo.dal.product.SecondhandImagesMapper;
|
|
|
import com.yohoufo.dal.product.SecondhandInfoMapper;
|
|
|
import com.yohoufo.dal.product.SizeAddRecordMapper;
|
|
|
import com.yohoufo.dal.product.SizeMapper;
|
|
|
import com.yohoufo.dal.product.StorageMapper;
|
|
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
|
|
import com.yohoufo.dal.product.model.Brand;
|
|
|
import com.yohoufo.dal.product.model.BrandSeries;
|
|
|
import com.yohoufo.dal.product.model.Goods;
|
|
|
import com.yohoufo.dal.product.model.GoodsImages;
|
|
|
import com.yohoufo.dal.product.model.PriceTrendModel;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.dal.product.model.ProductLimitSale;
|
|
|
import com.yohoufo.dal.product.model.ProductSales;
|
|
|
import com.yohoufo.dal.product.model.ProductSort;
|
|
|
import com.yohoufo.dal.product.model.SaleCategory;
|
|
|
import com.yohoufo.dal.product.model.SecondhandFlaw;
|
|
|
import com.yohoufo.dal.product.model.SecondhandImages;
|
|
|
import com.yohoufo.dal.product.model.SecondhandInfo;
|
|
|
import com.yohoufo.dal.product.model.Size;
|
|
|
import com.yohoufo.dal.product.model.SizeAddRecord;
|
|
|
import com.yohoufo.dal.product.model.Storage;
|
|
|
import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
import com.yohoufo.product.model.PriceTrendBO;
|
|
|
import com.yohoufo.product.model.ProductSeriesTemplate;
|
|
|
import com.yohoufo.product.model.ProductSortTemplate;
|
|
|
import com.yohoufo.product.model.SkupDetailForScreenInfo;
|
|
|
import com.yohoufo.product.model.SkupInfo;
|
|
|
import com.yohoufo.product.model.SkusBO;
|
|
|
import com.yohoufo.product.response.ProductSeriesTemplateResp;
|
|
|
import com.yohoufo.product.response.ProductSimpleResp;
|
|
|
import com.yohoufo.product.response.ProductSortTemplateResp;
|
|
|
import com.yohoufo.product.response.SaleCategoryBo;
|
|
|
import com.yohoufo.product.response.SecondHandProductResp;
|
|
|
import com.yohoufo.product.response.SkupDetailForScreenResp;
|
|
|
import com.yohoufo.product.response.StorageLeastPriceResp;
|
|
|
import com.yohoufo.product.service.ProductSearchService;
|
|
|
import com.yohoufo.product.service.ProductService;
|
|
|
|
...
|
...
|
@@ -80,9 +133,6 @@ public class ProductServiceImpl implements ProductService { |
|
|
private ProductSearchService productSearchService;
|
|
|
|
|
|
@Autowired
|
|
|
private PriceTrendSixtyDayMapper priceTrendSixtyDayMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private PriceTrendMonthMapper priceTrendMonthMapper;
|
|
|
|
|
|
@Autowired
|
...
|
...
|
@@ -108,7 +158,16 @@ public class ProductServiceImpl implements ProductService { |
|
|
|
|
|
@Autowired
|
|
|
private UfoServiceCaller ufoServiceCaller;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private ProductSortMapper productSortMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
@Autowired
|
|
|
private SizeAddRecordMapper sizeAddRecordMapper;
|
|
|
|
|
|
@Override
|
|
|
public ProductDetailResp queryProductDetailById(Integer productId) {
|
|
|
ProductDetailResp productDetailResp = new ProductDetailResp();
|
...
|
...
|
@@ -151,6 +210,11 @@ public class ProductServiceImpl implements ProductService { |
|
|
productInfo.setSecondHandLeastPrice(secondHandLeastPrice);
|
|
|
}
|
|
|
goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy));
|
|
|
List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsBOList);
|
|
|
if(!CollectionUtils.isEmpty(otherAddSizeList)) {
|
|
|
goodsBO.setCanAddSize(true);
|
|
|
goodsBO.setOtherSizeList(otherAddSizeList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
productInfo.setGoodsList(goodsBOList);
|
...
|
...
|
@@ -159,6 +223,76 @@ public class ProductServiceImpl implements ProductService { |
|
|
|
|
|
return productDetailResp;
|
|
|
}
|
|
|
|
|
|
private List<JSONObject> getOtherSizeList(Integer maxSortId, Integer midSortId, List<GoodsBO> goodsBOList) {
|
|
|
List<JSONObject> result = Lists.newArrayList();
|
|
|
String configMaxSortIds = configReader.getString("ufo.product.addSizeSortId", "");
|
|
|
if(StringUtils.isEmpty(configMaxSortIds)) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
List<Integer> configSortList = Lists.newArrayList();
|
|
|
String[] configSortArr = configMaxSortIds.split(",");
|
|
|
for(int i=0; i<configSortArr.length; i++) {
|
|
|
configSortList.add(Integer.parseInt(configSortArr[i]));
|
|
|
}
|
|
|
|
|
|
//如果没有配置这个品类,则不可以添加尺码
|
|
|
if(!configSortList.contains(maxSortId)) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
List<Size> sizeList = getAllSizeBySortId(midSortId);
|
|
|
if(CollectionUtils.isEmpty(sizeList)) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
List<Integer> sizeIdList = sizeList.stream().map(Size::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
if(!CollectionUtils.isEmpty(goodsBOList)) {
|
|
|
List<GoodsSize> goodsSizes = goodsBOList.get(0).getSizeList();
|
|
|
if(!CollectionUtils.isEmpty(goodsSizes)) {
|
|
|
List<Integer> goodsSizeIdList = goodsSizes.stream().map(GoodsSize::getSizeId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
sizeIdList.removeAll(goodsSizeIdList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(CollectionUtils.isEmpty(sizeIdList)) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Map<Integer, Size> sizeMap = sizeList.stream().collect(Collectors.toMap(Size::getId, s->s));
|
|
|
List<Size> resultSizeList = Lists.newArrayList();
|
|
|
|
|
|
//排序
|
|
|
for(Integer sizeId : sizeIdList) {
|
|
|
resultSizeList.add(sizeMap.get(sizeId));
|
|
|
}
|
|
|
resultSizeList.sort(Comparator.comparing(Size::getOrderBy));
|
|
|
|
|
|
JSONObject jsonObject;
|
|
|
for(Size item : resultSizeList) {
|
|
|
jsonObject = new JSONObject();
|
|
|
jsonObject.put("id", item.getId());
|
|
|
jsonObject.put("text", item.getSizeName());
|
|
|
result.add(jsonObject);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private List<Size> getAllSizeBySortId(Integer sortId) {
|
|
|
ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);
|
|
|
List<Size> sizes = Lists.newArrayList();
|
|
|
if (sort != null) {
|
|
|
List<Integer> idList = new ArrayList<>();
|
|
|
idList.add(sortId);
|
|
|
if (sort.getParentId() != null && sort.getParentId() > 0) {
|
|
|
idList.add(sort.getParentId());
|
|
|
}
|
|
|
sizes = sizeMapper.selectAllSizeBySortIdList(idList);
|
|
|
}
|
|
|
return sizes;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StorageLeastPriceResp queryStorageLeastPrice(Integer storageId) {
|
...
|
...
|
@@ -1475,6 +1609,45 @@ public class ProductServiceImpl implements ProductService { |
|
|
}
|
|
|
return productDetailResp;
|
|
|
}
|
|
|
|
|
|
public int addSizeForGoods(Integer productId, Integer goodsId, String sizeIds, Integer applyUid) {
|
|
|
Product product = productMapper.selectByPrimaryKey(productId);
|
|
|
if(null == product) {
|
|
|
throw new ServiceException(400, "productId不存在");
|
|
|
}
|
|
|
|
|
|
Goods goods = goodsMapper.selectByPrimaryKey(goodsId);
|
|
|
if(null == goods || !goods.getProductId().equals(productId)) {
|
|
|
throw new ServiceException(400, "goodsId不存在");
|
|
|
}
|
|
|
|
|
|
//校验sizetId
|
|
|
String[] sizeIdArr = sizeIds.split(",");
|
|
|
List<SizeAddRecord> recordList = Lists.newArrayList();
|
|
|
|
|
|
//goodsId现对应的尺码
|
|
|
List<Storage> storageList = storageMapper.selectByGoodsId(goodsId);
|
|
|
List<Integer> existSizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
|
|
|
List<Size> sizeList = sizeMapper.selectByIds(existSizeIdList);
|
|
|
Map<Integer, String> sizeIdNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
|
|
|
for(int i=0; i<sizeIdArr.length; i++) {
|
|
|
Integer sizeId = Integer.parseInt(sizeIdArr[i]);
|
|
|
if(existSizeIdList.contains(sizeId)) {
|
|
|
throw new ServiceException(400, "尺码" + sizeIdNameMap.get(sizeId) + "已存在,不需要添加,请重新选择");
|
|
|
}
|
|
|
|
|
|
SizeAddRecord record = new SizeAddRecord();
|
|
|
record.setProductId(productId);
|
|
|
record.setGoodsId(goodsId);
|
|
|
record.setSizeId(sizeId);
|
|
|
record.setApplyUid(applyUid);
|
|
|
record.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
recordList.add(record);
|
|
|
}
|
|
|
|
|
|
//添加尺码审核记录
|
|
|
return sizeAddRecordMapper.insertBatch(recordList);
|
|
|
}
|
|
|
|
|
|
private String getGoodsDeafultImage(Integer goodsId) {
|
|
|
List<GoodsImages> goodsImages = goodsImagesMapper.selectByGoodsId(goodsId);
|
...
|
...
|
|