Authored by wangnan9279

fix

Showing 19 changed files with 160 additions and 340 deletions
... ... @@ -13,10 +13,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
... ... @@ -61,12 +58,21 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application
/**
* 增量
*/
public List<UfoProductIndexBO> buildUfoProductIndexBOIncrease(List<Integer> idList) {
List<UfoProduct> ufoProductList = ufoProductMapper.selectByIdList(idList);
if (CollectionUtils.isEmpty(ufoProductList)) {
return new ArrayList<>(0);
public UfoProductIndexBO buildUfoProductIndexBOIncrease(Integer id) {
UfoProduct ufoProduct = ufoProductMapper.selectByPrimaryKey(id);
if (ufoProduct == null) {
return null;
}
return buildUfoProductIndexBOList(ufoProductList);
List<UfoProduct> ufoProductList = Arrays.asList(ufoProduct);
List<UfoProductIndexBO> ufoProductIndexBOList = buildUfoProductIndexBOList(ufoProductList);
if (CollectionUtils.isEmpty(ufoProductIndexBOList)) {
return null;
}
UfoProductIndexBO ufoProductIndexBO = ufoProductIndexBOList.get(0);
if (ufoProductIndexBO == null) {
return null;
}
return ufoProductIndexBO;
}
/**
... ... @@ -77,24 +83,28 @@ public class UfoProductIndexBuilder extends IIndexBuilder implements Application
for (UfoProduct ufoProduct : ufoProductList) {
UfoProductIndexBO ufoProductIndexBO = new UfoProductIndexBO();
BeanUtils.copyProperties(ufoProduct, ufoProductIndexBO);
//基本属性
ufoProductIndexBO.setIdString(ufoProduct.getId().toString());
ufoProductIndexBO.setGenderS("男,女");
if (ufoProduct.getGender() != null) {
if (ufoProduct.getGender().equals("1")) {
ufoProductIndexBO.setGenderS("男");
}
if (ufoProduct.getGender().equals("2")) {
ufoProductIndexBO.setGenderS("女");
}
}
this.buildSimpleField(ufoProduct, ufoProductIndexBO);
ufoProductIndexBOList.add(ufoProductIndexBO);
}
List<Integer> idList = ufoProductList.stream().map(UfoProduct::getId).collect(Collectors.toList());
//调用每个builder构建UfoProductIndexBO的各种属性数据
indexFieldBuilderList.stream().forEach(viewBuilder -> viewBuilder.build(ufoProductIndexBOList, idList));
indexFieldBuilderList.stream().forEach(builder -> builder.build(ufoProductIndexBOList, idList));
return ufoProductIndexBOList;
}
private void buildSimpleField(UfoProduct ufoProduct, UfoProductIndexBO ufoProductIndexBO) {
ufoProductIndexBO.setIdString(ufoProduct.getId().toString());
ufoProductIndexBO.setGenderS("男,女");
if (ufoProduct.getGender() == null) {
return;
}
if ("1".equals(ufoProduct.getGender())) {
ufoProductIndexBO.setGenderS("男");
}
if ("2".equals(ufoProduct.getGender())) {
ufoProductIndexBO.setGenderS("女");
}
}
}
... ...
... ... @@ -7,22 +7,13 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.tbl.TblBrandIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
import com.yoho.search.consumer.service.daoService.tbl.TblBrandService;
import com.yoho.search.consumer.service.daoService.tbl.TblProductService;
import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.TblBrand;
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;
/**
* Created by wangnan on 2016/12/16.
*/
... ... @@ -30,17 +21,11 @@ import java.util.List;
@SearchMqConsumerListerner(tableName = "tbl_brand")
public class TblBrandMqListener extends AbstractMqListener {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private TblBrandService tblBrandService;
@Autowired
private IYohoIndexService indexService;
@Autowired
private TblProductService tblProductService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Autowired
private BasicDataCacheService basicDataCacheService;
@Autowired
private TblBrandIndexBuilder tblBrandIndexBuilder;
... ... @@ -57,37 +42,19 @@ public class TblBrandMqListener extends AbstractMqListener {
@Override
protected void deleteData(String id) throws Exception {
long begin = System.currentTimeMillis();
// update DB
tblBrandService.delete(Integer.valueOf(id));
// update ES index:brand
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(null, "-" + id, this.getIndexName(), this.getIndexName(), true));
indexService.bulk(results);
logger.info("[func=deleteData][tableName=tblBrand][id={}][cost={}ms]", id, (System.currentTimeMillis() - begin));
indexService.deleteIndexData(this.getIndexName(), id);
}
@Override
protected void updateData(JSONObject data) throws Exception {
long begin = System.currentTimeMillis();
TblBrand tblBrand = (TblBrand) ConvertUtils.transMap2Bean(TblBrand.class, data);
if (tblBrand == null || tblBrand.getBrandId() == null) {
return;
}
//update DB
tblBrandService.saveOrUpdate(tblBrand);
//update TblBrand index
tblBrandIndexBuilder.filterTblBrand(tblBrand);
indexService.updateIndexData(this.getIndexName(), tblBrand.getBrandId().toString(), tblBrand);
//update ProductIndex、tblProduct index
List<Integer> sknList = tblProductService.getSknsByBrandId(tblBrand.getBrandId());
if (CollectionUtils.isEmpty(sknList)) {
return;
}
for (Integer skn : sknList) {
globalIndexBulkService.updateGlobalIndex(skn);
}
logger.info("[func=updateData][tableName=tblBrand][id={}][cost={}ms]", tblBrand.getBrandId(), (System.currentTimeMillis() - begin));
}
@Override
... ...
... ... @@ -3,14 +3,11 @@ package com.yoho.search.consumer.index.increment.tbl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
import com.yoho.search.consumer.service.daoService.tbl.TblProductService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.TblProduct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -21,45 +18,30 @@ import org.springframework.stereotype.Component;
@SearchMqConsumerListerner(tableName = "tbl_product")
public class TblProductMqListener extends AbstractMqListener {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private TblProductService tblProductService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLPRODUCTMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
long begin = System.currentTimeMillis();
// update DB
tblProductService.delete(Integer.valueOf(id));
// updateES Index: ProductIndex、TblProductNew
globalIndexBulkService.deleteGlobalIndex(Integer.valueOf(id));
logger.info("[func=deleteData][tableName=tblProduct][skn={}][cost={}ms]", Integer.valueOf(id), (System.currentTimeMillis() - begin));
}
@Override
protected void updateData(JSONObject data) throws Exception {
long begin = System.currentTimeMillis();
TblProduct tblProduct = (TblProduct) ConvertUtils.transMap2Bean(TblProduct.class, data);
if (tblProduct == null || tblProduct.getProductSkn() == null) {
return;
}
// updateDB
tblProductService.saveOrUpdate(tblProduct);
// updateES Index:ProductIndex、TblProductNew
globalIndexBulkService.updateGlobalIndex(tblProduct.getProductSkn());
logger.info("[func=updateData][tableName=tblProduct][skn={}][cost={}ms]", tblProduct.getProductSkn(), (System.currentTimeMillis() - begin));
}
}
... ...
... ... @@ -3,14 +3,11 @@ package com.yoho.search.consumer.index.increment.tbl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
import com.yoho.search.consumer.service.daoService.tbl.TblProductSkcService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.TblProductSkc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -21,49 +18,34 @@ import org.springframework.stereotype.Component;
@SearchMqConsumerListerner(tableName = "tbl_product_skc")
public class TblProductSkcMqListener extends AbstractMqListener {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private TblProductSkcService tblProductSkcService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLPRODUCTSKCMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
long begin = System.currentTimeMillis();
TblProductSkc tblProductSkc = tblProductSkcService.getById(Integer.valueOf(id));
if (tblProductSkc == null) {
return;
}
// delete DB
tblProductSkcService.delete(Integer.valueOf(id));
// update ES:ProductIndex、TblProductNew
globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());
logger.info("[func=deleteData][tableName=TblProductSkc][skc={}][cost={}ms]", tblProductSkc.getProductSkc(), (System.currentTimeMillis() - begin));
}
@Override
protected void updateData(JSONObject data) throws Exception {
long begin = System.currentTimeMillis();
TblProductSkc tblProductSkc = (TblProductSkc) ConvertUtils.transMap2Bean(TblProductSkc.class, data);
if (tblProductSkc == null || tblProductSkc.getProductSkc() == null) {
return;
}
// update DB
tblProductSkcService.saveOrUpdate(tblProductSkc);
// update ES:ProductIndex、TblProductNew
globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());
logger.info("[func=updateData][tableName=TblProductSkc][skc={}][cost={}ms]", tblProductSkc.getProductSkc(), (System.currentTimeMillis() - begin));
}
@Autowired
private TblProductSkcService tblProductSkcService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLPRODUCTSKCMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
TblProductSkc tblProductSkc = tblProductSkcService.getById(Integer.valueOf(id));
if (tblProductSkc == null) {
return;
}
tblProductSkcService.delete(Integer.valueOf(id));
globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());
}
@Override
protected void updateData(JSONObject data) throws Exception {
TblProductSkc tblProductSkc = (TblProductSkc) ConvertUtils.transMap2Bean(TblProductSkc.class, data);
if (tblProductSkc == null || tblProductSkc.getProductSkc() == null) {
return;
}
tblProductSkcService.saveOrUpdate(tblProductSkc);
globalIndexBulkService.updateGlobalIndex(tblProductSkc.getProductSkn());
}
}
... ...
... ... @@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.tbl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
import com.yoho.search.consumer.service.daoService.tbl.TblProductSkuService;
... ... @@ -23,47 +22,34 @@ public class TblProductSkuMqListener extends AbstractMqListener {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private TblProductSkuService tblProductSkuService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLPRODUCTSKUMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
long begin = System.currentTimeMillis();
TblProductSku tblProductSku = tblProductSkuService.getById(Integer.valueOf(id));
if (tblProductSku == null) {
return;
}
// delete DB
tblProductSkuService.delete(Integer.valueOf(id));
// update ES:ProductIndex、TblProductNew
globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());
logger.info("[func=deleteData][tableName=TblProductSku][sku={}][cost={}ms]", tblProductSku.getProductSku(), (System.currentTimeMillis() - begin));
}
@Override
protected void updateData(JSONObject data) throws Exception {
long begin = System.currentTimeMillis();
TblProductSku tblProductSku = (TblProductSku) ConvertUtils.transMap2Bean(TblProductSku.class, data);
if (tblProductSku == null || tblProductSku.getProductSku() == null) {
return;
}
// update DB
tblProductSkuService.saveOrUpdate(tblProductSku);
// update ES:ProductIndex、TblProductNew
globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());
logger.info("[func=updateData][tableName=TblProductSku][sku={}][cost={}ms]", tblProductSku.getProductSku(), (System.currentTimeMillis() - begin));
}
@Autowired
private TblProductSkuService tblProductSkuService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLPRODUCTSKUMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
TblProductSku tblProductSku = tblProductSkuService.getById(Integer.valueOf(id));
if (tblProductSku == null) {
return;
}
tblProductSkuService.delete(Integer.valueOf(id));
globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());
}
@Override
protected void updateData(JSONObject data) throws Exception {
TblProductSku tblProductSku = (TblProductSku) ConvertUtils.transMap2Bean(TblProductSku.class, data);
if (tblProductSku == null || tblProductSku.getProductSku() == null) {
return;
}
tblProductSkuService.saveOrUpdate(tblProductSku);
globalIndexBulkService.updateGlobalIndex(tblProductSku.getProductSkn());
}
}
... ...
... ... @@ -3,22 +3,14 @@ package com.yoho.search.consumer.index.increment.tbl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.index.increment.bulks.GlobalIndexBulkService;
import com.yoho.search.consumer.service.daoService.tbl.TblProductService;
import com.yoho.search.consumer.service.daoService.tbl.TblSiteService;
import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.TblSite;
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;
/**
* Created by wangnan on 2016/12/16.
*/
... ... @@ -26,65 +18,29 @@ import java.util.List;
@SearchMqConsumerListerner(tableName = "tbl_site")
public class TblSiteMqListener extends AbstractMqListener {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private TblSiteService tblSiteService;
@Autowired
private TblProductService tblProductService;
@Autowired
private GlobalIndexBulkService globalIndexBulkService;
@Autowired
private BasicDataCacheService basicDataCacheService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLSITEMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
long begin = System.currentTimeMillis();
TblSite tblSite = tblSiteService.getById(Integer.valueOf(id));
if (tblSite == null) {
return;
}
// update DB
tblSiteService.delete(Integer.valueOf(id));
// update ES:ProductIndex、TblProductNew
List<Integer> sknList = tblProductService.getSknsBySiteId(tblSite.getSiteId());
if (CollectionUtils.isEmpty(sknList)) {
return;
}
for (Integer skn : sknList) {
globalIndexBulkService.updateGlobalIndex(skn);
}
logger.info("[func=deleteData][tableName=TblSite][id={}][cost={}ms]", tblSite.getSiteId(), (System.currentTimeMillis() - begin));
}
@Override
protected void updateData(JSONObject data) throws Exception {
long begin = System.currentTimeMillis();
TblSite tblSite = (TblSite) ConvertUtils.transMap2Bean(TblSite.class, data);
if (tblSite == null || tblSite.getSiteId() == null) {
return;
}
// update DB
tblSiteService.saveOrUpdate(tblSite);
// update ES
List<Integer> sknList = tblProductService.getSknsBySiteId(tblSite.getSiteId());
if (CollectionUtils.isEmpty(sknList)) {
return;
}
for (Integer skn : sknList) {
globalIndexBulkService.updateGlobalIndex(skn);
}
logger.info("[func=updateData][tableName=TblSite][id={}][cost={}ms]", tblSite.getSiteId(), (System.currentTimeMillis() - begin));
}
@Override
... ...
... ... @@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.tbl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.daoService.tbl.TblSortService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
... ... @@ -18,31 +17,26 @@ import org.springframework.stereotype.Component;
@SearchMqConsumerListerner(tableName = "tbl_sort")
public class TblSortMqListener extends AbstractMqListener {
@Autowired
private TblSortService tblSortService;
@Autowired
private TblSortService tblSortService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLSORTMQLISTENER_ONMESSAGE;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.TBLSORTMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
tblSortService.delete(Integer.valueOf(id));
}
@Override
protected void deleteData(String id) throws Exception {
tblSortService.delete(Integer.valueOf(id));
}
@Override
protected void updateData(JSONObject data) throws Exception {
TblSort tblSort = (TblSort) ConvertUtils.transMap2Bean(TblSort.class, data);
if (tblSort == null || tblSort.getSortId() == null) {
return;
}
tblSortService.saveOrUpdate(tblSort);
}
@Override
protected void updateData(JSONObject data) throws Exception {
TblSort tblSort = (TblSort) ConvertUtils.transMap2Bean(TblSort.class, data);
if (tblSort == null || tblSort.getSortId() == null) {
return;
}
tblSortService.saveOrUpdate(tblSort);
}
}
... ...
... ... @@ -26,8 +26,6 @@ public class UfoBrandMqListener extends AbstractMqListener {
@Autowired
private IYohoIndexService indexService;
@Autowired
private UfoIndexUpdateHelper ufoIndexUpdateHelper;
@Autowired
private BasicDataCacheService basicDataCacheService;
@Override
... ... @@ -42,11 +40,7 @@ public class UfoBrandMqListener extends AbstractMqListener {
@Override
protected void deleteData(String id) throws Exception {
UfoBrand ufoBrand = ufoBrandService.getById(Short.valueOf(id));
ufoBrandService.delete(Short.valueOf(id));
if (ufoBrand != null) {
ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrand.getId());
}
indexService.deleteIndexData(this.getIndexName(), id);
}
... ... @@ -58,7 +52,6 @@ public class UfoBrandMqListener extends AbstractMqListener {
}
ufoBrandService.saveOrUpdate(ufoBrand);
indexService.updateIndexData(this.getIndexName(), ufoBrand.getId().toString(), ufoBrand);
ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrand.getId());
}
@Override
... ...
... ... @@ -22,8 +22,6 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener {
@Autowired
private UfoBrandSeriesService ufoBrandSeriesService;
@Autowired
private UfoIndexUpdateHelper ufoIndexUpdateHelper;
@Autowired
private BasicDataCacheService basicDataCacheService;
@Override
... ... @@ -33,11 +31,7 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener {
@Override
protected void deleteData(String id) throws Exception {
UfoBrandSeries ufoBrandSeries = ufoBrandSeriesService.getById(Short.valueOf(id));
ufoBrandSeriesService.delete(Short.valueOf(id));
if (ufoBrandSeries != null) {
ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrandSeries.getBrandId());
}
}
@Override
... ... @@ -47,7 +41,6 @@ public class UfoBrandSeriesMqListener extends AbstractMqListener {
return;
}
ufoBrandSeriesService.saveOrUpdate(ufoBrandSeries);
ufoIndexUpdateHelper.updateUfoProductIndexByBrandId(ufoBrandSeries.getBrandId());
}
@Override
... ...
... ... @@ -34,7 +34,8 @@ public class UfoGoodsMqListener extends AbstractMqListener {
UfoGoods ufoGoods = ufoGoodsService.getById(Integer.valueOf(id));
ufoGoodsService.delete(Integer.valueOf(id));
if (ufoGoods != null) {
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoGoods.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoGoods.getProductId());
ufoIndexUpdateHelper.updateYohoIndex(ufoGoods.getProductId());
}
}
... ... @@ -45,6 +46,7 @@ public class UfoGoodsMqListener extends AbstractMqListener {
return;
}
ufoGoodsService.saveOrUpdate(ufoGoods);
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoGoods.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoGoods.getProductId());
ufoIndexUpdateHelper.updateYohoIndex(ufoGoods.getProductId());
}
}
... ...
... ... @@ -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);
}
}
}
... ...
package com.yoho.search.consumer.index.increment.ufo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.ufo.UfoToYohoIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.daoService.ufo.UfoProductService;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.UfoProduct;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -30,8 +26,6 @@ public class UfoProductMqListener extends AbstractMqListener {
private IYohoIndexService indexService;
@Autowired
private UfoIndexUpdateHelper ufoIndexUpdateHelper;
@Autowired
private UfoToYohoIndexBuilder ufoToYohoIndexBuilder;
@Override
public String getIndexName() {
... ... @@ -48,8 +42,7 @@ public class UfoProductMqListener extends AbstractMqListener {
protected void deleteData(String id) throws Exception {
ufoProductService.delete(Integer.valueOf(id));
indexService.deleteIndexData(this.getIndexName(), id);
//更新YOHO索引
this.updateYohoIndex(Integer.valueOf(id));
ufoIndexUpdateHelper.updateYohoIndex(Integer.valueOf(id));
}
@Override
... ... @@ -59,18 +52,8 @@ public class UfoProductMqListener extends AbstractMqListener {
return;
}
ufoProductService.saveOrUpdate(ufoProduct);
//更新UFO索引
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoProduct.getId());
//更新YOHO索引
this.updateYohoIndex(ufoProduct.getId());
ufoIndexUpdateHelper.updateUfoIndex(ufoProduct.getId());
ufoIndexUpdateHelper.updateYohoIndex(ufoProduct.getId());
}
private void updateYohoIndex(Integer id) {
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));
}
}
... ...
... ... @@ -40,7 +40,7 @@ public class UfoProductPoolDetailMqListener extends AbstractMqListener {
UfoProductPoolDetail ufoProductPoolDetail = ufoProductPoolDetailService.getById(Integer.valueOf(id));
ufoProductPoolDetailService.delete(Integer.valueOf(id));
if (ufoProductPoolDetail != null) {
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoProductPoolDetail.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoProductPoolDetail.getProductId());
}
}
... ... @@ -51,6 +51,6 @@ public class UfoProductPoolDetailMqListener extends AbstractMqListener {
return;
}
ufoProductPoolDetailService.saveOrUpdate(ufoProductPoolDetail);
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoProductPoolDetail.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoProductPoolDetail.getProductId());
}
}
... ...
... ... @@ -3,7 +3,6 @@ package com.yoho.search.consumer.index.increment.ufo;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.daoService.ufo.UfoProductPoolService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
... ... @@ -23,12 +22,6 @@ public class UfoProductPoolMqListener extends AbstractMqListener {
private UfoProductPoolService ufoProductPoolService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.UFOPRODUCTPOOLMQLISTENER_ONMESSAGE;
}
... ...
... ... @@ -7,7 +7,6 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.common.IYohoIndexService;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.daoService.ufo.UfoProductSortService;
import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.UfoProductSort;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -25,15 +24,12 @@ public class UfoProductSortMqListener extends AbstractMqListener {
private UfoProductSortService ufoProductSortService;
@Autowired
private IYohoIndexService indexService;
@Autowired
private BasicDataCacheService basicDataCacheService;
@Override
public String getIndexName() {
return ISearchConstants.INDEX_NAME_UFO_SORT;
}
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.UFOPRODUCTSORTMQLISTENER_ONMESSAGE;
... ...
... ... @@ -33,7 +33,8 @@ public class UfoStorageMqListener extends AbstractMqListener {
UfoStorage ufoStorage = ufoStorageService.getById(Integer.valueOf(id));
ufoStorageService.delete(Integer.valueOf(id));
if (ufoStorage != null) {
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStorage.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoStorage.getProductId());
ufoIndexUpdateHelper.updateYohoIndex(ufoStorage.getProductId());
}
}
... ... @@ -45,6 +46,7 @@ public class UfoStorageMqListener extends AbstractMqListener {
return;
}
ufoStorageService.saveOrUpdate(ufoStorage);
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStorage.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoStorage.getProductId());
ufoIndexUpdateHelper.updateYohoIndex(ufoStorage.getProductId());
}
}
... ...
... ... @@ -33,8 +33,10 @@ public class UfoStoragePriceMqListener extends AbstractMqListener {
UfoStoragePrice ufoStoragePrice = ufoStoragePriceService.getById(Integer.valueOf(id));
ufoStoragePriceService.delete(Integer.valueOf(id));
if (ufoStoragePrice != null) {
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStoragePrice.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoStoragePrice.getProductId());
ufoIndexUpdateHelper.updateYohoIndex(ufoStoragePrice.getProductId());
}
}
@Override
... ... @@ -44,6 +46,7 @@ public class UfoStoragePriceMqListener extends AbstractMqListener {
return;
}
ufoStoragePriceService.saveOrUpdate(ufoStoragePrice);
ufoIndexUpdateHelper.updateUfoProductIndexByProductId(ufoStoragePrice.getProductId());
ufoIndexUpdateHelper.updateUfoIndex(ufoStoragePrice.getProductId());
ufoIndexUpdateHelper.updateYohoIndex(ufoStoragePrice.getProductId());
}
}
... ...
... ... @@ -53,8 +53,8 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
*/
public void executeYohoIndex() {
long begin = System.currentTimeMillis();
logger.info("executeYohoIndex start----[begin={}]", begin);
brandRelationUtils.buildBrandRelation();
logger.info("executeYohoIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_PROMOTIONINDEX);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_SIZE);
... ... @@ -95,15 +95,17 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
}
/**
* 手动调用重建ufo所有索引
* 重建ufo所有索引
*/
public void executeUfoIndex() {
//UFO
long begin = System.currentTimeMillis();
logger.info("executeUfoIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_BRAND);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SORT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_COLOR);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SIZE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX);
logger.info("executeUfoIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
}
... ...
... ... @@ -49,21 +49,10 @@ public class UfoToYohoGeneralService {
}
//其他
productIndexBO.setShopId(-2);
productIndexBO.setIsSoonSoldOut("N");
productIndexBO.setPhysicalChannels("1,2,3,4");
productIndexBO.setAgeLevel("1");
productIndexBO.setIsGlobal("N");
productIndexBO.setIslimited("N");
productIndexBO.setIsLimitbuy("N");
productIndexBO.setIsLimitTimeAdvance("N");
productIndexBO.setIsSpecial("N");
productIndexBO.setIspromotion(0);
productIndexBO.setIsAdvance("N");
productIndexBO.setIsDepositAdvance("N");
productIndexBO.setAttribute(1);
productIndexBO.setAgeLevel("1");
productIndexBO.setIsOutlets(2);
productIndexBO.setIsPhraseExist("N");
productIndexBO.setIsSeckill("N");
productIndexBO.setPhysicalChannels("1,2,3,4");
}
}
... ...