Commit 83d0bd6a02d2a851730cf76fabe0cd8d1d4c6212
1 parent
c5984e0d
[订单相关]
Showing
6 changed files
with
131 additions
and
86 deletions
src/main/java/com/diligrp/xtrade/order/dao/OrderItemDao.java
@@ -44,7 +44,7 @@ public interface OrderItemDao { | @@ -44,7 +44,7 @@ public interface OrderItemDao { | ||
44 | * @return | 44 | * @return |
45 | * @throws | 45 | * @throws |
46 | */ | 46 | */ |
47 | - List<OrderItemDo> selectOrderItemByOrderId(@Param("orderId") Long orderId); | 47 | + List<OrderItemDo> selectItemsByOrderId(@Param("orderId") Long orderId); |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * | 50 | * |
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderBuilder.java
0 → 100644
1 | +package com.diligrp.xtrade.order.domain.builder; | ||
2 | + | ||
3 | +import java.math.BigDecimal; | ||
4 | +import java.math.RoundingMode; | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +import com.diligrp.xtrade.order.domain.dto.AccountDto; | ||
8 | +import com.diligrp.xtrade.order.domain.dto.OrderItemDto; | ||
9 | +import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto; | ||
10 | +import com.diligrp.xtrade.order.domain.emuns.OrderType; | ||
11 | +import com.diligrp.xtrade.order.domain.emuns.SaleUnit; | ||
12 | +import com.diligrp.xtrade.order.domain.emuns.TradeType; | ||
13 | +import com.diligrp.xtrade.order.domain.entity.OrderDo; | ||
14 | +import com.diligrp.xtrade.order.domain.entity.OrderItemDo; | ||
15 | +import com.diligrp.xtrade.order.exception.OrderException; | ||
16 | + | ||
17 | +/** | ||
18 | + * @ClassName: DefaultOrderCreator | ||
19 | + * @Description 订单实体相关模型 | ||
20 | + * @author zhangxing | ||
21 | + * @date 2020年4月21日 | ||
22 | + */ | ||
23 | +public class DefaultOrderBuilder { | ||
24 | + | ||
25 | + /** | ||
26 | + * 构建初始订单数据 | ||
27 | + */ | ||
28 | + public static OrderDo initializeOrderBaseData(Long orderId, AccountDto saccountDto, Integer createSrc) { | ||
29 | + OrderDo order = new OrderDo(); | ||
30 | + order.setOrderId(orderId); | ||
31 | + order.setBaccount(saccountDto.getAccountId()); | ||
32 | + order.setSname(saccountDto.getAccountName()); | ||
33 | + order.setSmobile(saccountDto.getMobile()); | ||
34 | + order.setScardType(saccountDto.getType()); | ||
35 | + order.setCreatedSrc(createSrc); | ||
36 | + order.setOrderType(OrderType.NORMAL.getCode()); | ||
37 | + order.setTradeType(TradeType.NORMAL.getCode()); | ||
38 | + order.setMarketCode("SYDEV"); | ||
39 | + return order; | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * 订单详情初始化数据 | ||
44 | + */ | ||
45 | + public static OrderItemDo initializeOrderItemDoData(Long itemId, Long orderId, OrderItemDto orderItem){ | ||
46 | + OrderItemDo orderItemDo = new OrderItemDo(); | ||
47 | + orderItemDo.setItemId(itemId); | ||
48 | + orderItemDo.setOrderId(orderId); | ||
49 | + orderItemDo.setProductId(orderItem.getPid()); | ||
50 | + orderItemDo.setProductName(orderItem.getPname()); | ||
51 | + // 销售单价 | ||
52 | + BigDecimal price = BigDecimal.valueOf(orderItem.getPrice()); | ||
53 | + // 销售数量 | ||
54 | + BigDecimal amount = BigDecimal.valueOf(orderItem.getAmount()); | ||
55 | + | ||
56 | + orderItemDo.setAmount(orderItem.getAmount()); | ||
57 | + | ||
58 | + BigDecimal tempWeight = BigDecimal.valueOf(0.0D); | ||
59 | + | ||
60 | + if (SaleUnit.KILO.getCode() == orderItem.getSaleUnit()) { | ||
61 | + tempWeight = BigDecimal.valueOf(orderItem.getAmount()); | ||
62 | + } else if (SaleUnit.PIECE.getCode() == orderItem.getSaleUnit()) { | ||
63 | + if (orderItem.getUnitWeight() == null || orderItem.getUnitWeight() < 0) { | ||
64 | + throw new OrderException(String.format("%s件重非法", orderItem.getPname())); | ||
65 | + } | ||
66 | + BigDecimal dKiloPerItem = BigDecimal.valueOf(orderItem.getUnitWeight()); | ||
67 | + tempWeight = amount.multiply(dKiloPerItem); | ||
68 | + } | ||
69 | + orderItemDo.setWeight(tempWeight.doubleValue()); | ||
70 | + Long itemMoney = price.multiply(amount).setScale(0, RoundingMode.HALF_UP).longValue(); | ||
71 | + orderItemDo.setMoney(itemMoney); | ||
72 | + return orderItemDo; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * 构建基本的订单详情数据 | ||
77 | + */ | ||
78 | + public static OrderQueryResponseDto buildOrderDetail(OrderDo selectEntityByOrderId, | ||
79 | + List<OrderItemDo> selectItemsByOrderId) { | ||
80 | + OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto(); | ||
81 | + return orderQueryResponseDto; | ||
82 | + } | ||
83 | + | ||
84 | +} |
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderCreator.java deleted
100644 → 0
1 | -package com.diligrp.xtrade.order.domain.builder; | ||
2 | - | ||
3 | -import org.springframework.beans.BeanUtils; | ||
4 | - | ||
5 | -import com.diligrp.xtrade.order.domain.dto.AccountDto; | ||
6 | -import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto; | ||
7 | -import com.diligrp.xtrade.order.domain.entity.OrderDo; | ||
8 | - | ||
9 | -/** | ||
10 | - * @ClassName: DefaultOrderCreator | ||
11 | - * @Description 订单实体相关模型 | ||
12 | - * @author zhangxing | ||
13 | - * @date 2020年4月21日 | ||
14 | - */ | ||
15 | -public class DefaultOrderCreator { | ||
16 | - | ||
17 | - //最终订单数据 | ||
18 | - private OrderDo order; | ||
19 | - | ||
20 | - //订单创建请求实体 | ||
21 | - private OrderCreateRequestDto orderCreateRequestDto; | ||
22 | - | ||
23 | - //卖家实体 | ||
24 | - private AccountDto saccountDto; | ||
25 | - | ||
26 | - //买家实体 | ||
27 | - private AccountDto baccountDto; | ||
28 | - | ||
29 | - //无参构造器 | ||
30 | - public DefaultOrderCreator(){ | ||
31 | - | ||
32 | - } | ||
33 | - | ||
34 | - public DefaultOrderCreator(OrderCreateRequestDto orderCreateRequestDto, AccountDto saccountDto, AccountDto baccountDto){ | ||
35 | - this.orderCreateRequestDto = orderCreateRequestDto; | ||
36 | - this.baccountDto = baccountDto; | ||
37 | - this.saccountDto = saccountDto; | ||
38 | - } | ||
39 | - | ||
40 | - /** | ||
41 | - * 初始化订单数据用于后面的校验 | ||
42 | - */ | ||
43 | - public void initialize() { | ||
44 | - | ||
45 | - } | ||
46 | - | ||
47 | - public OrderDo getOrder() { | ||
48 | - return order; | ||
49 | - } | ||
50 | - | ||
51 | - public void setOrder(OrderDo order) { | ||
52 | - this.order = order; | ||
53 | - } | ||
54 | - | ||
55 | - public OrderCreateRequestDto getOrderCreateRequestDto() { | ||
56 | - return orderCreateRequestDto; | ||
57 | - } | ||
58 | - | ||
59 | - public void setOrderCreateRequestDto(OrderCreateRequestDto orderCreateRequestDto) { | ||
60 | - this.orderCreateRequestDto = orderCreateRequestDto; | ||
61 | - } | ||
62 | - | ||
63 | - public AccountDto getSaccountDto() { | ||
64 | - return saccountDto; | ||
65 | - } | ||
66 | - | ||
67 | - public void setSaccountDto(AccountDto saccountDto) { | ||
68 | - this.saccountDto = saccountDto; | ||
69 | - } | ||
70 | - | ||
71 | - public AccountDto getBaccountDto() { | ||
72 | - return baccountDto; | ||
73 | - } | ||
74 | - | ||
75 | - public void setBaccountDto(AccountDto baccountDto) { | ||
76 | - this.baccountDto = baccountDto; | ||
77 | - } | ||
78 | - | ||
79 | - public static OrderDo build(OrderCreateRequestDto orderCreateRequestDto) { | ||
80 | - OrderDo orderDo = new OrderDo(); | ||
81 | - BeanUtils.copyProperties(orderCreateRequestDto, orderDo); | ||
82 | - return orderDo; | ||
83 | - } | ||
84 | -} |
src/main/java/com/diligrp/xtrade/order/domain/entity/OrderDo.java
@@ -70,6 +70,9 @@ public class OrderDo extends BaseDo{ | @@ -70,6 +70,9 @@ public class OrderDo extends BaseDo{ | ||
70 | 70 | ||
71 | //订单类型 | 71 | //订单类型 |
72 | private Integer orderType; | 72 | private Integer orderType; |
73 | + | ||
74 | + //订单类型 | ||
75 | + private Integer tradeType; | ||
73 | 76 | ||
74 | //支付方式 | 77 | //支付方式 |
75 | private Integer payType; | 78 | private Integer payType; |
@@ -263,6 +266,14 @@ public class OrderDo extends BaseDo{ | @@ -263,6 +266,14 @@ public class OrderDo extends BaseDo{ | ||
263 | public void setOrderType(Integer orderType) { | 266 | public void setOrderType(Integer orderType) { |
264 | this.orderType = orderType; | 267 | this.orderType = orderType; |
265 | } | 268 | } |
269 | + | ||
270 | + public Integer getTradeType() { | ||
271 | + return tradeType; | ||
272 | + } | ||
273 | + | ||
274 | + public void setTradeType(Integer tradeType) { | ||
275 | + this.tradeType = tradeType; | ||
276 | + } | ||
266 | 277 | ||
267 | 278 | ||
268 | } | 279 | } |
src/main/java/com/diligrp/xtrade/order/rpc/feign/AccountResolver.java
0 → 100644
1 | +package com.diligrp.xtrade.order.rpc.feign; | ||
2 | + | ||
3 | +import javax.annotation.Resource; | ||
4 | + | ||
5 | +import org.springframework.http.HttpStatus; | ||
6 | +import org.springframework.stereotype.Component; | ||
7 | + | ||
8 | +import com.diligrp.xtrade.order.domain.dto.AccountDto; | ||
9 | +import com.diligrp.xtrade.order.exception.OrderException; | ||
10 | +import com.diligrp.xtrade.shared.domain.Message; | ||
11 | + | ||
12 | +/** | ||
13 | + * @ClassName: AccountResolver | ||
14 | + * @Description 远程卡务调用解析 | ||
15 | + * @author zhangxing | ||
16 | + * @date 2020年4月22日 | ||
17 | + */ | ||
18 | +@Component | ||
19 | +public class AccountResolver { | ||
20 | + | ||
21 | + @Resource | ||
22 | + private AccountRPC accountRPC; | ||
23 | + | ||
24 | + /** | ||
25 | + * 根据id获取账户信息 | ||
26 | + */ | ||
27 | + public AccountDto getAccount(Long accountId) { | ||
28 | + Message<AccountDto> message = accountRPC.getDltAccount(accountId); | ||
29 | + if (!HttpStatus.OK.equals(message.getCode())) { | ||
30 | + throw new OrderException(message.getMessage()); | ||
31 | + } | ||
32 | + return message.getData(); | ||
33 | + } | ||
34 | +} |
src/main/resources/mapping/com/diligrp/xtrade/order/OrderItemDao.xml
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | VALUES (#{itemId}, #{orderId}, #{productName}, #{productId}, #{price}, #{amount}, #{saleUnit}, #{unitWeight}, #{scommission}, #{bcommission}, #{ruleid}, #{ruleRate}, #{}weight, #{totalMoney}, NOW(), NOW()); | 13 | VALUES (#{itemId}, #{orderId}, #{productName}, #{productId}, #{price}, #{amount}, #{saleUnit}, #{unitWeight}, #{scommission}, #{bcommission}, #{ruleid}, #{ruleRate}, #{}weight, #{totalMoney}, NOW(), NOW()); |
14 | </insert> | 14 | </insert> |
15 | 15 | ||
16 | - <select id="selectOrderItemByItemId" parameterType="long" resultType="orderItemDo"> | 16 | + <select id="selectItemsByOrderId" parameterType="long" resultType="orderItemDo"> |
17 | SELECT | 17 | SELECT |
18 | <include refid="QUERY_COLUMN_LIST"/> | 18 | <include refid="QUERY_COLUMN_LIST"/> |
19 | FROM `xt_order_item` | 19 | FROM `xt_order_item` |