Skip to content

Commit e5d71ad

Browse files
committed
订单交易核心处理板块重构
1 parent 7164ec7 commit e5d71ad

21 files changed

Lines changed: 130 additions & 160 deletions

File tree

gpmall-shopping/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spring:
22
application:
33
name: gpmall-shopping
44
profiles:
5-
active: prod
5+
active: dev
66
server:
77
port: 8081
88

gpmall-user/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ spring:
22
application:
33
name: gpmall-user
44
profiles:
5-
active: prod
5+
active: dev
66
server:
77
port: 8080

order-services/order-provider/src/main/java/com/gpmall/order/biz/HandlerItem.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

order-services/order-provider/src/main/java/com/gpmall/order/biz/TransHandlerNode.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

order-services/order-provider/src/main/java/com/gpmall/order/biz/factory/AbstranctTransPipelineFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44

55
import com.gpmall.commons.result.AbstractRequest;
6-
import com.gpmall.order.biz.DefaultTransPipeline;
7-
import com.gpmall.order.biz.TransPipeline;
6+
import com.gpmall.order.biz.handler.DefaultTransPipeline;
7+
import com.gpmall.order.biz.handler.TransPipeline;
88
import com.gpmall.order.biz.context.AbsTransHandlerContext;
99
import com.gpmall.order.biz.context.TransHandlerContext;
1010
import com.gpmall.order.biz.TransOutboundInvoker;

order-services/order-provider/src/main/java/com/gpmall/order/biz/factory/OrderProcessPipelineFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* Created by mic on 2019/8/2.
33
*/
44

5-
import com.gpmall.order.biz.TransOutboundInvoker;
6-
import com.gpmall.order.biz.TransPipeline;
5+
import com.gpmall.order.biz.handler.TransPipeline;
76
import com.gpmall.order.biz.context.CreateOrderContext;
87
import com.gpmall.order.biz.context.TransHandlerContext;
98
import com.gpmall.order.biz.convert.CreateOrderConvert;
@@ -14,7 +13,6 @@
1413
import com.gpmall.order.biz.handler.ValidateHandler;
1514
import com.gpmall.order.dto.CreateOrderRequest;
1615
import lombok.extern.slf4j.Slf4j;
17-
import net.bytebuddy.asm.Advice;
1816
import org.springframework.beans.factory.annotation.Autowired;
1917
import org.springframework.stereotype.Service;
2018

order-services/order-provider/src/main/java/com/gpmall/order/biz/handler/AbstractTransHandler.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
* Created by mic on 2019/8/2.
33
*/
44

5-
import com.gpmall.order.biz.HandlerItem;
65
import com.gpmall.order.biz.callback.TransCallback;
76
import lombok.Data;
87

9-
import java.util.Map;
10-
118
/**
129
* 腾讯课堂搜索【咕泡学院】
1310
* 官网:www.gupaoedu.com
@@ -19,28 +16,5 @@ public abstract class AbstractTransHandler implements TransHandler {
1916

2017
public static final String DEFAULT = "default";
2118

22-
private Map<String,HandlerItem> handlerMap = null;
23-
24-
public Map<String, HandlerItem> getHandlerMap() {
25-
return handlerMap;
26-
}
27-
28-
public void setHandlerMap(Map<String, HandlerItem> handlerMap) {
29-
this.handlerMap = handlerMap;
30-
}
31-
32-
public HandlerItem getDefaultHanderItem() {
33-
return getHandlerMap().get(DEFAULT);
34-
}
35-
36-
public TransCallback callback;//需要注入回调的值
37-
38-
/**
39-
* 可以无回调
40-
*/
41-
public TransCallback setPostCallback(){return null;}
42-
43-
public void setCallback(TransCallback callback) {
44-
this.callback = setPostCallback();
45-
}
19+
public TransCallback getTransCallback(){return null;}
4620
}

order-services/order-provider/src/main/java/com/gpmall/order/biz/handler/ClearCartItemHandler.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
* Created by mic on 2019/8/1.
33
*/
44

5+
import com.gpmall.commons.tool.exception.BizException;
56
import com.gpmall.order.biz.callback.TransCallback;
67
import com.gpmall.order.biz.context.TransHandlerContext;
8+
import com.gpmall.order.constant.OrderRetCode;
9+
import com.gpmall.shopping.ICartService;
10+
import com.gpmall.shopping.dto.ClearCartItemRequest;
11+
import com.gpmall.shopping.dto.ClearCartItemResponse;
712
import lombok.extern.slf4j.Slf4j;
13+
import org.apache.dubbo.config.annotation.Reference;
814
import org.springframework.stereotype.Component;
915

