...
|
...
|
@@ -25,76 +25,84 @@ import java.util.stream.Collectors; |
|
|
@Component
|
|
|
public abstract class AbstractStorageRelatedMqListener extends AbstractMqListener {
|
|
|
|
|
|
@Autowired
|
|
|
private StorageService storageService;
|
|
|
@Autowired
|
|
|
private StorageService storageService;
|
|
|
|
|
|
@Autowired
|
|
|
private SizeService sizeService;
|
|
|
@Autowired
|
|
|
private SizeService sizeService;
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductGoodsLogicService productGoodsLogicService;
|
|
|
@Autowired
|
|
|
private ProductGoodsLogicService productGoodsLogicService;
|
|
|
|
|
|
protected void fillStorageNumAndSizeInfo(Integer productId, Map<String, Object> indexData) {
|
|
|
List<Storage> storageList = storageService.getStoragesByProductId(productId);
|
|
|
if (CollectionUtils.isNotEmpty(storageList)) {
|
|
|
// 过滤掉下架的无库存的storage
|
|
|
storageList = storageList.stream()
|
|
|
.filter(storage -> Integer.valueOf(1).equals(storage.getStatus()))
|
|
|
.filter(storage -> storage.getStorageNum() != null && storage.getStorageNum().intValue() > 0)
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
protected void fillStorageNumAndSizeInfo(Integer productId, Map<String, Object> indexData) {
|
|
|
List<Storage> storageList = storageService.getStoragesByProductId(productId);
|
|
|
// 过滤掉下架的storage
|
|
|
if (CollectionUtils.isNotEmpty(storageList)) {
|
|
|
storageList = storageList.stream().filter(storage -> Integer.valueOf(1).equals(storage.getStatus())).collect(Collectors.toList());
|
|
|
}
|
|
|
int totalSizeCount = storageList.size();
|
|
|
|
|
|
if (CollectionUtils.isEmpty(storageList)) {
|
|
|
indexData.put("storageNum", 0);
|
|
|
indexData.put("isSoonSoldOut", "Y");
|
|
|
indexData.put("isSoldOut", "Y");
|
|
|
indexData.put("soldOut", 0);
|
|
|
indexData.put("sizeIds", null);
|
|
|
} else {
|
|
|
int storageNum = 0;
|
|
|
Set<String> sizeSet = new HashSet<String>();
|
|
|
for (Storage stor : storageList) {
|
|
|
storageNum += stor.getStorageNum();
|
|
|
if (stor.getGoodsDimensionId() != null) {
|
|
|
sizeSet.add(stor.getGoodsDimensionId() + "");
|
|
|
}
|
|
|
}
|
|
|
indexData.put("storageNum", storageNum);
|
|
|
indexData.put("isSoonSoldOut", storageNum <= 2 ? "Y" : "N");
|
|
|
indexData.put("isSoldOut", storageNum == 0 ? "Y" : "N");
|
|
|
indexData.put("soldOut", storageNum == 0 ? 0 : 1);
|
|
|
if (!sizeSet.isEmpty()) {
|
|
|
// 设置尺码信息
|
|
|
indexData.put("sizeIds", StringUtils.join(sizeSet, ","));
|
|
|
indexData.put("sizeNames", sizeService.getSizeNamesBySizeIds(sizeSet.stream().map(Integer::valueOf).collect(Collectors.toList())));
|
|
|
} else {
|
|
|
indexData.put("sizeIds", null);
|
|
|
indexData.put("sizeNames", null);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 过滤掉无库存的storage
|
|
|
if (CollectionUtils.isNotEmpty(storageList)) {
|
|
|
storageList = storageList.stream().filter(storage -> storage.getStorageNum() != null && storage.getStorageNum().intValue() > 0).collect(Collectors.toList());
|
|
|
}
|
|
|
int effectiveSizeCount = storageList.size();
|
|
|
|
|
|
float breakSizePercent = 100 * (totalSizeCount - effectiveSizeCount)/totalSizeCount;
|
|
|
|
|
|
if (CollectionUtils.isEmpty(storageList)) {
|
|
|
indexData.put("storageNum", 0);
|
|
|
indexData.put("isSoonSoldOut", "Y");
|
|
|
indexData.put("isSoldOut", "Y");
|
|
|
indexData.put("soldOut", 0);
|
|
|
indexData.put("sizeIds", null);
|
|
|
indexData.put("breakSizePercent", 100);
|
|
|
} else {
|
|
|
int storageNum = 0;
|
|
|
Set<String> sizeSet = new HashSet<String>();
|
|
|
for (Storage stor : storageList) {
|
|
|
storageNum += stor.getStorageNum();
|
|
|
if (stor.getGoodsDimensionId() != null) {
|
|
|
sizeSet.add(stor.getGoodsDimensionId() + "");
|
|
|
}
|
|
|
}
|
|
|
indexData.put("storageNum", storageNum);
|
|
|
indexData.put("isSoonSoldOut", storageNum <= 2 ? "Y" : "N");
|
|
|
indexData.put("isSoldOut", storageNum == 0 ? "Y" : "N");
|
|
|
indexData.put("soldOut", storageNum == 0 ? 0 : 1);
|
|
|
if (!sizeSet.isEmpty()) {
|
|
|
// 设置尺码信息
|
|
|
indexData.put("sizeIds", StringUtils.join(sizeSet, ","));
|
|
|
indexData.put("sizeNames", sizeService.getSizeNamesBySizeIds(sizeSet.stream().map(Integer::valueOf).collect(Collectors.toList())));
|
|
|
} else {
|
|
|
indexData.put("sizeIds", null);
|
|
|
indexData.put("sizeNames", null);
|
|
|
}
|
|
|
indexData.put("breakSizePercent", breakSizePercent);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
protected void fillColor(Map<String, Object> indexData, Integer productId) {
|
|
|
Set<String> colorIdSet = new HashSet<String>();
|
|
|
Set<String> colorNameSet = new HashSet<String>();
|
|
|
// 第一步:获取goodsList
|
|
|
List<ProductGoodsBO> productGoodsBOList = goodsService.getProductGoodsByProductId(productId);
|
|
|
// 第二步、组装goods数据
|
|
|
if (productGoodsBOList != null && productGoodsBOList.size() == 1) {
|
|
|
ProductGoodsBO productGoodsBO = productGoodsBOList.get(0);
|
|
|
String goodsListJsonArrayStr = productGoodsBO.getGoodsList();
|
|
|
JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr);
|
|
|
productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color
|
|
|
indexData.put("goodsList", goodsListJsonArray);
|
|
|
indexData.put("colorIds", StringUtils.join(colorIdSet, ","));
|
|
|
indexData.put("colorNames", StringUtils.join(colorNameSet, ","));
|
|
|
} else {
|
|
|
indexData.put("goodsList", "");
|
|
|
indexData.put("colorIds", "");
|
|
|
indexData.put("colorNames", "");
|
|
|
}
|
|
|
}
|
|
|
protected void fillColor(Map<String, Object> indexData, Integer productId) {
|
|
|
Set<String> colorIdSet = new HashSet<String>();
|
|
|
Set<String> colorNameSet = new HashSet<String>();
|
|
|
// 第一步:获取goodsList
|
|
|
List<ProductGoodsBO> productGoodsBOList = goodsService.getProductGoodsByProductId(productId);
|
|
|
// 第二步、组装goods数据
|
|
|
if (productGoodsBOList != null && productGoodsBOList.size() == 1) {
|
|
|
ProductGoodsBO productGoodsBO = productGoodsBOList.get(0);
|
|
|
String goodsListJsonArrayStr = productGoodsBO.getGoodsList();
|
|
|
JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr);
|
|
|
productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);// 获取有库存且状态正常的color
|
|
|
indexData.put("goodsList", goodsListJsonArray);
|
|
|
indexData.put("colorIds", StringUtils.join(colorIdSet, ","));
|
|
|
indexData.put("colorNames", StringUtils.join(colorNameSet, ","));
|
|
|
} else {
|
|
|
indexData.put("goodsList", "");
|
|
|
indexData.put("colorIds", "");
|
|
|
indexData.put("colorNames", "");
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|