Authored by hugufei

Merge branch 'brandkeyword'

package com.yoho.search.dal;
import com.yoho.search.dal.model.CsBrandKeyword;
import java.util.List;
public interface CsBrandKeywordMapper {
int insert(CsBrandKeyword record);
int deleteByPrimaryKey(Integer id);
int updateByPrimaryKey(CsBrandKeyword record);
CsBrandKeyword selectByPrimaryKey(Integer id);
List<CsBrandKeyword> selectAll();
}
... ...
<?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.CsBrandKeywordMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.CsBrandKeyword">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="brand_id" property="brandId" jdbcType="INTEGER"/>
<result column="keyword" property="keyword" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, brand_id, keyword, status, update_time
</sql>
<insert id="insert" parameterType="com.yoho.search.dal.model.CsBrandKeyword" timeout="20000">
insert ignore into cs_brand_keyword (id, brand_id, keyword, status, update_time)
values (#{id,jdbcType=INTEGER},#{brandId,jdbcType=INTEGER}, #{keyword,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},#{updateTime,jdbcType=VARCHAR})
</insert>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" timeout="20000">
delete from cs_brand_keyword
where id = #{id,jdbcType=INTEGER}
</delete>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.CsBrandKeyword" timeout="20000">
update cs_brand_keyword
<set>
<if test="keyword != null">
keyword = #{keyword,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" timeout="20000">
select
<include refid="Base_Column_List"/>
from cs_brand_keyword
where id = #{id,jdbcType=INTEGER}
LIMIT 1
</select>
<select id="selectAll" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List" />
from cs_brand_keyword where status = 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -13,10 +13,7 @@ import com.yoho.search.consumer.service.logicService.ProductIndexBOToMapService;
import com.yoho.search.consumer.service.logicService.ProductSknCodeService;
import com.yoho.search.consumer.service.logicService.productIndex.IndexFieldBuilder;
import com.yoho.search.dal.ProductMapper;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.ProductSort;
import com.yoho.search.dal.model.Shops;
import com.yoho.search.dal.model.*;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
... ... @@ -56,10 +53,12 @@ public class ProductIndexIndexBuilder extends IIndexBuilder implements Applicati
private static Map<Integer, ProductSort> productSortMap = new HashMap<>();
private static Map<Integer, Brand> brandMap = new HashMap<>();
private static Map<Integer, Shops> shopMap = new HashMap<>();
private static Map<Integer, CsBrandKeyword> csBrandKeywordMap = new HashMap<>();
private static String CACHE_KEY = "productIndexIndexBuilder_cache";
private static String SORT_CACHE_KEY = "sort_cache_key";
private static String BRAND_CACHE_KEY = "brand_cache_key";
private static String SHOP_CACHE_KEY = "shop_cache_key";
private static String CSBRANDKEYWORD_CACHE_KEY = "csbrandkeyword_cache_key";
//guava本地缓存保存sort,brand,shop数据
LoadingCache<String, JSONObject> cache = CacheBuilder.newBuilder()
... ... @@ -73,6 +72,7 @@ public class ProductIndexIndexBuilder extends IIndexBuilder implements Applicati
jsonObject.put(SORT_CACHE_KEY, cacheDataService.getProductSortMap());
jsonObject.put(BRAND_CACHE_KEY, cacheDataService.getBrandMap());
jsonObject.put(SHOP_CACHE_KEY, cacheDataService.getShopMap());
jsonObject.put(CSBRANDKEYWORD_CACHE_KEY, cacheDataService.getCsBrandKeywordMap());
cacheLogger.info("[ProductIndexIndexBuilder][set data to cache end]");
return jsonObject;
}
... ... @@ -172,11 +172,12 @@ public class ProductIndexIndexBuilder extends IIndexBuilder implements Applicati
productSortMap = (Map<Integer, ProductSort>) jsonObject.get(SORT_CACHE_KEY);
brandMap = (Map<Integer, Brand>) jsonObject.get(BRAND_CACHE_KEY);
shopMap = (Map<Integer, Shops>) jsonObject.get(SHOP_CACHE_KEY);
csBrandKeywordMap = (Map<Integer, CsBrandKeyword>) jsonObject.get(CSBRANDKEYWORD_CACHE_KEY);
logger.info("[fun=getProductIBOs][get sort/brand/shop data from cache][cost: {}]", System.currentTimeMillis() - begin);
} catch (ExecutionException e) {
cacheLogger.error(e.getMessage());
}
List<ProductIBO> productIBOs = productILogicService.buildProductIBO(products, productSortMap, brandMap, shopMap);
List<ProductIBO> productIBOs = productILogicService.buildProductIBO(products, productSortMap, brandMap, shopMap, csBrandKeywordMap);
logger.info("[fun=getProductIBOs][build productIBOs success][cost: {}]", System.currentTimeMillis() - begin);
return productIBOs;
}
... ...
package com.yoho.search.consumer.index.increment.productIndex;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.CsBrandKeywordMapper;
import com.yoho.search.dal.model.CsBrandKeyword;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@SearchMqConsumerListerner(tableName = "cs_brand_keyword")
public class CsBrandKeywordMqListener extends AbstractMqListener {
@Autowired
private CsBrandKeywordMapper csBrandKeywordMapper;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.CSBRANDKEYWORDMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
if (StringUtils.isNotBlank(id)) {
csBrandKeywordMapper.deleteByPrimaryKey(Integer.valueOf(id));
}
}
@Override
protected void updateData(JSONObject data) throws Exception {
CsBrandKeyword csBrandKeyword = ConvertUtils.toJavaObject(CsBrandKeyword.class, data);
if (csBrandKeyword == null || csBrandKeyword.getId() == null) {
return;
}
if (csBrandKeywordMapper.selectByPrimaryKey(csBrandKeyword.getId()) == null) {
csBrandKeywordMapper.insert(csBrandKeyword);
}else {
csBrandKeywordMapper.updateByPrimaryKey(csBrandKeyword);
}
}
}
... ...
... ... @@ -290,6 +290,10 @@
"search_analyzer": "ik_complex_search",
"fielddata": "true"
},
"csBrandKeyword": {
"type": "text",
"analyzer": "comma_spliter"
},
"countryId": {
"type": "long"
},
... ...
... ... @@ -61,6 +61,7 @@ public class ProductIBO implements Serializable {
private String brandName;
private String brandDomain;
private String brandAlif;
private String csBrandKeyword;
private Integer countryId;
// inner join product_sort
... ... @@ -395,6 +396,14 @@ public class ProductIBO implements Serializable {
this.brandKeyword = brandKeyword == null ? null : brandKeyword.trim();
}
public String getCsBrandKeyword() {
return csBrandKeyword;
}
public void setCsBrandKeyword(String csBrandKeyword) {
this.csBrandKeyword = csBrandKeyword;
}
public String getBrandName() {
return brandName;
}
... ...
... ... @@ -34,6 +34,8 @@ public class CacheDataService {
private ParameterMakeMapper parameterMakeMapper;
@Autowired
private ProductColorMapper productColorMapper;
@Autowired
private CsBrandKeywordMapper csBrandKeywordMapper;
public Map<Integer, ProductSort> getProductSortMap() {
Map<Integer, ProductSort> productSortMap = new HashMap<>();
... ... @@ -91,4 +93,14 @@ public class CacheDataService {
}
return productColorsMap;
}
public Map<Integer, CsBrandKeyword> getCsBrandKeywordMap() {
Map<Integer, CsBrandKeyword> csBrandKeywordMap = new HashMap<>();
List<CsBrandKeyword> csBrandKeywords = csBrandKeywordMapper.selectAll();
cacheLogger.info("[query DB][table=cs_brand_keyword]");
if (CollectionUtils.isNotEmpty(csBrandKeywords)) {
csBrandKeywordMap = csBrandKeywords.stream().parallel().collect(Collectors.toMap(CsBrandKeyword::getBrandId, (p) -> p));
}
return csBrandKeywordMap;
}
}
\ No newline at end of file
... ...
... ... @@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.yoho.search.dal.model.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -12,10 +13,6 @@ import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.ProductSort;
import com.yoho.search.dal.model.Shops;
/**
* Created by wangnan on 2016/6/29.
... ... @@ -32,7 +29,7 @@ public class ProductILogicService {
* 拼装ProductIBO数据(包含了product,brand,sort,shop几部分信息),全量增量都有调用
*/
public List<ProductIBO> buildProductIBO(List<Product> products, Map<Integer, ProductSort> productSortMap, Map<Integer, Brand> brandMap,
Map<Integer, Shops> shopMap) {
Map<Integer, Shops> shopMap, Map<Integer, CsBrandKeyword> csBrandKeywordMap) {
long begin = System.currentTimeMillis();
List<ProductIBO> productIBOList = new ArrayList<>();
... ... @@ -132,7 +129,7 @@ public class ProductILogicService {
productIBO.setIsLimitTimeAdvance(p.getIsLimitTimeAdvance());
productIBO.setSellType(p.getSellType());
// 品牌
this.buildBrand(brandMap, p, productIBO);
this.buildBrand(brandMap, csBrandKeywordMap, p, productIBO);
// 品类
this.buildSort(productSortMap, p, productIBO);
// 店铺
... ... @@ -148,8 +145,9 @@ public class ProductILogicService {
return productIBOList;
}
private void buildBrand(Map<Integer, Brand> brandMap, Product p, ProductIBO productIBO) {
private void buildBrand(Map<Integer, Brand> brandMap, Map<Integer, CsBrandKeyword> csBrandKeywordMap, Product p, ProductIBO productIBO) {
Brand brand = brandMap.get(p.getBrandId());
CsBrandKeyword csBrandKeyword = csBrandKeywordMap.get(p.getBrandId());
if (brand != null) {
productIBO.setBrandNameCn(brand.getBrandNameCn());
productIBO.setBrandNameEn(brand.getBrandNameEn());
... ... @@ -159,6 +157,9 @@ public class ProductILogicService {
productIBO.setBrandAlif(brand.getBrandAlif());
productIBO.setCountryId(brand.getCountryId());
}
if (csBrandKeyword != null) {
productIBO.setCsBrandKeyword(csBrandKeyword.getKeyword());
}
}
private void buildSort(Map<Integer, ProductSort> ProductSortMap, Product p, ProductIBO productIBO) {
... ...
... ... @@ -33,6 +33,7 @@ public class ProductIndexBOToMapService {
map.put(ProductIndexEsField.brandNameEn, productIndexBO.getBrandNameEn());
map.put(ProductIndexEsField.brandKeyword, productIndexBO.getBrandKeyword());
map.put(ProductIndexEsField.brandName, productIndexBO.getBrandName());
map.put(ProductIndexEsField.csBrandKeyword, productIndexBO.getCsBrandKeyword());
map.put(ProductIndexEsField.style, productIndexBO.getStyle());
map.put(ProductIndexEsField.salesPhrase, productIndexBO.getSalesPhrase());
map.put(ProductIndexEsField.maxSortId, productIndexBO.getMaxSortId());
... ...