CutDownPriceActivityConsumer.java 1.72 KB
package com.yoho.dsf.mqapi.consumer;

import com.alibaba.fastjson.JSONObject;
import com.yoho.activity.common.redis.CacheKeyEnum;
import com.yoho.activity.common.redis.RedisValueCache;
import com.yoho.activity.dal.CutDownPriceActivityMapper;
import com.yoho.activity.dal.model.CutDownPriceActivity;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yoho.dsf.mqapi.constants.MqConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value="cutDownPriceActivityConsumer")
public class CutDownPriceActivityConsumer implements YhConsumer {
	private static final Logger LOGGER = LoggerFactory.getLogger(CutDownPriceActivityConsumer.class);

	@Autowired
	private CutDownPriceActivityMapper cutDownPriceActivityMapper;
	@Autowired
	private RedisValueCache redisValueCache;

	@Override
	public void handleMessage(Object message) {
		LOGGER.info("begin CutDownPriceActivityConsumer.handleMessage message is:{}, topic is:{}", MqConstants.MQ_SYN_CUTDOWNPRICE_ACTIVITY);
		try {
			CutDownPriceActivity cutDownPriceActivity = JSONObject.parseObject(String.valueOf(message), CutDownPriceActivity.class);
			if (null != cutDownPriceActivity){
				cutDownPriceActivityMapper.updateCutDownPriceActivity(cutDownPriceActivity);
				//更新的时候清除缓存
				if (cutDownPriceActivity.getActivityId() != null){
					String redisKeySuffix = cutDownPriceActivity.getActivityId() + "";
					redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_ACTIVITYBO_INFO,redisKeySuffix);
				}
			}
		} catch (Exception e) {
			LOGGER.warn("handle CutDownPriceActivityConsumer info message failed!! message is " + String.valueOf(message),e);
		}
	}

}