Authored by 胡古飞

Merge branch 'master' into gray

... ... @@ -12,3 +12,5 @@ deploy/.settings
dal/.settings/
search-consumer-index/.settings/
spider/.settings/
index/.settings/
web/.settings/
... ...
... ... @@ -6,17 +6,6 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ProductHeatValueMapper {
int deleteByPrimaryKey(Integer productSkn);
int insert(ProductHeatValue record);
int insertSelective(ProductHeatValue record);
ProductHeatValue selectByPrimaryKey(Integer productSkn);
int updateByPrimaryKeySelective(ProductHeatValue record);
int updateByPrimaryKey(ProductHeatValue record);
Integer selectLatestDateId();
... ... @@ -28,5 +17,5 @@ public interface ProductHeatValueMapper {
List<Long> selectSknByDate(@Param(value = "dateId") String dateId, @Param(value = "pageSize") int pageSize);
void deleteBatch(@Param(value = "sknList") List<Long> sknList,@Param(value = "dateId") String dateId);
void deleteBatch(@Param(value = "sknList") List<Long> sknList, @Param(value = "dateId") String dateId);
}
\ No newline at end of file
... ...
package com.yoho.search.dal;
import com.yoho.search.dal.model.ProductHeatValues;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ProductHeatValuesMapper {
Integer selectLatestDateId();
Integer selectCount(@Param(value = "dateId") Integer dateId);
List<ProductHeatValues> selectHeatValuesOfLatestDateBySkn(@Param(value = "sknList") List<Integer> sknList, @Param(value = "dateId") Integer dateId);
List<ProductHeatValues> selectHeatValuesOfLatestDate(@Param(value = "dateId") Integer dateId, @Param(value = "offset") Integer offset, @Param(value = "pageSize") Integer pageSize);
List<Long> selectSknByDate(@Param(value = "dateId") String dateId, @Param(value = "pageSize") int pageSize);
void deleteBatch(@Param(value = "sknList") List<Long> sknList, @Param(value = "dateId") String dateId);
}
\ No newline at end of file
... ...
package com.yoho.search.dal.model;
import java.math.BigDecimal;
public class ProductHeatValues {
private Integer productSkn;
private String dateId;
private BigDecimal shareorderNum;
private BigDecimal saleNum;
private BigDecimal cartNum;
private BigDecimal favoriteNum;
private BigDecimal commentsScore;
private BigDecimal ctrValue;
private BigDecimal saleAmount;
private BigDecimal profitAmount;
private Integer lastUpdateTime;
public Integer getProductSkn() {
return productSkn;
}
public void setProductSkn(Integer productSkn) {
this.productSkn = productSkn;
}
public String getDateId() {
return dateId;
}
public void setDateId(String dateId) {
this.dateId = dateId == null ? null : dateId.trim();
}
public BigDecimal getShareorderNum() {
return shareorderNum;
}
public void setShareorderNum(BigDecimal shareorderNum) {
this.shareorderNum = shareorderNum;
}
public BigDecimal getSaleNum() {
return saleNum;
}
public void setSaleNum(BigDecimal saleNum) {
this.saleNum = saleNum;
}
public BigDecimal getCartNum() {
return cartNum;
}
public void setCartNum(BigDecimal cartNum) {
this.cartNum = cartNum;
}
public BigDecimal getFavoriteNum() {
return favoriteNum;
}
public void setFavoriteNum(BigDecimal favoriteNum) {
this.favoriteNum = favoriteNum;
}
public BigDecimal getCommentsScore() {
return commentsScore;
}
public void setCommentsScore(BigDecimal commentsScore) {
this.commentsScore = commentsScore;
}
public BigDecimal getCtrValue() {
return ctrValue;
}
public void setCtrValue(BigDecimal ctrValue) {
this.ctrValue = ctrValue;
}
public BigDecimal getSaleAmount() {
return saleAmount;
}
public void setSaleAmount(BigDecimal saleAmount) {
this.saleAmount = saleAmount;
}
public BigDecimal getProfitAmount() {
return profitAmount;
}
public void setProfitAmount(BigDecimal profitAmount) {
this.profitAmount = profitAmount;
}
public Integer getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(Integer lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.search.dal.ProductHeatValueMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductHeatValue" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductHeatValue" >
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="date_id" property="dateId" jdbcType="VARCHAR" />
<result column="heat_value" property="heatValue" jdbcType="DECIMAL" />
<result column="last_update_time" property="lastUpdateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
</resultMap>
<sql id="Base_Column_List" >
product_skn, date_id, heat_value, last_update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from product_heat_value
where product_skn = #{productSkn,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from product_heat_value
where product_skn = #{productSkn,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.ProductHeatValue" >
insert into product_heat_value (product_skn, date_id, heat_value,
last_update_time)
values (#{productSkn,jdbcType=INTEGER}, #{dateId,jdbcType=VARCHAR}, #{heatValue,jdbcType=DECIMAL},
#{lastUpdateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.ProductHeatValue" >
insert into product_heat_value
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="productSkn != null" >
product_skn,
</if>
<if test="dateId != null" >
date_id,
</if>
<if test="heatValue != null" >
heat_value,
</if>
<if test="lastUpdateTime != null" >
last_update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="productSkn != null" >
#{productSkn,jdbcType=INTEGER},
</if>
<if test="dateId != null" >
#{dateId,jdbcType=VARCHAR},
</if>
<if test="heatValue != null" >
#{heatValue,jdbcType=DECIMAL},
</if>
<if test="lastUpdateTime != null" >
#{lastUpdateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.ProductHeatValue" >
update product_heat_value
<set >
<if test="dateId != null" >
date_id = #{dateId,jdbcType=VARCHAR},
</if>
<if test="heatValue != null" >
heat_value = #{heatValue,jdbcType=DECIMAL},
</if>
<if test="lastUpdateTime != null" >
last_update_time = #{lastUpdateTime,jdbcType=INTEGER},
</if>
</set>
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.ProductHeatValue" >
update product_heat_value
set date_id = #{dateId,jdbcType=VARCHAR},
heat_value = #{heatValue,jdbcType=DECIMAL},
last_update_time = #{lastUpdateTime,jdbcType=INTEGER}
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
</sql>
<select id="selectHeatValueOfLatestDateBySkn" resultMap="BaseResultMap" timeout="20000">
<![CDATA[
select * from product_heat_value p
... ... @@ -92,23 +26,28 @@
#{item}
</foreach>
</select>
<select id="selectHeatValueOfLatestDate" resultMap="BaseResultMap" timeout="20000">
select * from product_heat_value p
where
date_id = #{dateId}
limit #{offset},#{pageSize}
</select>
<select id="selectLatestDateId" resultType="java.lang.Integer">
select max(date_id) from product_heat_value
</select>
<select id="selectCount" resultType="java.lang.Integer" timeout="20000">
SELECT count(*) FROM product_heat_value
where
date_id = #{dateId}
</select>
<select id="selectSknByDate" resultType="java.lang.Long" timeout="20000">
SELECT product_skn FROM product_heat_value where date_id = #{dateId,jdbcType=VARCHAR} limit #{pageSize}
</select>
<delete id="deleteBatch">
<![CDATA[
DELETE FROM product_heat_value
... ... @@ -121,4 +60,5 @@
#{item}
</foreach>
</delete>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.search.dal.ProductHeatValuesMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductHeatValues" >
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="date_id" property="dateId" jdbcType="VARCHAR" />
<result column="shareorder_num" property="shareorderNum" jdbcType="DECIMAL" />
<result column="sale_num" property="saleNum" jdbcType="DECIMAL" />
<result column="cart_num" property="cartNum" jdbcType="DECIMAL" />
<result column="favorite_num" property="favoriteNum" jdbcType="DECIMAL" />
<result column="comments_score" property="commentsScore" jdbcType="DECIMAL" />
<result column="ctr_value" property="ctrValue" jdbcType="DECIMAL" />
<result column="sale_amount" property="saleAmount" jdbcType="DECIMAL" />
<result column="profit_amount" property="profitAmount" jdbcType="DECIMAL" />
<result column="last_update_time" property="lastUpdateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
product_skn, date_id, shareorder_num, sale_num, cart_num, favorite_num, comments_score,
ctr_value, sale_amount, profit_amount, last_update_time
</sql>
<select id="selectHeatValuesOfLatestDateBySkn" resultMap="BaseResultMap" timeout="20000">
<![CDATA[
select * from product_heat_values p
where
date_id = #{dateId}
and
p.product_skn in
]]>
<foreach item="item" index="index" collection="sknList"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectHeatValuesOfLatestDate" resultMap="BaseResultMap" timeout="20000">
select * from product_heat_values p
where
date_id = #{dateId}
limit #{offset},#{pageSize}
</select>
<select id="selectLatestDateId" resultType="java.lang.Integer">
select max(date_id) from product_heat_values
</select>
<select id="selectCount" resultType="java.lang.Integer" timeout="20000">
SELECT count(*) FROM product_heat_values
where
date_id = #{dateId}
</select>
<select id="selectSknByDate" resultType="java.lang.Long" timeout="20000">
SELECT product_skn FROM product_heat_values where date_id = #{dateId,jdbcType=VARCHAR} limit #{pageSize}
</select>
<delete id="deleteBatch">
<![CDATA[
DELETE FROM product_heat_values
WHERE
date_id = #{dateId,jdbcType=VARCHAR}
AND
]]>
product_skn in
<foreach item="item" index="index" collection="sknList" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
</mapper>
\ No newline at end of file
... ...
... ... @@ -5,12 +5,13 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.rebuild.RebuildFlagService;
import com.yoho.search.consumer.service.base.ProductService;
import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.HeatValueBuilder;
import com.yoho.search.consumer.suggests.common.RetryBusinessFlow;
import com.yoho.search.core.es.IElasticsearchClient;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.dal.ProductHeatValueMapper;
import com.yoho.search.dal.ProductHeatValuesMapper;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.ProductHeatValue;
import com.yoho.search.dal.model.ProductHeatValues;
import org.apache.commons.collections.CollectionUtils;
import org.elasticsearch.action.bulk.BulkResponse;
import org.slf4j.Logger;
... ... @@ -34,11 +35,13 @@ public class ProductIndexHeatValueUpdateFlow implements RetryBusinessFlow {
@Autowired
private RebuildFlagService rebuildFlagService;
@Autowired
private ProductHeatValueMapper productHeatValueMapper;
private ProductHeatValuesMapper productHeatsValueMapper;
@Autowired
private ProductService productService;
@Autowired
private IYohoIndexService yohoIndexService;
@Autowired
private HeatValueBuilder heatValueBuilder;
private Integer dateId = null;
... ... @@ -55,26 +58,26 @@ public class ProductIndexHeatValueUpdateFlow implements RetryBusinessFlow {
@Override
public int getTotalCount() {
return productHeatValueMapper.selectCount(productHeatValueMapper.selectLatestDateId());
return productHeatsValueMapper.selectCount(productHeatsValueMapper.selectLatestDateId());
}
@Override
public boolean doBusiness(int pageNo, int batchSize) {
int start = (pageNo - 1) * batchSize;
List<ProductHeatValue> productHeatValueList = productHeatValueMapper.selectHeatValueOfLatestDate(getDateId(), start, batchSize);
if (CollectionUtils.isEmpty(productHeatValueList)) {
List<ProductHeatValues> productHeatValuesList = productHeatsValueMapper.selectHeatValuesOfLatestDate(getDateId(), start, batchSize);
if (CollectionUtils.isEmpty(productHeatValuesList)) {
return true;
}
List<Integer> sknList = productHeatValueList.stream().map(ProductHeatValue::getProductSkn).collect(Collectors.toList());
List<Integer> sknList = productHeatValuesList.stream().map(ProductHeatValues::getProductSkn).collect(Collectors.toList());
List<Product> productList = productService.selectListSkns(sknList);
Map<Integer, Integer> skn2IDMap = productList.stream().collect(Collectors.toMap(Product::getErpProductId, Product::getId));
logger.info("[{} business][pageNo={}][productHeatValueList={}]", flowName(), pageNo, productHeatValueList.size());
logger.info("[{} business][pageNo={}][productHeatValuesList={}]", flowName(), pageNo, productHeatValuesList.size());
List<JSONObject> dataList = new ArrayList<JSONObject>();
productHeatValueList.stream().forEach((p) -> {
productHeatValuesList.stream().forEach((p) -> {
if (skn2IDMap.get(p.getProductSkn()) != null) {
JSONObject product = new JSONObject();
product.put("id", skn2IDMap.get(p.getProductSkn()));
product.put("heatValue", p.getHeatValue());
product.put("heatValue", heatValueBuilder.countHeatValue(p));
dataList.add(product);
}
});
... ... @@ -105,7 +108,7 @@ public class ProductIndexHeatValueUpdateFlow implements RetryBusinessFlow {
private Integer getDateId() {
if (dateId == null) {
dateId = productHeatValueMapper.selectLatestDateId();
dateId = productHeatsValueMapper.selectLatestDateId();
}
return dateId;
}
... ...
... ... @@ -2,10 +2,7 @@ package com.yoho.search.consumer.job;
import com.yoho.search.base.utils.DateStyle;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.flow.ProductIndexHeatValueUpdateFlow;
import com.yoho.search.consumer.suggests.common.RetryBusinessFlowExecutor;
import com.yoho.search.dal.ProductHeatValueMapper;
import com.yoho.search.dal.ProductHeatValuesMapper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -24,42 +21,41 @@ public class ProductHeatValueJob {
private static final Logger logger = LoggerFactory.getLogger(ProductHeatValueJob.class);
@Autowired
private ProductIndexHeatValueUpdateFlow productIndexHeatValueUpdateFlow;
@Autowired
private ProductHeatValueMapper productHeatValueMapper;
private ProductHeatValuesMapper productHeatValuesMapper;
private static final int CLEAN_BATCH_COUNT = 1000;
// /**
// * 每隔半个小时,更新一次数据到索引中
// */
// @Scheduled(cron = "0 0/30 * * * ?")
// public void doUpdateProductIndexHeatValue() {
// long begin = System.currentTimeMillis();
// logger.info("ProductHeatValueJob.doUpdateProductIndexHeatValue start----[begin={}]", begin);
// RetryBusinessFlowExecutor flowExecutor = new RetryBusinessFlowExecutor(productIndexHeatValueUpdateFlow, ISearchConstants.SEARCH_INDEX_BATCH_MAX_THREAD_SIZE, ISearchConstants.SEARCH_INDEX_BATCH_LIMIT);
// boolean result = flowExecutor.execute();
// logger.info("ProductHeatValueJob.doUpdateProductIndexHeatValue end----[result={}][cost={}]", result, System.currentTimeMillis() - begin);
// }
/**
* 每天1点,删除三天前那天的数据
*/
@Scheduled(cron = "0 0 1 * * ?")
public void clean() {
long begin = System.currentTimeMillis();
logger.info("ProductHeatValueJob.clean start----[begin={}]", begin);
logger.info("ProductHeatValuesJob.clean start----[begin={}]", begin);
// 默认取前三天
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -3);
calendar.set(Calendar.HOUR_OF_DAY, 0);
String generateDateStr = DateUtil.DateToString(calendar.getTime(), DateStyle.YYYYMMDD);
List<Long> sknList = productHeatValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
List<Long> sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productHeatValueMapper.deleteBatch(sknList,generateDateStr);
sknList = productHeatValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
productHeatValuesMapper.deleteBatch(sknList, generateDateStr);
sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("ProductHeatValueJob.clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
logger.info("ProductHeatValueJobs.clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
// /**
// * 每隔半个小时,更新一次数据到索引中
// */
// @Scheduled(cron = "0 0/30 * * * ?")
// public void doUpdateProductIndexHeatValue() {
// long begin = System.currentTimeMillis();
// logger.info("ProductHeatValueJob.doUpdateProductIndexHeatValue start----[begin={}]", begin);
// RetryBusinessFlowExecutor flowExecutor = new RetryBusinessFlowExecutor(productIndexHeatValueUpdateFlow, ISearchConstants.SEARCH_INDEX_BATCH_MAX_THREAD_SIZE, ISearchConstants.SEARCH_INDEX_BATCH_LIMIT);
// boolean result = flowExecutor.execute();
// logger.info("ProductHeatValueJob.doUpdateProductIndexHeatValue end----[result={}][cost={}]", result, System.currentTimeMillis() - begin);
// }
}
... ...
package com.yoho.search.consumer.restapi;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.flow.ProductIndexHeatValueUpdateFlow;
import com.yoho.search.consumer.suggests.common.RetryBusinessFlowExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
/**
* Created by wangnan on 2017/5/4.
*/
@Controller
public class ProductHeatValueController {
private static final Logger logger = LoggerFactory.getLogger(ProductHeatValueController.class);
@Autowired
private ProductIndexHeatValueUpdateFlow productIndexHeatValueUpdateFlow;
@RequestMapping(value = "/refreshProductHeatValue")
@ResponseBody
public Map<String, Object> refreshProductHeatValue() {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
long begin = System.currentTimeMillis();
RetryBusinessFlowExecutor flowExecutor = new RetryBusinessFlowExecutor(productIndexHeatValueUpdateFlow, ISearchConstants.SEARCH_INDEX_BATCH_MAX_THREAD_SIZE, ISearchConstants.SEARCH_INDEX_BATCH_LIMIT);
boolean result = flowExecutor.execute();
logger.info("[func=refreshProductHeatValue][result={}][cost={}]", result, System.currentTimeMillis() - begin);
if (result) {
resultMap.put("code", 200);
resultMap.put("message", "success");
} else {
resultMap.put("code", 400);
resultMap.put("message", "fail");
}
} catch (Exception e) {
e.printStackTrace();
resultMap.put("code", 400);
resultMap.put("message", e.getMessage());
}
return resultMap;
}
}
... ...
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.dal.ProductHeatValueMapper;
import com.yoho.search.dal.model.ProductHeatValue;
import com.yoho.search.dal.ProductHeatValuesMapper;
import com.yoho.search.dal.model.ProductHeatValues;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -10,9 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
... ... @@ -22,33 +22,67 @@ import java.util.stream.Collectors;
public class HeatValueBuilder implements ViewBuilder {
private final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER");
private Integer dateId = null;
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 ProductHeatValueMapper productHeatValueMapper;
private Integer dateId = null;
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<ProductHeatValue> productHeatValueList = productHeatValueMapper.selectHeatValueOfLatestDateBySkn(sknList, getDateId());
if (CollectionUtils.isEmpty(productHeatValueList)) {
List<ProductHeatValues> productHeatValuesList = productHeatValuesMapper.selectHeatValuesOfLatestDateBySkn(sknList, getDateId());
if (CollectionUtils.isEmpty(productHeatValuesList)) {
return;
}
Map<Integer, BigDecimal> productHeatValueMap = productHeatValueList.stream().collect(Collectors.toMap(ProductHeatValue::getProductSkn, ProductHeatValue::getHeatValue));
productIndexBOs.stream().forEach(productIndexBO -> productIndexBO.setHeatValue(Optional.ofNullable(productHeatValueMap.get(productIndexBO.getProductSkn()))
.orElse(new BigDecimal(0))
));
Map<Integer, ProductHeatValues> productHeatValueMap = productHeatValuesList.stream().collect(Collectors.toMap(ProductHeatValues::getProductSkn, (p) -> p));
for (ProductIndexBO productIndexBO : productIndexBOs) {
ProductHeatValues productHeatValues = productHeatValueMap.get(productIndexBO.getProductSkn());
productIndexBO.setHeatValue(new BigDecimal(0));
if (productHeatValues != null) {
productIndexBO.setHeatValue(countHeatValue(productHeatValues));
}
}
}
/**
* ProductIndexHeatValueUpdateFlow也调用
*/
public 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 Integer getDateId() {
if (dateId == null) {
dateId = productHeatValueMapper.selectLatestDateId();
dateId = productHeatValuesMapper.selectLatestDateId();
}
return dateId;
}
@Override
public void finish(){
public void finish() {
INDEX_REBUILD_LOG.info("HeatValueBuilder finish");
dateId = null;
}
... ...