...
|
...
|
@@ -4,21 +4,16 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.consumer.index.fullbuild.ufo.UfoProductIndexBuilder;
|
|
|
import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;
|
|
|
import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
|
|
|
import com.yoho.search.consumer.service.bo.ProductIndexBO;
|
|
|
import com.yoho.search.consumer.service.bo.UfoProductIndexBO;
|
|
|
import com.yoho.search.core.es.model.ESBluk;
|
|
|
import com.yoho.search.dal.UfoProductMapper;
|
|
|
import com.yoho.search.dal.model.UfoProduct;
|
|
|
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.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author wangnan
|
|
|
* @version 2018/9/14
|
...
|
...
|
@@ -29,45 +24,37 @@ public class UfoIndexUpdateHelper { |
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
@Autowired
|
|
|
private UfoProductMapper ufoProductMapper;
|
|
|
@Autowired
|
|
|
private UfoProductIndexBuilder ufoProductIndexBuilder;
|
|
|
@Autowired
|
|
|
protected CommonBulkService commonBulkService;
|
|
|
|
|
|
public void updateUfoProductIndexByBrandId(Short brandId) {
|
|
|
List<UfoProduct> ufoProductList = ufoProductMapper.selectByBrandId(brandId);
|
|
|
this.updateUfoProductIndexByProductList(ufoProductList);
|
|
|
}
|
|
|
|
|
|
public void updateUfoProductIndexByProductId(Integer productId) {
|
|
|
List<Integer> productIdList = new ArrayList<>(1);
|
|
|
productIdList.add(productId);
|
|
|
this.updateUfoProductIndexByProductIdList(productIdList);
|
|
|
}
|
|
|
private CommonBulkService commonBulkService;
|
|
|
@Autowired
|
|
|
private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;
|
|
|
|
|
|
private void updateUfoProductIndexByProductIdList(List<Integer> productIdList) {
|
|
|
List<UfoProduct> ufoProductList = ufoProductMapper.selectByIdList(productIdList);
|
|
|
this.updateUfoProductIndexByProductList(ufoProductList);
|
|
|
public void updateUfoIndex(Integer productId) {
|
|
|
try {
|
|
|
UfoProductIndexBO ufoProductIndexBO = ufoProductIndexBuilder.buildUfoProductIndexBOIncrease(productId);
|
|
|
if (ufoProductIndexBO == null) {
|
|
|
return;
|
|
|
}
|
|
|
JSONObject ufoProductIndexBOJSONObject = (JSONObject) JSON.toJSON(ufoProductIndexBO);
|
|
|
commonBulkService.add(new ESBluk(ufoProductIndexBOJSONObject.toJSONString(), ufoProductIndexBO.getId() + "", ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false));
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void updateUfoProductIndexByProductList(List<UfoProduct> ufoProductList) {
|
|
|
if (CollectionUtils.isEmpty(ufoProductList)) {
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> idList = ufoProductList.stream().map(UfoProduct::getId).collect(Collectors.toList());
|
|
|
List<UfoProductIndexBO> ufoProductIndexBOList = ufoProductIndexBuilder.buildUfoProductIndexBOIncrease(idList);
|
|
|
if (CollectionUtils.isEmpty(ufoProductIndexBOList)) {
|
|
|
return;
|
|
|
}
|
|
|
ufoProductIndexBOList.stream().forEach(p -> {
|
|
|
try {
|
|
|
JSONObject jsonObject = (JSONObject) JSON.toJSON(p);
|
|
|
commonBulkService.add(new ESBluk(jsonObject.toJSONString(), p.getId() + "", ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, false));
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
public void updateYohoIndex(Integer id) {
|
|
|
try {
|
|
|
ProductIndexBO productIndexBO = ufoToYohoIndexBuilder.buildProductIndexBOIncrease(id);
|
|
|
if (productIndexBO == null) {
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
|
JSONObject jsonObject = (JSONObject) JSON.toJSON(productIndexBO);
|
|
|
commonBulkService.add(new ESBluk(jsonObject.toJSONString(), productIndexBO.getId(), ISearchConstants.INDEX_NAME_PRODUCT_INDEX, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, false));
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|