Authored by LUOXC

refactor

@@ -10,10 +10,10 @@ import com.yoho.ufo.order.response.TradeBillsVo; @@ -10,10 +10,10 @@ import com.yoho.ufo.order.response.TradeBillsVo;
10 import com.yohobuy.ufo.model.order.common.AlipayBatchTransferErrorEnum; 10 import com.yohobuy.ufo.model.order.common.AlipayBatchTransferErrorEnum;
11 import org.apache.commons.lang3.ObjectUtils; 11 import org.apache.commons.lang3.ObjectUtils;
12 import org.apache.commons.lang3.StringUtils; 12 import org.apache.commons.lang3.StringUtils;
13 -import reactor.core.publisher.Mono;  
14 13
15 import java.util.List; 14 import java.util.List;
16 import java.util.Map; 15 import java.util.Map;
  16 +import java.util.Optional;
17 import java.util.stream.Collectors; 17 import java.util.stream.Collectors;
18 18
19 public class TradeBillsListBuilder { 19 public class TradeBillsListBuilder {
@@ -61,14 +61,13 @@ public class TradeBillsListBuilder { @@ -61,14 +61,13 @@ public class TradeBillsListBuilder {
61 61
62 62
63 private String buildPaidOrderCode(TradeBills item) { 63 private String buildPaidOrderCode(TradeBills item) {
64 - return Mono.justOrEmpty(item.getPaidOrderCode()) 64 + return Optional.ofNullable(item.getPaidOrderCode())
65 .filter(e -> e > 0) 65 .filter(e -> e > 0)
66 .map(Object::toString) 66 .map(Object::toString)
67 - .switchIfEmpty(Mono.justOrEmpty(item.getId())  
68 - .map(transferMessageMap::get)  
69 - .map(TradeBillsTransferMessage::getOutTradeNo))  
70 - .defaultIfEmpty("-")  
71 - .block(); 67 + .orElseGet(() -> Optional.ofNullable(item.getId())
  68 + .map(id -> transferMessageMap.get(id))
  69 + .map(TradeBillsTransferMessage::getOutTradeNo)
  70 + .orElse("-"));
72 } 71 }
73 72
74 private String buildTimeStr(Integer time) { 73 private String buildTimeStr(Integer time) {
@@ -85,14 +84,13 @@ public class TradeBillsListBuilder { @@ -85,14 +84,13 @@ public class TradeBillsListBuilder {
85 .filter(e -> e.isFail()) 84 .filter(e -> e.isFail())
86 .ifPresent(e -> { 85 .ifPresent(e -> {
87 //打款失败原因 86 //打款失败原因
88 - String failReason = Mono.justOrEmpty(item.getId()) 87 + String failReason = Optional.ofNullable(item.getId())
89 .map(transferMessageMap::get) 88 .map(transferMessageMap::get)
90 .map(TradeBillsTransferMessage::tradeResultMessage) 89 .map(TradeBillsTransferMessage::tradeResultMessage)
91 - .switchIfEmpty(Mono.justOrEmpty(item.getPayErrorCode()) 90 + .orElseGet(() -> Optional.ofNullable(item.getPayErrorCode())
92 .map(AlipayBatchTransferErrorEnum::getByCode) 91 .map(AlipayBatchTransferErrorEnum::getByCode)
93 - .map(AlipayBatchTransferErrorEnum::getDesc))  
94 - .defaultIfEmpty("-")  
95 - .block(); 92 + .map(AlipayBatchTransferErrorEnum::getDesc)
  93 + .orElse(e.getDesc()));
96 desc.append(failReason); 94 desc.append(failReason);
97 }); 95 });
98 return desc.toString(); 96 return desc.toString();