|
|
package com.yoho.ufo.service.impl;
|
|
|
|
|
|
import com.yoho.ufo.dal.*;
|
|
|
import com.yoho.ufo.dal.model.Goods;
|
|
|
import com.yoho.ufo.dal.model.Product;
|
|
|
import com.yoho.ufo.dal.model.Storage;
|
|
|
import com.yoho.ufo.model.brand.Brand;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.size.Size;
|
|
|
import com.yoho.ufo.util.CollectionUtil;
|
|
|
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by li.ma on 2018/9/18.
|
|
|
*/
|
|
|
@Service
|
|
|
public class ProductAssistService {
|
|
|
|
|
|
@Autowired
|
|
|
private ProductSortMapper productSortMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private BrandMapper brandMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsMapper goodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsImagesMapper goodsImagesMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private UfoProductColorMapper productColorMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private StorageMapper storageMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private StoragePriceMapper storagePriceMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private UfoSizeMapper sizeMapper;
|
|
|
|
|
|
// 商品列表填充品牌名称
|
|
|
public ProductAssistService fillBrandName(List<ProductResponceBo> productResponceBos) {
|
|
|
if (CollectionUtils.isEmpty(productResponceBos)) {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
//List<Integer> productIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getId);
|
|
|
//List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
|
|
|
//Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
|
|
|
List<Brand> brandList = brandMapper.selectBrandByIdList(CollectionUtil.distinct(productResponceBos, ProductResponceBo::getBrandId));
|
|
|
Map<Integer, Brand> brandMap = CollectionUtil.extractMap(brandList, Brand::getId);
|
|
|
//List<Integer> sortIdList = CollectionUtil.distinct(productList, Product::getMaxSortId);
|
|
|
//sortIdList.addAll(CollectionUtil.distinct(productList, Product::getMidSortId));
|
|
|
//List<ProductSort> productSortList = productSortMapper.selectSortByIdList(sortIdList);
|
|
|
//Map<Integer, ProductSort> productSortMap = CollectionUtil.extractMap(productSortList, ProductSort::getId);
|
|
|
productResponceBos.forEach(respBo -> {
|
|
|
Brand brand = brandMap.get(respBo.getBrandId());
|
|
|
if (brand != null) {
|
|
|
respBo.setBrandName(brand.getBrandName());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
|
|
|
// 商品列表填充商品表信息
|
|
|
public ProductAssistService fillProductDetail(List<ProductResponceBo> productResponceBos) {
|
|
|
if (CollectionUtils.isEmpty(productResponceBos)) {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
List<Integer> productIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getId);
|
|
|
List<Product> products = productMapper.selectProductListByIds(productIdList);
|
|
|
Map<Integer, Product> productMap = CollectionUtil.extractMap(products, Product::getId);
|
|
|
productResponceBos.forEach(respBo -> {
|
|
|
Product item = productMap.get(respBo.getId());
|
|
|
if (item != null) {
|
|
|
respBo.setBrandId(item.getBrandId());
|
|
|
respBo.setMaxSortId(item.getMaxSortId());
|
|
|
respBo.setMaxSortId(item.getMidSortId());
|
|
|
}
|
|
|
});
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
|
|
|
// 商品列表填充商品表信息
|
|
|
public ProductAssistService fillGoodsColor(List<ProductResponceBo> productResponceBos) {
|
|
|
if (CollectionUtils.isEmpty(productResponceBos)) {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
List<Integer> goodsIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getGoodsId);
|
|
|
List<Goods> goodsList = goodsMapper.selectByIds(goodsIdList);
|
|
|
Map<Integer, String> goodsNamesMap = CollectionUtil.extractMap(goodsList, Goods::getId, Goods::getGoodsName);
|
|
|
|
|
|
productResponceBos.forEach(respBo -> {
|
|
|
respBo.setGoodsName(goodsNamesMap.get(respBo.getGoodsId()));
|
|
|
});
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
|
|
|
// 商品列表填充商品表信息
|
|
|
public ProductAssistService fillSortName(List<ProductResponceBo> productResponceBos) {
|
|
|
if (CollectionUtils.isEmpty(productResponceBos)) {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
List<Integer> storageIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getStorageId);
|
|
|
List<Storage> storageList = storageMapper.selectByIds(storageIdList);
|
|
|
Map<Integer, Integer> storageMap = CollectionUtil.extractMap(storageList, Storage::getId, Storage::getSizeId);
|
|
|
|
|
|
|
|
|
List<Size> sizes = sizeMapper.selectByIdList(new ArrayList<>(storageMap.values()));
|
|
|
Map<Integer, String> sizeNameMap = CollectionUtil.extractMap(sizes, Size::getId, Size::getSizeName);
|
|
|
|
|
|
|
|
|
productResponceBos.forEach(respBo -> {
|
|
|
Integer storageId = respBo.getStorageId();
|
|
|
String sizeName = sizeNameMap.get(storageMap.get(storageId));
|
|
|
respBo.setSizeName(sizeName);
|
|
|
});
|
|
|
return this;
|
|
|
}
|
|
|
} |
...
|
...
|
|