Authored by LUOXC

refactor

package com.yohoufo.order.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.ServiceException;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -30,19 +33,37 @@ public abstract class JsonObjectMessageConsumer<M> implements YhConsumer {
messageClass = (Class) params[0];
}
public abstract String getTopic();
public abstract void handle(M message);
@Override
public void handleMessage(Object o) throws Exception {
public void handleMessage(Object jsonText) throws Exception {
String topic = getTopic();
M message;
logger.info("in topic {}, msg {}", topic, jsonText);
try {
message = JSONObject.parseObject(o.toString(), messageClass);
message = JSONObject.parseObject(jsonText.toString(), messageClass);
} catch (Exception e) {
getLogger().warn("parse message {} fail", o, e);
getLogger().warn("parse message fail, topic {}, msg {}", topic, jsonText, e);
return;
}
handle(message);
try {
handle(message);
} catch (ServiceException e) {
getLogger().warn("handler message fail, topic {}, msg {}", topic, jsonText, e);
} catch (Exception e) {
getLogger().warn("handler message fail, topic {}, msg {}", topic, jsonText, e);
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(
topic,
"ufo_mq_consumer_exception",
e.toString()
);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
}
public abstract void handle(M message);
public Logger getLogger() {
return logger;
... ...
... ... @@ -16,7 +16,8 @@ public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageC
@Autowired
private BuyerOrderCancelService buyerOrderCancelService;
public String getMessageTopic() {
@Override
public String getTopic() {
return TopicConstants.SELLER_ORDER_AUTO_CANCEL_DELIVER;
}
... ...
package com.yohoufo.order.service.impl;
import com.google.common.base.Verify;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.OrderStatus;
... ... @@ -128,9 +129,7 @@ public class BuyerOrderCancelHandler {
}
public void cancel() {
if (expectStatus == null || targetStatus == null) {
throw new ServiceException(ServiceError.ORDER_SERVICE_ERROR);
}
verify();
// 获取买家订单
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid);
// 当前状态不可取消订单
... ... @@ -146,6 +145,14 @@ public class BuyerOrderCancelHandler {
}
}
private void verify() {
Verify.verify(uid > 0, "uid is %s", uid);
Verify.verify(orderCode > 0, "orderCode is %s", orderCode);
Verify.verifyNotNull(expectStatus, "expectStatus is null");
Verify.verifyNotNull(targetStatus, "targetStatus is null");
Verify.verifyNotNull(buyerOrderMapper, "buyerOrderMapper is null");
}
private boolean updateBuyerOrderStatus() {
int rows = buyerOrderMapper.updateStatusByOrderCode(
orderCode,
... ...