Showing
3 changed files
with
38 additions
and
9 deletions
1 | package com.yohoufo.order.mq.consumer; | 1 | package com.yohoufo.order.mq.consumer; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | +import com.aliyun.oss.ServiceException; | ||
4 | import com.yoho.core.rabbitmq.YhConsumer; | 5 | import com.yoho.core.rabbitmq.YhConsumer; |
6 | +import com.yohoufo.common.alarm.EventBusPublisher; | ||
7 | +import com.yohoufo.common.alarm.SmsAlarmEvent; | ||
5 | import com.yohoufo.order.utils.LoggerUtils; | 8 | import com.yohoufo.order.utils.LoggerUtils; |
6 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
7 | 10 | ||
@@ -30,19 +33,37 @@ public abstract class JsonObjectMessageConsumer<M> implements YhConsumer { | @@ -30,19 +33,37 @@ public abstract class JsonObjectMessageConsumer<M> implements YhConsumer { | ||
30 | messageClass = (Class) params[0]; | 33 | messageClass = (Class) params[0]; |
31 | } | 34 | } |
32 | 35 | ||
36 | + | ||
37 | + public abstract String getTopic(); | ||
38 | + | ||
39 | + public abstract void handle(M message); | ||
40 | + | ||
33 | @Override | 41 | @Override |
34 | - public void handleMessage(Object o) throws Exception { | 42 | + public void handleMessage(Object jsonText) throws Exception { |
43 | + String topic = getTopic(); | ||
35 | M message; | 44 | M message; |
45 | + logger.info("in topic {}, msg {}", topic, jsonText); | ||
36 | try { | 46 | try { |
37 | - message = JSONObject.parseObject(o.toString(), messageClass); | 47 | + message = JSONObject.parseObject(jsonText.toString(), messageClass); |
38 | } catch (Exception e) { | 48 | } catch (Exception e) { |
39 | - getLogger().warn("parse message {} fail", o, e); | 49 | + getLogger().warn("parse message fail, topic {}, msg {}", topic, jsonText, e); |
40 | return; | 50 | return; |
41 | } | 51 | } |
42 | - handle(message); | 52 | + try { |
53 | + handle(message); | ||
54 | + } catch (ServiceException e) { | ||
55 | + getLogger().warn("handler message fail, topic {}, msg {}", topic, jsonText, e); | ||
56 | + } catch (Exception e) { | ||
57 | + getLogger().warn("handler message fail, topic {}, msg {}", topic, jsonText, e); | ||
58 | + SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent( | ||
59 | + topic, | ||
60 | + "ufo_mq_consumer_exception", | ||
61 | + e.toString() | ||
62 | + ); | ||
63 | + EventBusPublisher.publishEvent(smsAlarmEvent); | ||
64 | + } | ||
43 | } | 65 | } |
44 | 66 | ||
45 | - public abstract void handle(M message); | ||
46 | 67 | ||
47 | public Logger getLogger() { | 68 | public Logger getLogger() { |
48 | return logger; | 69 | return logger; |
@@ -16,7 +16,8 @@ public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageC | @@ -16,7 +16,8 @@ public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageC | ||
16 | @Autowired | 16 | @Autowired |
17 | private BuyerOrderCancelService buyerOrderCancelService; | 17 | private BuyerOrderCancelService buyerOrderCancelService; |
18 | 18 | ||
19 | - public String getMessageTopic() { | 19 | + @Override |
20 | + public String getTopic() { | ||
20 | return TopicConstants.SELLER_ORDER_AUTO_CANCEL_DELIVER; | 21 | return TopicConstants.SELLER_ORDER_AUTO_CANCEL_DELIVER; |
21 | } | 22 | } |
22 | 23 |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | +import com.google.common.base.Verify; | ||
3 | import com.yoho.error.ServiceError; | 4 | import com.yoho.error.ServiceError; |
4 | import com.yoho.error.exception.ServiceException; | 5 | import com.yoho.error.exception.ServiceException; |
5 | import com.yohobuy.ufo.model.order.common.OrderStatus; | 6 | import com.yohobuy.ufo.model.order.common.OrderStatus; |
@@ -128,9 +129,7 @@ public class BuyerOrderCancelHandler { | @@ -128,9 +129,7 @@ public class BuyerOrderCancelHandler { | ||
128 | } | 129 | } |
129 | 130 | ||
130 | public void cancel() { | 131 | public void cancel() { |
131 | - if (expectStatus == null || targetStatus == null) { | ||
132 | - throw new ServiceException(ServiceError.ORDER_SERVICE_ERROR); | ||
133 | - } | 132 | + verify(); |
134 | // 获取买家订单 | 133 | // 获取买家订单 |
135 | BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid); | 134 | BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid); |
136 | // 当前状态不可取消订单 | 135 | // 当前状态不可取消订单 |
@@ -146,6 +145,14 @@ public class BuyerOrderCancelHandler { | @@ -146,6 +145,14 @@ public class BuyerOrderCancelHandler { | ||
146 | } | 145 | } |
147 | } | 146 | } |
148 | 147 | ||
148 | + private void verify() { | ||
149 | + Verify.verify(uid > 0, "uid is %s", uid); | ||
150 | + Verify.verify(orderCode > 0, "orderCode is %s", orderCode); | ||
151 | + Verify.verifyNotNull(expectStatus, "expectStatus is null"); | ||
152 | + Verify.verifyNotNull(targetStatus, "targetStatus is null"); | ||
153 | + Verify.verifyNotNull(buyerOrderMapper, "buyerOrderMapper is null"); | ||
154 | + } | ||
155 | + | ||
149 | private boolean updateBuyerOrderStatus() { | 156 | private boolean updateBuyerOrderStatus() { |
150 | int rows = buyerOrderMapper.updateStatusByOrderCode( | 157 | int rows = buyerOrderMapper.updateStatusByOrderCode( |
151 | orderCode, | 158 | orderCode, |
-
Please register or login to post a comment