商品索引添加商品热度字段,支持全量和定时增量。
Showing
7 changed files
with
217 additions
and
11 deletions
1 | +package com.yoho.search.dal; | ||
2 | + | ||
3 | +import com.yoho.search.dal.model.ProductHeatValue; | ||
4 | +import org.apache.ibatis.annotations.Param; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +public interface ProductHeatValueMapper { | ||
9 | + int deleteByPrimaryKey(Integer productSkn); | ||
10 | + | ||
11 | + int insert(ProductHeatValue record); | ||
12 | + | ||
13 | + int insertSelective(ProductHeatValue record); | ||
14 | + | ||
15 | + ProductHeatValue selectByPrimaryKey(Integer productSkn); | ||
16 | + | ||
17 | + int updateByPrimaryKeySelective(ProductHeatValue record); | ||
18 | + | ||
19 | + int updateByPrimaryKey(ProductHeatValue record); | ||
20 | + | ||
21 | + Integer selectLatestDateId(); | ||
22 | + | ||
23 | + List<ProductHeatValue> selectHeatValueOfLatestDate(@Param(value="sknList")List<Integer> sknList, @Param(value="dateId")Integer dateId); | ||
24 | +} |
1 | +package com.yoho.search.dal.model; | ||
2 | + | ||
3 | +import java.math.BigDecimal; | ||
4 | + | ||
5 | +public class ProductHeatValue { | ||
6 | + private Integer productSkn; | ||
7 | + | ||
8 | + private String dateId; | ||
9 | + | ||
10 | + private BigDecimal heatValue; | ||
11 | + | ||
12 | + private Integer lastUpdateTime; | ||
13 | + | ||
14 | + public Integer getProductSkn() { | ||
15 | + return productSkn; | ||
16 | + } | ||
17 | + | ||
18 | + public void setProductSkn(Integer productSkn) { | ||
19 | + this.productSkn = productSkn; | ||
20 | + } | ||
21 | + | ||
22 | + public String getDateId() { | ||
23 | + return dateId; | ||
24 | + } | ||
25 | + | ||
26 | + public void setDateId(String dateId) { | ||
27 | + this.dateId = dateId == null ? null : dateId.trim(); | ||
28 | + } | ||
29 | + | ||
30 | + public BigDecimal getHeatValue() { | ||
31 | + return heatValue; | ||
32 | + } | ||
33 | + | ||
34 | + public void setHeatValue(BigDecimal heatValue) { | ||
35 | + this.heatValue = heatValue; | ||
36 | + } | ||
37 | + | ||
38 | + public Integer getLastUpdateTime() { | ||
39 | + return lastUpdateTime; | ||
40 | + } | ||
41 | + | ||
42 | + public void setLastUpdateTime(Integer lastUpdateTime) { | ||
43 | + this.lastUpdateTime = lastUpdateTime; | ||
44 | + } | ||
45 | +} |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
3 | +<mapper namespace="com.yoho.search.dal.ProductHeatValueMapper" > | ||
4 | + <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ProductHeatValue" > | ||
5 | + <id column="product_skn" property="productSkn" jdbcType="INTEGER" /> | ||
6 | + <result column="date_id" property="dateId" jdbcType="VARCHAR" /> | ||
7 | + <result column="heat_value" property="heatValue" jdbcType="DECIMAL" /> | ||
8 | + <result column="last_update_time" property="lastUpdateTime" jdbcType="INTEGER" /> | ||
9 | + </resultMap> | ||
10 | + <sql id="Base_Column_List" > | ||
11 | + product_skn, date_id, heat_value, last_update_time | ||
12 | + </sql> | ||
13 | + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | ||
14 | + select | ||
15 | + <include refid="Base_Column_List" /> | ||
16 | + from product_heat_value | ||
17 | + where product_skn = #{productSkn,jdbcType=INTEGER} | ||
18 | + </select> | ||
19 | + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > | ||
20 | + delete from product_heat_value | ||
21 | + where product_skn = #{productSkn,jdbcType=INTEGER} | ||
22 | + </delete> | ||
23 | + <insert id="insert" parameterType="com.yoho.search.dal.model.ProductHeatValue" > | ||
24 | + insert into product_heat_value (product_skn, date_id, heat_value, | ||
25 | + last_update_time) | ||
26 | + values (#{productSkn,jdbcType=INTEGER}, #{dateId,jdbcType=VARCHAR}, #{heatValue,jdbcType=DECIMAL}, | ||
27 | + #{lastUpdateTime,jdbcType=INTEGER}) | ||
28 | + </insert> | ||
29 | + <insert id="insertSelective" parameterType="com.yoho.search.dal.model.ProductHeatValue" > | ||
30 | + insert into product_heat_value | ||
31 | + <trim prefix="(" suffix=")" suffixOverrides="," > | ||
32 | + <if test="productSkn != null" > | ||
33 | + product_skn, | ||
34 | + </if> | ||
35 | + <if test="dateId != null" > | ||
36 | + date_id, | ||
37 | + </if> | ||
38 | + <if test="heatValue != null" > | ||
39 | + heat_value, | ||
40 | + </if> | ||
41 | + <if test="lastUpdateTime != null" > | ||
42 | + last_update_time, | ||
43 | + </if> | ||
44 | + </trim> | ||
45 | + <trim prefix="values (" suffix=")" suffixOverrides="," > | ||
46 | + <if test="productSkn != null" > | ||
47 | + #{productSkn,jdbcType=INTEGER}, | ||
48 | + </if> | ||
49 | + <if test="dateId != null" > | ||
50 | + #{dateId,jdbcType=VARCHAR}, | ||
51 | + </if> | ||
52 | + <if test="heatValue != null" > | ||
53 | + #{heatValue,jdbcType=DECIMAL}, | ||
54 | + </if> | ||
55 | + <if test="lastUpdateTime != null" > | ||
56 | + #{lastUpdateTime,jdbcType=INTEGER}, | ||
57 | + </if> | ||
58 | + </trim> | ||
59 | + </insert> | ||
60 | + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.ProductHeatValue" > | ||
61 | + update product_heat_value | ||
62 | + <set > | ||
63 | + <if test="dateId != null" > | ||
64 | + date_id = #{dateId,jdbcType=VARCHAR}, | ||
65 | + </if> | ||
66 | + <if test="heatValue != null" > | ||
67 | + heat_value = #{heatValue,jdbcType=DECIMAL}, | ||
68 | + </if> | ||
69 | + <if test="lastUpdateTime != null" > | ||
70 | + last_update_time = #{lastUpdateTime,jdbcType=INTEGER}, | ||
71 | + </if> | ||
72 | + </set> | ||
73 | + where product_skn = #{productSkn,jdbcType=INTEGER} | ||
74 | + </update> | ||
75 | + <update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.ProductHeatValue" > | ||
76 | + update product_heat_value | ||
77 | + set date_id = #{dateId,jdbcType=VARCHAR}, | ||
78 | + heat_value = #{heatValue,jdbcType=DECIMAL}, | ||
79 | + last_update_time = #{lastUpdateTime,jdbcType=INTEGER} | ||
80 | + where product_skn = #{productSkn,jdbcType=INTEGER} | ||
81 | + </update> | ||
82 | + <select id="selectHeatValueOfLatestDate" resultMap="BaseResultMap" timeout="20000"> | ||
83 | + <![CDATA[ | ||
84 | + select * from product_heat_value p | ||
85 | + where | ||
86 | + date_id = #{dateId} | ||
87 | + and | ||
88 | + p.product_skn in | ||
89 | + ]]> | ||
90 | + <foreach item="item" index="index" collection="sknList" | ||
91 | + open="(" separator="," close=")"> | ||
92 | + #{item} | ||
93 | + </foreach> | ||
94 | + </select> | ||
95 | + <select id="selectLatestDateId" resultType="java.lang.Integer"> | ||
96 | + select max(date_id) from product_heat_value | ||
97 | + </select> | ||
98 | +</mapper> |
1 | package com.yoho.search.consumer.service.base; | 1 | package com.yoho.search.consumer.service.base; |
2 | 2 | ||
3 | -import java.math.BigDecimal; | ||
4 | -import java.util.HashMap; | ||
5 | -import java.util.Map; | ||
6 | - | 3 | +import com.alibaba.fastjson.JSONArray; |
4 | +import com.alibaba.fastjson.JSONException; | ||
5 | +import com.yoho.search.base.utils.ProductIndexEsField; | ||
6 | +import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
7 | +import com.yoho.search.consumer.service.logic.tools.SpecialDealLogicService; | ||
7 | import org.apache.commons.lang.StringUtils; | 8 | import org.apache.commons.lang.StringUtils; |
8 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
9 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
12 | 13 | ||
13 | -import com.alibaba.fastjson.JSONArray; | ||
14 | -import com.alibaba.fastjson.JSONException; | ||
15 | -import com.yoho.search.base.utils.ProductIndexEsField; | ||
16 | -import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
17 | -import com.yoho.search.consumer.service.logic.tools.SpecialDealLogicService; | 14 | +import java.math.BigDecimal; |
15 | +import java.util.HashMap; | ||
16 | +import java.util.Map; | ||
18 | 17 | ||
19 | @Component | 18 | @Component |
20 | public class ProductIndexService { | 19 | public class ProductIndexService { |
@@ -203,6 +202,7 @@ public class ProductIndexService { | @@ -203,6 +202,7 @@ public class ProductIndexService { | ||
203 | map.put(ProductIndexEsField.shopDomain, productIndexBO.getShopDomain()); | 202 | map.put(ProductIndexEsField.shopDomain, productIndexBO.getShopDomain()); |
204 | map.put(ProductIndexEsField.productAttrField, productIndexBO.getProductAttrField()); | 203 | map.put(ProductIndexEsField.productAttrField, productIndexBO.getProductAttrField()); |
205 | map.put(ProductIndexEsField.bundleType, productIndexBO.getBundleType()); | 204 | map.put(ProductIndexEsField.bundleType, productIndexBO.getBundleType()); |
205 | + map.put(ProductIndexEsField.heatValue, productIndexBO.getHeatValue()); | ||
206 | return map; | 206 | return map; |
207 | } | 207 | } |
208 | 208 |
@@ -114,8 +114,8 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -114,8 +114,8 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
114 | private String shopDomain; | 114 | private String shopDomain; |
115 | 115 | ||
116 | private String productAttrField; | 116 | private String productAttrField; |
117 | + private BigDecimal heatValue; | ||
117 | 118 | ||
118 | - // get | ||
119 | public BigDecimal getSpecialPrice() { | 119 | public BigDecimal getSpecialPrice() { |
120 | return specialPrice; | 120 | return specialPrice; |
121 | } | 121 | } |
@@ -264,7 +264,6 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -264,7 +264,6 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
264 | return poolId; | 264 | return poolId; |
265 | } | 265 | } |
266 | 266 | ||
267 | - // set | ||
268 | public void setSpecialPrice(BigDecimal specialPrice) { | 267 | public void setSpecialPrice(BigDecimal specialPrice) { |
269 | this.specialPrice = specialPrice; | 268 | this.specialPrice = specialPrice; |
270 | } | 269 | } |
@@ -532,4 +531,12 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -532,4 +531,12 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
532 | public void setProductAttrField(String productAttrField) { | 531 | public void setProductAttrField(String productAttrField) { |
533 | this.productAttrField = productAttrField; | 532 | this.productAttrField = productAttrField; |
534 | } | 533 | } |
534 | + | ||
535 | + public BigDecimal getHeatValue() { | ||
536 | + return heatValue; | ||
537 | + } | ||
538 | + | ||
539 | + public void setHeatValue(BigDecimal heatValue) { | ||
540 | + this.heatValue = heatValue; | ||
541 | + } | ||
535 | } | 542 | } |
1 | +package com.yoho.search.consumer.service.logic.productIndex.viewBuilder; | ||
2 | + | ||
3 | +import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
4 | +import com.yoho.search.dal.ProductHeatValueMapper; | ||
5 | +import com.yoho.search.dal.model.ProductHeatValue; | ||
6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | +import org.springframework.stereotype.Component; | ||
8 | + | ||
9 | +import java.math.BigDecimal; | ||
10 | +import java.util.List; | ||
11 | +import java.util.Map; | ||
12 | +import java.util.stream.Collectors; | ||
13 | + | ||
14 | +/** | ||
15 | + * Created by wangnan on 2017/4/10. | ||
16 | + */ | ||
17 | +@Component | ||
18 | +public class HeatValueBuilder implements ViewBuilder { | ||
19 | + | ||
20 | + @Autowired | ||
21 | + private ProductHeatValueMapper productHeatValueMapper; | ||
22 | + | ||
23 | + @Override | ||
24 | + public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) { | ||
25 | + List<ProductHeatValue> productHeatValueList = productHeatValueMapper.selectHeatValueOfLatestDate(sknList, productHeatValueMapper.selectLatestDateId()); | ||
26 | + Map<Integer, BigDecimal> productHeatValueMap = productHeatValueList.parallelStream().collect(Collectors.toMap(ProductHeatValue::getProductSkn, ProductHeatValue::getHeatValue)); | ||
27 | + productIndexBOs.stream().forEach((p) -> {p.setHeatValue(productHeatValueMap.get(p.getProductSkn()));}); | ||
28 | + } | ||
29 | +} |
-
Please register or login to post a comment