Showing
8 changed files
with
203 additions
and
1 deletions
1 | +package com.yoho.search.dal; | ||
2 | + | ||
3 | +import com.yoho.search.dal.model.BigdataUvScore; | ||
4 | +import org.apache.ibatis.annotations.Param; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +public interface BigdataUvScoreMapper { | ||
9 | + | ||
10 | + Integer selectLatestDateId(); | ||
11 | + | ||
12 | + List<BigdataUvScore> selectList(@Param("sknList") List<Integer> sknList, @Param("dateId") Integer dateId); | ||
13 | + | ||
14 | + List<Integer> selectSknListByDateId(@Param(value = "dateId") Integer dateId, @Param(value = "pageSize") Integer pageSize); | ||
15 | + | ||
16 | + void deleteBatch(@Param(value = "sknList") List<Integer> sknList, @Param(value = "dateId") Integer dateId); | ||
17 | +} |
1 | +package com.yoho.search.dal.model; | ||
2 | + | ||
3 | +import java.math.BigDecimal; | ||
4 | + | ||
5 | +public class BigdataUvScore { | ||
6 | + | ||
7 | + private Integer productSkn; | ||
8 | + | ||
9 | + private Integer dateId; | ||
10 | + | ||
11 | + private BigDecimal uvScore; | ||
12 | + | ||
13 | + private Integer createTime; | ||
14 | + | ||
15 | + public Integer getProductSkn() { | ||
16 | + return productSkn; | ||
17 | + } | ||
18 | + | ||
19 | + public void setProductSkn(Integer productSkn) { | ||
20 | + this.productSkn = productSkn; | ||
21 | + } | ||
22 | + | ||
23 | + public Integer getDateId() { | ||
24 | + return dateId; | ||
25 | + } | ||
26 | + | ||
27 | + public void setDateId(Integer dateId) { | ||
28 | + this.dateId = dateId; | ||
29 | + } | ||
30 | + | ||
31 | + public BigDecimal getUvScore() { | ||
32 | + return uvScore; | ||
33 | + } | ||
34 | + | ||
35 | + public void setUvScore(BigDecimal uvScore) { | ||
36 | + this.uvScore = uvScore; | ||
37 | + } | ||
38 | + | ||
39 | + public Integer getCreateTime() { | ||
40 | + return createTime; | ||
41 | + } | ||
42 | + | ||
43 | + public void setCreateTime(Integer createTime) { | ||
44 | + this.createTime = createTime; | ||
45 | + } | ||
46 | +} |
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.BigdataUvScoreMapper"> | ||
4 | + <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.BigdataUvScore"> | ||
5 | + <id column="product_skn" property="productSkn" jdbcType="INTEGER"/> | ||
6 | + <id column="date_id" property="dateId" jdbcType="INTEGER"/> | ||
7 | + <result column="uv_score" property="uvScore" jdbcType="DECIMAL"/> | ||
8 | + <result column="create_time" property="createTime" jdbcType="INTEGER"/> | ||
9 | + </resultMap> | ||
10 | + <sql id="Base_Column_List"> | ||
11 | + product_skn, date_id, uv_score, create_time | ||
12 | + </sql> | ||
13 | + | ||
14 | + <select id="selectLatestDateId" resultType="java.lang.Integer"> | ||
15 | + select max(date_id) from bigdata_uvscore limit 1 | ||
16 | + </select> | ||
17 | + | ||
18 | + <select id="selectList" resultMap="BaseResultMap" timeout="20000"> | ||
19 | + select | ||
20 | + <include refid="Base_Column_List"/> | ||
21 | + from bigdata_uvscore | ||
22 | + WHERE | ||
23 | + product_skn in | ||
24 | + <foreach item="item" index="index" collection="sknList" open="(" separator="," close=")"> | ||
25 | + #{item} | ||
26 | + </foreach> | ||
27 | + AND | ||
28 | + date_id = #{dateId,jdbcType=INTEGER} | ||
29 | + </select> | ||
30 | + | ||
31 | + <select id="selectSknListByDateId" resultType="java.lang.Integer" timeout="20000"> | ||
32 | + select product_skn from bigdata_uvscore WHERE date_id = #{dateId,jdbcType=INTEGER} | ||
33 | + limit #{pageSize} | ||
34 | + </select> | ||
35 | + | ||
36 | + <delete id="deleteBatch"> | ||
37 | + DELETE FROM bigdata_uvscore | ||
38 | + WHERE | ||
39 | + product_skn in | ||
40 | + <foreach item="item" index="index" collection="sknList" open="(" separator="," close=")"> | ||
41 | + #{item} | ||
42 | + </foreach> | ||
43 | + AND | ||
44 | + date_id = #{dateId,jdbcType=INTEGER} | ||
45 | + </delete> | ||
46 | + | ||
47 | +</mapper> |
@@ -95,7 +95,9 @@ public class CleanDataJob { | @@ -95,7 +95,9 @@ public class CleanDataJob { | ||
95 | //15.bigdata_ufo_sales_money [ufo_search] | 95 | //15.bigdata_ufo_sales_money [ufo_search] |
96 | this.cleanBigdataUfoSalesMoney(jobIndex++); | 96 | this.cleanBigdataUfoSalesMoney(jobIndex++); |
97 | this.safeSleep(10); | 97 | this.safeSleep(10); |
98 | - | 98 | + //16.bigdata_uvscore |
99 | + this.cleanBigdataUvScore(jobIndex++); | ||
100 | + this.safeSleep(10); | ||
99 | } | 101 | } |
100 | 102 | ||
101 | @Autowired | 103 | @Autowired |
@@ -511,6 +513,34 @@ public class CleanDataJob { | @@ -511,6 +513,34 @@ public class CleanDataJob { | ||
511 | } | 513 | } |
512 | } | 514 | } |
513 | 515 | ||
516 | + @Autowired | ||
517 | + private BigdataUvScoreMapper bigdataUvScoreMapper; | ||
518 | + | ||
519 | + private void cleanBigdataUvScore(int jobIndex) { | ||
520 | + try { | ||
521 | + //1、记录开始日志 | ||
522 | + String jobName = "cleanBigdataUvScore"; | ||
523 | + long begin = System.currentTimeMillis(); | ||
524 | + String generateDateStr = getLastFiveDayDate(); | ||
525 | + this.addBeginLog(jobIndex, jobName, generateDateStr, begin); | ||
526 | + Integer dateId = Integer.valueOf(generateDateStr); | ||
527 | + | ||
528 | + // 2、执行清理 | ||
529 | + int delCount = 0; | ||
530 | + List<Integer> idList = bigdataUvScoreMapper.selectSknListByDateId(dateId, CLEAN_BATCH_COUNT); | ||
531 | + while (CollectionUtils.isNotEmpty(idList)) { | ||
532 | + delCount = delCount + idList.size(); | ||
533 | + bigdataUvScoreMapper.deleteBatch(idList, dateId); | ||
534 | + idList = bigdataUvScoreMapper.selectSknListByDateId(dateId, CLEAN_BATCH_COUNT); | ||
535 | + } | ||
536 | + | ||
537 | + //3、记录结束日志 | ||
538 | + this.addFinishLog(jobIndex, jobName, generateDateStr, delCount, begin); | ||
539 | + } catch (Exception e) { | ||
540 | + logger.error(e.getMessage(), e); | ||
541 | + } | ||
542 | + } | ||
543 | + | ||
514 | 544 | ||
515 | 545 | ||
516 | 546 |
@@ -45,6 +45,9 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -45,6 +45,9 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
45 | //from bigdata_sales_num | 45 | //from bigdata_sales_num |
46 | private Integer totalSalesNum; | 46 | private Integer totalSalesNum; |
47 | 47 | ||
48 | + //from bigdata_uvscore | ||
49 | + private BigDecimal uvScore; | ||
50 | + | ||
48 | // from product_goods | 51 | // from product_goods |
49 | private String goodsList; | 52 | private String goodsList; |
50 | 53 | ||
@@ -723,4 +726,11 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | @@ -723,4 +726,11 @@ public class ProductIndexBO extends ProductIBO implements Serializable { | ||
723 | this.totalSalesNum = totalSalesNum; | 726 | this.totalSalesNum = totalSalesNum; |
724 | } | 727 | } |
725 | 728 | ||
729 | + public BigDecimal getUvScore() { | ||
730 | + return uvScore; | ||
731 | + } | ||
732 | + | ||
733 | + public void setUvScore(BigDecimal uvScore) { | ||
734 | + this.uvScore = uvScore; | ||
735 | + } | ||
726 | } | 736 | } |
@@ -190,6 +190,7 @@ public class ProductIndexBOToMapService { | @@ -190,6 +190,7 @@ public class ProductIndexBOToMapService { | ||
190 | map.put(ProductIndexEsField.heatValue, productIndexBO.getHeatValue()); | 190 | map.put(ProductIndexEsField.heatValue, productIndexBO.getHeatValue()); |
191 | map.put(ProductIndexEsField.ctrValue, productIndexBO.getCtrValue()); | 191 | map.put(ProductIndexEsField.ctrValue, productIndexBO.getCtrValue()); |
192 | map.put(ProductIndexEsField.recallValue, productIndexBO.getRecallValue()); | 192 | map.put(ProductIndexEsField.recallValue, productIndexBO.getRecallValue()); |
193 | + map.put(ProductIndexEsField.uvScore, productIndexBO.getUvScore()); | ||
193 | 194 | ||
194 | map.put(ProductIndexEsField.skuIds, productIndexBO.getSkuIds()); | 195 | map.put(ProductIndexEsField.skuIds, productIndexBO.getSkuIds()); |
195 | 196 |
service/src/main/java/com/yoho/search/consumer/service/logicService/productIndex/UvScoreBuilder.java
0 → 100644
1 | +package com.yoho.search.consumer.service.logicService.productIndex; | ||
2 | + | ||
3 | +import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
4 | +import com.yoho.search.dal.BigdataUvScoreMapper; | ||
5 | +import com.yoho.search.dal.model.BigdataUvScore; | ||
6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | +import org.springframework.stereotype.Component; | ||
8 | + | ||
9 | +import java.math.BigDecimal; | ||
10 | +import java.util.ArrayList; | ||
11 | +import java.util.List; | ||
12 | +import java.util.Map; | ||
13 | +import java.util.stream.Collectors; | ||
14 | + | ||
15 | +@Component | ||
16 | +public class UvScoreBuilder implements IndexFieldBuilder { | ||
17 | + | ||
18 | + @Autowired | ||
19 | + private BigdataUvScoreMapper bigdataUvScoreMapper; | ||
20 | + | ||
21 | + private Integer dateId = null; | ||
22 | + | ||
23 | + @Override | ||
24 | + public void init() { | ||
25 | + dateId = bigdataUvScoreMapper.selectLatestDateId(); | ||
26 | + } | ||
27 | + | ||
28 | + @Override | ||
29 | + public void build(List<ProductIndexBO> productIndexBOs, List<Integer> idList, List<Integer> sknList) { | ||
30 | + List<BigdataUvScore> bigdataUvScoreList; | ||
31 | + if (dateId == null) { | ||
32 | + bigdataUvScoreList = new ArrayList<>(); | ||
33 | + } else { | ||
34 | + bigdataUvScoreList = bigdataUvScoreMapper.selectList(sknList, dateId); | ||
35 | + } | ||
36 | + Map<Integer, BigDecimal> sknUvscoreMap = bigdataUvScoreList.stream().collect(Collectors.toMap(BigdataUvScore::getProductSkn, BigdataUvScore::getUvScore)); | ||
37 | + productIndexBOs.stream().forEach(productIndexBO -> { | ||
38 | + BigDecimal uvScore = sknUvscoreMap.getOrDefault(productIndexBO.getProductSkn(),BigDecimal.ZERO); | ||
39 | + productIndexBO.setUvScore(uvScore); | ||
40 | + }); | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public void finish() { | ||
45 | + dateId = null; | ||
46 | + } | ||
47 | + | ||
48 | +} |
-
Please register or login to post a comment