Commit 482e60c73ce4d205d98c8b12efd6ccacb5370256

Authored by yangfan
2 parents cce2ed15 3e9131cc
src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderBuilder.java renamed to src/main/java/com/diligrp/xtrade/order/domain/builder/DefaultOrderCreator.java
... ... @@ -2,9 +2,11 @@ package com.diligrp.xtrade.order.domain.builder;
2 2  
3 3 import java.math.BigDecimal;
4 4 import java.math.RoundingMode;
  5 +import java.util.ArrayList;
5 6 import java.util.List;
6 7  
7 8 import com.diligrp.xtrade.order.domain.dto.AccountDto;
  9 +import com.diligrp.xtrade.order.domain.dto.OrderCreateRequestDto;
8 10 import com.diligrp.xtrade.order.domain.dto.OrderItemDto;
9 11 import com.diligrp.xtrade.order.domain.dto.OrderQueryResponseDto;
10 12 import com.diligrp.xtrade.order.domain.emuns.OrderType;
... ... @@ -20,32 +22,53 @@ import com.diligrp.xtrade.order.exception.OrderException;
20 22 * @author zhangxing
21 23 * @date 2020年4月21日
22 24 */
23   -public class DefaultOrderBuilder {
  25 +public class DefaultOrderCreator {
  26 +
  27 + private OrderDo orderDo = new OrderDo();
  28 +
  29 + private List<OrderItemDo> items = new ArrayList<OrderItemDo>();
  30 +
  31 + private AccountDto saccountDto;
  32 +
  33 + private OrderCreateRequestDto orderCreateDto;
  34 +
  35 + public DefaultOrderCreator() {
  36 + }
  37 +
  38 + public DefaultOrderCreator(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto) {
  39 + this.saccountDto = saccountDto;
  40 + this.orderCreateDto = orderCreateDto;
  41 + }
24 42  
  43 + public static DefaultOrderCreator builder(AccountDto saccountDto, OrderCreateRequestDto orderCreateDto, Long orderId) {
  44 + orderCreateDto.setOrderId(orderId);
  45 + return new DefaultOrderCreator(saccountDto, orderCreateDto);
  46 + }
  47 +
25 48 /**
26   - * 构建初始订单数据 TODO need modify because of change
  49 + * 构建初始订单数据 TODO need modify because of change
27 50 */
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;
  51 + public void initializeOrderBaseData() {
  52 + OrderDo orderDo = new OrderDo();
  53 + orderDo.setOrderId(orderCreateDto.getOrderId());
  54 + orderDo.setBaccount(saccountDto.getAccountId());
  55 + orderDo.setSname(saccountDto.getAccountName());
  56 + orderDo.setSmobile(saccountDto.getMobile());
  57 + orderDo.setScardType(saccountDto.getType());
  58 + orderDo.setCreatedSrc(orderCreateDto.getCreatedSrc());
  59 + orderDo.setOrderType(OrderType.NORMAL.getCode());
  60 + orderDo.setTradeType(TradeType.NORMAL.getCode());
  61 + orderDo.setMarketCode("SYDEV");
  62 + this.setOrderDo(orderDo);
40 63 }
41   -
  64 +
42 65 /**
43 66 * 订单详情初始化数据 TODO need modify because of change
44 67 */
45   - public static OrderItemDo initializeItemData(Long itemId, Long orderId, OrderItemDto orderItem){
  68 + public void initializeItemData(Long itemId, OrderItemDto orderItem) {
46 69 OrderItemDo orderItemDo = new OrderItemDo();
47 70 orderItemDo.setItemId(itemId);
48   - orderItemDo.setOrderId(orderId);
  71 + orderItemDo.setOrderId(orderDo.getOrderId());
49 72 orderItemDo.setProductId(orderItem.getPid());
50 73 orderItemDo.setProductName(orderItem.getPname());
51 74 // 销售单价
... ... @@ -69,16 +92,50 @@ public class DefaultOrderBuilder {
69 92 orderItemDo.setWeight(tempWeight.doubleValue());
70 93 Long itemMoney = price.multiply(amount).setScale(0, RoundingMode.HALF_UP).longValue();
71 94 orderItemDo.setMoney(itemMoney);
72   - return orderItemDo;
  95 + orderDo.setTotalMoney(orderDo.getTotalMoney() + orderItemDo.getMoney());
  96 + orderDo.setWeight(
  97 + BigDecimal.valueOf(orderDo.getWeight()).add(BigDecimal.valueOf(orderItemDo.getWeight())).doubleValue());
  98 + items.add(orderItemDo);
73 99 }
74 100  
75 101 /**
76   - * 构建基本的订单详情数据 TODO need modify because of change
  102 + * 构建基本的订单详情数据 TODO need modify because of change
77 103 */
78   - public static OrderQueryResponseDto buildOrderDetail(OrderDo order,
79   - List<OrderItemDo> orderItem) {
  104 + public static OrderQueryResponseDto buildOrderDetail(OrderDo order, List<OrderItemDo> orderItem) {
80 105 OrderQueryResponseDto orderQueryResponseDto = new OrderQueryResponseDto();
81 106 return orderQueryResponseDto;
82 107 }
83   -
  108 +
  109 + public List<OrderItemDo> getItems() {
  110 + return items;
  111 + }
  112 +
  113 + public void setItems(List<OrderItemDo> items) {
  114 + this.items = items;
  115 + }
  116 +
  117 + public OrderDo getOrderDo() {
  118 + return orderDo;
  119 + }
  120 +
  121 + public void setOrderDo(OrderDo orderDo) {
  122 + this.orderDo = orderDo;
  123 + }
  124 +
  125 + public AccountDto getSaccountDto() {
  126 + return saccountDto;
  127 + }
  128 +
  129 + public void setSaccountDto(AccountDto saccountDto) {
  130 + this.saccountDto = saccountDto;
  131 + }
  132 +
  133 + public OrderCreateRequestDto getOrderCreateDto() {
  134 + return orderCreateDto;
  135 + }
  136 +
  137 + public void setOrderCreateDto(OrderCreateRequestDto orderCreateDto) {
  138 + this.orderCreateDto = orderCreateDto;
  139 + }
  140 +
84 141 }
... ...
src/main/java/com/diligrp/xtrade/order/domain/dto/OrderCreateRequestDto.java
... ... @@ -12,6 +12,8 @@ import javax.validation.constraints.NotNull;
12 12 */
13 13 public class OrderCreateRequestDto {
14 14  
  15 + private Long orderId;
  16 +
15 17 // 卖家账号
16 18 @NotNull(message = "卖家账号不能为空")
17 19 private Long saccount;
... ... @@ -25,7 +27,7 @@ public class OrderCreateRequestDto {
25 27 // 总金额
26 28 private Long totalMoney;
27 29  
28   - // 订单来源
  30 + //订单来源
29 31 @NotNull(message = "订单创建来源不能为空")
30 32 private Integer createdSrc;
31 33  
... ... @@ -81,5 +83,13 @@ public class OrderCreateRequestDto {
81 83 this.createdSrc = createdSrc;
82 84 }
83 85  
  86 + public Long getOrderId() {
  87 + return orderId;
  88 + }
  89 +
  90 + public void setOrderId(Long orderId) {
  91 + this.orderId = orderId;
  92 + }
  93 +
84 94  
85 95 }
... ...
src/main/java/com/diligrp/xtrade/order/domain/entity/OrderDo.java
... ... @@ -57,7 +57,7 @@ public class OrderDo extends BaseDo{
57 57 private Long tradeNo;
58 58  
59 59 //总金额
60   - private Long totalMoney;
  60 + private Long totalMoney = 0L;
61 61  
62 62 //卖家佣金
63 63 private Long scommission;
... ... @@ -66,7 +66,7 @@ public class OrderDo extends BaseDo{
66 66 private Long bcommission;
67 67  
68 68 //总重量
69   - private Double weight;
  69 + private Double weight = 0.0D;
70 70  
71 71 //订单类型
72 72 private Integer orderType;
... ...
src/main/java/com/diligrp/xtrade/order/service/impl/OrderServiceImpl.java
... ... @@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
12 12  
13 13 import com.diligrp.xtrade.order.dao.OrderDao;
14 14 import com.diligrp.xtrade.order.dao.OrderItemDao;
15   -import com.diligrp.xtrade.order.domain.builder.DefaultOrderBuilder;
  15 +import com.diligrp.xtrade.order.domain.builder.DefaultOrderCreator;
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;
... ... @@ -44,22 +44,21 @@ public class OrderServiceImpl implements OrderService {
44 44 @Override
45 45 @Transactional(rollbackFor = Exception.class)
46 46 public void createOrder(OrderCreateRequestDto orderCreateDto) {
47   - Long orderId = getOrderKey();
  47 +
48 48 AccountDto saccountDto = accountResolver.getAccount(orderCreateDto.getSaccount());
49   - OrderDo order = DefaultOrderBuilder.initializeOrderBaseData(orderId, saccountDto,
50   - orderCreateDto.getCreatedSrc());
51   - Long totalMoney = 0L;
52   - BigDecimal weight = BigDecimal.valueOf(0.0D);
53   - List<OrderItemDo> orderItemDos = new ArrayList<OrderItemDo>();
54   - for (OrderItemDto orderItem : orderCreateDto.getItems()) {
  49 +
  50 + DefaultOrderCreator orderCreator = DefaultOrderCreator.builder(saccountDto, orderCreateDto, getOrderKey());
  51 +
  52 + orderCreator.initializeOrderBaseData();
  53 +
  54 + for (OrderItemDto orderItemDto : orderCreateDto.getItems()) {
55 55 // 订单详情数据封装
56   - OrderItemDo orderItemDo = DefaultOrderBuilder.initializeItemData(getOrderItemKey(), orderId, orderItem);
57   - totalMoney += orderItemDo.getMoney();
58   - weight = weight.add(BigDecimal.valueOf(orderItemDo.getWeight()));
59   - orderItemDos.add(orderItemDo);
  56 + orderCreator.initializeItemData(getOrderItemKey(), orderItemDto);
60 57 }
61   - orderItemDao.insertBatch(orderItemDos);
62   - orderDao.insertEntity(order);
  58 +
  59 + orderItemDao.insertBatch(orderCreator.getItems());
  60 +
  61 + orderDao.insertEntity(orderCreator.getOrderDo());
63 62 }
64 63  
65 64 // TODO need modify because of change
... ... @@ -80,7 +79,7 @@ public class OrderServiceImpl implements OrderService {
80 79 // TODO need modify because of change
81 80 @Override
82 81 public OrderQueryResponseDto orderDetail(Long orderId) {
83   - OrderQueryResponseDto orderQueryResponseDto = DefaultOrderBuilder
  82 + OrderQueryResponseDto orderQueryResponseDto = DefaultOrderCreator
84 83 .buildOrderDetail(orderDao.selectEntityByOrderId(orderId), orderItemDao.selectItemsByOrderId(orderId));
85 84 return orderQueryResponseDto;
86 85 }
... ...
src/main/resources/mapping/com/diligrp/xtrade/product/MerchantDao.xml
... ... @@ -53,12 +53,7 @@
53 53 <if test="description != null and description != ''">
54 54 `description` = #{description},
55 55 </if>
56   - <if test="createdTime != null">
57   - created_time = #{createdTime},
58   - </if>
59   - <if test="modifiedTime != null">
60   - modified_time = #{modifiedTime},
61   - </if>
  56 + modified_time = now(),
62 57 </set>
63 58 </sql>
64 59  
... ... @@ -119,7 +114,7 @@
119 114 insert into xt_merchant(mer_id, mer_name, market_id, account_id, account_name, type, status, description,
120 115 created_time, modified_time)
121 116 values (#{merId}, #{merName}, #{marketId}, #{accountId}, #{accountName}, #{type}, #{status}, #{description},
122   - #{createdTime}, #{modifiedTime})
  117 + now(), now())
123 118 </insert>
124 119  
125 120 <!--通过主键修改数据-->
... ...