...
|
...
|
@@ -6,8 +6,13 @@ import com.yoho.error.event.SearchLogsEvent; |
|
|
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.service.base.ProductService;
|
|
|
import com.yoho.search.consumer.service.base.ProductTimingService;
|
|
|
import com.yoho.search.consumer.service.logic.ProductIndexLogicService;
|
|
|
import com.yoho.search.dal.model.Product;
|
|
|
import com.yoho.search.dal.model.ProductTiming;
|
|
|
import com.yoho.search.dal.model.StorageUpdateTime;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -18,13 +23,16 @@ import org.springframework.context.ApplicationEventPublisher; |
|
|
import org.springframework.context.ApplicationEventPublisherAware;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by wangnan on 2016/11/24.
|
|
|
*/
|
|
|
@Component
|
|
|
public class ProductTimingMqListener implements ChannelAwareMessageListener, ApplicationEventPublisherAware {
|
|
|
public class ProductTimingMqListener extends AbstractMqListener implements ChannelAwareMessageListener, ApplicationEventPublisherAware {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductTimingMqListener.class);
|
|
|
|
...
|
...
|
@@ -32,6 +40,10 @@ public class ProductTimingMqListener implements ChannelAwareMessageListener, App |
|
|
|
|
|
@Autowired
|
|
|
private ProductTimingService productTimingService;
|
|
|
@Autowired
|
|
|
private ProductIndexLogicService productIndexLogicService;
|
|
|
@Autowired
|
|
|
private ProductService productService;
|
|
|
|
|
|
protected ApplicationEventPublisher publisher;
|
|
|
|
...
|
...
|
@@ -48,7 +60,7 @@ public class ProductTimingMqListener implements ChannelAwareMessageListener, App |
|
|
JSONObject json = JSONObject.parseObject(messageStr);
|
|
|
String idField = "id";
|
|
|
if (ISearchConstants.ACTION_DELETE.equals(json.getString("action"))) {
|
|
|
deleteData(json.getString("data"));
|
|
|
deleteData(json.getObject("data", Map.class), idField);
|
|
|
} else if (ISearchConstants.ACTION_UPDATE.equals(json.getString("action"))) {
|
|
|
updateData(json.getObject("data", Map.class), idField);
|
|
|
} else {
|
...
|
...
|
@@ -77,14 +89,48 @@ public class ProductTimingMqListener implements ChannelAwareMessageListener, App |
|
|
productTimingService.saveOrUpdate(productTiming);
|
|
|
String idValue = data.get(idField).toString();
|
|
|
logger.info("[func=updateData][step=success][tableName=productTiming][id={}][cost={}ms]", idValue, (System.currentTimeMillis() - begin));
|
|
|
//更新productIndex
|
|
|
Product product = productService.getBySkn(productTiming.getProductSkn());
|
|
|
if(product!=null&&product.getId()!=null&&product.getId()!=null){
|
|
|
this.updateProductIndex(product.getId(),product.getErpProductId(), System.currentTimeMillis());
|
|
|
logger.info("[class=ProductTimingMqListener][func=updateProductIndex][id={}][cost={}ms]", idValue, (System.currentTimeMillis() - begin));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void deleteData(final String id) {
|
|
|
if (StringUtils.isBlank(id)) {
|
|
|
public void deleteData(final Map data, final String idField) {
|
|
|
if (StringUtils.isBlank(idField)) {
|
|
|
return;
|
|
|
}
|
|
|
long begin = System.currentTimeMillis();
|
|
|
productTimingService.delete(Integer.valueOf(id));
|
|
|
logger.info("[func=deleteData][step=success][tableName=productTiming][id={}][cost={}ms]", id, (System.currentTimeMillis() - begin));
|
|
|
ProductTiming productTiming = new ProductTiming();
|
|
|
productTiming = (ProductTiming) ConvertUtils.toJavaBean(productTiming, data);
|
|
|
if (productTiming == null || productTiming.getId() == null) {
|
|
|
return;
|
|
|
}
|
|
|
//更新productIndex
|
|
|
Product product = productService.getBySkn(productTiming.getProductSkn());
|
|
|
if(product!=null&&product.getId()!=null&&product.getId()!=null){
|
|
|
this.updateProductIndex(product.getId(),product.getErpProductId(), System.currentTimeMillis());
|
|
|
logger.info("[class=ProductTimingMqListener][func=updateProductIndex][id={}][cost={}ms]", idField, (System.currentTimeMillis() - begin));
|
|
|
}
|
|
|
productTimingService.delete(Integer.valueOf(idField));
|
|
|
logger.info("[func=deleteData][step=success][tableName=productTiming][id={}][cost={}ms]", idField, (System.currentTimeMillis() - begin));
|
|
|
}
|
|
|
|
|
|
private void updateProductIndex(Integer productId,Integer productSkn, long begin) {
|
|
|
Map<String, Object> indexData = new HashMap<String, Object>();
|
|
|
indexData.put("productId", productId);
|
|
|
//获取storageUpdateTime
|
|
|
List<Integer> productIds = new ArrayList<>();
|
|
|
List<Integer> skns = new ArrayList<>();
|
|
|
productIds.add(productId);
|
|
|
skns.add(productSkn);
|
|
|
List<StorageUpdateTime> storageUpdateTimes = productIndexLogicService.getStorageUpdateTimeBO(productIds,skns);
|
|
|
if (CollectionUtils.isNotEmpty(storageUpdateTimes)) {
|
|
|
StorageUpdateTime storageUpdateTime = storageUpdateTimes.get(0);
|
|
|
indexData.put("storageUpdateTime", storageUpdateTime.getStorageUpdateTime());
|
|
|
}
|
|
|
this.updateProductIndexWithDataMap(indexData, productId, null, begin);
|
|
|
}
|
|
|
} |
...
|
...
|
|