|
|
package com.yoho.search.consumer.service.logic.productIndex.viewBuilder;
|
|
|
|
|
|
import com.yoho.search.consumer.service.bo.ProductIndexBO;
|
|
|
import com.yoho.search.dal.ShopMapper;
|
|
|
import com.yoho.search.dal.model.Shops;
|
|
|
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.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by wangnan on 2017/3/23.
|
|
|
*/
|
|
|
@Component
|
|
|
public class ShopBuilder implements ViewBuilder {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(ShopBuilder.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ShopMapper shopMapper;
|
|
|
|
|
|
@Override
|
|
|
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) {
|
|
|
List<Shops> shopsList = shopMapper.getPageLists(0, Integer.MAX_VALUE);
|
|
|
if (CollectionUtils.isEmpty(shopsList)) {
|
|
|
logger.warn("[class=GeneralDataBuilder][func=buildDataFromProductI] shopsList is empty");
|
|
|
return;
|
|
|
}
|
|
|
Map<Integer, Shops> shopMap = new HashMap<>();
|
|
|
shopsList.stream().collect(Collectors.toList()).forEach(shops -> shopMap.put(shops.getShopsId(), shops));
|
|
|
|
|
|
for (ProductIndexBO productIndexBO : productIndexBOs) {
|
|
|
Shops shops = shopMap.get(productIndexBO.getShopId());
|
|
|
if (shops != null) {
|
|
|
productIndexBO.setShopName(shops.getShopName());
|
|
|
productIndexBO.setShopDomain(shops.getShopDomain());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|