Merge branch 'hotfix-20200305' into test6.9.22
Showing
4 changed files
with
55 additions
and
20 deletions
1 | package com.yohoufo.dal.order.model; | 1 | package com.yohoufo.dal.order.model; |
2 | 2 | ||
3 | -import lombok.Data; | 3 | +import lombok.Getter; |
4 | +import lombok.Setter; | ||
4 | 5 | ||
5 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
7 | +import java.util.Objects; | ||
6 | 8 | ||
7 | /** | 9 | /** |
8 | * 交易流水表 | 10 | * 交易流水表 |
9 | */ | 11 | */ |
10 | -@Data | 12 | +@Getter |
13 | +@Setter | ||
11 | public class TradeBills { | 14 | public class TradeBills { |
12 | 15 | ||
13 | /** | 16 | /** |
@@ -38,7 +41,7 @@ public class TradeBills { | @@ -38,7 +41,7 @@ public class TradeBills { | ||
38 | private Integer tradeType; | 41 | private Integer tradeType; |
39 | 42 | ||
40 | //1:用户收入; 2:用户支出 | 43 | //1:用户收入; 2:用户支出 |
41 | - private Integer incomeOutcome; | 44 | + private Integer incomeOutcome; |
42 | 45 | ||
43 | private BigDecimal amount; | 46 | private BigDecimal amount; |
44 | 47 | ||
@@ -66,22 +69,39 @@ public class TradeBills { | @@ -66,22 +69,39 @@ public class TradeBills { | ||
66 | //支付阶段,0:普通,1:定金 | 69 | //支付阶段,0:普通,1:定金 |
67 | private int payLevel = 0; | 70 | private int payLevel = 0; |
68 | 71 | ||
69 | - /** | ||
70 | - * suggest use new enum, define class as blow | ||
71 | - * {@link com.yohoufo.order.common.BillTradeStatus} | ||
72 | - */ | 72 | + @Override |
73 | + public boolean equals(Object o) { | ||
74 | + if (this == o) return true; | ||
75 | + if (o == null || getClass() != o.getClass()) return false; | ||
76 | + TradeBills that = (TradeBills) o; | ||
77 | + return Objects.equals(uid, that.uid) && | ||
78 | + Objects.equals(orderCode, that.orderCode) && | ||
79 | + Objects.equals(userType, that.userType) && | ||
80 | + Objects.equals(tradeType, that.tradeType) && | ||
81 | + Objects.equals(incomeOutcome, that.incomeOutcome); | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public int hashCode() { | ||
86 | + return Objects.hash(uid, orderCode, userType, tradeType, incomeOutcome); | ||
87 | + } | ||
88 | + | ||
73 | @Deprecated | 89 | @Deprecated |
74 | public enum Status { | 90 | public enum Status { |
75 | - | ||
76 | - Null(0); | ||
77 | - | ||
78 | - Status(int code) { | ||
79 | - this.code = code; | ||
80 | - } | ||
81 | - private int code; | ||
82 | - public int getCode() { | ||
83 | - return code; | ||
84 | - } | ||
85 | - | 91 | + |
92 | + Null(0); | ||
93 | + | ||
94 | + Status(int code) { | ||
95 | + this.code = code; | ||
96 | + } | ||
97 | + | ||
98 | + private int code; | ||
99 | + | ||
100 | + public int getCode() { | ||
101 | + return code; | ||
102 | + } | ||
103 | + | ||
86 | } | 104 | } |
105 | + | ||
106 | + | ||
87 | } | 107 | } |
@@ -2,10 +2,14 @@ package com.yohoufo.order.repository; | @@ -2,10 +2,14 @@ package com.yohoufo.order.repository; | ||
2 | 2 | ||
3 | import com.yohoufo.dal.order.model.TradeBills; | 3 | import com.yohoufo.dal.order.model.TradeBills; |
4 | 4 | ||
5 | +import java.util.List; | ||
6 | + | ||
5 | public interface TradeBillsRepository { | 7 | public interface TradeBillsRepository { |
6 | 8 | ||
7 | int save(TradeBills record); | 9 | int save(TradeBills record); |
8 | 10 | ||
11 | + List<TradeBills> findByOrderCode(Long orderCode); | ||
12 | + | ||
9 | int lock(Integer id); | 13 | int lock(Integer id); |
10 | 14 | ||
11 | int unlock(Integer id); | 15 | int unlock(Integer id); |
1 | package com.yohoufo.order.repository; | 1 | package com.yohoufo.order.repository; |
2 | 2 | ||
3 | +import com.google.common.collect.Lists; | ||
3 | import com.yohoufo.common.alarm.EventBusPublisher; | 4 | import com.yohoufo.common.alarm.EventBusPublisher; |
4 | import com.yohoufo.dal.order.TradeBillsMapper; | 5 | import com.yohoufo.dal.order.TradeBillsMapper; |
5 | import com.yohoufo.dal.order.model.TradeBills; | 6 | import com.yohoufo.dal.order.model.TradeBills; |
@@ -7,6 +8,7 @@ import com.yohoufo.order.event.TradeBillsChangeEvent; | @@ -7,6 +8,7 @@ import com.yohoufo.order.event.TradeBillsChangeEvent; | ||
7 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
8 | import org.springframework.stereotype.Repository; | 9 | import org.springframework.stereotype.Repository; |
9 | 10 | ||
11 | +import java.util.List; | ||
10 | import java.util.Objects; | 12 | import java.util.Objects; |
11 | 13 | ||
12 | @Repository | 14 | @Repository |
@@ -27,6 +29,11 @@ public class TradeBillsRepositoryImpl implements TradeBillsRepository { | @@ -27,6 +29,11 @@ public class TradeBillsRepositoryImpl implements TradeBillsRepository { | ||
27 | } | 29 | } |
28 | 30 | ||
29 | @Override | 31 | @Override |
32 | + public List<TradeBills> findByOrderCode(Long orderCode) { | ||
33 | + return tradeBillsMapper.selectByOrderCodeList(Lists.newArrayList(orderCode)); | ||
34 | + } | ||
35 | + | ||
36 | + @Override | ||
30 | public int lock(Integer id) { | 37 | public int lock(Integer id) { |
31 | return tradeBillsMapper.updateLock(id); | 38 | return tradeBillsMapper.updateLock(id); |
32 | } | 39 | } |
@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; | @@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; | ||
28 | import javax.annotation.Resource; | 28 | import javax.annotation.Resource; |
29 | import java.math.BigDecimal; | 29 | import java.math.BigDecimal; |
30 | import java.util.Arrays; | 30 | import java.util.Arrays; |
31 | +import java.util.List; | ||
31 | import java.util.Objects; | 32 | import java.util.Objects; |
32 | import java.util.Optional; | 33 | import java.util.Optional; |
33 | 34 | ||
@@ -84,9 +85,12 @@ public class TransferManager { | @@ -84,9 +85,12 @@ public class TransferManager { | ||
84 | @Transactional(propagation = Propagation.REQUIRES_NEW) | 85 | @Transactional(propagation = Propagation.REQUIRES_NEW) |
85 | @Database(ForceMaster = true, DataSource = "ufo_order") | 86 | @Database(ForceMaster = true, DataSource = "ufo_order") |
86 | public ServiceException save(TransferBill transferBill) { | 87 | public ServiceException save(TransferBill transferBill) { |
87 | - if (Objects.isNull(transferBill.getTradeBills().getId())) { | 88 | + TradeBills tradeBills = transferBill.getTradeBills(); |
89 | + if (Objects.isNull(tradeBills.getId())) { | ||
88 | ServiceException serviceException = transferBill.resetTradeStatus(); | 90 | ServiceException serviceException = transferBill.resetTradeStatus(); |
89 | - tradeBillsRepository.save(transferBill.getTradeBills()); | 91 | + List<TradeBills> histories = tradeBillsRepository.findByOrderCode(tradeBills.getOrderCode()); |
92 | + throwServiceExceptionIf(histories.contains(tradeBills), 500, "转账单已存在"); | ||
93 | + tradeBillsRepository.save(tradeBills); | ||
90 | ordersPayTransferMapper.insert(transferBill.getTransfer()); | 94 | ordersPayTransferMapper.insert(transferBill.getTransfer()); |
91 | publishEvent(transferBill); | 95 | publishEvent(transferBill); |
92 | return serviceException; | 96 | return serviceException; |
-
Please register or login to post a comment