|
|
@@ -43,6 +43,8 @@ public class AppClient {
|
|
|
private String timeoutUnpaidOrdersUrl;
|
|
|
@Value("${hobbystocks.host.paidOrdersLastThreeDaysUrl:}")
|
|
|
private String paidOrdersLastThreeDaysUrl;
|
|
|
+ @Value("${hobbystocks.host.settlementOrdersUrl:}")
|
|
|
+ private String settlementOrdersUrl;
|
|
|
|
|
|
@Value("${hobbystocks.host.noticeUrl}")
|
|
|
private String noticeUrl;
|
|
|
@@ -220,6 +222,37 @@ public class AppClient {
|
|
|
return queryLotOrders(getPaidOrdersLastThreeDaysUrl(), "query paid lot orders last three days");
|
|
|
}
|
|
|
|
|
|
+ public Optional<List<Order>> querySettlementOrders(Long userId, Long lotId, Long auctionId) {
|
|
|
+ Map<String, Object> params = Maps.newHashMap();
|
|
|
+ params.put("userId", userId);
|
|
|
+ if (lotId != null) {
|
|
|
+ params.put("lotId", lotId);
|
|
|
+ }
|
|
|
+ if (auctionId != null) {
|
|
|
+ params.put("auctionId", auctionId);
|
|
|
+ }
|
|
|
+ String url = getSettlementOrdersUrl();
|
|
|
+ ForestResponse<CommonForestClient.Response<Map<String, Object>>> response;
|
|
|
+ try {
|
|
|
+ response = client.sendPost(url, getDefaultHeaderMap(), params);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("query settlement orders fail {}", url, e);
|
|
|
+ return Optional.empty();
|
|
|
+ }
|
|
|
+ if (Objects.isNull(response)
|
|
|
+ || !Objects.equals(response.getStatusCode(), 200)
|
|
|
+ || Objects.isNull(response.getResult())
|
|
|
+ || !isSuccessCode(response.getResult().getCode())) {
|
|
|
+ log.error("query settlement orders fail {}", url);
|
|
|
+ return Optional.empty();
|
|
|
+ }
|
|
|
+ Map<String, Object> data = response.getResult().getData();
|
|
|
+ if (CollectionUtils.isEmpty(data) || Objects.isNull(data.get("lotOrders"))) {
|
|
|
+ return Optional.of(Lists.newArrayList());
|
|
|
+ }
|
|
|
+ return Optional.of(JSON.parseArray(JSON.toJSONString(data.get("lotOrders")), Order.class));
|
|
|
+ }
|
|
|
+
|
|
|
private List<Order> queryLotOrders(String url, String operation) {
|
|
|
ForestResponse<CommonForestClient.Response<Map<String, Object>>> response = null;
|
|
|
try {
|
|
|
@@ -263,6 +296,13 @@ public class AppClient {
|
|
|
return orderUrl.replaceFirst("/create$", "/queryPaidOrdersLastThreeDays");
|
|
|
}
|
|
|
|
|
|
+ private String getSettlementOrdersUrl() {
|
|
|
+ if (Objects.nonNull(settlementOrdersUrl) && !settlementOrdersUrl.trim().isEmpty()) {
|
|
|
+ return settlementOrdersUrl;
|
|
|
+ }
|
|
|
+ return orderUrl.replaceFirst("/create$", "/querySettlementOrders");
|
|
|
+ }
|
|
|
+
|
|
|
private boolean isSuccessCode(Integer code) {
|
|
|
return Objects.equals(code, 0) || Objects.equals(code, 200);
|
|
|
}
|