...
|
...
|
@@ -37,7 +37,6 @@ public class ProductGoodsLogicService { |
|
|
@Autowired
|
|
|
private StorageService storageService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 全量增量都有调用
|
|
|
*/
|
...
|
...
|
@@ -53,11 +52,10 @@ public class ProductGoodsLogicService { |
|
|
|
|
|
//2、构建库存相关数据
|
|
|
Map<Integer, Integer> goodStorageNumMap = goodsRelatedStorageLogicService.buildGoodStorageNumMap(storageList);
|
|
|
Map<Integer, List<Storage>> productStorageMap = goodsRelatedStorageLogicService.buildProductStorageListMap(goodsList,storageList);
|
|
|
Map<Integer, List<Storage>> productStorageMap = goodsRelatedStorageLogicService.buildProductStorageListMap(goodsList, storageList);
|
|
|
|
|
|
//3、构建图片相关数据
|
|
|
Map<Integer, String> defaultImageMap = goodsRelatedImageLogicService.buildProductDefaultImage(goodsImages, goodStorageNumMap);
|
|
|
Map<Integer, GoodsCoverImage> goodsCoverImagesMap = goodsRelatedImageLogicService.selectGoodsCoverImage(goodsImages);
|
|
|
Map<Integer, GoodsImageInfo> goodsImageInfoMap = goodsRelatedImageLogicService.selectGoodsCoverImage(goodsImages);
|
|
|
|
|
|
//4、批量查询尺码信息
|
|
|
Map<Integer, String> sizeId2NameMap = productSizesLogicService.buildSizeId2NameMap(storageList);
|
...
|
...
|
@@ -65,19 +63,17 @@ public class ProductGoodsLogicService { |
|
|
//5、构建product2GoodsMap
|
|
|
Map<Integer, List<ProductGoodInfo>> productGoodsMap = new HashMap<>();
|
|
|
for (Goods goods : goodsList) {
|
|
|
ProductGoodInfo goodInfo = buildProductGoodInfo(goods, goodsCoverImagesMap, goodStorageNumMap);
|
|
|
ProductGoodInfo goodInfo = buildProductGoodInfo(goods, goodsImageInfoMap, goodStorageNumMap);
|
|
|
List<ProductGoodInfo> goodInfoList = productGoodsMap.computeIfAbsent(goods.getProductId(), a -> new ArrayList<>());
|
|
|
goodInfoList.add(goodInfo);
|
|
|
}
|
|
|
|
|
|
//6、构建productGoodsBOs
|
|
|
|
|
|
|
|
|
List<ProductGoodsBO> productGoodsBOs = new ArrayList<>();
|
|
|
for (Map.Entry<Integer, List<ProductGoodInfo>> entry : productGoodsMap.entrySet()) {
|
|
|
ProductGoodsBO productGoodsBO = new ProductGoodsBO(entry.getKey(), entry.getValue());
|
|
|
//填充图片
|
|
|
fillProductImage(productGoodsBO, defaultImageMap);
|
|
|
fillProductImage(productGoodsBO);
|
|
|
//填充颜色
|
|
|
fillColorInfo(productGoodsBO);
|
|
|
//填充尺码
|
...
|
...
|
@@ -91,35 +87,83 @@ public class ProductGoodsLogicService { |
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
private void fillProductImage(ProductGoodsBO productGoodsBO, Map<Integer, String> defaultImageMap) {
|
|
|
String imagesUrl = "";
|
|
|
/**
|
|
|
* 转成good对象
|
|
|
*/
|
|
|
private ProductGoodInfo buildProductGoodInfo(Goods goods, Map<Integer, GoodsImageInfo> goodsImagesInfoMap, Map<Integer, Integer> goodStorageMap) {
|
|
|
Map<Integer, ProductColor> productColorsMap = basicDataCacheService.getColor();
|
|
|
ProductGoodInfo productGoodInfo = new ProductGoodInfo();
|
|
|
// 来自Goods
|
|
|
productGoodInfo.setGoods_id(String.valueOf(goods.getId()));
|
|
|
productGoodInfo.setColor_name(StringUtils.isBlank(goods.getColorName()) ? "" : goods.getColorName());
|
|
|
productGoodInfo.setImages_url(StringUtils.isBlank(goods.getColorImage()) ? "" : goods.getColorImage());
|
|
|
productGoodInfo.setIs_default(StringUtils.isBlank(goods.getIsDefault()) ? "N" : goods.getIsDefault());
|
|
|
productGoodInfo.setColor_id(goods.getColorId() == null ? "" : goods.getColorId().toString());
|
|
|
productGoodInfo.setStatus(goods.getStatus() == null ? "0" : goods.getStatus().toString());
|
|
|
productGoodInfo.setProduct_skc(goods.getProductSkc() == null ? "" : goods.getProductSkc().toString());
|
|
|
productGoodInfo.setColor_value("");
|
|
|
// 来自productColorsMap
|
|
|
ProductColor productColor = productColorsMap.get(goods.getColorId());
|
|
|
if (productColor != null) {
|
|
|
String colorCode = productColor.getColorCode();
|
|
|
productGoodInfo.setColor_code(colorCode);
|
|
|
}
|
|
|
// 来自goodsCoverImagesMap
|
|
|
GoodsImageInfo goodsImageInfo = goodsImagesInfoMap.get(goods.getId());
|
|
|
String cover_1 = "";
|
|
|
String cover_2 = "";
|
|
|
if (goodsImageInfo != null) {
|
|
|
cover_1 = goodsImageInfo.getCover_1();
|
|
|
cover_2 = goodsImageInfo.getCover_2();
|
|
|
// Images_url兜底
|
|
|
if (StringUtils.isBlank(productGoodInfo.getImages_url())) {
|
|
|
productGoodInfo.setImages_url(goodsImageInfo.getImage_url());
|
|
|
}
|
|
|
}
|
|
|
productGoodInfo.setCover_1(StringUtils.isBlank(cover_1) ? "" : cover_1);
|
|
|
productGoodInfo.setCover_2(StringUtils.isBlank(cover_2) ? "" : cover_2);
|
|
|
// 来自storageMap
|
|
|
Integer storage_num = goodStorageMap.get(goods.getId());
|
|
|
productGoodInfo.setStorage_num(storage_num == null ? "0" : storage_num.toString());
|
|
|
return productGoodInfo;
|
|
|
}
|
|
|
|
|
|
private void fillProductImage(ProductGoodsBO productGoodsBO) {
|
|
|
String defaultImage = "";
|
|
|
String cover1 = "";
|
|
|
String cover2 = "";
|
|
|
for (ProductGoodInfo goodInfo : productGoodsBO.getGoodsList()) {
|
|
|
// 如果此goods是is_default=Y的,用这个goods,否则不用
|
|
|
// 如果此goods是is_default=Y的,并且有库存用这个goods的信息
|
|
|
if ("Y".equals(goodInfo.getIs_default()) && Integer.valueOf(goodInfo.getStorage_num()) > 0) {
|
|
|
imagesUrl = goodInfo.getImages_url();
|
|
|
defaultImage = goodInfo.getImages_url();
|
|
|
cover1 = goodInfo.getCover_1();
|
|
|
cover2 = goodInfo.getCover_2();
|
|
|
if (StringUtils.isNotBlank(imagesUrl)) {
|
|
|
//找到了则退出循环
|
|
|
if (StringUtils.isNotBlank(defaultImage)) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
cover1 = StringUtils.isNotBlank(cover1) ? cover1 : imagesUrl;
|
|
|
cover2 = StringUtils.isNotBlank(cover2) ? cover2 : imagesUrl;
|
|
|
productGoodsBO.setCover_1(cover1);
|
|
|
productGoodsBO.setCover_2(cover2);
|
|
|
String defaultImage = defaultImageMap.get(productGoodsBO.getProductId());
|
|
|
//default_images灾备
|
|
|
if (StringUtils.isBlank(defaultImage)) {
|
|
|
defaultImage = getImageNotNull(productGoodsBO.getGoodsList());
|
|
|
defaultImage = getImageNotNull(productGoodsBO.getGoodsList(), true);
|
|
|
if (StringUtils.isBlank(defaultImage)) {
|
|
|
defaultImage = getImageNotNull(productGoodsBO.getGoodsList(), false);
|
|
|
}
|
|
|
}
|
|
|
// cover1 cover2不存在则取defaultImage
|
|
|
cover1 = StringUtils.isNotBlank(cover1) ? cover1 : defaultImage;
|
|
|
cover2 = StringUtils.isNotBlank(cover2) ? cover2 : defaultImage;
|
|
|
productGoodsBO.setCover_1(cover1);
|
|
|
productGoodsBO.setCover_2(cover2);
|
|
|
productGoodsBO.setDefaultImage(defaultImage);
|
|
|
}
|
|
|
|
|
|
private String getImageNotNull(List<ProductGoodInfo> goodsList) {
|
|
|
private String getImageNotNull(List<ProductGoodInfo> goodsList, boolean filterStorage) {
|
|
|
for (ProductGoodInfo goods : goodsList) {
|
|
|
if (filterStorage && Integer.valueOf(goods.getStorage_num()) <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
String imagesUrl = goods.getImages_url();
|
|
|
if (StringUtils.isNotBlank(imagesUrl)) {
|
|
|
return imagesUrl;
|
...
|
...
|
@@ -136,7 +180,6 @@ public class ProductGoodsLogicService { |
|
|
return "";
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取有库存且状态正常的color
|
|
|
*/
|
...
|
...
|
@@ -163,40 +206,6 @@ public class ProductGoodsLogicService { |
|
|
productGoodsBO.setColorNames(colorNameSet);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转成good对象
|
|
|
*/
|
|
|
private ProductGoodInfo buildProductGoodInfo(Goods goods, Map<Integer, GoodsCoverImage> goodsCoverImagesMap, Map<Integer, Integer> goodStorageMap) {
|
|
|
Map<Integer, ProductColor> productColorsMap = basicDataCacheService.getColor();
|
|
|
ProductGoodInfo productGoodInfo = new ProductGoodInfo();
|
|
|
// 来自Goods
|
|
|
productGoodInfo.setGoods_id(String.valueOf(goods.getId()));
|
|
|
productGoodInfo.setColor_name(StringUtils.isBlank(goods.getColorName()) ? "" : goods.getColorName());
|
|
|
productGoodInfo.setImages_url(StringUtils.isBlank(goods.getColorImage()) ? "" : goods.getColorImage());
|
|
|
productGoodInfo.setIs_default(StringUtils.isBlank(goods.getIsDefault()) ? "N" : goods.getIsDefault());
|
|
|
productGoodInfo.setColor_id(goods.getColorId() == null ? "" : goods.getColorId().toString());
|
|
|
productGoodInfo.setStatus(goods.getStatus() == null ? "0" : goods.getStatus().toString());
|
|
|
productGoodInfo.setProduct_skc(goods.getProductSkc() == null ? "" : goods.getProductSkc().toString());
|
|
|
productGoodInfo.setColor_value("");
|
|
|
// 来自productColorsMap
|
|
|
ProductColor productColor = productColorsMap.get(goods.getColorId());
|
|
|
if (productColor != null) {
|
|
|
String colorCode = productColor.getColorCode();
|
|
|
productGoodInfo.setColor_code(colorCode);
|
|
|
}
|
|
|
// 来自goodsCoverImagesMap
|
|
|
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(goods.getId());
|
|
|
String cover_1 = "";
|
|
|
String cover_2 = "";
|
|
|
if (goodsCoverImage != null) {
|
|
|
cover_1 = goodsCoverImage.getCover_1();
|
|
|
cover_2 = goodsCoverImage.getCover_2();
|
|
|
}
|
|
|
productGoodInfo.setCover_1(StringUtils.isBlank(cover_1) ? "" : cover_1);
|
|
|
productGoodInfo.setCover_2(StringUtils.isBlank(cover_2) ? "" : cover_2);
|
|
|
// 来自storageMap
|
|
|
Integer storage_num = goodStorageMap.get(goods.getId());
|
|
|
productGoodInfo.setStorage_num(storage_num == null ? "0" : storage_num.toString());
|
|
|
return productGoodInfo;
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|