Authored by unknown

customizetag

... ... @@ -23,4 +23,7 @@ public interface ActivityTagMapper {
List<ActivityTag> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize);
int selectCount();
List<ActivityTag> selectLists();
}
\ No newline at end of file
... ...
... ... @@ -179,4 +179,7 @@
<select id="selectCount" resultType="java.lang.Integer" timeout="20000" >
SELECT count(1) FROM activity_tag
</select>
<select id="selectLists" resultMap="BaseResultMap" timeout="20000">
select <include refid="Base_Column_List" /> from activity_tag where status = 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.increment.AbstractIndexMqListener;
import com.yoho.search.consumer.service.daoService.ActivityTagService;
import com.yoho.search.consumer.service.logicService.productIndex.ProductCustomizeTagBuilder;
import com.yoho.search.dal.model.ActivityTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -21,6 +22,8 @@ public class ActivityTagMqListener extends AbstractIndexMqListener {
private ActivityTagService activityTagService;
@Autowired
private IYohoIndexService indexService;
@Autowired
private ProductCustomizeTagBuilder productCustomizeTagBuilder;
@Override
protected String getIndexName() {
... ... @@ -35,6 +38,7 @@ public class ActivityTagMqListener extends AbstractIndexMqListener {
@Override
protected void deleteData(String id) throws Exception {
activityTagService.delete(Integer.valueOf(id));
productCustomizeTagBuilder.buildActivityTagsMap();
indexService.deleteIndexData(this.getIndexName(), id);
}
... ... @@ -45,6 +49,7 @@ public class ActivityTagMqListener extends AbstractIndexMqListener {
return;
}
activityTagService.saveOrUpdate(activityTag);
productCustomizeTagBuilder.buildActivityTagsMap();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",activityTag.getId());
jsonObject.put("activityName",activityTag.getActivityName());
... ...
... ... @@ -9,12 +9,11 @@ import com.yoho.search.consumer.common.CostStatistics;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.ProductIndexIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractIndexMqListener;
import com.yoho.search.consumer.service.daoService.ProductPriceService;
import com.yoho.search.consumer.service.daoService.ProductService;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductPriceBO;
import com.yoho.search.consumer.service.logicService.ProductPriceBOLogicService;
import com.yoho.search.consumer.service.logicService.productIndex.ProductPriceBuilder;
import com.yoho.search.consumer.service.logicService.productIndex.ProductCustomizeTagBuilder;
import com.yoho.search.dal.model.Product;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -34,15 +33,13 @@ public class ProductMqListener extends AbstractIndexMqListener {
@Autowired
private ProductService productService;
@Autowired
private ProductPriceService productPriceService;
@Autowired
private ProductIndexMqListener productIndexMqListener;
@Autowired
private ProductPriceBuilder productPriceBuilder;
@Autowired
private ProductIndexIndexBuilder productIndexIndexBuilder;
@Autowired
private ProductPriceBOLogicService productPriceBOLogicService;
@Autowired
private ProductCustomizeTagBuilder productCustomizeTagBuilder;
@Override
public String getIndexName() {
... ... @@ -106,6 +103,8 @@ public class ProductMqListener extends AbstractIndexMqListener {
if(productPriceBO!=null){
jsonObject.putAll((JSONObject) JSON.toJSON(productPriceBO));
}
jsonObject.put("customizeTags", productCustomizeTagBuilder.buildCustomizeTagByProductId(productId));
// 4、更新到ES
try {
this.updateProductIndexWithDataMap(jsonObject, productId);
... ...
... ... @@ -9,13 +9,14 @@ import com.yoho.search.dal.model.ActivityTag;
import com.yoho.search.dal.model.Product;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by wangnan on 2017/9/11.
... ... @@ -28,21 +29,15 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder {
@Autowired
private ProductMapper productMapper;
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<Product> productList = productMapper.selectListByIds(ids);
if (CollectionUtils.isEmpty(productList)) {
return;
}
List<Integer> promotionIdList = productList.stream().map(Product::getIsPromotion).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(promotionIdList)) {
return;
}
List<ActivityTag> activityTagList = activityTagMapper.selectByIsPromotionIdList(promotionIdList);
private static Map<Integer, ActivityTag> activityTagsMap = new HashMap<>();
@PostConstruct
public void buildActivityTagsMap() throws BeansException {
activityTagsMap.clear();
List<ActivityTag> activityTagList = activityTagMapper.selectLists();
if (CollectionUtils.isEmpty(activityTagList)) {
return;
}
Map<Integer, ActivityTag> activityTagMap = new HashMap<>();
for (ActivityTag activityTag : activityTagList) {
String[] isPromotionIdArray = activityTag.getIsPromotionIds().split(",");
if (isPromotionIdArray.length == 0) {
... ... @@ -50,12 +45,21 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder {
}
for (String promotionId : isPromotionIdArray) {
if (StringUtils.isNotBlank(promotionId)) {
activityTagMap.put(Integer.valueOf(promotionId), activityTag);
activityTagsMap.put(Integer.valueOf(promotionId), activityTag);
}
}
}
}
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
List<Product> productList = productMapper.selectListByIds(ids);
if (CollectionUtils.isEmpty(productList)) {
return;
}
productIndexBOs.stream().forEach(productIndexBO -> {
ActivityTag activityTag = activityTagMap.get(productIndexBO.getIspromotion());
ActivityTag activityTag = activityTagsMap.get(productIndexBO.getIspromotion());
if (activityTag != null) {
JSONObject customizeTag = new JSONObject();
customizeTag.put("id", activityTag.getId());
... ... @@ -67,4 +71,29 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder {
}
});
}
public JSONArray buildCustomizeTagByProductId(Integer productId) {
Product product = productMapper.selectByPrimaryKey(productId);
if (product == null) {
return new JSONArray(0);
}
Integer promotionId = product.getIsPromotion();
if (promotionId == null) {
return new JSONArray(0);
}
ActivityTag activityTag = activityTagsMap.get(promotionId);
if (activityTag != null) {
JSONObject customizeTag = new JSONObject();
customizeTag.put("id", activityTag.getId());
customizeTag.put("name", activityTag.getActivityName());
customizeTag.put("url", activityTag.getTagUrl());
JSONArray customizeTags = new JSONArray();
customizeTags.add(customizeTag);
return customizeTags;
}
return new JSONArray(0);
}
}
... ...