Commit b3d92023409f6eee9507bfb85dbe96655ac2bddc
Merge remote-tracking branch 'origin/master'
Showing
4 changed files
with
57 additions
and
46 deletions
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderCreator.java
... | ... | @@ -26,30 +26,28 @@ public class DefaultOrderCreator { |
26 | 26 | private OrderDo orderDo = new OrderDo(); |
27 | 27 | |
28 | 28 | private List<OrderItemDo> items = new ArrayList<OrderItemDo>(); |
29 | - | |
29 | + | |
30 | 30 | private AccountDto saccountDto; |
31 | - | |
31 | + | |
32 | 32 | private AccountDto baccountDto; |
33 | - | |
33 | + | |
34 | 34 | private OrderCreateRequestDto orderCreateDto; |
35 | - | |
36 | - public DefaultOrderCreator() { | |
37 | - } | |
38 | - | |
39 | - public DefaultOrderCreator(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto) { | |
35 | + | |
36 | + private DefaultOrderCreator(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto) { | |
40 | 37 | this.saccountDto = saccountDto; |
41 | 38 | this.orderCreateDto = orderCreateDto; |
42 | 39 | } |
43 | - | |
44 | - public static DefaultOrderCreator builder(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto, Long orderId) { | |
40 | + | |
41 | + public static DefaultOrderCreator builder(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto, | |
42 | + Long orderId) { | |
45 | 43 | orderCreateDto.setOrderId(orderId); |
46 | 44 | return new DefaultOrderCreator(saccountDto, orderCreateDto); |
47 | 45 | } |
48 | - | |
46 | + | |
49 | 47 | public OrderDo createOrder() { |
50 | 48 | return this.orderDo; |
51 | 49 | } |
52 | - | |
50 | + | |
53 | 51 | public List<OrderItemDo> createOrderItems() { |
54 | 52 | return this.items; |
55 | 53 | } |
... | ... | @@ -58,18 +56,18 @@ public class DefaultOrderCreator { |
58 | 56 | * 构建初始订单数据 TODO need modify because of change |
59 | 57 | */ |
60 | 58 | public void initializeOrderBaseData() { |
61 | - | |
62 | - //基本信息 | |
59 | + | |
60 | + // 基本信息 | |
63 | 61 | buildBaseInfo(); |
64 | - | |
65 | - //卖家信息 | |
62 | + | |
63 | + // 卖家信息 | |
66 | 64 | buildSeller(); |
67 | - | |
68 | - //买家信息 | |
65 | + | |
66 | + // 买家信息 | |
69 | 67 | if (isBuildBuyerInfo()) { |
70 | 68 | buildBuyer(); |
71 | 69 | } |
72 | - | |
70 | + | |
73 | 71 | } |
74 | 72 | |
75 | 73 | /** |
... | ... | @@ -107,11 +105,11 @@ public class DefaultOrderCreator { |
107 | 105 | BigDecimal.valueOf(orderDo.getWeight()).add(BigDecimal.valueOf(orderItemDo.getWeight())).doubleValue()); |
108 | 106 | items.add(orderItemDo); |
109 | 107 | } |
110 | - | |
108 | + | |
111 | 109 | public boolean isBuildBuyerInfo() { |
112 | 110 | return orderCreateDto.getBaccount() == null ? false : true; |
113 | 111 | } |
114 | - | |
112 | + | |
115 | 113 | /** |
116 | 114 | * 构建卖家信息 |
117 | 115 | */ |
... | ... | @@ -121,7 +119,7 @@ public class DefaultOrderCreator { |
121 | 119 | orderDo.setSmobile(saccountDto.getMobile()); |
122 | 120 | orderDo.setScardType(saccountDto.getType()); |
123 | 121 | } |
124 | - | |
122 | + | |
125 | 123 | /** |
126 | 124 | * 构建买家信息 |
127 | 125 | */ |
... | ... | @@ -131,7 +129,7 @@ public class DefaultOrderCreator { |
131 | 129 | orderDo.setBmobile(baccountDto.getMobile()); |
132 | 130 | orderDo.setBcardType(baccountDto.getType()); |
133 | 131 | } |
134 | - | |
132 | + | |
135 | 133 | /** |
136 | 134 | * 构建基本信息 |
137 | 135 | */ |
... | ... | @@ -141,6 +139,5 @@ public class DefaultOrderCreator { |
141 | 139 | orderDo.setTradeType(TradeType.NORMAL.getCode()); |
142 | 140 | orderDo.setMarketCode("SYDEV"); |
143 | 141 | } |
144 | - | |
145 | 142 | |
146 | 143 | } | ... | ... |
src/main/java/com/diligrp/xtrade/order/domain/builder/OrderResponseBuilder.java renamed to src/main/java/com/diligrp/xtrade/order/domain/builder/OrderDataBuilder.java
... | ... | @@ -2,6 +2,9 @@ package com.diligrp.xtrade.order.domain.builder; |
2 | 2 | |
3 | 3 | import java.util.List; |
4 | 4 | |
5 | +import org.springframework.beans.BeanUtils; | |
6 | + | |
7 | +import com.diligrp.xtrade.order.domain.dto.OrderItemDto; | |
5 | 8 | import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto; |
6 | 9 | import com.diligrp.xtrade.order.domain.entity.OrderDo; |
7 | 10 | import com.diligrp.xtrade.order.domain.entity.OrderItemDo; |
... | ... | @@ -13,14 +16,20 @@ import com.diligrp.xtrade.order.domain.entity.OrderItemDo; |
13 | 16 | * @author zhangxing |
14 | 17 | * @date 2020年4月22日 |
15 | 18 | */ |
16 | -public class OrderResponseBuilder { | |
19 | +public class OrderDataBuilder { | |
17 | 20 | |
18 | 21 | /** |
19 | 22 | * 构建基本的订单详情数据 TODO need modify because of change |
20 | 23 | */ |
21 | 24 | public static OrderQueryResponseDto buildOrderDetail(OrderDo order, List<OrderItemDo> orderItem) { |
22 | - OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto(); | |
23 | - return orderQueryResponseDto; | |
25 | + OrderQueryResponseDto orderResponseDto = new OrderQueryResponseDto(); | |
26 | + BeanUtils.copyProperties(order, orderResponseDto); | |
27 | + for (OrderItemDo orderItemDo : orderItem) { | |
28 | + OrderItemDto orderItemDto = new OrderItemDto(); | |
29 | + BeanUtils.copyProperties(orderItemDo, orderItemDto); | |
30 | + orderResponseDto.addItems(orderItemDto); | |
31 | + } | |
32 | + return orderResponseDto; | |
24 | 33 | } |
25 | 34 | |
26 | 35 | } | ... | ... |
src/main/java/com/diligrp/xtrade/order/domain/dto/OrderQueryResponseDto.java
1 | 1 | package com.diligrp.xtrade.order.domain.dto; |
2 | 2 | |
3 | 3 | import java.time.LocalDateTime; |
4 | +import java.util.ArrayList; | |
4 | 5 | import java.util.List; |
5 | 6 | |
6 | 7 | /** |
... | ... | @@ -82,7 +83,11 @@ public class OrderQueryResponseDto { |
82 | 83 | private LocalDateTime payTime; |
83 | 84 | |
84 | 85 | //订单详情 |
85 | - private List<OrderItemDto> items; | |
86 | + private List<OrderItemDto> items = new ArrayList<OrderItemDto>(); | |
87 | + | |
88 | + public void addItems(OrderItemDto item) { | |
89 | + items.add(item); | |
90 | + } | |
86 | 91 | |
87 | 92 | public Long getOrderId() { |
88 | 93 | return orderId; | ... | ... |
src/main/java/com/diligrp/xtrade/order/service/impl/OrderServiceImpl.java
... | ... | @@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional; |
12 | 12 | import com.diligrp.xtrade.order.dao.OrderDao; |
13 | 13 | import com.diligrp.xtrade.order.dao.OrderItemDao; |
14 | 14 | import com.diligrp.xtrade.order.domain.builder.DefaultOrderCreator; |
15 | -import com.diligrp.xtrade.order.domain.builder.OrderResponseBuilder; | |
15 | +import com.diligrp.xtrade.order.domain.builder.OrderDataBuilder; | |
16 | 16 | import com.diligrp.xtrade.order.domain.dto.AccountDto; |
17 | 17 | import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto; |
18 | 18 | import com.diligrp.xtrade.order.domain.dto.OrderItemDto; |
... | ... | @@ -42,27 +42,27 @@ public class OrderServiceImpl implements OrderService { |
42 | 42 | // TODO need modify because of change |
43 | 43 | @Override |
44 | 44 | @Transactional(rollbackFor = Exception.class) |
45 | - public void createOrder(OrderCreateRequestDto orderCreateDto) { | |
45 | + public void createOrder(OrderCreateRequestDto orderDto) { | |
46 | 46 | |
47 | - //获取相关信息 | |
48 | - AccountDto saccountDto = accountResolver.getAccount(orderCreateDto.getSaccount()); | |
47 | + // 获取相关信息 | |
48 | + AccountDto saccount = accountResolver.getAccount(orderDto.getSaccount()); | |
49 | 49 | |
50 | - //构建订单创建者 | |
51 | - DefaultOrderCreator orderCreator = DefaultOrderCreator.builder(saccountDto, orderCreateDto, getOrderKey()); | |
50 | + // 构建订单创建者 | |
51 | + DefaultOrderCreator defaultOrderCreator = DefaultOrderCreator.builder(saccount, orderDto, orderKey()); | |
52 | 52 | |
53 | - //初始化订单基本信息 | |
54 | - orderCreator.initializeOrderBaseData(); | |
53 | + // 初始化订单基本信息 | |
54 | + defaultOrderCreator.initializeOrderBaseData(); | |
55 | 55 | |
56 | 56 | // 订单详情数据封装 |
57 | - for (OrderItemDto orderItemDto : orderCreateDto.getItems()) { | |
58 | - orderCreator.initializeItemData(getOrderItemKey(), orderItemDto); | |
57 | + for (OrderItemDto orderItemDto : orderDto.getItems()) { | |
58 | + defaultOrderCreator.initializeItemData(orderItemKey(), orderItemDto); | |
59 | 59 | } |
60 | 60 | |
61 | - //批量插入订单详情 | |
62 | - orderItemDao.insertBatch(orderCreator.createOrderItems()); | |
61 | + // 批量插入订单详情 | |
62 | + orderItemDao.insertBatch(defaultOrderCreator.createOrderItems()); | |
63 | 63 | |
64 | - //插入订单信息 | |
65 | - orderDao.insertEntity(orderCreator.createOrder()); | |
64 | + // 插入订单信息 | |
65 | + orderDao.insertEntity(defaultOrderCreator.createOrder()); | |
66 | 66 | } |
67 | 67 | |
68 | 68 | // TODO need modify because of change |
... | ... | @@ -83,22 +83,22 @@ public class OrderServiceImpl implements OrderService { |
83 | 83 | // TODO need modify because of change |
84 | 84 | @Override |
85 | 85 | public OrderQueryResponseDto orderDetail(Long orderId) { |
86 | - OrderQueryResponseDto orderQueryResponseDto = OrderResponseBuilder | |
86 | + OrderQueryResponseDto orderResponseDto = OrderDataBuilder | |
87 | 87 | .buildOrderDetail(orderDao.selectEntityByOrderId(orderId), orderItemDao.selectItemsByOrderId(orderId)); |
88 | - return orderQueryResponseDto; | |
88 | + return orderResponseDto; | |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * 获取订单业务主键 |
93 | 93 | */ |
94 | - private Long getOrderKey() { | |
94 | + private Long orderKey() { | |
95 | 95 | return keyGeneratorManager.getKeyGenerator(IdGenerator.ORDER_SEQUENCE).nextId(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * 获取订单详情主键 |
100 | 100 | */ |
101 | - private Long getOrderItemKey() { | |
101 | + private Long orderItemKey() { | |
102 | 102 | return keyGeneratorManager.getKeyGenerator(IdGenerator.ORDER_ITEM_SEQUENCE).nextId(); |
103 | 103 | } |
104 | 104 | ... | ... |