Commit 3ac3320d03b5a3afea9f0764fe8871d28aa89abb

Authored by huanggang
2 parents 05f0cda4 1c8a3651

Merge branch 'main' of git3.nong12.com:cashierdesk/dili-cashier

cashier-mall/src/main/java/com/diligrp/cashier/mall/api/RtMallOrderRefundApi.java
@@ -41,7 +41,12 @@ public class RtMallOrderRefundApi { @@ -41,7 +41,12 @@ public class RtMallOrderRefundApi {
41 @PostMapping("/refund/v1") 41 @PostMapping("/refund/v1")
42 @ParamLogPrint(outPrint = true) 42 @ParamLogPrint(outPrint = true)
43 @Sign(sign = RtMallSign.class) 43 @Sign(sign = RtMallSign.class)
44 - @RepeatSubmit(prefix = "refund:", value = {"#req['order_id']", "#req['trade_id']"}, duplicationSubmit = SpelDuplicationSubmit.class) 44 + @RepeatSubmit(
  45 + prefix = "refund:",
  46 + waitTime = 5,
  47 + leaseTime = 10,
  48 + value = {"#req['order_id']", "#req['trade_id']"},
  49 + duplicationSubmit = SpelDuplicationSubmit.class)
45 public RtMarkMessage<RefundSuccessVO> refund(@RequestBody Object req) { 50 public RtMarkMessage<RefundSuccessVO> refund(@RequestBody Object req) {
46 RefundCO refundCo = JsonUtils.convertValue(req, RefundCO.class); 51 RefundCO refundCo = JsonUtils.convertValue(req, RefundCO.class);
47 RtMallValidateUtils.valid(refundCo); 52 RtMallValidateUtils.valid(refundCo);
cashier-mall/src/main/java/com/diligrp/cashier/mall/api/RtMallScanOrderRefundApi.java
@@ -41,7 +41,12 @@ public class RtMallScanOrderRefundApi { @@ -41,7 +41,12 @@ public class RtMallScanOrderRefundApi {
41 @PostMapping("/refund/v1") 41 @PostMapping("/refund/v1")
42 @ParamLogPrint(outPrint = true) 42 @ParamLogPrint(outPrint = true)
43 @Sign(sign = RtMallSign.class) 43 @Sign(sign = RtMallSign.class)
44 - @RepeatSubmit(prefix = "refund:", value = {"#req['order_id']", "#req['trade_id']"}, duplicationSubmit = SpelDuplicationSubmit.class) 44 + @RepeatSubmit(
  45 + prefix = "refund:",
  46 + waitTime = 5,
  47 + leaseTime = 10,
  48 + value = {"#req['order_id']", "#req['trade_id']"},
  49 + duplicationSubmit = SpelDuplicationSubmit.class)
45 public RtMarkMessage<RefundSuccessVO> refund(@RequestBody Object req) { 50 public RtMarkMessage<RefundSuccessVO> refund(@RequestBody Object req) {
46 RefundCO refundCo = JsonUtils.convertValue(req, RefundCO.class); 51 RefundCO refundCo = JsonUtils.convertValue(req, RefundCO.class);
47 RtMallValidateUtils.valid(refundCo); 52 RtMallValidateUtils.valid(refundCo);
cashier-mall/src/main/java/com/diligrp/cashier/mall/dao/MallBizRefundDao.java
@@ -22,5 +22,5 @@ public interface MallBizRefundDao extends MybatisMapperSupport { @@ -22,5 +22,5 @@ public interface MallBizRefundDao extends MybatisMapperSupport {
22 22
23 MallBizRefund getByRefundTradeId(@Param("refundTradeId") String refundTradeId); 23 MallBizRefund getByRefundTradeId(@Param("refundTradeId") String refundTradeId);
24 24
25 - int countRefund(@Param("bizOrderId") Long bizOrderId); 25 + long sumRefundFee(@Param("bizOrderId") Long bizOrderId);
26 } 26 }
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/biz/MallBizRefundService.java
@@ -19,7 +19,7 @@ public interface MallBizRefundService { @@ -19,7 +19,7 @@ public interface MallBizRefundService {
19 19
20 MallBizRefund getByRefundTradeId(String refundId); 20 MallBizRefund getByRefundTradeId(String refundId);
21 21
22 - int countRefund(Long bizOrderId); 22 + long sumRefundFee(Long bizOrderId);
23 23
24 void updateByPay(MallBizRefund mallBizRefund); 24 void updateByPay(MallBizRefund mallBizRefund);
25 } 25 }
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/biz/impl/MallBizRefundServiceImpl.java
@@ -63,10 +63,11 @@ public class MallBizRefundServiceImpl implements MallBizRefundService { @@ -63,10 +63,11 @@ public class MallBizRefundServiceImpl implements MallBizRefundService {
63 @Override 63 @Override
64 @Transactional(rollbackFor = {Exception.class}) 64 @Transactional(rollbackFor = {Exception.class})
65 public RefundSuccessVO refund(RefundCO refundCo) { 65 public RefundSuccessVO refund(RefundCO refundCo) {
66 - MallBizRefund mallBizRefund = mallBizRefundDao.getMallBizRefund(new MallBizRefund(refundCo.getOrderId(), refundCo.getTradeId()));  
67 - if (Objects.nonNull(mallBizRefund)) {  
68 - throw new RtMartMallException(RtMarkErrorCode.E5006);  
69 - } 66 + // 允许重复退款
  67 +// MallBizRefund mallBizRefund = mallBizRefundDao.getMallBizRefund(new MallBizRefund(refundCo.getOrderId(), refundCo.getTradeId()));
  68 +// if (Objects.nonNull(mallBizRefund)) {
  69 +// throw new RtMartMallException(RtMarkErrorCode.E5006);
  70 +// }
70 71
71 MallBizOrder mallBizOrder = mallBizOrderDao.getByOrderId(refundCo.getOrderId()); 72 MallBizOrder mallBizOrder = mallBizOrderDao.getByOrderId(refundCo.getOrderId());
72 if (Objects.isNull(mallBizOrder)) { 73 if (Objects.isNull(mallBizOrder)) {
@@ -167,8 +168,8 @@ public class MallBizRefundServiceImpl implements MallBizRefundService { @@ -167,8 +168,8 @@ public class MallBizRefundServiceImpl implements MallBizRefundService {
167 * countNoRefund 168 * countNoRefund
168 */ 169 */
169 @Override 170 @Override
170 - public int countRefund(Long bizOrderId) {  
171 - return mallBizRefundDao.countRefund(bizOrderId); 171 + public long sumRefundFee(Long bizOrderId) {
  172 + return mallBizRefundDao.sumRefundFee(bizOrderId);
172 } 173 }
173 174
174 @Override 175 @Override
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/sourcechannel/AbstractSourceChannel.java
@@ -14,7 +14,6 @@ import com.diligrp.cashier.mall.property.RtMallDynamicProperty; @@ -14,7 +14,6 @@ import com.diligrp.cashier.mall.property.RtMallDynamicProperty;
14 import com.diligrp.cashier.mall.service.biz.MallBizPaymentService; 14 import com.diligrp.cashier.mall.service.biz.MallBizPaymentService;
15 import com.diligrp.cashier.mall.service.biz.MallBizRefundService; 15 import com.diligrp.cashier.mall.service.biz.MallBizRefundService;
16 import com.diligrp.cashier.mall.type.OrderState; 16 import com.diligrp.cashier.mall.type.OrderState;
17 -import com.diligrp.cashier.mall.type.OrderType;  
18 import com.diligrp.cashier.mall.type.RtMarkErrorCode; 17 import com.diligrp.cashier.mall.type.RtMarkErrorCode;
19 import com.diligrp.cashier.pipeline.type.PaymentState; 18 import com.diligrp.cashier.pipeline.type.PaymentState;
20 import com.diligrp.cashier.shared.spi.domain.PaymentResultBO; 19 import com.diligrp.cashier.shared.spi.domain.PaymentResultBO;
@@ -129,8 +128,8 @@ public abstract class AbstractSourceChannel { @@ -129,8 +128,8 @@ public abstract class AbstractSourceChannel {
129 List<MallBizPaymentOrder> paymentOrderList = mallBizPaymentService.listPaymentOrderByBizOrderId(mallBizRefund.getBizOrderId()); 128 List<MallBizPaymentOrder> paymentOrderList = mallBizPaymentService.listPaymentOrderByBizOrderId(mallBizRefund.getBizOrderId());
130 boolean success = paymentOrderList.stream().allMatch(vo -> Objects.equals(vo.getPayState(), PaymentState.SUCCESS.getCode())); 129 boolean success = paymentOrderList.stream().allMatch(vo -> Objects.equals(vo.getPayState(), PaymentState.SUCCESS.getCode()));
131 if (success) { 130 if (success) {
132 - long count = mallBizRefundService.countRefund(mallBizRefund.getBizOrderId());  
133 - if (paymentOrderList.size() == count) { 131 + long sumRefundFee = mallBizRefundService.sumRefundFee(mallBizRefund.getBizOrderId());
  132 + if (paymentOrderList.stream().mapToLong(MallBizPaymentOrder::getPayFee).sum() == sumRefundFee) {
134 LOG.info("订单全部退款完成,orderId:{}", mallBizRefund.getBizOrderId()); 133 LOG.info("订单全部退款完成,orderId:{}", mallBizRefund.getBizOrderId());
135 mallBizOrderDao.updateByIds(List.of(mallBizRefund.getBizOrderId()), OrderState.PAYED_CANCEL.code); 134 mallBizOrderDao.updateByIds(List.of(mallBizRefund.getBizOrderId()), OrderState.PAYED_CANCEL.code);
136 } 135 }
cashier-mall/src/main/resources/com/diligrp/cashier/dao/mapper/MallBizRefundDao.xml
@@ -339,8 +339,9 @@ @@ -339,8 +339,9 @@
339 where refund_trade_id = #{refundTradeId} 339 where refund_trade_id = #{refundTradeId}
340 </select> 340 </select>
341 341
342 - <select id="countRefund" resultType="java.lang.Integer">  
343 - select count(*) 342 + <select id="sumRefundFee" resultType="java.lang.Long">
  343 + select
  344 + sum(refund_fee) as refundFee
344 from mall_biz_refund 345 from mall_biz_refund
345 where biz_order_id = #{bizOrderId} 346 where biz_order_id = #{bizOrderId}
346 and refund_state = 4 347 and refund_state = 4