尽量服用,和优化采样区块,交易所在区块的资源参数 获取不需要每次获取有下单租赁订单都获取一遍,应该是全局异步获取是不是就可以,帮我设计合理方案。 和清理逻辑
This commit is contained in:
1 parent
13665668ac
commit
1538cd0819
24 files changed
+1894
-230
No files matched your search
@@ -13,6 +13,8 @@ import java.util.function.Supplier;
|
||||
@Service
|
||||
@lombok.extern.slf4j.Slf4j
|
||||
public class RentalTasks {
|
||||
@org.springframework.beans.factory.annotation.Autowired(required = false)
|
||||
private org.springframework.context.ApplicationEventPublisher deliveryEvents;
|
||||
private final RentalStore store;
|
||||
private final RentalChain chain;
|
||||
private final RentalIdentity identity;
|
||||
@@ -423,6 +425,7 @@ public class RentalTasks {
|
||||
java.time.LocalDateTime.ofInstant(
|
||||
Instant.ofEpochMilli(signed), java.time.ZoneOffset.UTC),
|
||||
taskNo);
|
||||
RentalDeliveryEvents.afterCommit(deliveryEvents, false, nodeId);
|
||||
}
|
||||
|
||||
public void reclaim(long orderId) {
|
||||
@@ -634,6 +637,7 @@ public class RentalTasks {
|
||||
Map<String, Object> fields = new LinkedHashMap<>(proof);
|
||||
fields.remove("delivery_proven");
|
||||
fields.remove("history_proof");
|
||||
fields.remove("delivery_evidence_gap");
|
||||
fields.put("evidence", orders.encode(proof));
|
||||
fields.put("confirmed_at", now());
|
||||
store.update("transaction", number(record, "id"), fields);
|
||||
@@ -682,11 +686,18 @@ public class RentalTasks {
|
||||
if (delegate) {
|
||||
Instant start = time(proof.get("block_time")),
|
||||
expires = start.plusSeconds(number(order, "duration_seconds"));
|
||||
boolean delivered =
|
||||
Boolean.TRUE.equals(proof.get("delivery_proven"))
|
||||
&& number(proof, "verified_resource_quantity")
|
||||
>= number(order, "target_resource_quantity")
|
||||
&& expires.isAfter(Instant.now());
|
||||
Instant checkedAt = Instant.now();
|
||||
// 在同一次判断中固定核验时间;记录所有未满足项,避免日志与状态跨租期边界不一致。
|
||||
String reviewReason = RentalDeliveryDiagnostics.explain(
|
||||
Boolean.TRUE.equals(proof.get("delivery_proven")),
|
||||
proof.get("verified_resource_quantity") == null ? null
|
||||
: number(proof, "verified_resource_quantity"),
|
||||
number(order, "target_resource_quantity"), expires, checkedAt);
|
||||
String gap = RentalDeliveryDiagnostics.evidenceGap(text(proof, "delivery_evidence_gap"));
|
||||
if (!gap.isEmpty() && !Boolean.TRUE.equals(proof.get("delivery_proven"))) {
|
||||
reviewReason += ";" + gap;
|
||||
}
|
||||
boolean delivered = reviewReason.isEmpty();
|
||||
if (delivered) {
|
||||
funds.charge(order);
|
||||
}
|
||||
@@ -710,6 +721,14 @@ public class RentalTasks {
|
||||
delivered ? null : "DELIVERY_EVIDENCE_REVIEW"));
|
||||
if (delivered) {
|
||||
orders.webhook(order, "SUCCESS", "ORDER:" + orderId + ":SUCCESS");
|
||||
} else {
|
||||
// 与人工核对状态同事务保存,查询端无需推测或重新查询链上即可展示当时的原因。
|
||||
store.event("ORDER", orderId, "DELIVERY_REVIEW", 0, reviewReason);
|
||||
log.warn("租赁履约未通过 orderId={} taskId={} txId={} historyProven={}"
|
||||
+ " verifiedQuantity={} targetQuantity={} reason={}",
|
||||
orderId, taskId, record.get("tx_id"), proof.get("delivery_proven"),
|
||||
proof.get("verified_resource_quantity"), order.get("target_resource_quantity"),
|
||||
reviewReason);
|
||||
}
|
||||
} else {
|
||||
store.update(
|
||||
|
||||
Reference in new issue
Block a user