Authored by wangnan

fix

... ... @@ -8,6 +8,9 @@ import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.service.base.ShopsBrandsService;
import com.yoho.search.consumer.service.bo.ShopsBO;
import com.yoho.search.consumer.service.logic.ShopsLogicService;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.dal.model.ShopsBrands;
import org.apache.commons.lang.StringUtils;
... ... @@ -17,7 +20,10 @@ import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
... ... @@ -30,6 +36,8 @@ public class ShopsBrandsMqListener extends AbstractMqListener implements Channel
private IYohoIndexService indexService;
@Autowired
private ShopsBrandsService shopsBrandsService;
@Autowired
private ShopsLogicService shopsLogicService;
@Override
public void onMessage(Message message, Channel channel) throws Exception {
... ... @@ -51,7 +59,7 @@ public class ShopsBrandsMqListener extends AbstractMqListener implements Channel
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SHOPSBRADNSMQLISTENER_ONMESSAGE.getEventName(),
EventReportEnum.SHOPSBRADNSMQLISTENER_ONMESSAGE.getFunctionName(),
EventReportEnum.SHOPSBRADNSMQLISTENER_ONMESSAGE.getMoudleName(),"exception", IgnoreSomeException.filterSomeException(e),null));
EventReportEnum.SHOPSBRADNSMQLISTENER_ONMESSAGE.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
Thread.sleep(1000);
throw e;
}
... ... @@ -68,7 +76,15 @@ public class ShopsBrandsMqListener extends AbstractMqListener implements Channel
String idValue = shopsBrands.getId().toString();
shopsBrandsService.saveOrUpdate(shopsBrands);
logger.info("[func=updateData][step=saveToDb][indexName={}] [id={}][cost={}ms]", indexName, idValue, (System.currentTimeMillis() - begin));
indexService.updateIndexData(indexName, idValue, data);
List<Integer> ids = new ArrayList<>();
ids.add(shopsBrands.getShopsId());
List<ShopsBO> shopBOs = shopsLogicService.getShopsBOs(ids);
if (!CollectionUtils.isEmpty(shopBOs)) {
ShopsBO shopsBO = shopBOs.get(0);
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(JSONObject.toJSONString(this.beanToMap(shopsBO)), shopsBO.getShopsId().toString(), indexName, indexName, false));
indexService.bulk(results);
}
logger.info("[func=updateData][step=success][indexName={}] [id={}][cost={}ms]", indexName, idValue, (System.currentTimeMillis() - begin));
}
... ... @@ -77,9 +93,23 @@ public class ShopsBrandsMqListener extends AbstractMqListener implements Channel
return;
}
long begin = System.currentTimeMillis();
ShopsBrands shopsBrands = shopsBrandsService.getById(Integer.valueOf(id));
shopsBrandsService.delete(Integer.valueOf(id));
logger.info("[func=deleteData][step=deleteFromDb][indexName={}] [id={}][cost={}ms]", indexName, id, (System.currentTimeMillis() - begin));
indexService.deleteIndexData(indexName, id);
List<Integer> ids = new ArrayList<>();
ids.add(shopsBrands.getShopsId());
List<ShopsBO> shopBOs = shopsLogicService.getShopsBOs(ids);
if (!CollectionUtils.isEmpty(shopBOs)) {
ShopsBO shopsBO = shopBOs.get(0);
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(JSONObject.toJSONString(this.beanToMap(shopsBO)), shopsBO.getShopsId().toString(), indexName, indexName, false));
indexService.bulk(results);
}
logger.info("[func=deleteData][step=success][indexName={}][id={}][cost={}ms]", indexName, id, (System.currentTimeMillis() - begin));
}
private Map<String, Object> beanToMap(ShopsBO shopsBO) {
JSONObject josnoJsonObject = (JSONObject) JSONObject.toJSON(shopsBO);
return josnoJsonObject;
}
}
... ...
... ... @@ -20,11 +20,13 @@ import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by wangnan on 2016/12/1.
*/
... ... @@ -79,10 +81,12 @@ public class ShopsMqListener extends AbstractMqListener implements ChannelAwareM
List<Integer> ids = new ArrayList<>();
ids.add(shops.getShopsId());
List<ShopsBO> shopBOs = shopsLogicService.getShopsBOs(ids);
ShopsBO shopsBO = shopBOs.get(0);
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(JSONObject.toJSONString(this.beanToMap(shopsBO)), shopsBO.getShopsId().toString(), indexName, indexName, false));
indexService.bulk(results);
if(!CollectionUtils.isEmpty(shopBOs)){
ShopsBO shopsBO = shopBOs.get(0);
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(JSONObject.toJSONString(this.beanToMap(shopsBO)), shopsBO.getShopsId().toString(), indexName, indexName, false));
indexService.bulk(results);
}
logger.info("[func=updateData][step=success][indexName={}] [id={}][cost={}ms]", indexName, idValue, (System.currentTimeMillis() - begin));
}
... ...
... ... @@ -66,7 +66,7 @@ public class ShopsLogicService {
StringBuilder brandNameCn = new StringBuilder();
StringBuilder brandNameEn = new StringBuilder();
StringBuilder brandDomain = new StringBuilder();
for (ShopsBrands shopsBrand : shopsBrandss) {
for (SshophopsBrands shopsBrand : shopsBrandss) {
Brand brand = brandMapper.selectByPrimaryKey(shopsBrand.getBrandId());
if (brand != null) {
brandName.append(brand.getBrandName() + ",");
... ...