Authored by wangnan

【曝光值、曝光类型】 建到PI里

package com.yoho.search.dal;
import com.yoho.search.dal.model.SknCtrValue;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SknCtrValueMapper {
int deleteByPrimaryKey(Integer productSkn);
int insert(SknCtrValue record);
int insertSelective(SknCtrValue record);
SknCtrValue selectByPrimaryKey(Integer productSkn);
int updateByPrimaryKeySelective(SknCtrValue record);
int updateByPrimaryKey(SknCtrValue record);
Integer selectLatestDateId();
List<SknCtrValue> selectLatestDateBySkn(@Param(value = "sknList") List<Integer> sknList, @Param(value = "dateId") Integer dateId);
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;
import com.yoho.search.dal.model.SknFlow;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SknFlowMapper {
int deleteByPrimaryKey(Integer productSkn);
int insert(SknFlow record);
int insertSelective(SknFlow record);
SknFlow selectByPrimaryKey(Integer productSkn);
int updateByPrimaryKeySelective(SknFlow record);
int updateByPrimaryKey(SknFlow record);
Integer selectLatestDateId();
List<SknFlow> selectLatestDateBySkn(@Param(value = "sknList") List<Integer> sknList, @Param(value = "dateId") Integer dateId);
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;
public class SknCtrValue {
private Integer productSkn;
private String dateId;
private Integer ctrValue;
private Integer createTime;
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 Integer getCtrValue() {
return ctrValue;
}
public void setCtrValue(Integer ctrValue) {
this.ctrValue = ctrValue;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
package com.yoho.search.dal.model;
public class SknFlow {
private Integer productSkn;
private String dateId;
private Integer flowType;
private Integer createTime;
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 Integer getFlowType() {
return flowType;
}
public void setFlowType(Integer flowType) {
this.flowType = flowType;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ 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.SknCtrValueMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SknCtrValue" >
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="date_id" property="dateId" jdbcType="VARCHAR" />
<result column="ctr_value" property="ctrValue" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
product_skn, date_id, ctr_value, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from skn_ctr_value
where product_skn = #{productSkn,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from skn_ctr_value
where product_skn = #{productSkn,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.SknCtrValue" >
insert into skn_ctr_value (product_skn, date_id, ctr_value,
create_time)
values (#{productSkn,jdbcType=INTEGER}, #{dateId,jdbcType=VARCHAR}, #{ctrValue,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.SknCtrValue" >
insert into skn_ctr_value
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="productSkn != null" >
product_skn,
</if>
<if test="dateId != null" >
date_id,
</if>
<if test="ctrValue != null" >
ctr_value,
</if>
<if test="createTime != null" >
create_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="ctrValue != null" >
#{ctrValue,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.SknCtrValue" >
update skn_ctr_value
<set >
<if test="dateId != null" >
date_id = #{dateId,jdbcType=VARCHAR},
</if>
<if test="ctrValue != null" >
ctr_value = #{ctrValue,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.SknCtrValue" >
update skn_ctr_value
set date_id = #{dateId,jdbcType=VARCHAR},
ctr_value = #{ctrValue,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<select id="selectLatestDateId" resultType="java.lang.Integer">
select max(date_id) from skn_ctr_value
</select>
<select id="selectLatestDateBySkn" resultMap="BaseResultMap" timeout="20000">
<![CDATA[
select * from skn_ctr_value s
where
date_id = #{dateId}
and
s.product_skn in
]]>
<foreach item="item" index="index" collection="sknList"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectSknByDate" resultType="java.lang.Long" timeout="20000">
SELECT product_skn FROM skn_ctr_value where date_id = #{dateId,jdbcType=VARCHAR} limit #{pageSize}
</select>
<delete id="deleteBatch">
<![CDATA[
DELETE FROM skn_ctr_value
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
... ...
<?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.SknFlowMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SknFlow" >
<id column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="date_id" property="dateId" jdbcType="VARCHAR" />
<result column="flow_type" property="flowType" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
product_skn, date_id, flow_type, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from skn_flow
where product_skn = #{productSkn,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from skn_flow
where product_skn = #{productSkn,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.SknFlow" >
insert into skn_flow (product_skn, date_id, flow_type,
create_time)
values (#{productSkn,jdbcType=INTEGER}, #{dateId,jdbcType=VARCHAR}, #{flowType,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.SknFlow" >
insert into skn_flow
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="productSkn != null" >
product_skn,
</if>
<if test="dateId != null" >
date_id,
</if>
<if test="flowType != null" >
flow_type,
</if>
<if test="createTime != null" >
create_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="flowType != null" >
#{flowType,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.SknFlow" >
update skn_flow
<set >
<if test="dateId != null" >
date_id = #{dateId,jdbcType=VARCHAR},
</if>
<if test="flowType != null" >
flow_type = #{flowType,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.SknFlow" >
update skn_flow
set date_id = #{dateId,jdbcType=VARCHAR},
flow_type = #{flowType,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where product_skn = #{productSkn,jdbcType=INTEGER}
</update>
<select id="selectLatestDateId" resultType="java.lang.Integer">
select max(date_id) from skn_flow
</select>
<select id="selectLatestDateBySkn" resultMap="BaseResultMap" timeout="20000">
<![CDATA[
select * from skn_flow s
where
date_id = #{dateId}
and
s.product_skn in
]]>
<foreach item="item" index="index" collection="sknList"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectSknByDate" resultType="java.lang.Long" timeout="20000">
SELECT product_skn FROM skn_flow where date_id = #{dateId,jdbcType=VARCHAR} limit #{pageSize}
</select>
<delete id="deleteBatch">
<![CDATA[
DELETE FROM skn_flow
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
... ...
package com.yoho.search.consumer.index.common.impl;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.common.IYohoIndexRebuildListener;
import com.yoho.search.consumer.index.fullbuild.ProductIndexIndexBuilder;
... ... @@ -12,9 +8,10 @@ import com.yoho.search.consumer.service.base.Product15DaySalesNumService;
import com.yoho.search.consumer.service.logic.ProductVectorFeatureLogicService;
import com.yoho.search.consumer.service.logic.PromotionConditionLogicService;
import com.yoho.search.consumer.service.logic.productIndex.ProductHeatValueLogicService;
import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.BasePinRatioBuilder;
import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.BrokenCodeBuilder;
import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.ProductModelValueBuilder;
import com.yoho.search.consumer.service.logic.productIndex.viewBuilder.*;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ProductIndexRebuildListener implements IYohoIndexRebuildListener, InitializingBean {
... ... @@ -39,6 +36,10 @@ public class ProductIndexRebuildListener implements IYohoIndexRebuildListener, I
private BasePinRatioBuilder basePinRatioBuilder;
@Autowired
private ProductHeatValueLogicService productHeatValueLogicService;
@Autowired
private CtrValueBuilder ctrValueBuilder;
@Autowired
private FlowTypeBuilder flowTypeBuilder;
@Override
public void afterPropertiesSet() throws Exception {
... ... @@ -68,7 +69,9 @@ public class ProductIndexRebuildListener implements IYohoIndexRebuildListener, I
basePinRatioBuilder.finish();
productHeatValueLogicService.finish();
productModelValueBuilder.finish();
flowTypeBuilder.finish();
product15DaySalesNumService.finish();
ctrValueBuilder.finish();
}
}
... ...
... ... @@ -3,6 +3,9 @@ package com.yoho.search.consumer.job;
import com.yoho.search.base.utils.DateStyle;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.dal.ProductHeatValuesMapper;
import com.yoho.search.dal.ProductModelValueMapper;
import com.yoho.search.dal.SknCtrValueMapper;
import com.yoho.search.dal.SknFlowMapper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -14,35 +17,67 @@ import java.util.Calendar;
import java.util.List;
/**
* Created by wangnan on 2017/4/10.
* Created by wangnan on 2017/8/24.
*/
@Component
public class ProductHeatValueJob {
private static final Logger logger = LoggerFactory.getLogger(ProductHeatValueJob.class);
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
private static final int CLEAN_BATCH_COUNT = 1000;
/**
* 每天1点,删除三天前那天的数据
*/
@Scheduled(cron = "0 0 1 * * ?")
public void clean() {
long begin = System.currentTimeMillis();
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 = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productHeatValuesMapper.deleteBatch(sknList, generateDateStr);
sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("ProductHeatValueJobs.clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
public class CleanDataJob {
private static final Logger logger = LoggerFactory.getLogger(CleanDataJob.class);
@Autowired
private ProductHeatValuesMapper productHeatValuesMapper;
@Autowired
private ProductModelValueMapper productModelValueMapper;
@Autowired
private SknFlowMapper sknFlowMapper;
@Autowired
private SknCtrValueMapper sknCtrValueMapper;
private static final int CLEAN_BATCH_COUNT = 1000;
/**
* 每天1点,删除三天前那天的数据
*/
@Scheduled(cron = "0 0 1 * * ?")
public void clean() {
// 默认取前三天
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);
//productHeatValues
long begin = System.currentTimeMillis();
logger.info("productHeatValues clean start----[begin={}]", begin);
List<Long> sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productHeatValuesMapper.deleteBatch(sknList, generateDateStr);
sknList = productHeatValuesMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("productHeatValues clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
//productModelValue
begin = System.currentTimeMillis();
logger.info("productModelValue clean start----[begin={}]", begin);
while (CollectionUtils.isNotEmpty(sknList)) {
productModelValueMapper.deleteBatch(sknList,generateDateStr);
sknList = productModelValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("productModelValue clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
//sknFlow
begin = System.currentTimeMillis();
logger.info("sknFlow clean start----[begin={}]", begin);
while (CollectionUtils.isNotEmpty(sknList)) {
sknFlowMapper.deleteBatch(sknList,generateDateStr);
sknList = sknFlowMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("sknFlow clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
//sknCtrValue
begin = System.currentTimeMillis();
logger.info("sknCtrValue clean start----[begin={}]", begin);
while (CollectionUtils.isNotEmpty(sknList)) {
sknCtrValueMapper.deleteBatch(sknList,generateDateStr);
sknList = sknCtrValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("sknCtrValue clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
}
... ...
package com.yoho.search.consumer.job;
import com.yoho.search.base.utils.DateStyle;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.dal.ProductModelValueMapper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.List;
/**
* Created by wangnan on 2017/4/18.
*/
@Component
public class ProductModelValueJob {
private static final Logger logger = LoggerFactory.getLogger(ProductModelValueJob.class);
private static final int CLEAN_BATCH_COUNT = 1000;
@Autowired
private ProductModelValueMapper productModelValueMapper;
/**
* 每天1点半,删除三天前那天的数据
*/
@Scheduled(cron = "0 30 1 * * ?")
public void clean() {
long begin = System.currentTimeMillis();
logger.info("ProductModelValueJob.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 = productModelValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
while (CollectionUtils.isNotEmpty(sknList)) {
productModelValueMapper.deleteBatch(sknList,generateDateStr);
sknList = productModelValueMapper.selectSknByDate(generateDateStr, CLEAN_BATCH_COUNT);
}
logger.info("ProductModelValueJob.clean end----[clearDateStr={}][cost={}]", generateDateStr, System.currentTimeMillis() - begin);
}
}
... ... @@ -767,6 +767,12 @@
"toAddScore": {
"type": "string",
"index": "not_analyzed"
},
"ctrValue": {
"type": "long"
},
"flowType": {
"type": "long"
}
}
}
... ...
... ... @@ -138,7 +138,29 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
// from videos
private String specialSearchFieldVideo;
public Integer getLastReducePriceTime() {
//from ctr_value
private Integer ctrValue;
//skn_flow
private Integer flowType;
public Integer getCtrValue() {
return ctrValue;
}
public void setCtrValue(Integer ctrValue) {
this.ctrValue = ctrValue;
}
public Integer getFlowType() {
return flowType;
}
public void setFlowType(Integer flowType) {
this.flowType = flowType;
}
public Integer getLastReducePriceTime() {
return lastReducePriceTime;
}
... ...
package com.yoho.search.consumer.service.logic.productIndex;
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 org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
@Component
public class ProductIndexBOToMapService {
... ... @@ -214,6 +213,9 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.specialSearchFieldPrice, productIndexBO.getSpecialSearchFieldPrice());
map.put(ProductIndexEsField.specialSearchFieldVideo, productIndexBO.getSpecialSearchFieldVideo());
map.put(ProductIndexEsField.ctrValue, productIndexBO.getCtrValue());
map.put(ProductIndexEsField.flowType, productIndexBO.getFlowType());
return map;
}
... ...
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.dal.SknCtrValueMapper;
import com.yoho.search.dal.model.SknCtrValue;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by wangnan on 2017/8/24.
*/
@Component
public class CtrValueBuilder implements ViewBuilder {
private final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER");
@Autowired
private SknCtrValueMapper sknCtrValueMapper;
private Integer dateId = null;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<SknCtrValue> sknCtrValueList = sknCtrValueMapper.selectLatestDateBySkn(sknList,getDateId());
if (CollectionUtils.isEmpty(sknCtrValueList)) {
return;
}
Map<Integer,Integer> ctrValueMap = sknCtrValueList.stream().parallel().collect(Collectors.toMap(SknCtrValue::getProductSkn,SknCtrValue::getCtrValue));
productIndexBOs.stream().forEach(p->{
if (ctrValueMap.containsKey(p.getProductSkn())) {
p.setCtrValue(ctrValueMap.get(p.getProductSkn()));
}
});
}
private Integer getDateId() {
if (dateId == null) {
dateId = sknCtrValueMapper.selectLatestDateId();
}
return dateId;
}
@Override
public void finish(){
INDEX_REBUILD_LOG.info("CtrValueBuilder finish");
dateId = null;
}
}
... ...
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.dal.SknFlowMapper;
import com.yoho.search.dal.model.SknFlow;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by wangnan on 2017/8/24.
*/
@Component
public class FlowTypeBuilder implements ViewBuilder {
private final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER");
@Autowired
private SknFlowMapper sknFlowMapper;
private Integer dateId = null;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<SknFlow> sknFlowList = sknFlowMapper.selectLatestDateBySkn(sknList,getDateId());
if (CollectionUtils.isEmpty(sknFlowList)) {
return;
}
Map<Integer,Integer> sknFlowMap = sknFlowList.stream().parallel().collect(Collectors.toMap(SknFlow::getProductSkn,SknFlow::getFlowType));
productIndexBOs.stream().forEach(p->{
if (sknFlowMap.containsKey(p.getProductSkn())) {
p.setFlowType(sknFlowMap.get(p.getProductSkn()));
}
});
}
private Integer getDateId() {
if (dateId == null) {
dateId = sknFlowMapper.selectLatestDateId();
}
return dateId;
}
@Override
public void finish(){
INDEX_REBUILD_LOG.info("FlowTypeBuilder finish");
dateId = null;
}
}
... ...
... ... @@ -54,7 +54,7 @@ public class ProductModelValueBuilder implements ViewBuilder {
}
@Override
public void finish(){
public void finish() {
INDEX_REBUILD_LOG.info("ProductModelValueBuilder finish");
dateId = null;
}
... ...
... ... @@ -4,8 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.FileUtils;
import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
import com.yoho.search.consumer.job.ProductHeatValueJob;
import com.yoho.search.consumer.job.ProductModelValueJob;
import com.yoho.search.consumer.job.CleanDataJob;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.dal.SknImageVectorsMapper;
import com.yoho.search.dal.model.SknImageVectors;
... ... @@ -28,9 +27,7 @@ public class TestApiController {
private static final Logger logger = LoggerFactory.getLogger(TestApiController.class);
@Autowired
private ProductHeatValueJob productHeatValueJob;
@Autowired
private ProductModelValueJob productModelValueJob;
private CleanDataJob cleanDataJobJob;
@Autowired
private CommonBulkService commonBulkService;
@Autowired
... ... @@ -48,14 +45,14 @@ public class TestApiController {
return testResult;
}
@RequestMapping(value = "/doCleanHeatValue")
@RequestMapping(value = "/doCleanData")
@ResponseBody
public Map<String, Object> doCleanHeatValue() {
Map<String, Object> returnMap = new HashMap<String, Object>();
try {
returnMap.put("code", 200);
returnMap.put("message", "success");
productHeatValueJob.clean();
cleanDataJobJob.clean();
} catch (Exception e) {
logger.error(e.getMessage(), e);
returnMap.put("code", 400);
... ... @@ -64,21 +61,6 @@ public class TestApiController {
return returnMap;
}
@RequestMapping(value = "/doCleanProductModelValue")
@ResponseBody
public Map<String, Object> doCleanProductModelValue() {
Map<String, Object> returnMap = new HashMap<String, Object>();
try {
returnMap.put("code", 200);
returnMap.put("message", "success");
productModelValueJob.clean();
} catch (Exception e) {
logger.error(e.getMessage(), e);
returnMap.put("code", 400);
returnMap.put("message", e.getMessage());
}
return returnMap;
}
@RequestMapping(value = "/putImageVectorDataToDB")
@ResponseBody
... ...