Authored by wangnan

商品索引添加商品热度字段,支持全量和定时增量。

package com.yoho.search.dal;
import com.yoho.search.dal.model.ProductHeatValue;
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();
List<ProductHeatValue> selectHeatValueOfLatestDate(@Param(value="sknList")List<Integer> sknList, @Param(value="dateId")Integer dateId);
}
\ No newline at end of file
... ...
package com.yoho.search.dal.model;
import java.math.BigDecimal;
public class ProductHeatValue {
private Integer productSkn;
private String dateId;
private BigDecimal heatValue;
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 getHeatValue() {
return heatValue;
}
public void setHeatValue(BigDecimal heatValue) {
this.heatValue = heatValue;
}
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" >
<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" >
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>
<select id="selectHeatValueOfLatestDate" resultMap="BaseResultMap" timeout="20000">
<![CDATA[
select * from product_heat_value 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="selectLatestDateId" resultType="java.lang.Integer">
select max(date_id) from product_heat_value
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -1030,6 +1030,9 @@
}
},
"type": "multi_field"
},
"heatValue": {
"type": "double"
}
}
}
... ...
package com.yoho.search.consumer.service.base;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.logic.tools.SpecialDealLogicService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.logic.tools.SpecialDealLogicService;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
@Component
public class ProductIndexService {
... ... @@ -203,6 +202,7 @@ public class ProductIndexService {
map.put(ProductIndexEsField.shopDomain, productIndexBO.getShopDomain());
map.put(ProductIndexEsField.productAttrField, productIndexBO.getProductAttrField());
map.put(ProductIndexEsField.bundleType, productIndexBO.getBundleType());
map.put(ProductIndexEsField.heatValue, productIndexBO.getHeatValue());
return map;
}
... ...
... ... @@ -114,8 +114,8 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
private String shopDomain;
private String productAttrField;
private BigDecimal heatValue;
// get
public BigDecimal getSpecialPrice() {
return specialPrice;
}
... ... @@ -264,7 +264,6 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
return poolId;
}
// set
public void setSpecialPrice(BigDecimal specialPrice) {
this.specialPrice = specialPrice;
}
... ... @@ -532,4 +531,12 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
public void setProductAttrField(String productAttrField) {
this.productAttrField = productAttrField;
}
public BigDecimal getHeatValue() {
return heatValue;
}
public void setHeatValue(BigDecimal heatValue) {
this.heatValue = heatValue;
}
}
\ No newline at end of file
... ...
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 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;
/**
* Created by wangnan on 2017/4/10.
*/
@Component
public class HeatValueBuilder implements ViewBuilder {
@Autowired
private ProductHeatValueMapper productHeatValueMapper;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<ProductHeatValue> productHeatValueList = productHeatValueMapper.selectHeatValueOfLatestDate(sknList, productHeatValueMapper.selectLatestDateId());
Map<Integer, BigDecimal> productHeatValueMap = productHeatValueList.parallelStream().collect(Collectors.toMap(ProductHeatValue::getProductSkn, ProductHeatValue::getHeatValue));
productIndexBOs.stream().forEach((p) -> {p.setHeatValue(productHeatValueMap.get(p.getProductSkn()));});
}
}
... ...