Merge branch 'dev_bargain' into test6.9.5
Showing
15 changed files
with
199 additions
and
14 deletions
@@ -23,11 +23,12 @@ | @@ -23,11 +23,12 @@ | ||
23 | <result column="seller_delivery_status" jdbcType="INTEGER" property="sellerDeliveryStatus" /> | 23 | <result column="seller_delivery_status" jdbcType="INTEGER" property="sellerDeliveryStatus" /> |
24 | <result column="seller_delivery_deal" jdbcType="INTEGER" property="sellerDeliveryDeal" /> | 24 | <result column="seller_delivery_deal" jdbcType="INTEGER" property="sellerDeliveryDeal" /> |
25 | <result column="seller_delivery_deal_again" jdbcType="INTEGER" property="sellerDeliveryDealAgain" /> | 25 | <result column="seller_delivery_deal_again" jdbcType="INTEGER" property="sellerDeliveryDealAgain" /> |
26 | + <result column="activity_type" jdbcType="INTEGER" property="activityType" /> | ||
26 | </resultMap> | 27 | </resultMap> |
27 | <sql id="Base_Column_List"> | 28 | <sql id="Base_Column_List"> |
28 | id, uid, order_code, seller_uid, client_type, payment, payment_type, is_cancel, amount, | 29 | id, uid, order_code, seller_uid, client_type, payment, payment_type, is_cancel, amount, |
29 | ship_fee, status, create_time, update_time, buyer_order_status, seller_order_status, channel_no, attributes,platform_delivery_status, | 30 | ship_fee, status, create_time, update_time, buyer_order_status, seller_order_status, channel_no, attributes,platform_delivery_status, |
30 | - seller_delivery_status,seller_delivery_deal,seller_delivery_deal_again | 31 | + seller_delivery_status,seller_delivery_deal,seller_delivery_deal_again,activity_type |
31 | </sql> | 32 | </sql> |
32 | 33 | ||
33 | 34 |
1 | package com.yohoufo.order.event; | 1 | package com.yohoufo.order.event; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.common.OrderCodeType; | 3 | import com.yohobuy.ufo.model.order.common.OrderCodeType; |
4 | +import com.yohobuy.ufo.model.order.common.OrderStatus; | ||
4 | import com.yohoufo.dal.order.model.BuyerOrder; | 5 | import com.yohoufo.dal.order.model.BuyerOrder; |
5 | 6 | ||
6 | /** | 7 | /** |
7 | * Created by jiexiang.wu on 2019/5/23. | 8 | * Created by jiexiang.wu on 2019/5/23. |
8 | */ | 9 | */ |
9 | public class BuyerOrderChangeEvent extends OrderChangeEvent { | 10 | public class BuyerOrderChangeEvent extends OrderChangeEvent { |
10 | - | ||
11 | private BuyerOrder buyerOrder; | 11 | private BuyerOrder buyerOrder; |
12 | private BizCase bizCase; | 12 | private BizCase bizCase; |
13 | + //事件发生后的状态,可能为null | ||
14 | + private OrderStatus targetStatus; | ||
13 | 15 | ||
14 | public BuyerOrderChangeEvent(BuyerOrder buyerOrder, BizCase bizCase) { | 16 | public BuyerOrderChangeEvent(BuyerOrder buyerOrder, BizCase bizCase) { |
17 | + this(buyerOrder, bizCase, null); | ||
18 | + } | ||
19 | + | ||
20 | + public BuyerOrderChangeEvent(BuyerOrder buyerOrder, BizCase bizCase, OrderStatus targetStatus) { | ||
15 | this.buyerOrder = buyerOrder; | 21 | this.buyerOrder = buyerOrder; |
16 | this.bizCase = bizCase; | 22 | this.bizCase = bizCase; |
23 | + this.targetStatus = targetStatus; | ||
17 | } | 24 | } |
18 | 25 | ||
19 | 26 | ||
@@ -30,7 +37,17 @@ public class BuyerOrderChangeEvent extends OrderChangeEvent { | @@ -30,7 +37,17 @@ public class BuyerOrderChangeEvent extends OrderChangeEvent { | ||
30 | return buyerOrder; | 37 | return buyerOrder; |
31 | } | 38 | } |
32 | 39 | ||
33 | - public enum BizCase { | 40 | + @Override |
41 | + public String toShortString() { | ||
42 | + return new StringBuilder(128).append("BuyerOrderChangeEvent[") | ||
43 | + .append("uid=").append(buyerOrder.getUid()) | ||
44 | + .append(",orderCode=").append(buyerOrder.getOrderCode()) | ||
45 | + .append(",bizCase=").append(bizCase) | ||
46 | + .append(",targetStatus=").append(targetStatus == null ? -999 : targetStatus.getCode()) | ||
47 | + .append("]").toString(); | ||
48 | + } | ||
34 | 49 | ||
50 | + public enum BizCase { | ||
51 | + CANCEL_BYBUYER, CANCEL_BYCS, CANCEL_BYSYSAUTO, CANCEL_BYSELLER, PAY_SUCCESS; | ||
35 | } | 52 | } |
36 | } | 53 | } |
@@ -2,18 +2,33 @@ package com.yohoufo.order.event; | @@ -2,18 +2,33 @@ package com.yohoufo.order.event; | ||
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.common.OrderCodeType; | 3 | import com.yohobuy.ufo.model.order.common.OrderCodeType; |
4 | import com.yohoufo.common.alarm.Event; | 4 | import com.yohoufo.common.alarm.Event; |
5 | +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * Created by jiexiang.wu on 2019/5/23. | 8 | * Created by jiexiang.wu on 2019/5/23. |
8 | * 订单状态发生变化后,有很多事情需要处理,其他有一些可以异步处理,异步服务可以对该类事件进行监控 | 9 | * 订单状态发生变化后,有很多事情需要处理,其他有一些可以异步处理,异步服务可以对该类事件进行监控 |
10 | + * @implNote 该直接只能被OrderChangeListenerContainer处理 | ||
9 | */ | 11 | */ |
10 | public abstract class OrderChangeEvent extends Event { | 12 | public abstract class OrderChangeEvent extends Event { |
11 | 13 | ||
12 | /** | 14 | /** |
15 | + * 简单描述 | ||
16 | + * | ||
17 | + * @return | ||
18 | + */ | ||
19 | + public abstract String toShortString(); | ||
20 | + | ||
21 | + /** | ||
13 | * 订单类型:买家、卖家 | 22 | * 订单类型:买家、卖家 |
14 | * | 23 | * |
15 | * @return | 24 | * @return |
16 | */ | 25 | */ |
17 | abstract OrderCodeType getOrderCodeType(); | 26 | abstract OrderCodeType getOrderCodeType(); |
18 | 27 | ||
28 | + | ||
29 | + @Override | ||
30 | + public String toString() { | ||
31 | + return ReflectionToStringBuilder.toString(this); | ||
32 | + } | ||
33 | + | ||
19 | } | 34 | } |
@@ -3,6 +3,7 @@ package com.yohoufo.order.model.bo; | @@ -3,6 +3,7 @@ package com.yohoufo.order.model.bo; | ||
3 | import lombok.Builder; | 3 | import lombok.Builder; |
4 | import lombok.Data; | 4 | import lombok.Data; |
5 | import lombok.ToString; | 5 | import lombok.ToString; |
6 | + | ||
6 | import java.math.BigDecimal; | 7 | import java.math.BigDecimal; |
7 | 8 | ||
8 | /** | 9 | /** |
@@ -18,4 +19,14 @@ public class ActivityBo { | @@ -18,4 +19,14 @@ public class ActivityBo { | ||
18 | private int activityType; | 19 | private int activityType; |
19 | //减免金额 | 20 | //减免金额 |
20 | private BigDecimal activityCutAmount; | 21 | private BigDecimal activityCutAmount; |
22 | + | ||
23 | + //json需要 | ||
24 | + public ActivityBo() { | ||
25 | + } | ||
26 | + | ||
27 | + public ActivityBo(int userActivityId, int activityType, BigDecimal activityCutAmount) { | ||
28 | + this.userActivityId = userActivityId; | ||
29 | + this.activityType = activityType; | ||
30 | + this.activityCutAmount = activityCutAmount; | ||
31 | + } | ||
21 | } | 32 | } |
@@ -17,6 +17,7 @@ import com.yohoufo.dal.order.BuyerOrderMetaMapper; | @@ -17,6 +17,7 @@ import com.yohoufo.dal.order.BuyerOrderMetaMapper; | ||
17 | import com.yohoufo.dal.order.SellerOrderGoodsMapper; | 17 | import com.yohoufo.dal.order.SellerOrderGoodsMapper; |
18 | import com.yohoufo.dal.order.model.*; | 18 | import com.yohoufo.dal.order.model.*; |
19 | import com.yohoufo.order.constants.MetaKey; | 19 | import com.yohoufo.order.constants.MetaKey; |
20 | +import com.yohoufo.order.event.BuyerOrderChangeEvent; | ||
20 | import com.yohoufo.order.event.DeliverNoticeEvent; | 21 | import com.yohoufo.order.event.DeliverNoticeEvent; |
21 | import com.yohoufo.order.event.ErpBuyerOrderEvent; | 22 | import com.yohoufo.order.event.ErpBuyerOrderEvent; |
22 | import com.yohoufo.order.event.SellerCancelDeliverEvent; | 23 | import com.yohoufo.order.event.SellerCancelDeliverEvent; |
@@ -28,6 +29,7 @@ import com.yohoufo.order.service.cache.CacheCleaner; | @@ -28,6 +29,7 @@ import com.yohoufo.order.service.cache.CacheCleaner; | ||
28 | import com.yohoufo.order.service.cache.CacheKeyBuilder; | 29 | import com.yohoufo.order.service.cache.CacheKeyBuilder; |
29 | import com.yohoufo.order.service.impl.MetaConfigService; | 30 | import com.yohoufo.order.service.impl.MetaConfigService; |
30 | import com.yohoufo.order.service.impl.OrderOverTimeService; | 31 | import com.yohoufo.order.service.impl.OrderOverTimeService; |
32 | +import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | ||
31 | import com.yohoufo.order.service.proxy.DeliveryMinutesService; | 33 | import com.yohoufo.order.service.proxy.DeliveryMinutesService; |
32 | import com.yohoufo.order.service.proxy.InBoxFacade; | 34 | import com.yohoufo.order.service.proxy.InBoxFacade; |
33 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 35 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
@@ -80,6 +82,9 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | @@ -80,6 +82,9 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | ||
80 | @Autowired | 82 | @Autowired |
81 | private OrderOverTimeService orderOverTimeService; | 83 | private OrderOverTimeService orderOverTimeService; |
82 | 84 | ||
85 | + @Autowired | ||
86 | + private OrderChangeListenerContainer orderChangeListenerContainer; | ||
87 | + | ||
83 | /** | 88 | /** |
84 | * 更新订单状态 | 89 | * 更新订单状态 |
85 | * @param orderInfo | 90 | * @param orderInfo |
@@ -169,6 +174,12 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | @@ -169,6 +174,12 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | ||
169 | Integer uid = orderInfo.getUid(); | 174 | Integer uid = orderInfo.getUid(); |
170 | Integer sellerUid = orderInfo.getSellerUid(); | 175 | Integer sellerUid = orderInfo.getSellerUid(); |
171 | long orderCode = orderInfo.getOrderCode(); | 176 | long orderCode = orderInfo.getOrderCode(); |
177 | + | ||
178 | + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
179 | + | ||
180 | + //订单事件 | ||
181 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.PAY_SUCCESS)); | ||
182 | + | ||
172 | // 通知卖家发货 | 183 | // 通知卖家发货 |
173 | BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(uid, orderCode); | 184 | BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(uid, orderCode); |
174 | int skup = buyerOrderGoods.getSkup(); | 185 | int skup = buyerOrderGoods.getSkup(); |
@@ -38,6 +38,7 @@ import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; | @@ -38,6 +38,7 @@ import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; | ||
38 | import com.yohoufo.order.service.handler.penalty.PenaltyResult; | 38 | import com.yohoufo.order.service.handler.penalty.PenaltyResult; |
39 | import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator; | 39 | import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator; |
40 | import com.yohoufo.order.service.impl.function.BuyerNoticeSender; | 40 | import com.yohoufo.order.service.impl.function.BuyerNoticeSender; |
41 | +import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | ||
41 | import com.yohoufo.order.service.proxy.InBoxFacade; | 42 | import com.yohoufo.order.service.proxy.InBoxFacade; |
42 | import com.yohoufo.order.service.proxy.OrderOperateRecordService; | 43 | import com.yohoufo.order.service.proxy.OrderOperateRecordService; |
43 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 44 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
@@ -130,6 +131,9 @@ public class AppraiseService { | @@ -130,6 +131,9 @@ public class AppraiseService { | ||
130 | @Autowired | 131 | @Autowired |
131 | private ProductMapper productMapper; | 132 | private ProductMapper productMapper; |
132 | 133 | ||
134 | + @Autowired | ||
135 | + private OrderChangeListenerContainer orderChangeListenerContainer; | ||
136 | + | ||
133 | @Resource(name = "tradeMqProducer") | 137 | @Resource(name = "tradeMqProducer") |
134 | private YhProducer tradeMqProducer; | 138 | private YhProducer tradeMqProducer; |
135 | 139 | ||
@@ -1365,6 +1369,7 @@ public class AppraiseService { | @@ -1365,6 +1369,7 @@ public class AppraiseService { | ||
1365 | .withRefundCoupon(BuyerRefundCouponEvent.BizCase.APPRAISE_UNSURE) | 1369 | .withRefundCoupon(BuyerRefundCouponEvent.BizCase.APPRAISE_UNSURE) |
1366 | .withCacheCleaner(cacheCleaner::delete) | 1370 | .withCacheCleaner(cacheCleaner::delete) |
1367 | .withFailAlarm(AlarmConfig.APPRAISE_UNSURE) | 1371 | .withFailAlarm(AlarmConfig.APPRAISE_UNSURE) |
1372 | + .withOrderChangeListenerContainer(orderChangeListenerContainer) | ||
1368 | .cancel(); | 1373 | .cancel(); |
1369 | } | 1374 | } |
1370 | 1375 |
@@ -22,6 +22,7 @@ import com.yohoufo.order.common.RefundCase; | @@ -22,6 +22,7 @@ import com.yohoufo.order.common.RefundCase; | ||
22 | import com.yohoufo.order.common.TransferCase; | 22 | import com.yohoufo.order.common.TransferCase; |
23 | import com.yohoufo.order.constants.AlarmConfig; | 23 | import com.yohoufo.order.constants.AlarmConfig; |
24 | import com.yohoufo.order.event.BillLogEvent; | 24 | import com.yohoufo.order.event.BillLogEvent; |
25 | +import com.yohoufo.order.event.BuyerOrderChangeEvent; | ||
25 | import com.yohoufo.order.event.BuyerRefundCouponEvent; | 26 | import com.yohoufo.order.event.BuyerRefundCouponEvent; |
26 | import com.yohoufo.order.model.request.PaymentRequest; | 27 | import com.yohoufo.order.model.request.PaymentRequest; |
27 | import com.yohoufo.order.model.request.TranseferCellNode; | 28 | import com.yohoufo.order.model.request.TranseferCellNode; |
@@ -32,6 +33,7 @@ import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenalty | @@ -32,6 +33,7 @@ import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenalty | ||
32 | import com.yohoufo.order.service.impl.function.BuyerNoticeSender; | 33 | import com.yohoufo.order.service.impl.function.BuyerNoticeSender; |
33 | import com.yohoufo.order.service.impl.function.RecordSuppleExpressSender; | 34 | import com.yohoufo.order.service.impl.function.RecordSuppleExpressSender; |
34 | import com.yohoufo.order.service.impl.function.SellerNoticeSender; | 35 | import com.yohoufo.order.service.impl.function.SellerNoticeSender; |
36 | +import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | ||
35 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 37 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
36 | import lombok.Data; | 38 | import lombok.Data; |
37 | import lombok.experimental.Accessors; | 39 | import lombok.experimental.Accessors; |
@@ -89,6 +91,8 @@ class BuyerOrderCancelHandler { | @@ -89,6 +91,8 @@ class BuyerOrderCancelHandler { | ||
89 | 91 | ||
90 | private Consumer<List<RedisKeyBuilder>> cacheCleaner; | 92 | private Consumer<List<RedisKeyBuilder>> cacheCleaner; |
91 | 93 | ||
94 | + private OrderChangeListenerContainer orderChangeListenerContainer; | ||
95 | + | ||
92 | BuyerOrderCancelHandler(int uid, long orderCode) { | 96 | BuyerOrderCancelHandler(int uid, long orderCode) { |
93 | this.uid = uid; | 97 | this.uid = uid; |
94 | this.orderCode = orderCode; | 98 | this.orderCode = orderCode; |
@@ -155,6 +159,16 @@ class BuyerOrderCancelHandler { | @@ -155,6 +159,16 @@ class BuyerOrderCancelHandler { | ||
155 | return this; | 159 | return this; |
156 | } | 160 | } |
157 | 161 | ||
162 | + /** | ||
163 | + * 异步事件 | ||
164 | + * @param orderChangeListenerContainer | ||
165 | + * @return | ||
166 | + */ | ||
167 | + public BuyerOrderCancelHandler withOrderChangeListenerContainer(OrderChangeListenerContainer orderChangeListenerContainer) { | ||
168 | + this.orderChangeListenerContainer = orderChangeListenerContainer; | ||
169 | + return this; | ||
170 | + } | ||
171 | + | ||
158 | public void cancel() { | 172 | public void cancel() { |
159 | log.info("cancel order {} from {} to {}", orderCode, expectStatus, targetStatus); | 173 | log.info("cancel order {} from {} to {}", orderCode, expectStatus, targetStatus); |
160 | verify(); | 174 | verify(); |
@@ -191,6 +205,8 @@ class BuyerOrderCancelHandler { | @@ -191,6 +205,8 @@ class BuyerOrderCancelHandler { | ||
191 | noticeSeller(sellerOrderGoods); | 205 | noticeSeller(sellerOrderGoods); |
192 | noticeBuyer(buyerOrder, buyerOrderGoods); | 206 | noticeBuyer(buyerOrder, buyerOrderGoods); |
193 | cleanCache(buyerOrder, sellerOrderGoods); | 207 | cleanCache(buyerOrder, sellerOrderGoods); |
208 | + //取消事件 | ||
209 | + fireAsyncEvent(buyerOrder); | ||
194 | } else { | 210 | } else { |
195 | log.info("cancel order {} fail, order status has changed", orderCode); | 211 | log.info("cancel order {} fail, order status has changed", orderCode); |
196 | throwServiceException("当前状态不可取消订单"); | 212 | throwServiceException("当前状态不可取消订单"); |
@@ -422,6 +438,14 @@ class BuyerOrderCancelHandler { | @@ -422,6 +438,14 @@ class BuyerOrderCancelHandler { | ||
422 | } | 438 | } |
423 | } | 439 | } |
424 | 440 | ||
441 | + /** | ||
442 | + * 订单取消异步事件 | ||
443 | + * @param buyerOrder | ||
444 | + */ | ||
445 | + public void fireAsyncEvent(BuyerOrder buyerOrder) { | ||
446 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.CANCEL_BYCS, targetStatus)); | ||
447 | + } | ||
448 | + | ||
425 | @Data | 449 | @Data |
426 | @Accessors(fluent = true) | 450 | @Accessors(fluent = true) |
427 | class RefundEarnestMoney { | 451 | class RefundEarnestMoney { |
@@ -29,6 +29,7 @@ import com.yohoufo.order.service.concurrent.ThreadPoolFactory; | @@ -29,6 +29,7 @@ import com.yohoufo.order.service.concurrent.ThreadPoolFactory; | ||
29 | import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; | 29 | import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; |
30 | import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler; | 30 | import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler; |
31 | import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; | 31 | import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; |
32 | +import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | ||
32 | import com.yohoufo.order.service.proxy.CouponProxyService; | 33 | import com.yohoufo.order.service.proxy.CouponProxyService; |
33 | import com.yohoufo.order.service.proxy.InBoxFacade; | 34 | import com.yohoufo.order.service.proxy.InBoxFacade; |
34 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 35 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
@@ -98,6 +99,8 @@ public class BuyerOrderCancelService { | @@ -98,6 +99,8 @@ public class BuyerOrderCancelService { | ||
98 | @Autowired | 99 | @Autowired |
99 | private OrderStatusFlowService orderStatusFlowService; | 100 | private OrderStatusFlowService orderStatusFlowService; |
100 | 101 | ||
102 | + @Autowired | ||
103 | + private OrderChangeListenerContainer orderChangeListenerContainer; | ||
101 | 104 | ||
102 | public void cancel(BeforeSellerDeliverEvent bsdEvent){ | 105 | public void cancel(BeforeSellerDeliverEvent bsdEvent){ |
103 | int buyerUid = bsdEvent.getBuyerUid(); | 106 | int buyerUid = bsdEvent.getBuyerUid(); |
@@ -209,6 +212,7 @@ public class BuyerOrderCancelService { | @@ -209,6 +212,7 @@ public class BuyerOrderCancelService { | ||
209 | .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT) | 212 | .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT) |
210 | .withCacheCleaner(cacheCleaner::delete) | 213 | .withCacheCleaner(cacheCleaner::delete) |
211 | .withFailAlarm(AlarmConfig.DELIVER_TIME_OUT) | 214 | .withFailAlarm(AlarmConfig.DELIVER_TIME_OUT) |
215 | + .withOrderChangeListenerContainer(orderChangeListenerContainer) | ||
212 | .cancel(); | 216 | .cancel(); |
213 | } | 217 | } |
214 | 218 | ||
@@ -231,6 +235,7 @@ public class BuyerOrderCancelService { | @@ -231,6 +235,7 @@ public class BuyerOrderCancelService { | ||
231 | .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_SHAM_SEND_OUT) | 235 | .withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_SHAM_SEND_OUT) |
232 | .withCacheCleaner(cacheCleaner::delete) | 236 | .withCacheCleaner(cacheCleaner::delete) |
233 | .withFailAlarm(AlarmConfig.SELLER_SHAM_SEND_OUT) | 237 | .withFailAlarm(AlarmConfig.SELLER_SHAM_SEND_OUT) |
238 | + .withOrderChangeListenerContainer(orderChangeListenerContainer) | ||
234 | .cancel(); | 239 | .cancel(); |
235 | } | 240 | } |
236 | 241 |
@@ -39,6 +39,7 @@ import com.yohoufo.order.service.cache.CacheCleaner; | @@ -39,6 +39,7 @@ import com.yohoufo.order.service.cache.CacheCleaner; | ||
39 | import com.yohoufo.order.service.cache.CacheKeyBuilder; | 39 | import com.yohoufo.order.service.cache.CacheKeyBuilder; |
40 | import com.yohoufo.order.service.cache.OrderCacheService; | 40 | import com.yohoufo.order.service.cache.OrderCacheService; |
41 | import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; | 41 | import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; |
42 | +import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | ||
42 | import com.yohoufo.order.service.pay.AbstractPayService; | 43 | import com.yohoufo.order.service.pay.AbstractPayService; |
43 | import com.yohoufo.order.service.proxy.InBoxFacade; | 44 | import com.yohoufo.order.service.proxy.InBoxFacade; |
44 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 45 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
@@ -110,6 +111,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | @@ -110,6 +111,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | ||
110 | @Autowired | 111 | @Autowired |
111 | private ProductMapper productMapper; | 112 | private ProductMapper productMapper; |
112 | 113 | ||
114 | + @Autowired | ||
115 | + private OrderChangeListenerContainer orderChangeListenerContainer; | ||
116 | + | ||
113 | 117 | ||
114 | /** | 118 | /** |
115 | * 提交订单 | 119 | * 提交订单 |
@@ -346,6 +350,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | @@ -346,6 +350,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | ||
346 | DataNode node = checkBase(orderRequest); | 350 | DataNode node = checkBase(orderRequest); |
347 | cancelBeforePaid(orderRequest, node, expectStatus, targetStatus); | 351 | cancelBeforePaid(orderRequest, node, expectStatus, targetStatus); |
348 | 352 | ||
353 | + //取消事件 | ||
354 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(node.buyerOrderInDB, BuyerOrderChangeEvent.BizCase.CANCEL_BYSYSAUTO, targetStatus)); | ||
355 | + | ||
349 | //记录状态变更信息 | 356 | //记录状态变更信息 |
350 | logger.info("in cancelByAuto record status change, orderRequest {}", orderRequest); | 357 | logger.info("in cancelByAuto record status change, orderRequest {}", orderRequest); |
351 | orderStatusFlowService.addAsy(orderRequest.getOrderCode(),targetStatus.getCode()); | 358 | orderStatusFlowService.addAsy(orderRequest.getOrderCode(),targetStatus.getCode()); |
@@ -370,6 +377,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | @@ -370,6 +377,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | ||
370 | targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_PAY; | 377 | targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_PAY; |
371 | cancelBeforePaid(orderRequest, node, expectStatus, targetStatus); | 378 | cancelBeforePaid(orderRequest, node, expectStatus, targetStatus); |
372 | 379 | ||
380 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.CANCEL_BYBUYER, targetStatus)); | ||
381 | + | ||
373 | //记录状态变更信息 | 382 | //记录状态变更信息 |
374 | logger.info("in doCancel record status WAITING_PAY change, orderRequest {}", orderRequest); | 383 | logger.info("in doCancel record status WAITING_PAY change, orderRequest {}", orderRequest); |
375 | orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode()); | 384 | orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode()); |
@@ -385,6 +394,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | @@ -385,6 +394,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | ||
385 | .amount(buyerOrder.getAmount()) | 394 | .amount(buyerOrder.getAmount()) |
386 | .build(); | 395 | .build(); |
387 | buyerOrderCancelService.cancel(bsde); | 396 | buyerOrderCancelService.cancel(bsde); |
397 | + | ||
398 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.CANCEL_BYBUYER, targetStatus)); | ||
399 | + | ||
388 | //记录状态变更信息 | 400 | //记录状态变更信息 |
389 | logger.info("in doCancel record status HAS_PAYED change, orderRequest {}", orderRequest); | 401 | logger.info("in doCancel record status HAS_PAYED change, orderRequest {}", orderRequest); |
390 | orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode()); | 402 | orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode()); |
@@ -400,6 +412,10 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | @@ -400,6 +412,10 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { | ||
400 | .amount(buyerOrder.getAmount()) | 412 | .amount(buyerOrder.getAmount()) |
401 | .build(); | 413 | .build(); |
402 | buyerOrderCancelService.cancel(bdre); | 414 | buyerOrderCancelService.cancel(bdre); |
415 | + | ||
416 | + //取消事件 | ||
417 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.CANCEL_BYBUYER, targetStatus)); | ||
418 | + | ||
403 | //记录状态变更信息 | 419 | //记录状态变更信息 |
404 | logger.info("in doCancel record status HAS_PAYED change, orderRequest {}", orderRequest); | 420 | logger.info("in doCancel record status HAS_PAYED change, orderRequest {}", orderRequest); |
405 | orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode()); | 421 | orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetStatus.getCode()); |
@@ -37,6 +37,7 @@ import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; | @@ -37,6 +37,7 @@ import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler; | ||
37 | import com.yohoufo.order.service.handler.penalty.PenaltyResult; | 37 | import com.yohoufo.order.service.handler.penalty.PenaltyResult; |
38 | import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator; | 38 | import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator; |
39 | import com.yohoufo.order.service.impl.visitor.*; | 39 | import com.yohoufo.order.service.impl.visitor.*; |
40 | +import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | ||
40 | import com.yohoufo.order.service.pay.AbstractPayService; | 41 | import com.yohoufo.order.service.pay.AbstractPayService; |
41 | import com.yohoufo.order.service.proxy.InBoxFacade; | 42 | import com.yohoufo.order.service.proxy.InBoxFacade; |
42 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; | 43 | import com.yohoufo.order.service.proxy.OrderStatusFlowService; |
@@ -125,6 +126,10 @@ public class SellerOrderCancelService { | @@ -125,6 +126,10 @@ public class SellerOrderCancelService { | ||
125 | 126 | ||
126 | @Autowired | 127 | @Autowired |
127 | private SellerGoodsStatusFlowService sellerGoodsStatusFlowService; | 128 | private SellerGoodsStatusFlowService sellerGoodsStatusFlowService; |
129 | + | ||
130 | + @Autowired | ||
131 | + private OrderChangeListenerContainer orderChangeListenerContainer; | ||
132 | + | ||
128 | /** | 133 | /** |
129 | * TODO 如何控制好并发,必须控制不能重复转账 退款 | 134 | * TODO 如何控制好并发,必须控制不能重复转账 退款 |
130 | * 使用乐观锁,带着查询到的状态且符合条件时再去更新 | 135 | * 使用乐观锁,带着查询到的状态且符合条件时再去更新 |
@@ -544,6 +549,10 @@ public class SellerOrderCancelService { | @@ -544,6 +549,10 @@ public class SellerOrderCancelService { | ||
544 | BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.SELLER_PLAY_BUYER) | 549 | BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.SELLER_PLAY_BUYER) |
545 | .uid(buyerUid).orderCode(buyerOrderCode).build(); | 550 | .uid(buyerUid).orderCode(buyerOrderCode).build(); |
546 | EventBusPublisher.publishEvent(brce); | 551 | EventBusPublisher.publishEvent(brce); |
552 | + | ||
553 | + //取消事件 | ||
554 | + orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.CANCEL_BYSELLER, targetBOStatus)); | ||
555 | + | ||
547 | //清理买家、卖家订单相关缓存 | 556 | //清理买家、卖家订单相关缓存 |
548 | SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(sellerOrder.getSkup()); | 557 | SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(sellerOrder.getSkup()); |
549 | cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()), | 558 | cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()), |
1 | -package com.yohoufo.order.service.impl; | 1 | +package com.yohoufo.order.service.listener; |
2 | 2 | ||
3 | +import com.yohoufo.dal.order.BuyerOrderMetaMapper; | ||
3 | import com.yohoufo.dal.order.model.BuyerOrder; | 4 | import com.yohoufo.dal.order.model.BuyerOrder; |
4 | import com.yohoufo.order.constants.ActivityTypeEnum; | 5 | import com.yohoufo.order.constants.ActivityTypeEnum; |
6 | +import com.yohoufo.order.constants.MetaKey; | ||
5 | import com.yohoufo.order.event.BuyerOrderChangeEvent; | 7 | import com.yohoufo.order.event.BuyerOrderChangeEvent; |
6 | -import com.yohoufo.order.service.IOrderChangeListener; | 8 | +import com.yohoufo.order.event.OrderChangeEvent; |
9 | +import com.yohoufo.order.model.bo.ActivityBo; | ||
10 | +import com.yohoufo.order.service.proxy.BargainProxyService; | ||
11 | +import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport; | ||
12 | +import com.yohoufo.order.utils.LoggerUtils; | ||
13 | +import org.slf4j.Logger; | ||
14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | import org.springframework.stereotype.Component; | 15 | import org.springframework.stereotype.Component; |
8 | 16 | ||
9 | import java.util.Objects; | 17 | import java.util.Objects; |
@@ -13,25 +21,53 @@ import java.util.Objects; | @@ -13,25 +21,53 @@ import java.util.Objects; | ||
13 | */ | 21 | */ |
14 | @Component | 22 | @Component |
15 | public class BuyOrderChangeListener implements IOrderChangeListener<BuyerOrderChangeEvent> { | 23 | public class BuyOrderChangeListener implements IOrderChangeListener<BuyerOrderChangeEvent> { |
24 | + final private Logger logger = LoggerUtils.getBuyerOrderLogger(); | ||
25 | + | ||
26 | + @Autowired | ||
27 | + private BuyerOrderMetaMapperSupport buyerOrderMetaMapperSupport; | ||
28 | + | ||
29 | + @Autowired | ||
30 | + private BargainProxyService bargainProxyService; | ||
31 | + | ||
32 | + @Override | ||
33 | + public boolean shouldHandle(OrderChangeEvent event) { | ||
34 | + return event instanceof BuyerOrderChangeEvent; | ||
35 | + } | ||
36 | + | ||
16 | @Override | 37 | @Override |
17 | public void handleEvent(BuyerOrderChangeEvent buyerOrderChangeEvent) { | 38 | public void handleEvent(BuyerOrderChangeEvent buyerOrderChangeEvent) { |
18 | BuyerOrder buyerOrder = buyerOrderChangeEvent.getBuyerOrder(); | 39 | BuyerOrder buyerOrder = buyerOrderChangeEvent.getBuyerOrder(); |
19 | if (Objects.equals(buyerOrder.getActivityType(), ActivityTypeEnum.BARGAIN.getCode())) { | 40 | if (Objects.equals(buyerOrder.getActivityType(), ActivityTypeEnum.BARGAIN.getCode())) { |
41 | + //砍价订单 | ||
20 | handleBargainOrderEvent(buyerOrderChangeEvent.getBizCase(), buyerOrder); | 42 | handleBargainOrderEvent(buyerOrderChangeEvent.getBizCase(), buyerOrder); |
21 | } | 43 | } |
22 | } | 44 | } |
23 | 45 | ||
24 | /** | 46 | /** |
25 | * 砍价订单 | 47 | * 砍价订单 |
48 | + * | ||
26 | * @param bizCase | 49 | * @param bizCase |
27 | * @param buyerOrder | 50 | * @param buyerOrder |
28 | */ | 51 | */ |
29 | private void handleBargainOrderEvent(BuyerOrderChangeEvent.BizCase bizCase, BuyerOrder buyerOrder) { | 52 | private void handleBargainOrderEvent(BuyerOrderChangeEvent.BizCase bizCase, BuyerOrder buyerOrder) { |
53 | + ActivityBo activityBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.ACTIVITY_KEY, ActivityBo.class); | ||
30 | 54 | ||
31 | - | ||
32 | - | 55 | + if (activityBo == null || activityBo.getUserActivityId() < 0) { |
56 | + logger.warn("[{}] has no userActivityId for orderCode: {}", buyerOrder.getOrderCode()); | ||
57 | + return; | ||
58 | + } | ||
33 | switch (bizCase) { | 59 | switch (bizCase) { |
34 | - //处理 | 60 | + case CANCEL_BYSYSAUTO: |
61 | + case CANCEL_BYBUYER: | ||
62 | + case CANCEL_BYCS: | ||
63 | + case CANCEL_BYSELLER: | ||
64 | + bargainProxyService.cancelCutPriceUseRecord(buyerOrder.getUid(), buyerOrder.getOrderCode(), activityBo.getUserActivityId()); | ||
65 | + break; | ||
66 | + case PAY_SUCCESS: | ||
67 | + bargainProxyService.payCutPrice(buyerOrder.getUid(), buyerOrder.getOrderCode(), activityBo.getUserActivityId()); | ||
68 | + break; | ||
69 | + default: | ||
70 | + throw new IllegalStateException("unknown bizCase" + bizCase); | ||
35 | } | 71 | } |
36 | } | 72 | } |
37 | } | 73 | } |
1 | -package com.yohoufo.order.service; | 1 | +package com.yohoufo.order.service.listener; |
2 | 2 | ||
3 | import com.yohoufo.order.event.OrderChangeEvent; | 3 | import com.yohoufo.order.event.OrderChangeEvent; |
4 | 4 | ||
@@ -7,5 +7,7 @@ import com.yohoufo.order.event.OrderChangeEvent; | @@ -7,5 +7,7 @@ import com.yohoufo.order.event.OrderChangeEvent; | ||
7 | */ | 7 | */ |
8 | public interface IOrderChangeListener<T extends OrderChangeEvent> { | 8 | public interface IOrderChangeListener<T extends OrderChangeEvent> { |
9 | 9 | ||
10 | + boolean shouldHandle(OrderChangeEvent event); | ||
11 | + | ||
10 | void handleEvent(T t); | 12 | void handleEvent(T t); |
11 | } | 13 | } |
1 | -package com.yohoufo.order.service.impl; | 1 | +package com.yohoufo.order.service.listener; |
2 | 2 | ||
3 | +import com.google.common.eventbus.Subscribe; | ||
3 | import com.yohoufo.common.alarm.EventBusPublisher; | 4 | import com.yohoufo.common.alarm.EventBusPublisher; |
4 | import com.yohoufo.common.alarm.IEventHandler; | 5 | import com.yohoufo.common.alarm.IEventHandler; |
5 | import com.yohoufo.common.alarm.SmsAlarmEvent; | 6 | import com.yohoufo.common.alarm.SmsAlarmEvent; |
6 | import com.yohoufo.order.event.OrderChangeEvent; | 7 | import com.yohoufo.order.event.OrderChangeEvent; |
7 | -import com.yohoufo.order.service.IOrderChangeListener; | ||
8 | import com.yohoufo.order.utils.LoggerUtils; | 8 | import com.yohoufo.order.utils.LoggerUtils; |
9 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -37,22 +37,25 @@ public class OrderChangeListenerContainer implements IEventHandler<OrderChangeEv | @@ -37,22 +37,25 @@ public class OrderChangeListenerContainer implements IEventHandler<OrderChangeEv | ||
37 | } | 37 | } |
38 | 38 | ||
39 | //触发异步处理 | 39 | //触发异步处理 |
40 | - public void fireAsycEvent(OrderChangeEvent event) { | 40 | + public void fireAsyncEvent(OrderChangeEvent event) { |
41 | eventBusPublisher.publishEvent(event); | 41 | eventBusPublisher.publishEvent(event); |
42 | } | 42 | } |
43 | 43 | ||
44 | @Override | 44 | @Override |
45 | + @Subscribe | ||
45 | public void handle(OrderChangeEvent event) { | 46 | public void handle(OrderChangeEvent event) { |
46 | logger.info("handle order change event:{}", event); | 47 | logger.info("handle order change event:{}", event); |
47 | for (IOrderChangeListener listener : listeners) { | 48 | for (IOrderChangeListener listener : listeners) { |
48 | try { | 49 | try { |
50 | + if (listener.shouldHandle(event)) { | ||
49 | listener.handleEvent(event); | 51 | listener.handleEvent(event); |
52 | + } | ||
50 | } catch (Exception ex) { | 53 | } catch (Exception ex) { |
51 | logger.warn("handler:{} handle event:{} error", listener.getClass().getName(), event, ex); | 54 | logger.warn("handler:{} handle event:{} error", listener.getClass().getName(), event, ex); |
52 | //告警 | 55 | //告警 |
53 | EventBusPublisher.publishEvent( | 56 | EventBusPublisher.publishEvent( |
54 | new SmsAlarmEvent("ufo.orderChangeEvent", "handle_exception", | 57 | new SmsAlarmEvent("ufo.orderChangeEvent", "handle_exception", |
55 | - listener.getClass().getName() + "(" + event.toString() + ")", ex) | 58 | + listener.getClass().getName() + "(" + event.toShortString() + ")", ex) |
56 | ); | 59 | ); |
57 | } | 60 | } |
58 | } | 61 | } |
@@ -38,7 +38,7 @@ public abstract class AbsServiceCaller { | @@ -38,7 +38,7 @@ public abstract class AbsServiceCaller { | ||
38 | throw e; | 38 | throw e; |
39 | } catch (Exception e) { | 39 | } catch (Exception e) { |
40 | logger.warn("doPost fail, url is {} object is {}", url, object, e); | 40 | logger.warn("doPost fail, url is {} object is {}", url, object, e); |
41 | - return new ApiResponse.ApiResponseBuilder().code(500).message("服务访问异常").build(); | 41 | + throw e; |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 |
1 | +package com.yohoufo.order.service.support; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.yohoufo.dal.order.BuyerOrderMetaMapper; | ||
5 | +import com.yohoufo.dal.order.model.BuyerOrderMeta; | ||
6 | +import com.yohoufo.order.utils.LoggerUtils; | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.stereotype.Component; | ||
10 | + | ||
11 | +/** | ||
12 | + * Created by jiexiang.wu on 2019/5/23. | ||
13 | + */ | ||
14 | +@Component | ||
15 | +public class BuyerOrderMetaMapperSupport { | ||
16 | + | ||
17 | + private final static Logger logger = LoggerUtils.getBuyerOrderLogger(); | ||
18 | + | ||
19 | + @Autowired | ||
20 | + BuyerOrderMetaMapper buyerOrderMetaMapper; | ||
21 | + | ||
22 | + public <T> T selectByMetaKey(int uid, long orderCode, String metaKey, Class<T> clazz) { | ||
23 | + BuyerOrderMeta orderMeta = buyerOrderMetaMapper.selectByMetaKey(uid, orderCode, metaKey); | ||
24 | + if (orderMeta == null) { | ||
25 | + logger.warn("no orderMeta for orderCode: {}, uid: {}, metaKey: {}", orderCode, uid, metaKey); | ||
26 | + return null; | ||
27 | + } | ||
28 | + return JSON.parseObject(orderMeta.getMetaValue(), clazz); | ||
29 | + } | ||
30 | +} |
-
Please register or login to post a comment