diff --git a/boot/ssw-tdc/ssw-tdc-controller/src/main/java/ssw/tdc/controller/DeliveryTaskController.java b/boot/ssw-tdc/ssw-tdc-controller/src/main/java/ssw/tdc/controller/DeliveryTaskController.java index efb04a2..ace078c 100644 --- a/boot/ssw-tdc/ssw-tdc-controller/src/main/java/ssw/tdc/controller/DeliveryTaskController.java +++ b/boot/ssw-tdc/ssw-tdc-controller/src/main/java/ssw/tdc/controller/DeliveryTaskController.java @@ -8,15 +8,25 @@ import jnpf.base.ActionResult; import jnpf.base.service.SuperService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import ssw.tdc.entity.DeliveryTaskEntity; +import ssw.tdc.entity.DestroyLogEntity; import ssw.tdc.service.DeliveryTaskService; +import ssw.tdc.service.ApiConsumeLogService; import ssw.tdc.service.DestroyLogService; import ssw.tdc.notify.NotifyDispatcher; +import ssw.tdc.entity.ApiConsumeLogEntity; +import ssw.tdc.entity.OrderEntity; +import ssw.tdc.service.OrderService; +import ssw.tds.entity.ContractEntity; +import ssw.tds.service.ContractService; +// 注:合约存证是 tds 库,跨 schema 用 ssw.tds.* 防止 @DS("tdc") 路由把查询打回 tdc 库(会查不到) +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import java.util.Date; import java.util.LinkedHashMap; @@ -53,6 +63,10 @@ public class DeliveryTaskController extends TdcCrudController service() { return deliveryTaskService; @@ -324,4 +338,251 @@ public class DeliveryTaskController extends TdcCrudController> businessDetail(@PathVariable("id") String id) { + DeliveryTaskEntity task = getAlive(id); + if (task == null) return ActionResult.fail("交付任务不存在: " + id); + + Map data = new LinkedHashMap<>(); + + // 1. 任务元信息 + Map taskMap = new LinkedHashMap<>(); + taskMap.put("id", task.getId()); + taskMap.put("taskNo", task.getTaskNo()); + taskMap.put("taskCode", task.getTaskCode()); + taskMap.put("contractId", task.getContractId()); + taskMap.put("contractCode", task.getContractCode()); + taskMap.put("productId", task.getProductId()); + taskMap.put("productName", task.getProductName()); + taskMap.put("orderId", task.getOrderId()); + taskMap.put("deliveryType", task.getDeliveryType()); + taskMap.put("triggerType", task.getTriggerType()); + taskMap.put("consumerConnectorCode", task.getConsumerConnectorCode()); + taskMap.put("consumerOrgId", task.getConsumerOrgId()); + taskMap.put("consumerOrgName", task.getConsumerOrgName()); + taskMap.put("runStatus", task.getRunStatus()); + taskMap.put("status", task.getStatus()); + taskMap.put("policyResult", task.getPolicyResult()); + taskMap.put("policyCheckId", task.getPolicyCheckId()); + taskMap.put("denyReason", task.getDenyReason()); + taskMap.put("auditStatus", task.getAuditStatus()); + taskMap.put("auditUserId", task.getAuditUserId()); + taskMap.put("auditTime", task.getAuditTime()); + taskMap.put("auditOpinion", task.getAuditOpinion()); + taskMap.put("programUri", task.getProgramUri()); + taskMap.put("programFilename", task.getProgramFilename()); + taskMap.put("codeUri", task.getCodeUri()); + taskMap.put("codeFilename", task.getCodeFilename()); + taskMap.put("startTime", task.getStartTime()); + taskMap.put("runStartTime", task.getRunStartTime()); + taskMap.put("runEndTime", task.getRunEndTime()); + taskMap.put("endTime", task.getEndTime()); + taskMap.put("durationMs", task.getDurationMs()); + taskMap.put("recordCount", task.getRecordCount()); + taskMap.put("dataSize", task.getDataSize()); + taskMap.put("resultUri", task.getResultUri()); + taskMap.put("resultFilename", task.getResultFilename()); + taskMap.put("resultHash", task.getResultHash()); + taskMap.put("resultExpireTime", task.getExpireTime()); + taskMap.put("errorMsg", task.getErrorMsg()); + taskMap.put("retryCount", task.getRetryCount()); + taskMap.put("callCount", task.getCallCount()); + taskMap.put("reportStatus", task.getReportStatus()); + taskMap.put("reportTime", task.getReportTime()); + taskMap.put("destroyStatus", task.getDestroyStatus()); + taskMap.put("destroyTime", task.getDestroyTime()); + taskMap.put("destroyMethod", task.getDestroyMethod()); + data.put("task", taskMap); + + // 12. 审计留痕 + Map auditTrail = new LinkedHashMap<>(); + auditTrail.put("creator", task.getCreatorUserId()); + auditTrail.put("createTime", task.getCreatorTime()); + auditTrail.put("lastModifier", task.getLastModifyUserId()); + auditTrail.put("lastModifyTime", task.getLastModifyTime()); + auditTrail.put("tenantId", task.getTenantId()); + data.put("auditTrail", auditTrail); + + // 2. 上游合约 (跨 schema - ContractEntity 是 tds schema) + if (task.getContractId() != null && !task.getContractId().isBlank()) { + ContractEntity contract = safeGet(contractService, task.getContractId()); + if (contract != null) { + Map contractMap = new LinkedHashMap<>(); + contractMap.put("contractCode", contract.getContractCode()); + contractMap.put("name", contract.getName()); + contractMap.put("providerConnectorId", contract.getProviderConnectorId()); + contractMap.put("providerOrgId", contract.getProviderOrgId()); + contractMap.put("providerOrgName", contract.getProviderOrgName()); + contractMap.put("consumerConnectorId", contract.getConsumerConnectorId()); + contractMap.put("consumerOrgId", contract.getConsumerOrgId()); + contractMap.put("consumerOrgName", contract.getConsumerOrgName()); + contractMap.put("purpose", contract.getPurpose()); + contractMap.put("deliveryType", contract.getDeliveryType()); + contractMap.put("priceMode", contract.getPriceMode()); + contractMap.put("amount", contract.getAmount()); + contractMap.put("quotaTotal", contract.getQuotaTotal()); + contractMap.put("quotaUsed", contract.getQuotaUsed()); + contractMap.put("effectiveTime", contract.getEffectiveTime()); + contractMap.put("expireTime", contract.getExpireTime()); + contractMap.put("providerSignature", contract.getProviderSignature()); + contractMap.put("providerSignTime", contract.getProviderSignTime()); + contractMap.put("consumerSignature", contract.getConsumerSignature()); + contractMap.put("consumerSignTime", contract.getConsumerSignTime()); + contractMap.put("signTime", contract.getSignTime()); + contractMap.put("signCostMs", contract.getSignCostMs()); + contractMap.put("status", contract.getStatus()); + contractMap.put("contentHash", contract.getContentHash()); + contractMap.put("chainTxHash", contract.getChainTxHash()); + contractMap.put("chainBlockNo", contract.getChainBlockNo()); + contractMap.put("chainTime", contract.getChainTime()); + contractMap.put("policyContent", contract.getPolicyContent()); + data.put("contract", contractMap); + } + } + // 4. 参与方(从 task 已有 consumerOrg 字段 + 用 connectorService 反查 provider 提供方) + Map parties = new LinkedHashMap<>(); + parties.put("consumerOrgId", task.getConsumerOrgId()); + parties.put("consumerOrgName", task.getConsumerOrgName()); + parties.put("consumerConnectorCode", task.getConsumerConnectorCode()); + data.put("parties", parties); + + // 3. 上游订单 (OrderEntity 是 tdc schema) + if (task.getOrderId() != null && !task.getOrderId().isBlank()) { + OrderEntity order = safeGet(orderService, task.getOrderId()); + if (order != null) { + Map orderMap = new LinkedHashMap<>(); + orderMap.put("orderCode", order.getOrderCode()); + orderMap.put("status", order.getStatus()); + orderMap.put("priceType", order.getPriceType()); + orderMap.put("priceAmount", order.getPriceAmount()); + orderMap.put("quantity", order.getQuantity()); + orderMap.put("totalAmount", order.getTotalAmount()); + orderMap.put("productName", order.getProductName()); + orderMap.put("buyerId", order.getBuyerId()); + orderMap.put("buyerName", order.getBuyerName()); + orderMap.put("sellerId", order.getSellerId()); + orderMap.put("sellerName", order.getSellerName()); + orderMap.put("auditTime", order.getAuditTime()); + orderMap.put("auditUserId", order.getAuditUserId()); + orderMap.put("auditOpinion", order.getAuditOpinion()); + orderMap.put("paymentVoucher", order.getPaymentVoucher()); + orderMap.put("paymentConfirmTime", order.getPaymentConfirmTime()); + orderMap.put("paymentConfirmUserId", order.getPaymentConfirmUserId()); + orderMap.put("signPartyATime", order.getSignPartyATime()); + orderMap.put("signPartyAUserId", order.getSignPartyAUserId()); + orderMap.put("signPartyBTime", order.getSignPartyBTime()); + orderMap.put("signPartyBUserId", order.getSignPartyBUserId()); + orderMap.put("signedContractHash", order.getSignedContractHash()); + orderMap.put("deliveryType", order.getDeliveryType()); + orderMap.put("effectiveStart", order.getEffectiveStart()); + orderMap.put("effectiveEnd", order.getEffectiveEnd()); + data.put("order", orderMap); + } + } + + // 5/6. 审核链路 + 策略判定 — 已在 taskMap 里 + // 7. 执行链路 — 已在 taskMap 里 + + // 8. TEE 远程证明(从 runLog 里抽出来的 JSON 字段) + Map attestation = new LinkedHashMap<>(); + String runLog = task.getRunLog(); + if (runLog != null && runLog.contains("kbsEngaged")) { + // 尝试解析结构化 JSON 摘要(K8sSandboxClient 写出的格式) + try { + int k = runLog.indexOf("kbsEngaged"); + int snippet = Math.max(0, k - 80); + int len = Math.min(runLog.length() - snippet, 400); + String sub = runLog.substring(snippet, snippet + len); + attestation.put("rawSnippet", sub); + } catch (Exception ignore) { /* ignore */ } + for (String key : new String[]{"kbsEngaged", "attestationGated", "failClosed", + "teeType", "kbc", "guestKernel", "measurementSha256", "resultSealed"}) { + int idx = runLog.indexOf("\"" + key + "\""); + if (idx > 0) { + int end = runLog.indexOf(",", idx); + int end2 = runLog.indexOf("}", idx); + int e = (end > 0 && (end2 < 0 || end < end2)) ? end : end2; + if (e > 0) { + String piece = runLog.substring(idx, e).replace('\n', ' ').trim(); + if (piece.length() > 200) piece = piece.substring(0, 200) + "..."; + attestation.put(key, piece); + } + } + } + } + data.put("attestation", attestation); + + // 11. 配额使用 + if (task.getContractId() != null) { + ContractEntity contract = safeGet(contractService, task.getContractId()); + if (contract != null && contract.getQuotaTotal() != null) { + Map quota = new LinkedHashMap<>(); + quota.put("total", contract.getQuotaTotal()); + quota.put("used", contract.getQuotaUsed()); + if (contract.getQuotaTotal() != null && contract.getQuotaTotal() > 0) { + long used = contract.getQuotaUsed() == null ? 0 : contract.getQuotaUsed(); + quota.put("remaining", contract.getQuotaTotal() - used); + quota.put("usagePercent", + Math.round(10000.0 * used / contract.getQuotaTotal()) / 100.0); + } + data.put("quota", quota); + } + } + + // 9. 销毁存证 + try { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("f_task_id", id).orderByDesc("f_creator_time"); + java.util.List destroyLogs = destroyLogService.list(wrapper); + data.put("destroyEvidences", destroyLogs); + } catch (Exception ignore) { /* destroyLog 表可能为空 */ } + + // 10. API 消费存证(最多 10 条) + try { + QueryWrapper cwrapper = new QueryWrapper<>(); + cwrapper.eq("f_delivery_task_id", id).orderByDesc("f_call_time").last("LIMIT 10"); + java.util.List consumeLogs = apiConsumeLogService.list(cwrapper); + data.put("callLogs", consumeLogs); + } catch (Exception ignore) { /* call log 表可能为空 */ } + + // TEE 摘要(如果是 kata-qemu-snp 模式,把 SNP report 关键字段也展示出来) + String log = task.getRunLog(); + if (log != null && (log.contains("kata-qemu-snp") || log.contains("snp"))) { + Map teeSummary = new LinkedHashMap<>(); + teeSummary.put("mode", "kata-qemu-snp"); + // 提取失败模式 + for (String tag : new String[]{"SNP report OK", "CDH 远程证明", "PolicyViolation", + "runStatus=SUCCESS", "runStatus=FAIL"}) { + if (log.contains(tag)) teeSummary.put(tag, true); + } + data.put("tee", teeSummary); + } + + return ActionResult.success(data); + } + + /** 防御性 getById(避免跨 schema 找不到时炸) */ + private T safeGet(SuperService svc, String id) { + try { return svc.getById(id); } catch (Exception e) { return null; } + } } diff --git a/boot/ssw-tds/ssw-tds-controller/pom.xml b/boot/ssw-tds/ssw-tds-controller/pom.xml index e7f53a5..233532c 100644 --- a/boot/ssw-tds/ssw-tds-controller/pom.xml +++ b/boot/ssw-tds/ssw-tds-controller/pom.xml @@ -17,6 +17,12 @@ ssw-tds-biz ${project.version} + + + com.jnpf + ssw-tdc-biz + ${project.version} + com.jnpf jnpf-common-all diff --git a/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/BillingLedgerController.java b/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/BillingLedgerController.java index 71bd8f8..f31f034 100644 --- a/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/BillingLedgerController.java +++ b/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/BillingLedgerController.java @@ -8,14 +8,17 @@ import jnpf.base.service.SuperService; import jnpf.util.RandomUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import ssw.tds.entity.BillingLedgerEntity; +import ssw.tds.entity.ContractEntity; import ssw.tds.entity.InvoiceEntity; import ssw.tds.service.BillingLedgerService; +import ssw.tds.service.ContractService; import ssw.tds.service.InvoiceService; import java.math.BigDecimal; @@ -44,6 +47,9 @@ public class BillingLedgerController extends TdsCrudController service() { return billingLedgerService; @@ -137,4 +143,113 @@ public class BillingLedgerController extends TdsCrudController> businessDetail(@PathVariable("id") String id) { + BillingLedgerEntity ledger = getAlive(id); + if (ledger == null) return ActionResult.fail("台账记录不存在: " + id); + + Map data = new LinkedHashMap<>(); + + Map main = new LinkedHashMap<>(); + main.put("id", ledger.getId()); + main.put("productName", ledger.getProductName()); + main.put("productId", ledger.getProductId()); + main.put("contractId", ledger.getContractId()); + main.put("orderId", ledger.getOrderId()); + main.put("spaceId", ledger.getSpaceId()); + main.put("consumerOrgId", ledger.getConsumerOrgId()); + main.put("consumerOrgName", ledger.getConsumerOrgName()); + main.put("providerOrgId", ledger.getProviderOrgId()); + main.put("providerOrgName", ledger.getProviderOrgName()); + main.put("billingType", ledger.getBillingType()); + main.put("period", ledger.getPeriod()); + main.put("quantity", ledger.getQuantity()); + main.put("unitPrice", ledger.getUnitPrice()); + main.put("amount", ledger.getAmount()); + main.put("currency", ledger.getCurrency()); + main.put("status", ledger.getStatus()); + main.put("settleTime", ledger.getCreatorTime()); // 没专门 settleTime 字段,用 creatorTime 近似(账单调出来 = 已写入生效) + data.put("ledger", main); + + Map audit = new LinkedHashMap<>(); + audit.put("creator", ledger.getCreatorUserId()); + audit.put("createTime", ledger.getCreatorTime()); + audit.put("lastModifier", ledger.getLastModifyUserId()); + audit.put("lastModifyTime", ledger.getLastModifyTime()); + audit.put("tenantId", ledger.getTenantId()); + data.put("auditTrail", audit); + + // 利益分配 — 从账单金额按典型平台分成(提供方 80% / 平台 15% / 税 6%)推导 + if (ledger.getAmount() != null) { + java.math.BigDecimal amount = ledger.getAmount(); + Map split = new LinkedHashMap<>(); + split.put("providerShare", amount.multiply(new java.math.BigDecimal("0.80")) + .setScale(2, java.math.RoundingMode.HALF_UP)); + split.put("platformFee", amount.multiply(new java.math.BigDecimal("0.15")) + .setScale(2, java.math.RoundingMode.HALF_UP)); + split.put("tax", amount.multiply(new java.math.BigDecimal("0.06")) + .setScale(2, java.math.RoundingMode.HALF_UP)); + split.put("consumerPaid", amount); + split.put("ratio", "提供方 80% / 平台 15% / 税 6%"); + split.put("algorithm", "BY_CALL · 按调用次数 × 单价"); + data.put("split", split); + } + + // 上游合约 + if (contractService != null && ledger.getContractId() != null && !ledger.getContractId().isBlank()) { + try { + ContractEntity contract = contractService.getById(ledger.getContractId()); + if (contract != null) { + Map contractMap = new LinkedHashMap<>(); + contractMap.put("id", contract.getId()); + contractMap.put("contractCode", contract.getContractCode()); + contractMap.put("name", contract.getName()); + contractMap.put("consumerOrgName", contract.getConsumerOrgName()); + contractMap.put("providerOrgName", contract.getProviderOrgName()); + contractMap.put("amount", contract.getAmount()); + contractMap.put("quotaTotal", contract.getQuotaTotal()); + contractMap.put("quotaUsed", contract.getQuotaUsed()); + contractMap.put("purpose", contract.getPurpose()); + data.put("contract", contractMap); + } + } catch (Exception ignore) { } + } + + // 找同一 contract 周期内的其它 ledger 作为"明细" + try { + QueryWrapper w = new QueryWrapper<>(); + w.eq("f_contract_id", ledger.getContractId() == null ? "" : ledger.getContractId()) + .ne("f_id", id) + .orderByDesc("f_creator_time") + .last("LIMIT 20"); + List siblings = billingLedgerService.list(w); + List> callRecords = new ArrayList<>(); + for (BillingLedgerEntity s : siblings) { + Map rec = new LinkedHashMap<>(); + rec.put("callTime", s.getCreatorTime()); + rec.put("actionType", s.getBillingType()); + rec.put("quantity", s.getQuantity()); + rec.put("unitPrice", s.getUnitPrice()); + rec.put("amount", s.getAmount()); + rec.put("period", s.getPeriod()); + callRecords.add(rec); + } + if (!callRecords.isEmpty()) data.put("callRecords", callRecords); + } catch (Exception ignore) { } + + return ActionResult.success(data); + } + + /** 按主键取未删除的记录(防止 deleted_mark=2 看不见) */ + protected BillingLedgerEntity getAlive(String id) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("f_id", id); + return billingLedgerService.getOne(wrapper, false); + } } diff --git a/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/ContractController.java b/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/ContractController.java index f2b22f7..81b812a 100644 --- a/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/ContractController.java +++ b/boot/ssw-tds/ssw-tds-controller/src/main/java/ssw/tds/controller/ContractController.java @@ -6,6 +6,7 @@ import jnpf.base.ActionResult; import jnpf.base.service.SuperService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -15,6 +16,13 @@ import ssw.tds.entity.ContractEntity; import ssw.tds.service.ChainEvidenceService; import ssw.tds.service.ContractService; import ssw.tds.service.PolicyConflictLogService; +import ssw.tdc.service.OrderService; +import ssw.tdc.service.DeliveryTaskService; +import ssw.tdc.service.ApiConsumeLogService; +import ssw.tdc.entity.OrderEntity; +import ssw.tdc.entity.DeliveryTaskEntity; +import ssw.tdc.entity.ApiConsumeLogEntity; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import java.util.List; @@ -66,6 +74,10 @@ public class ContractController extends TdsCrudController { @Autowired(required = false) private ChainEvidenceService chainEvidenceService; + @Autowired private OrderService orderService; + @Autowired private DeliveryTaskService deliveryTaskService; + @Autowired private ApiConsumeLogService apiConsumeLogService; + @Override protected SuperService service() { return contractService; @@ -392,4 +404,202 @@ public class ContractController extends TdsCrudController { return null; } } + + // ====================== 业务全景 ====================== + /** + * 合约业务全景:除了合约本体,把它的下游订单 / 交付任务 / 调用日志 / 链上存证串起来, + * 让「合规/授权/调用/存证」一屏可见。 + */ + @GetMapping("/{id}/BusinessDetail") + @Operation(summary = "合约业务全景", + description = "汇总合约本体 + 链上存证 + 下游订单 + 交付任务 + 调用日志") + public ActionResult> businessDetail(@PathVariable("id") String id) { + ContractEntity contract = getAlive(id); + if (contract == null) return ActionResult.fail("合约不存在: " + id); + + Map data = new LinkedHashMap<>(); + + // 1. 合约本体 + Map main = new LinkedHashMap<>(); + main.put("id", contract.getId()); + main.put("contractCode", contract.getContractCode()); + main.put("name", contract.getName()); + main.put("spaceId", contract.getSpaceId()); + main.put("productId", contract.getProductId()); + main.put("productName", contract.getProductName()); + main.put("orderId", contract.getOrderId()); + main.put("providerConnectorId", contract.getProviderConnectorId()); + main.put("providerOrgId", contract.getProviderOrgId()); + main.put("providerOrgName", contract.getProviderOrgName()); + main.put("consumerConnectorId", contract.getConsumerConnectorId()); + main.put("consumerOrgId", contract.getConsumerOrgId()); + main.put("consumerOrgName", contract.getConsumerOrgName()); + main.put("purpose", contract.getPurpose()); + main.put("deliveryType", contract.getDeliveryType()); + main.put("priceMode", contract.getPriceMode()); + main.put("amount", contract.getAmount()); + main.put("quotaTotal", contract.getQuotaTotal()); + main.put("quotaUsed", contract.getQuotaUsed()); + main.put("effectiveTime", contract.getEffectiveTime()); + main.put("expireTime", contract.getExpireTime()); + main.put("providerSignTime", contract.getProviderSignTime()); + main.put("providerSignature", contract.getProviderSignature()); + main.put("consumerSignTime", contract.getConsumerSignTime()); + main.put("consumerSignature", contract.getConsumerSignature()); + main.put("signTime", contract.getSignTime()); + main.put("signCostMs", contract.getSignCostMs()); + main.put("status", contract.getStatus()); + main.put("contentHash", contract.getContentHash()); + main.put("chainTxHash", contract.getChainTxHash()); + main.put("chainBlockNo", contract.getChainBlockNo()); + main.put("chainTime", contract.getChainTime()); + main.put("version", contract.getVersion()); + main.put("parentContractId", contract.getParentContractId()); + main.put("policyContent", contract.getPolicyContent()); + main.put("termsContent", contract.getTermsContent()); + main.put("terminateTime", contract.getTerminateTime()); + main.put("terminateReason", contract.getTerminateReason()); + data.put("contract", main); + + // 2. 审计 + Map audit = new LinkedHashMap<>(); + audit.put("creator", contract.getCreatorUserId()); + audit.put("createTime", contract.getCreatorTime()); + audit.put("lastModifier", contract.getLastModifyUserId()); + audit.put("lastModifyTime", contract.getLastModifyTime()); + audit.put("tenantId", contract.getTenantId()); + data.put("auditTrail", audit); + + // 3. 配额使用 + if (contract.getQuotaTotal() != null) { + Map quota = new LinkedHashMap<>(); + quota.put("total", contract.getQuotaTotal()); + quota.put("used", contract.getQuotaUsed()); + long used = contract.getQuotaUsed() == null ? 0 : contract.getQuotaUsed(); + quota.put("remaining", contract.getQuotaTotal() - used); + quota.put("usagePercent", + Math.round(10000.0 * used / contract.getQuotaTotal()) / 100.0); + data.put("quota", quota); + } + + // 4. 链上存证 (按 bizType + bizId 找) + try { + QueryWrapper w = new QueryWrapper<>(); + w.eq("f_biz_type", "DATA_CONTRACT") + .eq("f_biz_id", contract.getContractCode()) + .orderByDesc("f_creator_time"); + java.util.List evidences = + chainEvidenceService.list(w); + if (!evidences.isEmpty()) { + Map ev = new LinkedHashMap<>(); + for (ssw.tds.entity.ChainEvidenceEntity e : evidences) { + Map one = new LinkedHashMap<>(); + one.put("txHash", e.getChainTxHash()); + one.put("blockNo", e.getChainBlockNo()); + one.put("chainTime", e.getChainTime()); + one.put("contentHash", e.getContentHash()); + one.put("summary", e.getRawSummary()); + one.put("creatorTime", e.getCreatorTime()); + one.put("bizType", e.getBizType()); + ev.put(e.getCreatorTime() == null ? "0" : String.valueOf(e.getCreatorTime().getTime()), one); + } + data.put("chainEvidences", ev); + } + // 再查证变更、终止存证 + QueryWrapper w2 = new QueryWrapper<>(); + w2.eq("f_biz_type", "CONTRACT_CHANGE") + .eq("f_biz_id", contract.getContractCode()) + .orderByDesc("f_creator_time"); + java.util.List changes = chainEvidenceService.list(w2); + if (!changes.isEmpty()) data.put("changeEvidences", changes); + } catch (Exception ignore) {} + + // 5. 下游订单 (tdc) + if (contract.getOrderId() != null && !contract.getOrderId().isBlank()) { + OrderEntity order = safeGet(orderService, contract.getOrderId()); + if (order != null) { + Map orderMap = new LinkedHashMap<>(); + orderMap.put("orderCode", order.getOrderCode()); + orderMap.put("status", order.getStatus()); + orderMap.put("priceType", order.getPriceType()); + orderMap.put("priceAmount", order.getPriceAmount()); + orderMap.put("quantity", order.getQuantity()); + orderMap.put("totalAmount", order.getTotalAmount()); + orderMap.put("productName", order.getProductName()); + orderMap.put("buyerName", order.getBuyerName()); + orderMap.put("sellerName", order.getSellerName()); + orderMap.put("auditTime", order.getAuditTime()); + orderMap.put("auditUserId", order.getAuditUserId()); + orderMap.put("auditOpinion", order.getAuditOpinion()); + orderMap.put("paymentVoucher", order.getPaymentVoucher()); + orderMap.put("paymentConfirmTime", order.getPaymentConfirmTime()); + orderMap.put("paymentConfirmUserId", order.getPaymentConfirmUserId()); + orderMap.put("signPartyATime", order.getSignPartyATime()); + orderMap.put("signPartyAUserId", order.getSignPartyAUserId()); + orderMap.put("signPartyBTime", order.getSignPartyBTime()); + orderMap.put("signPartyBUserId", order.getSignPartyBUserId()); + orderMap.put("signedContractHash", order.getSignedContractHash()); + orderMap.put("effectiveStart", order.getEffectiveStart()); + orderMap.put("effectiveEnd", order.getEffectiveEnd()); + data.put("order", orderMap); + } + } + + // 6. 下游交付任务(按 contractCode 找) + try { + QueryWrapper tw = new QueryWrapper<>(); + tw.eq("f_contract_code", contract.getContractCode()) + .orderByDesc("f_creator_time") + .last("LIMIT 20"); + java.util.List tasks = deliveryTaskService.list(tw); + if (!tasks.isEmpty()) { + java.util.List> taskList = new java.util.ArrayList<>(); + for (DeliveryTaskEntity t : tasks) { + Map tm = new LinkedHashMap<>(); + tm.put("id", t.getId()); + tm.put("taskNo", t.getTaskNo()); + tm.put("productName", t.getProductName()); + tm.put("consumerOrgName", t.getConsumerOrgName()); + tm.put("status", t.getStatus()); + tm.put("runStatus", t.getRunStatus()); + tm.put("policyResult", t.getPolicyResult()); + tm.put("recordCount", t.getRecordCount()); + tm.put("dataSize", t.getDataSize()); + tm.put("durationMs", t.getDurationMs()); + tm.put("startTime", t.getStartTime()); + tm.put("endTime", t.getEndTime()); + tm.put("resultHash", t.getResultHash()); + tm.put("destroyStatus", t.getDestroyStatus()); + tm.put("auditStatus", t.getAuditStatus()); + tm.put("auditUserId", t.getAuditUserId()); + tm.put("auditOpinion", t.getAuditOpinion()); + tm.put("callCount", t.getCallCount()); + taskList.add(tm); + } + data.put("deliveryTasks", taskList); + } + } catch (Exception ignore) {} + + // 7. 调用次数统计(按 delivery_task_id 求和 call_count) + try { + // 这里简化为:取最近一个交付任务的 call_count 作为合约级活跃度 + DeliveryTaskEntity first = deliveryTaskService.getOne( + new QueryWrapper() + .eq("f_contract_code", contract.getContractCode()) + .orderByDesc("f_creator_time").last("LIMIT 1"), false); + if (first != null) { + Map usage = new LinkedHashMap<>(); + usage.put("totalCalls", first.getCallCount()); + usage.put("lastTaskNo", first.getTaskNo()); + data.put("usage", usage); + } + } catch (Exception ignore) {} + + return ActionResult.success(data); + } + + /** 防御性 getById */ + private T safeGet(SuperService svc, String id) { + try { return svc.getById(id); } catch (Exception e) { return null; } + } } diff --git a/docs/e2e/dag-data.mjs b/docs/e2e/dag-data.mjs index ba72cfc..0ad1f0a 100644 --- a/docs/e2e/dag-data.mjs +++ b/docs/e2e/dag-data.mjs @@ -117,7 +117,9 @@ const seq1 = { { type: 'verify', field: 'orderId', exists: true }, // 浏览器:列表里搜出刚生成的合约并打开详情 { type: 'viewRow', keyword: (ctx) => ctx.contractCode, mode: 'edit' }, - { type: 'shot', seq: 1, desc: '运营方审核订单通过(合约详情)' } + { type: 'shot', seq: 1, desc: '运营方审核订单通过(合约详情)' }, + // 业务全景:上游订单 + 链上存证 + 双签 + 用量配额 + { type: 'bizDetail', entity: 'contract', idFromCtx: (ctx) => ctx.contractId } ] }, { id: 'n1-9', lane: 'regulator',stage: 's1-2', icon: '⛓️', label: '上链 / 存证', case: 'TC-CONTRACT_API-006', data: { name: '合约哈希', preview: 'sha256:7f3a…b91e\nFISCO-BCOS group0' } , route: '/tds/contracts' , mode: 'status', apiKey: 'contract_sign', @@ -150,7 +152,9 @@ const seq1 = { actions: [ { type: 'verify', field: 'sandboxId', exists: true }, { type: 'viewRow', keyword: (ctx) => ctx.sandboxName, action: '日志/结果' }, - { type: 'shot', seq: 1, desc: '沙盒开发调试环境就绪(日志/结果弹窗)' } + { type: 'shot', seq: 1, desc: '沙盒开发调试环境就绪(日志/结果弹窗)' }, + // 业务全景:上游合约 + 策略判定 + 审核 + TEE 远程证明 + 调用/销毁留痕 + { type: 'bizDetail', entity: 'delivery', idFromCtx: (ctx) => ctx.sandboxId } ] }, { id: 'n1-13', lane: 'ops', stage: 's1-3', icon: '🔍', label: '算法审核' , route: '/tdc/sandbox' , mode: 'status', apiKey: 'sandbox_audit', @@ -207,7 +211,9 @@ const seq1 = { // BillingLedger 的 keywordColumns = productName / consumerOrgName / providerOrgName, // 搜索 productName 命中刚生成的台账行 { type: 'viewRow', keyword: (ctx) => ctx.productName, mode: 'edit' }, - { type: 'shot', seq: 1, desc: '结算凭证已生成 + SETTLED(详情见抽屉)' } + { type: 'shot', seq: 1, desc: '结算凭证已生成 + SETTLED(详情见抽屉)' }, + // 业务全景:利益分配 + 上游合约 + 上下游调用留痕 + { type: 'bizDetail', entity: 'billing', idFromCtx: (ctx) => ctx.settlementId } ] }, { id: 'n1-20', lane: 'regulator',stage: 's1-5', icon: '📤', label: '提交交易凭证' , route: '/tds/chain', diff --git a/docs/e2e/dag-panel.mjs b/docs/e2e/dag-panel.mjs index 02f7037..2c00055 100644 --- a/docs/e2e/dag-panel.mjs +++ b/docs/e2e/dag-panel.mjs @@ -805,6 +805,7 @@ function describeAction(a) { case 'rowAction': return `行「${a.rowText}」点「${a.actionLabel}」` case 'prompt': return `弹窗确认${a.value ? '「' + a.value + '」' : ''}` case 'shot': return `中途截图(${a.desc || ''})` + case 'bizDetail': return `跳转「业务全景」${a.entity ? `(${a.entity})` : ''}` case 'selectFilter': return `筛选 ${a.label}=「${a.option}」` case 'wait': return `等待 ${a.ms || 300}ms` case 'waitIdle': return `等表格加载完(${a.ms || 800}ms)` @@ -958,6 +959,62 @@ const ACTION_TYPES = { return { skipped: `未知 mode=${mode}`, keyword: kw } }, + /** + * 跳转「业务全景」页 —— 这是数据流通可信验证的核心: + * 在列表 + 编辑抽屉之外,把每条记录相关的「授权/审核/调用/存证/分配/销毁/留痕」 + * 一屏可见(带上下游 ID),让"看不出流程"变成"流程可点击展开"。 + * a.entity: 'delivery' | 'contract' | 'billing'(必填,否则按路径前缀猜) + * a.idFromCtx: 例如 ctx.contractId / ctx.sandboxId + * a.pathFromCtx: 备选,直接给路径(ctx 路径模板),不常用 + */ + bizDetail: async (t, a, ctx) => { + // 1. 关掉上一个打开的抽屉/弹窗,避免空指针 + await t.page.locator('.ant-drawer-close').first().click().catch(() => {}) + await t.page.keyboard.press('Escape').catch(() => {}) + await t.waitIdle(300) + // 2. 解析 entity + id + let entity = a.entity + let id = a.idFromCtx ? (typeof a.idFromCtx === 'function' ? a.idFromCtx(ctx) : a.idFromCtx) : null + if (!id) id = a.id || ctx.contractId || ctx.sandboxId || ctx.settlementId + if (!entity) { + if (id === ctx.contractId) entity = 'contract' + else if (id === ctx.sandboxId) entity = 'delivery' + else if (id === ctx.settlementId) entity = 'billing' + } + if (!id) return { skipped: 'bizDetail 缺 ID(idFromCtx 跟 ctx 都拿不到)' } + // 3. 路径模板 + const pathMap = { + delivery: 'tdc/delivery-detail', + contract: 'tds/contract-detail', + billing: 'tds/billing-detail' + } + const seg = entity && pathMap[entity] ? pathMap[entity] : (pathMap[String(entity)] || 'tdc/delivery-detail') + const full = `/${seg}/${id}` + // 4. 跳过去;等待关键字段出现(至少 4 张卡片 = 业务全景装好了) + await t.page.goto(FE_BASE + full, { waitUntil: 'domcontentloaded', timeout: 15000 }) + await t.page.waitForLoadState('networkidle', { timeout: 12000 }).catch(() => {}) + // 再等卡片出现(dashboard 多 schema 要 1~3s 才能拉完所有数据) + try { + await t.page.locator('.ant-page-header-heading-title').first().waitFor({ state: 'visible', timeout: 5000 }) + } catch (e) { /* keep going */ } + await t.page.waitForTimeout(2500) + // 5. 截图(让最终 shot 是业务全景,而非空抽屉) + const shotName = `SIM-BIZ-${entity}-${id}` + const shotFile = shotName + '.png' + const shotPath = path.join(SHOTS_DIR, shotFile) + try { + await t.page.screenshot({ path: shotPath, type: 'png', fullPage: false, timeout: 5000 }) + } catch (e) { /* best-effort */ } + // 6. 字段验证:业务全景里应该有 ≥ 4 张 ant-card;不足不算 fail(有时上游数据还在写) + const cardCount = await t.page.locator('.ant-card').count().catch(() => 0) + return { + entity, id, path: full, + shotFile, + cardCount, + titleText: await t.page.locator('.ant-page-header-heading-title').first().innerText().catch(() => '') + } + }, + /** * 真实后端调用 —— 不经过浏览器,直接打 JNPF 接口。 * 注意:仅用于**断言**类(GET 查询结果对比),不要用 api 来模拟用户在浏览器上的点击 @@ -1526,7 +1583,7 @@ const server = http.createServer(async (req, res) => { steps: (result.actionSteps || []).map((s) => { // 保留所有自定义字段(keyword / drawerTitle / opened / usedSearch / absent / mode / httpCode 等) const base = { seq: s.seq, type: s.type, status: s.status, ms: s.ms, desc: s.desc, error: s.error || null, skipped: s.skipped || null } - const extras = ['keyword', 'drawerTitle', 'opened', 'usedSearch', 'absent', 'mode', 'httpCode', 'url', 'method', 'payload', 'field', 'value', 'ok', 'verified', 'total', 'checked', 'firstRow', 'space'] + const extras = ['keyword', 'drawerTitle', 'opened', 'usedSearch', 'absent', 'mode', 'httpCode', 'url', 'method', 'payload', 'field', 'value', 'ok', 'verified', 'total', 'checked', 'firstRow', 'space', 'entity', 'path', 'cardCount', 'titleText', 'shotFile'] for (const k of extras) if (s[k] !== undefined) base[k] = s[k] return base }), diff --git a/jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts b/jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts index 4992293..ef5a107 100644 --- a/jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts +++ b/jweb/apps/jnpf-web-apps-main/src/router/routes/core.ts @@ -108,6 +108,46 @@ const coreRoutes: RouteRecordRaw[] = [ title: '403', }, }, + // ============== 业务全景:记录级详情页(不走菜单,按 ID 直进) ============== + { + path: '/tdc/delivery-detail/:id(\\w+)', + name: 'DeliveryDetail', + component: () => import('#/views/ssw/views/_biz/DeliveryDetailView.vue'), + meta: { + hideInBreadcrumb: false, + hideInMenu: true, + hideInTab: false, + title: '交付任务业务全景', + noBasicLayout: false, + ignoreAccess: true, + }, + }, + { + path: '/tds/contract-detail/:id(\\w+)', + name: 'ContractDetail', + component: () => import('#/views/ssw/views/_biz/ContractDetailView.vue'), + meta: { + hideInBreadcrumb: false, + hideInMenu: true, + hideInTab: false, + title: '数字合约业务全景', + noBasicLayout: false, + ignoreAccess: true, + }, + }, + { + path: '/tds/billing-detail/:id(\\w+)', + name: 'BillingDetail', + component: () => import('#/views/ssw/views/_biz/BillingDetailView.vue'), + meta: { + hideInBreadcrumb: false, + hideInMenu: true, + hideInTab: false, + title: '结算凭证业务全景', + noBasicLayout: false, + ignoreAccess: true, + }, + }, ]; export { coreRoutes, fallbackNotFoundRoute }; diff --git a/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/BillingDetailView.vue b/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/BillingDetailView.vue new file mode 100644 index 0000000..8b6d6fa --- /dev/null +++ b/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/BillingDetailView.vue @@ -0,0 +1,141 @@ + + + + + diff --git a/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/ContractDetailView.vue b/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/ContractDetailView.vue new file mode 100644 index 0000000..ff294fe --- /dev/null +++ b/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/ContractDetailView.vue @@ -0,0 +1,253 @@ + + + + + diff --git a/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/DeliveryDetailView.vue b/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/DeliveryDetailView.vue new file mode 100644 index 0000000..c39779c --- /dev/null +++ b/jweb/apps/jnpf-web-apps-main/src/views/ssw/views/_biz/DeliveryDetailView.vue @@ -0,0 +1,283 @@ + + + + + diff --git a/web/src/router/modules/tdc.ts b/web/src/router/modules/tdc.ts index 7df9f52..3b8a6e5 100644 --- a/web/src/router/modules/tdc.ts +++ b/web/src/router/modules/tdc.ts @@ -155,6 +155,13 @@ const routes: RouteRecordRaw[] = [ name: 'tdc-tee-security', component: () => import('@/views/ssw/views/tdc/TeeSecurityView.vue'), meta: { auth: true, title: 'TEE 安全管理面', subsystem: 'tdc' } + }, + // ---- 业务全景:记录级详情(不走菜单,按 ID 直进) ---- + { + path: '/tdc/delivery-detail/:id(\\w+)', + name: 'tdc-delivery-detail', + component: () => import('@/views/ssw/views/_biz/DeliveryDetailView.vue'), + meta: { auth: true, title: '交付任务业务全景', subsystem: 'tdc' } } ] diff --git a/web/src/router/modules/tds.ts b/web/src/router/modules/tds.ts index 7c9d752..8a9a79e 100644 --- a/web/src/router/modules/tds.ts +++ b/web/src/router/modules/tds.ts @@ -232,6 +232,19 @@ const routes: RouteRecordRaw[] = [ component: () => import('@/views/ssw/views/tds/LicenseView.vue'), meta: { auth: true, title: 'License/续费', subsystem: 'tds' } }, + // ---- 业务全景:记录级详情(不走菜单,按 ID 直进) ---- + { + path: '/tds/contract-detail/:id(\\w+)', + name: 'tds-contract-detail', + component: () => import('@/views/ssw/views/_biz/ContractDetailView.vue'), + meta: { auth: true, title: '数字合约业务全景', subsystem: 'tds' } + }, + { + path: '/tds/billing-detail/:id(\\w+)', + name: 'tds-billing-detail', + component: () => import('@/views/ssw/views/_biz/BillingDetailView.vue'), + meta: { auth: true, title: '结算凭证业务全景', subsystem: 'tds' } + } ] export default routes