|
|
package com.yoho.dsf.mqapi.consumer;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.rabbitmq.YhConsumer;
|
|
|
import com.yoho.dsf.mqapi.constants.MqConstants;
|
|
|
import com.yoho.dsf.mqapi.model.CutDownPriceProduct;
|
|
|
import com.yoho.dsf.mqapi.service.CutDownPriceProductService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service(value="collageProductConsumer")
|
|
|
public class CutDownPriceProductConsumer implements YhConsumer {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceProductConsumer.class);
|
|
|
|
|
|
@Autowired
|
|
|
private CutDownPriceProductService cutDownPriceProductService;
|
|
|
|
|
|
@Override
|
|
|
public void handleMessage(Object message) {
|
|
|
LOGGER.info("begin CutDownPriceProductConsumer.handleMessage message is:{}, topic is:{}", MqConstants.MQ_SYN_CUTDOWNPRICE_PRODUCT);
|
|
|
try {
|
|
|
List<CutDownPriceProduct> cutDownPriceProductList = getCutDownPriceProductList(message);
|
|
|
if (CollectionUtils.isEmpty(cutDownPriceProductList)) {
|
|
|
return;
|
|
|
}
|
|
|
if (null == cutDownPriceProductList.get(0).getActivityId()){
|
|
|
cutDownPriceProductService.updateCutDownPriceProductStatus(cutDownPriceProductList.get(0).getProductSkn(),cutDownPriceProductList.get(0).getStatus());
|
|
|
}else{
|
|
|
cutDownPriceProductService.updateCutDownPriceProduct(cutDownPriceProductList);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.warn("handle CutDownPriceProductConsumer info message failed!! message is " + String.valueOf(message),e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<CutDownPriceProduct> getCutDownPriceProductList(Object message) {
|
|
|
// 如果是单个变价,则是以 {字符 开始 否则是以 [ 字符开始
|
|
|
String value = String.valueOf(message);
|
|
|
if (StringUtils.startsWith(value, "[")) {
|
|
|
return JSON.parseArray(value, CutDownPriceProduct.class);
|
|
|
} else {
|
|
|
return Lists.newArrayList(JSON.parseObject(value, CutDownPriceProduct.class));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|