Authored by hugufei

索引中添加ctr_value

package com.yoho.search.consumer.service.bo;
import java.math.BigDecimal;
public class ProductHeatValueBO {
private Integer productId;
private BigDecimal ctrValue;
private BigDecimal heatValue;
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public BigDecimal getCtrValue() {
return ctrValue;
}
public void setCtrValue(BigDecimal ctrValue) {
this.ctrValue = ctrValue;
}
public BigDecimal getHeatValue() {
return heatValue;
}
public void setHeatValue(BigDecimal heatValue) {
this.heatValue = heatValue;
}
}
... ...
... ... @@ -9,7 +9,8 @@ public class ProductSizesBO {
private String sizeIds;// 当前有效的尺码ids
private double breakSizePercent;//断码率
private String sizeNames;// 当前有效的颜色名称
private BigDecimal heatValue;
private BigDecimal heatValue;//人气值
private BigDecimal ctrValue;//转化率
private String skuIds;// 当前有效的sku列表
public Integer getProductId() {
... ... @@ -72,4 +73,11 @@ public class ProductSizesBO {
return storageNum == null || storageNum <= 2 ? "Y" : "N";
}
public BigDecimal getCtrValue() {
return ctrValue;
}
public void setCtrValue(BigDecimal ctrValue) {
this.ctrValue = ctrValue;
}
}
... ...
... ... @@ -6,7 +6,10 @@ 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.yoho.search.consumer.service.bo.ProductHeatValueBO;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -18,98 +21,129 @@ import com.yoho.search.dal.ProductHeatValuesOneDayMapper;
import com.yoho.search.dal.ProductMapper;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.ProductHeatValues;
import sun.applet.Main;
@Component
public class ProductHeatValueLogicService {
private static final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER");
private static final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER");
private static final BigDecimal shareOrderNumFactor = new BigDecimal(1);
private static final BigDecimal saleNumFactor = new BigDecimal(1);
private static final BigDecimal cartNumFactor = new BigDecimal(1);
private static final BigDecimal favoriteNumFactor = new BigDecimal(1);
private static final BigDecimal commentsScoreFactor = new BigDecimal(1);
private static final BigDecimal ctrValueFactor = new BigDecimal(1);
private static final BigDecimal saleAmountFactor = new BigDecimal(2);
private static final BigDecimal profitAmountFactor = new BigDecimal(2);
private static final BigDecimal shareOrderNumFactor = new BigDecimal(1);
private static final BigDecimal saleNumFactor = new BigDecimal(1);
private static final BigDecimal cartNumFactor = new BigDecimal(1);
private static final BigDecimal favoriteNumFactor = new BigDecimal(1);
private static final BigDecimal commentsScoreFactor = new BigDecimal(1);
private static final BigDecimal ctrValueFactor = new BigDecimal(1);
private static final BigDecimal saleAmountFactor = new BigDecimal(2);
private static final BigDecimal profitAmountFactor = new BigDecimal(2);
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
@Autowired
private ProductHeatValuesOneDayMapper productHeatValuesOneDayMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
@Autowired
private ProductHeatValuesOneDayMapper productHeatValuesOneDayMapper;
@Autowired
private ProductMapper productMapper;
private Integer dateId = null;
private Integer dateId = null;
public Map<Integer, BigDecimal> queryProductIdHeatValue(List<Integer> productIds) {
if (productIds == null || productIds.isEmpty()) {
return new HashMap<>();
}
List<Product> products = productMapper.selectListByIds(productIds);
if (products == null || products.isEmpty()) {
return new HashMap<>();
}
List<Integer> sknList = new ArrayList<Integer>();
Map<Integer, Integer> productSknToIdMap = new HashMap<Integer, Integer>();
for (Product product : products) {
sknList.add(product.getErpProductId());
productSknToIdMap.put(product.getErpProductId(), product.getId());
}
List<ProductHeatValues> productHeatValuesList = productHeatValuesMapper.selectHeatValuesOfLatestDateBySkn(sknList, this.getDateId());
List<ProductHeatValues> productHeatValuesOneDayList = productHeatValuesOneDayMapper.selectHeatValuesOfLatestDateBySkn(sknList, this.getDateId());
if (CollectionUtils.isEmpty(productHeatValuesList) && CollectionUtils.isEmpty(productHeatValuesOneDayList)) {
return new HashMap<>();
}
Map<Integer, BigDecimal> result = new HashMap<Integer, BigDecimal>();
for (ProductHeatValues productHeatValues : productHeatValuesList) {
Integer productId = productSknToIdMap.get(productHeatValues.getProductSkn());
if (productId != null) {
result.put(productId, this.countHeatValue(productHeatValues));
}
}
for (ProductHeatValues productHeatValues : productHeatValuesOneDayList) {
Integer productId = productSknToIdMap.get(productHeatValues.getProductSkn());
if (productId == null) {
continue;
}
BigDecimal oldValue = result.get(productId);
if (oldValue == null) {
oldValue = BigDecimal.ZERO;
}
result.put(productId, oldValue.add(this.countHeatValue(productHeatValues)));
}
return result;
}
public Map<Integer, ProductHeatValueBO> queryProductIdHeatValue(List<Integer> productIds) {
if (productIds == null || productIds.isEmpty()) {
return new HashMap<>();
}
List<Product> products = productMapper.selectListByIds(productIds);
if (products == null || products.isEmpty()) {
return new HashMap<>();
}
List<Integer> sknList = new ArrayList<Integer>();
Map<Integer, Integer> productSknToIdMap = new HashMap<Integer, Integer>();
for (Product product : products) {
sknList.add(product.getErpProductId());
productSknToIdMap.put(product.getErpProductId(), product.getId());
}
List<ProductHeatValues> productHeatValuesList = productHeatValuesMapper.selectHeatValuesOfLatestDateBySkn(sknList, this.getDateId());
List<ProductHeatValues> productHeatValuesOneDayList = productHeatValuesOneDayMapper.selectHeatValuesOfLatestDateBySkn(sknList, this.getDateId());
if (CollectionUtils.isEmpty(productHeatValuesList) && CollectionUtils.isEmpty(productHeatValuesOneDayList)) {
return new HashMap<>();
}
Map<Integer, ProductHeatValues> productHeatValuesOneDayMap = productHeatValuesOneDayList.stream().collect(Collectors.toMap(ProductHeatValues::getProductSkn, Function.identity()));
Map<Integer, ProductHeatValueBO> result = new HashMap<>();
for (ProductHeatValues productHeatValues : productHeatValuesList) {
Integer productId = productSknToIdMap.get(productHeatValues.getProductSkn());
if (productId == null) {
continue;
}
ProductHeatValues productHeatValuesOneDay = productHeatValuesOneDayMap.get(productHeatValues.getProductSkn());
result.put(productId, this.countProductHeatValueBO(productId, productHeatValues, productHeatValuesOneDay));
}
return result;
}
private BigDecimal countHeatValue(ProductHeatValues productHeatValues) {
// 每个值乘以系数
BigDecimal shareOrderNum = productHeatValues.getShareorderNum().multiply(shareOrderNumFactor);
BigDecimal saleNum = productHeatValues.getSaleNum().multiply(saleNumFactor);
BigDecimal cartNum = productHeatValues.getCartNum().multiply(cartNumFactor);
BigDecimal favoriteNum = productHeatValues.getFavoriteNum().multiply(favoriteNumFactor);
BigDecimal commentsScore = productHeatValues.getCommentsScore().multiply(commentsScoreFactor);
BigDecimal ctrValue = productHeatValues.getCtrValue().multiply(ctrValueFactor);
BigDecimal saleAmount = productHeatValues.getSaleAmount().multiply(saleAmountFactor);
BigDecimal profitAmount = productHeatValues.getProfitAmount().multiply(profitAmountFactor);
// 每个值相加
BigDecimal heatValue = shareOrderNum.add(saleNum).add(cartNum).add(favoriteNum).add(commentsScore).add(ctrValue).add(saleAmount).add(profitAmount);
// 保留2位小数
DecimalFormat decimalFormat = new DecimalFormat("0.00");
String heatValueString = decimalFormat.format(heatValue);
heatValue = new BigDecimal(heatValueString);
return heatValue;
}
private ProductHeatValueBO countProductHeatValueBO(Integer productId, ProductHeatValues productHeatValues, ProductHeatValues productHeatValuesOneDay) {
try {
ProductHeatValueBO productHeatValueBO = new ProductHeatValueBO();
productHeatValueBO.setProductId(productId);
productHeatValueBO.setHeatValue(countHeatValue(productHeatValues).add(countHeatValue(productHeatValuesOneDay)));
productHeatValueBO.setCtrValue(countCtrValue(productHeatValues).add(countCtrValue(productHeatValuesOneDay)));
return productHeatValueBO;
} catch (Exception e) {
INDEX_REBUILD_LOG.error(e.getMessage(), e);
return null;
}
}
private Integer getDateId() {
if (dateId == null) {
dateId = productHeatValuesMapper.selectLatestDateId();
}
return dateId;
}
private BigDecimal countHeatValue(ProductHeatValues productHeatValues) {
if (productHeatValues == null) {
return BigDecimal.ZERO;
}
// 每个值乘以系数
BigDecimal shareOrderNum = productHeatValues.getShareorderNum().multiply(shareOrderNumFactor);
BigDecimal saleNum = productHeatValues.getSaleNum().multiply(saleNumFactor);
BigDecimal cartNum = productHeatValues.getCartNum().multiply(cartNumFactor);
BigDecimal favoriteNum = productHeatValues.getFavoriteNum().multiply(favoriteNumFactor);
BigDecimal commentsScore = productHeatValues.getCommentsScore().multiply(commentsScoreFactor);
BigDecimal ctrValue = productHeatValues.getCtrValue().multiply(ctrValueFactor);
BigDecimal saleAmount = productHeatValues.getSaleAmount().multiply(saleAmountFactor);
BigDecimal profitAmount = productHeatValues.getProfitAmount().multiply(profitAmountFactor);
// 每个值相加
BigDecimal heatValue = shareOrderNum.add(saleNum).add(cartNum).add(favoriteNum).add(commentsScore).add(ctrValue).add(saleAmount).add(profitAmount);
// 保留2位小数
DecimalFormat decimalFormat = new DecimalFormat("0.00");
String heatValueString = decimalFormat.format(heatValue);
heatValue = new BigDecimal(heatValueString);
return heatValue;
}
public void finish() {
INDEX_REBUILD_LOG.info("ProductHeatValueLogicService Finish");
dateId = null;
}
private BigDecimal countCtrValue(ProductHeatValues productHeatValues) {
if (productHeatValues == null) {
return BigDecimal.ZERO;
}
// 使用加购数做过滤
BigDecimal cartNum = productHeatValues.getCartNum();
if (cartNum.compareTo(new BigDecimal(0.4)) < 0) {
return BigDecimal.ZERO;
}
// 使用10*ctrValue+favoriteNum+cartNum做真实的转换率
BigDecimal favoriteNum = productHeatValues.getFavoriteNum();
BigDecimal ctrValue = productHeatValues.getCtrValue().multiply(new BigDecimal(10)).add(favoriteNum).add(cartNum);
DecimalFormat decimalFormat = new DecimalFormat("0.00");
String heatValueString = decimalFormat.format(ctrValue);
ctrValue = new BigDecimal(heatValueString);
return ctrValue;
}
private Integer getDateId() {
if (dateId == null) {
dateId = productHeatValuesMapper.selectLatestDateId();
}
return dateId;
}
public void finish() {
INDEX_REBUILD_LOG.info("ProductHeatValueLogicService Finish");
dateId = null;
}
public static void main(String[] args) {
System.out.println(new BigDecimal(0.3).compareTo(new BigDecimal(0.4)));
}
}
... ...
... ... @@ -175,6 +175,7 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.productAttrField, productIndexBO.getProductAttrField());
map.put(ProductIndexEsField.bundleType, productIndexBO.getBundleType());
map.put(ProductIndexEsField.heatValue, productIndexBO.getHeatValue());
map.put(ProductIndexEsField.ctrValue, productIndexBO.getCtrValue());
map.put(ProductIndexEsField.priceArea, productIndexBO.getPriceArea());
map.put(ProductIndexEsField.skuIds, productIndexBO.getSkuIds());
... ... @@ -193,7 +194,6 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.specialSearchField, productIndexBO.getSpecialSearchField());
map.put(ProductIndexEsField.specialSearchFieldVideo, productIndexBO.getSpecialSearchFieldVideo());
map.put(ProductIndexEsField.ctrValue, productIndexBO.getCtrValue());
map.put(ProductIndexEsField.flowType, productIndexBO.getFlowType());
map.put(ProductIndexEsField.sevendayMoney, productIndexBO.getSevendayMoney());
... ...
... ... @@ -10,6 +10,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.yoho.search.consumer.service.bo.ProductHeatValueBO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -29,147 +30,155 @@ import com.yoho.search.dal.model.Storage;
@Component
public class ProductSizesLogicService {
private static final Integer VALID_STATUS = Integer.valueOf(1);
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
private SizeMapper sizeMapper;
@Autowired
private ProductHeatValueLogicService productHeatValueLogicService;
/**
* 全量增量都有调用
*/
public List<ProductSizesBO> getProductSizeBOList(List<Integer> productIds) {
// 获取ProductId对应的上架的goodsId列表
List<Goods> validGoodsList = goodsMapper.selectValidListByProductIds(productIds);
if (CollectionUtils.isEmpty(validGoodsList)) {
return new ArrayList<>();
}
// 获取goodsId对应得Storage列表
List<Integer> validGoodsIdList = validGoodsList.stream().map(Goods::getId).collect(Collectors.toList());
List<Storage> storageList = storageMapper.selectByGoodsIds(validGoodsIdList);
if (CollectionUtils.isEmpty(storageList)) {
return new ArrayList<>();
}
// 按productId分组
Map<Integer, List<Storage>> productStorageMap = new HashMap<Integer, List<Storage>>();
for (Storage storage : storageList) {
Integer productId = storage.getProductId();
List<Storage> productStorageList = productStorageMap.get(productId);
if (productStorageList == null) {
productStorageList = new ArrayList<Storage>();
productStorageMap.put(productId, productStorageList);
}
productStorageList.add(storage);
}
// 批量获取尺码信息
Set<Integer> sizeIdSet = new HashSet<>();
for (Storage s : storageList) {
sizeIdSet.add(s.getGoodsDimensionId());
}
List<Size> sizeList = sizeMapper.selectByIds(sizeIdSet.stream().collect(Collectors.toList()));
Map<Integer, String> sizeNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
// 批量获取人气值信息
Map<Integer, BigDecimal> heatValueMap = productHeatValueLogicService.queryProductIdHeatValue(productIds);
// 构造ProductSizesBO
List<ProductSizesBO> results = new ArrayList<ProductSizesBO>();
for (Map.Entry<Integer, List<Storage>> entry : productStorageMap.entrySet()) {
Integer productId = entry.getKey();
List<Storage> productStorageList = entry.getValue();
ProductSizesBO productSizesBO = new ProductSizesBO();
productSizesBO.setProductId(productId);
productSizesBO.setBreakSizePercent(this.getBreakSizePercent(productStorageList));// 计算断码率
// 过滤出有效的和有库存的库存
List<Storage> validteStorages = productStorageList.stream()
.filter(storage -> VALID_STATUS.equals(storage.getStatus()) && storage.getStorageNum() != null && storage.getStorageNum() > 0)
.collect(Collectors.toList());
// 获取信息
Set<Integer> sizeIds = new HashSet<Integer>();
List<Integer> skuIds = new ArrayList<Integer>();
int storageNum = 0;
for (Storage storage : validteStorages) {
sizeIds.add(storage.getGoodsDimensionId());
skuIds.add(storage.getErpSkuId());
storageNum = storageNum + storage.getStorageNum();
}
productSizesBO.setSkuIds(StringUtils.join(skuIds, ","));
productSizesBO.setSizeIds(StringUtils.join(sizeIds, ","));
productSizesBO.setStorageNum(storageNum);
// 填充尺码名称
productSizesBO.setSizeNames(StringUtils.join((this.getSizeNames(sizeIds, sizeNameMap)), ","));
// 填充人气值[断码率>50,则人气值减半]
BigDecimal heatValue = heatValueMap.get(productSizesBO.getProductId());
if (heatValue == null) {
heatValue = new BigDecimal(0);
}
if (productSizesBO.getBreakSizePercent() > 50) {
heatValue = heatValue.multiply(new BigDecimal("0.5"));
}
productSizesBO.setHeatValue(heatValue);
results.add(productSizesBO);
}
return results;
}
private double getBreakSizePercent(List<Storage> storageList) {
Set<Integer> productValidStatusSizes = new HashSet<Integer>();// 上架了的尺码【计算断码率】
Set<Integer> productHasStorageSizes = new HashSet<Integer>();// 有库存的尺码【计算断码率】
for (Storage storage : storageList) {
// 处理未下架的sku
if (!VALID_STATUS.equals(storage.getStatus())) {
continue;
}
// 记录有效的尺码id
productValidStatusSizes.add(storage.getGoodsDimensionId());
// 处理有库存的sku
if (storage.getStorageNum() == null || storage.getStorageNum().intValue() <= 0) {
continue;
}
// 记录有库存的尺码id
productHasStorageSizes.add(storage.getGoodsDimensionId());
}
return this.getBreakSizePercent(productValidStatusSizes.size(), productHasStorageSizes.size());
}
private List<String> getSizeNames(Collection<Integer> sizeIds, Map<Integer, String> sizeNameMap) {
List<String> results = new ArrayList<String>();
for (Integer sizeId : sizeIds) {
String sizeName = sizeNameMap.get(sizeId);
if (sizeName == null) {
continue;
}
results.add(sizeName);
}
return results;
}
/**
* 保留两位小数
*/
private double getBreakSizePercent(Integer validStatusSizeCount, Integer hasStorageSizeCount) {
if (validStatusSizeCount == null || validStatusSizeCount <= 0) {
return 100d;
}
if (hasStorageSizeCount == null || hasStorageSizeCount <= 0) {
return 100d;
}
double breakSizePercent = 100d * (validStatusSizeCount - hasStorageSizeCount) / validStatusSizeCount;
BigDecimal bg = new BigDecimal(breakSizePercent);
double result = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return result;
}
private static final Integer VALID_STATUS = Integer.valueOf(1);
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
private SizeMapper sizeMapper;
@Autowired
private ProductHeatValueLogicService productHeatValueLogicService;
/**
* 全量增量都有调用
*/
public List<ProductSizesBO> getProductSizeBOList(List<Integer> productIds) {
// 获取ProductId对应的上架的goodsId列表
List<Goods> validGoodsList = goodsMapper.selectValidListByProductIds(productIds);
if (CollectionUtils.isEmpty(validGoodsList)) {
return new ArrayList<>();
}
// 获取goodsId对应得Storage列表
List<Integer> validGoodsIdList = validGoodsList.stream().map(Goods::getId).collect(Collectors.toList());
List<Storage> storageList = storageMapper.selectByGoodsIds(validGoodsIdList);
if (CollectionUtils.isEmpty(storageList)) {
return new ArrayList<>();
}
// 按productId分组
Map<Integer, List<Storage>> productStorageMap = new HashMap<Integer, List<Storage>>();
for (Storage storage : storageList) {
Integer productId = storage.getProductId();
List<Storage> productStorageList = productStorageMap.get(productId);
if (productStorageList == null) {
productStorageList = new ArrayList<>();
productStorageMap.put(productId, productStorageList);
}
productStorageList.add(storage);
}
// 批量获取尺码信息
Set<Integer> sizeIdSet = new HashSet<>();
for (Storage s : storageList) {
sizeIdSet.add(s.getGoodsDimensionId());
}
List<Size> sizeList = sizeMapper.selectByIds(sizeIdSet.stream().collect(Collectors.toList()));
Map<Integer, String> sizeNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
// 批量获取人气值相关数据
Map<Integer, ProductHeatValueBO> heatValueMap = productHeatValueLogicService.queryProductIdHeatValue(productIds);
// 构造ProductSizesBO
List<ProductSizesBO> results = new ArrayList<ProductSizesBO>();
for (Map.Entry<Integer, List<Storage>> entry : productStorageMap.entrySet()) {
Integer productId = entry.getKey();
List<Storage> productStorageList = entry.getValue();
ProductSizesBO productSizesBO = new ProductSizesBO();
productSizesBO.setProductId(productId);
productSizesBO.setBreakSizePercent(this.getBreakSizePercent(productStorageList));// 计算断码率
// 过滤出有效的和有库存的库存
List<Storage> validteStorages = productStorageList.stream()
.filter(storage -> VALID_STATUS.equals(storage.getStatus()) && storage.getStorageNum() != null && storage.getStorageNum() > 0)
.collect(Collectors.toList());
// 获取信息
Set<Integer> sizeIds = new HashSet<Integer>();
List<Integer> skuIds = new ArrayList<Integer>();
int storageNum = 0;
for (Storage storage : validteStorages) {
sizeIds.add(storage.getGoodsDimensionId());
skuIds.add(storage.getErpSkuId());
storageNum = storageNum + storage.getStorageNum();
}
productSizesBO.setSkuIds(StringUtils.join(skuIds, ","));
productSizesBO.setSizeIds(StringUtils.join(sizeIds, ","));
productSizesBO.setStorageNum(storageNum);
// 填充尺码名称
productSizesBO.setSizeNames(StringUtils.join((this.getSizeNames(sizeIds, sizeNameMap)), ","));
// 填充人气值[断码率>50,则人气值减半]
ProductHeatValueBO productHeatValueBO = heatValueMap.get(productSizesBO.getProductId());
BigDecimal heatValue = null;
BigDecimal ctrValue = null;
if (productHeatValueBO == null) {
heatValue = new BigDecimal(0);
ctrValue = new BigDecimal(0);
} else {
heatValue = productHeatValueBO.getHeatValue();
ctrValue = productHeatValueBO.getCtrValue();
}
if (productSizesBO.getBreakSizePercent() > 50) {
heatValue = heatValue.multiply(new BigDecimal("0.5"));
ctrValue = ctrValue.multiply(new BigDecimal("0.5"));
}
productSizesBO.setHeatValue(heatValue);
productSizesBO.setCtrValue(ctrValue);
results.add(productSizesBO);
}
return results;
}
private double getBreakSizePercent(List<Storage> storageList) {
Set<Integer> productValidStatusSizes = new HashSet<Integer>();// 上架了的尺码【计算断码率】
Set<Integer> productHasStorageSizes = new HashSet<Integer>();// 有库存的尺码【计算断码率】
for (Storage storage : storageList) {
// 处理未下架的sku
if (!VALID_STATUS.equals(storage.getStatus())) {
continue;
}
// 记录有效的尺码id
productValidStatusSizes.add(storage.getGoodsDimensionId());
// 处理有库存的sku
if (storage.getStorageNum() == null || storage.getStorageNum().intValue() <= 0) {
continue;
}
// 记录有库存的尺码id
productHasStorageSizes.add(storage.getGoodsDimensionId());
}
return this.getBreakSizePercent(productValidStatusSizes.size(), productHasStorageSizes.size());
}
private List<String> getSizeNames(Collection<Integer> sizeIds, Map<Integer, String> sizeNameMap) {
List<String> results = new ArrayList<String>();
for (Integer sizeId : sizeIds) {
String sizeName = sizeNameMap.get(sizeId);
if (sizeName == null) {
continue;
}
results.add(sizeName);
}
return results;
}
/**
* 保留两位小数
*/
private double getBreakSizePercent(Integer validStatusSizeCount, Integer hasStorageSizeCount) {
if (validStatusSizeCount == null || validStatusSizeCount <= 0) {
return 100d;
}
if (hasStorageSizeCount == null || hasStorageSizeCount <= 0) {
return 100d;
}
double breakSizePercent = 100d * (validStatusSizeCount - hasStorageSizeCount) / validStatusSizeCount;
BigDecimal bg = new BigDecimal(breakSizePercent);
double result = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return result;
}
}
... ...
... ... @@ -30,6 +30,7 @@ public class StorageRelatedLogicService {
indexData.put(ProductIndexEsField.sizeNames, "");
indexData.put(ProductIndexEsField.breakSizePercent, 100);
indexData.put(ProductIndexEsField.heatValue, 0);
indexData.put(ProductIndexEsField.ctrValue, 0);
indexData.put(ProductIndexEsField.skuIds, "");
return;
}
... ... @@ -40,6 +41,7 @@ public class StorageRelatedLogicService {
indexData.put(ProductIndexEsField.sizeNames, productSizesBO.getSizeNames());
indexData.put(ProductIndexEsField.breakSizePercent, productSizesBO.getBreakSizePercent());
indexData.put(ProductIndexEsField.heatValue, productSizesBO.getHeatValue());
indexData.put(ProductIndexEsField.ctrValue, productSizesBO.getCtrValue());
indexData.put(ProductIndexEsField.skuIds, productSizesBO.getSkuIds());
}
... ...
package com.yoho.search.consumer.service.logicService.productIndex;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.ProductSizesBO;
import com.yoho.search.consumer.service.logicService.ProductSizesLogicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.ProductSizesBO;
import com.yoho.search.consumer.service.logicService.ProductSizesLogicService;
/**
* Created by wangnan on 2017/1/6.
*/
... ... @@ -33,6 +32,7 @@ public class ProductSizesBuilder implements IndexFieldBuilder {
productIndexBO.setSizeNames("");
productIndexBO.setBreakSizePercent(100);
productIndexBO.setHeatValue(new BigDecimal(0));
productIndexBO.setCtrValue(new BigDecimal(0));
productIndexBO.setSkuIds("");
ProductSizesBO productSizesBO = productSizesMap.get(productIndexBO.getProductId());
if (productSizesBO != null) {
... ... @@ -42,6 +42,7 @@ public class ProductSizesBuilder implements IndexFieldBuilder {
productIndexBO.setSizeNames(productSizesBO.getSizeNames());
productIndexBO.setBreakSizePercent(productSizesBO.getBreakSizePercent());
productIndexBO.setHeatValue(productSizesBO.getHeatValue());
productIndexBO.setCtrValue(productSizesBO.getCtrValue());
productIndexBO.setSkuIds(productSizesBO.getSkuIds());
}
}
... ...