1016
/**
@@ -17,19 +23,30 @@
1723
@Slf4j
1824
@Component
1925
public class ClearCartItemHandler extends AbstractTransHandler {
26+
@Reference
27+
ICartService cartService;
2028

29+
//是否采用异步方式执行
2130
@Override
2231
public boolean isAsync() {
2332
return false;
2433
}
2534

2635
@Override
2736
public boolean handle(TransHandlerContext context) {
28-
return false;
37+
log.info("begin - ClearCartItemHandler-context:"+context);
38+
//TODO 缓存失效和下单是属于两个事物操作,需要保证成功,后续可以改造成消息队列的形式来实现
39+
ClearCartItemRequest request=new ClearCartItemRequest();
40+
// request.setProductIds(context.getBuyProductIds());
41+
// request.setUserId(context.getRequest().getUserId());
42+
ClearCartItemResponse response=cartService.clearCartItemByUserID(request);
43+
if(OrderRetCode.SUCCESS.getCode().equals(response.getCode())){
44+
return true;
45+
}else{
46+
throw new BizException(response.getCode(),response.getMsg());
47+
}
2948
}
30-
31-
/*@Reference
32-
ICartService cartService;
49+
/*
3350
3451
3552
@Override

order-services/order-provider/src/main/java/com/gpmall/order/biz/DefaultTransPipeline.java renamed to order-services/order-provider/src/main/java/com/gpmall/order/biz/handler/DefaultTransPipeline.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package com.gpmall.order.biz;/**
1+
package com.gpmall.order.biz.handler;/**
22
* Created by mic on 2019/8/2.
33
*/
44

55
import com.gpmall.commons.tool.exception.BizException;
66
import com.gpmall.order.biz.context.TransHandlerContext;
7-
import com.gpmall.order.biz.handler.TransHandler;
87
import com.gpmall.order.constant.OrderRetCode;
98
import lombok.extern.slf4j.Slf4j;
109

@@ -18,7 +17,7 @@
1817
public class DefaultTransPipeline implements TransPipeline{
1918

2019

21-
private TransHandlerNode tail = new TransHandlerNode();
20+
private TransHandlerNode tail;
2221

2322
private TransHandlerNode head = new TransHandlerNode();
2423

@@ -55,7 +54,6 @@ public void addLast(TransHandler... handlers) {
5554
TransHandlerNode node = new TransHandlerNode();
5655
node.setHandler(handler);
5756
next.setNext(node);
58-
5957
next = node;
6058
}
6159

@@ -67,7 +65,7 @@ public void start() {
6765
try {
6866
head.getNext().exec(getContext());
6967
} catch (Exception ex) {
70-
log.error("Transcore pipeline系统运行异常.", ex);
68+
log.error("pipeline系统运行异常.", ex);
7169
throw new BizException(OrderRetCode.PIPELINE_RUN_EXCEPTION.getCode(),OrderRetCode.PIPELINE_RUN_EXCEPTION.getMessage());//TODI
7270
}
7371
}

order-services/order-provider/src/main/java/com/gpmall/order/biz/handler/InitOrderHandler.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@
2020
@Slf4j
2121
@Component
2222
public class InitOrderHandler extends AbstractTransHandler {
23+
2324
@Autowired
2425
SendEmailCallback sendEmailCallback;
2526

27+
@Override
28+
public TransCallback getTransCallback() {
29+
return sendEmailCallback;
30+
}
31+
2632
@Override
2733
public boolean isAsync() {
2834
return false;
2935
}
3036

3137
@Override
3238
public boolean handle(TransHandlerContext context) {
33-
return false;
39+
log.info("begin InitOrderHandler :context:"+context);
40+
return true;
3441
}
3542

3643
/*@Autowired
@@ -82,8 +89,4 @@ public void handler(OrderContext context, HandlerChain<OrderContext, BizExceptio
8289
}
8390
}*/
8491

85-
@Override
86-
public TransCallback setPostCallback() {
87-
return sendEmailCallback;
88-
}
8992
}

0 commit comments

Comments
 (0)