|
|
package com.yohoufo.product.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.yohoufo.dal.product.StorageMapper;
|
|
|
import com.yohoufo.dal.product.model.StorageGoodProductSize;
|
|
|
import com.yoho.core.common.helpers.ImagesHelper;
|
|
|
import com.yohoufo.dal.product.*;
|
|
|
import com.yohoufo.dal.product.model.*;
|
|
|
import com.yohoufo.product.model.GoodsImageBO;
|
|
|
import com.yohoufo.product.model.GoodsSize;
|
|
|
import com.yohoufo.product.model.GoodsBO;
|
|
|
import com.yohoufo.product.model.ProductInfo;
|
|
|
import com.yohoufo.product.response.StorageDataResp;
|
|
|
import com.yohoufo.product.response.StorageLeastPriceResp;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
|
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
import com.yohoufo.product.request.StoragePriceBo;
|
|
|
import com.yohoufo.product.response.ProductDetailResp;
|
|
|
import com.yohoufo.product.service.ProductService;
|
|
|
|
|
|
import com.yohoufo.resource.util.DateUtils;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -37,11 +45,118 @@ public class ProductServiceImpl implements ProductService{ |
|
|
@Autowired
|
|
|
private StorageMapper storageMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private BrandMapper brandMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private BrandSeriesMapper brandSeriesMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsMapper goodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsImagesMapper goodsImagesMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SizeMapper sizeMapper;
|
|
|
|
|
|
@Override
|
|
|
public ProductDetailResp queryProductDetailById(Integer productId) {
|
|
|
return null;
|
|
|
|
|
|
ProductDetailResp productDetailResp = new ProductDetailResp();
|
|
|
|
|
|
Product product = productMapper.selectByPrimaryKey(productId);
|
|
|
if (product != null) {
|
|
|
ProductInfo productInfo = new ProductInfo();
|
|
|
productInfo.setProductId(product.getId());
|
|
|
productInfo.setProductName(product.getProductName());
|
|
|
productInfo.setProductCode(product.getProductCode());
|
|
|
productInfo.setSaleTime(DateUtils.getDateString(product.getSaleTime()));
|
|
|
|
|
|
if (product.getBrandId() != null) {
|
|
|
Brand brand = brandMapper.selectByPrimaryKey(product.getBrandId());
|
|
|
if (brand != null) {
|
|
|
productInfo.setBrandName(brand.getBrandName());
|
|
|
}
|
|
|
}
|
|
|
if (product.getSeriesId() != null) {
|
|
|
BrandSeries series = brandSeriesMapper.selectByPrimaryKey(product.getSeriesId());
|
|
|
if (series != null) {
|
|
|
productInfo.setSeriesName(series.getSeriesName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<Goods> goodsList = goodsMapper.selectByProductId(productId);
|
|
|
if (!CollectionUtils.isEmpty(goodsList) && goodsList.get(0) != null) {
|
|
|
Goods goods = goodsList.get(0);
|
|
|
|
|
|
List<GoodsBO> goodsBOs = new ArrayList<>();
|
|
|
GoodsBO goodsBO = new GoodsBO();
|
|
|
goodsBO.setId(goods.getId());
|
|
|
goodsBO.setColorName(goods.getColorName());
|
|
|
goodsBO.setGoodsName(goods.getGoodsName());
|
|
|
List<GoodsImageBO> imageList = new ArrayList<>();
|
|
|
goodsBO.setImageList(imageList);
|
|
|
List<GoodsSize> goodSizeList = new ArrayList<>();
|
|
|
goodsBO.setSizeList(goodSizeList);
|
|
|
goodsBOs.add(goodsBO);
|
|
|
|
|
|
List<GoodsImages> goodsImages = goodsImagesMapper.selectByGoodsId(goods.getId());
|
|
|
if (!CollectionUtils.isEmpty(goodsImages)) {
|
|
|
List<String> imageUrlList = goodsImages.stream().map(GoodsImages::getImageUrl).filter(StringUtils::isBlank).map(this::buildImageFullUrl).collect(Collectors.toList());
|
|
|
imageUrlList.forEach(e -> imageList.add(GoodsImageBO.create(e)));
|
|
|
}
|
|
|
|
|
|
List<Storage> storageList = storageMapper.selectByGoodsId(goods.getId());
|
|
|
if (!CollectionUtils.isEmpty(storageList)) {
|
|
|
Map<Integer, Size> sizeMap = new HashMap<>();
|
|
|
List<Integer> sizeIds = storageList.stream().map(Storage::getSizeId).filter(e -> e != null && 0 != e).collect(Collectors.toList());
|
|
|
if (!CollectionUtils.isEmpty(sizeIds)) {
|
|
|
List<Size> sizes = sizeMapper.selectByIds(sizeIds);
|
|
|
if (!CollectionUtils.isEmpty(sizes)) {
|
|
|
sizeMap = sizes.stream().collect(Collectors.toMap(Size::getId, Function.identity()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Map<Integer, StoragePrice> storagePriceMap = new HashMap<>();
|
|
|
List<Integer> storageIds = storageList.stream().map(Storage::getId).collect(Collectors.toList());
|
|
|
List<StoragePrice> storagePrices = storagePriceMapper.selectByStorageIds(storageIds);
|
|
|
if (!CollectionUtils.isEmpty(storagePrices)) {
|
|
|
storagePriceMap = storagePrices.stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity()));
|
|
|
}
|
|
|
|
|
|
for (Storage storage : storageList) {
|
|
|
GoodsSize goodsSize = new GoodsSize();
|
|
|
goodsSize.setId(storage.getId());
|
|
|
goodsSize.setStorageNum(storage.getStorageNum());
|
|
|
goodsSize.setSizeId(storage.getSizeId());
|
|
|
Size size = sizeMap.get(storage.getSizeId());
|
|
|
goodsSize.setSizeName(size == null ? "" : size.getSizeName());
|
|
|
goodsSize.setOrderBy(size == null ? 0 : size.getOrderBy());
|
|
|
|
|
|
StoragePrice storagePrice = storagePriceMap.get(storage.getId());
|
|
|
goodsSize.setLeastPrice(storagePrice == null ? null : storagePrice.getPrice());
|
|
|
goodsSize.setStatus(storagePrice == null ? null : storagePrice.getStatus());
|
|
|
goodSizeList.add(goodsSize);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
productDetailResp.setProduct_info(productInfo);
|
|
|
}
|
|
|
|
|
|
return productDetailResp;
|
|
|
}
|
|
|
|
|
|
private String buildImageFullUrl(String url) {
|
|
|
if (!StringUtils.startsWith(url, "http")){
|
|
|
return ImagesHelper.template2(url, ImagesHelper.SYS_BUCKET.get(ImagesHelper.SYS_GOODS_NAME)).replaceAll("extent\\/\\{width}x\\{height}\\/","");
|
|
|
}else{
|
|
|
return url;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public StorageLeastPriceResp queryStorageLeastPrice(Integer storageId) {
|
|
|
StoragePrice storagePrice = storagePriceMapper.selectLeastPrice(storageId);
|
...
|
...
|
@@ -57,21 +172,30 @@ public class ProductServiceImpl implements ProductService{ |
|
|
|
|
|
@Override
|
|
|
public StorageDataResp queryStorageInfo(Integer storageId) {
|
|
|
StorageGoodProductSize sgps = storageMapper.selectStroageProductInfo(storageId);
|
|
|
if (sgps == null) {
|
|
|
StorageDataResp resp = new StorageDataResp();
|
|
|
Storage storage = storageMapper.selectByPrimaryKey(storageId);
|
|
|
if (storage == null) {
|
|
|
return null;
|
|
|
}
|
|
|
StorageDataResp resp = new StorageDataResp();
|
|
|
resp.setProductId(sgps.getProductId());
|
|
|
resp.setProductName(sgps.getProductName());
|
|
|
resp.setColorId(sgps.getColorId() + "");
|
|
|
resp.setColorName(sgps.getColorName());
|
|
|
resp.setImageUrl(sgps.getColorImage());
|
|
|
GoodsSize goodsSize = new GoodsSize();
|
|
|
goodsSize.setSizeId(sgps.getSizeId());
|
|
|
goodsSize.setSizeName(sgps.getSizeName());
|
|
|
goodsSize.setSizeId(storage.getSizeId());
|
|
|
Size size = sizeMapper.selectByPrimaryKey(storage.getSizeId());
|
|
|
if (size != null) {
|
|
|
goodsSize.setSizeName(size.getSizeName());
|
|
|
}
|
|
|
resp.setSize(goodsSize);
|
|
|
Goods goods = goodsMapper.selectByPrimaryKey(storage.getGoodsId());
|
|
|
if (goods != null) {
|
|
|
resp.setColorId(goods.getColorId().toString());
|
|
|
resp.setColorName(goods.getColorName());
|
|
|
resp.setImageUrl(goods.getColorImage());
|
|
|
|
|
|
Product product = productMapper.selectByPrimaryKey(goods.getProductId());
|
|
|
if (product != null) {
|
|
|
resp.setProductId(product.getId());
|
|
|
resp.setProductName(product.getProductName());
|
|
|
}
|
|
|
}
|
|
|
return resp;
|
|
|
}
|
|
|
|
...
|
...
|
|