@chenchaolong/plugin-trade-compliance-workbench 1.0.102 → 1.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1121,7 +1121,6 @@ let TradeComplianceWorkbenchService = class TradeComplianceWorkbenchService {
1121
1121
  return current;
1122
1122
  }
1123
1123
  const counts = await this.catalogBatchCounts(manager, scope, current);
1124
- const outcome = catalogTerminalOutcome(counts);
1125
1124
  current.progress.successCount = counts.successCount;
1126
1125
  current.progress.duplicateCount = counts.duplicateCount;
1127
1126
  current.progress.invalidCount = counts.invalidCount;
@@ -1135,9 +1134,21 @@ let TradeComplianceWorkbenchService = class TradeComplianceWorkbenchService {
1135
1134
  current.completedAt = null;
1136
1135
  return repo.save(current);
1137
1136
  }
1138
- current.progress.outcome = outcome.outcome;
1139
- if (outcome.status === 'FAILED') {
1140
- await this.applyImportTaskFailure(manager, scope, current, 'FAILED', outcome.errorCode, outcome.errorMessage);
1137
+ if (counts.successCount > 0 && current.progress.reviewPendingCount > 0) {
1138
+ await this.closeUnresolvedCatalogReviews(manager, scope, current);
1139
+ const settledCounts = await this.catalogBatchCounts(manager, scope, current);
1140
+ current.progress.successCount = settledCounts.successCount;
1141
+ current.progress.duplicateCount = settledCounts.duplicateCount;
1142
+ current.progress.invalidCount = settledCounts.invalidCount;
1143
+ current.progress.skippedCount = settledCounts.skippedCount;
1144
+ }
1145
+ const terminalCounts = counts.successCount > 0 && current.progress.reviewPendingCount === 0
1146
+ ? await this.catalogBatchCounts(manager, scope, current)
1147
+ : counts;
1148
+ const terminalOutcome = catalogTerminalOutcome(terminalCounts);
1149
+ current.progress.outcome = terminalOutcome.outcome;
1150
+ if (terminalOutcome.status === 'FAILED') {
1151
+ await this.applyImportTaskFailure(manager, scope, current, 'FAILED', terminalOutcome.errorCode, terminalOutcome.errorMessage);
1141
1152
  }
1142
1153
  else {
1143
1154
  await this.publishCatalogDraft(manager, scope, current);
@@ -1541,6 +1552,10 @@ let TradeComplianceWorkbenchService = class TradeComplianceWorkbenchService {
1541
1552
  await this.reconcileCatalogReviewPendingCount(reviewRepo, scope, task);
1542
1553
  task.progress.progressVersion += 1;
1543
1554
  task.progress.lastProgressAt = new Date().toISOString();
1555
+ const currentCounts = await this.catalogBatchCounts(manager, scope, task);
1556
+ if (currentCounts.successCount > 0 && task.progress.reviewPendingCount > 0) {
1557
+ await this.closeUnresolvedCatalogReviews(manager, scope, task);
1558
+ }
1544
1559
  if (task.progress.reviewPendingCount === 0) {
1545
1560
  const counts = await this.catalogBatchCounts(manager, scope, task);
1546
1561
  const outcome = catalogTerminalOutcome(counts);
@@ -1586,6 +1601,36 @@ let TradeComplianceWorkbenchService = class TradeComplianceWorkbenchService {
1586
1601
  task.progress.reviewPendingCount = pendingCount;
1587
1602
  return pendingCount;
1588
1603
  }
1604
+ async closeUnresolvedCatalogReviews(manager, scope, task) {
1605
+ const reviewRepo = manager.getRepository(CatalogReviewBlock);
1606
+ const blocks = await reviewRepo.find({ where: {
1607
+ ...activeScope(scope), importTaskId: task.id, status: In(['PENDING', 'LEASED'])
1608
+ }, order: { ordinal: 'ASC' } });
1609
+ if (blocks.length === 0) {
1610
+ await this.reconcileCatalogReviewPendingCount(reviewRepo, scope, task);
1611
+ return;
1612
+ }
1613
+ const batch = await this.appendUnresolvedCatalogReviewIssues(manager, scope, task, blocks);
1614
+ const now = new Date();
1615
+ for (const block of blocks) {
1616
+ block.status = 'REJECTED';
1617
+ block.leaseToken = null;
1618
+ block.leaseExpiresAt = null;
1619
+ block.resolvedAt = now;
1620
+ block.resolutionFingerprint = null;
1621
+ await reviewRepo.save(block);
1622
+ }
1623
+ if (task.progress) {
1624
+ task.progress.reviewRejectedCount += blocks.length;
1625
+ task.progress.reviewPendingCount = 0;
1626
+ if (batch) {
1627
+ task.progress.successCount = batch.successCount;
1628
+ task.progress.duplicateCount = batch.duplicateCount;
1629
+ task.progress.invalidCount = batch.invalidCount;
1630
+ task.progress.skippedCount = batch.skippedCount;
1631
+ }
1632
+ }
1633
+ }
1589
1634
  async setImportObserverConversation(scope, taskId, conversationId) {
1590
1635
  const normalizedConversationId = requiredId(conversationId, '观察会话标识');
1591
1636
  return this.dataSource.transaction(async (manager) => {
@@ -1701,6 +1746,42 @@ let TradeComplianceWorkbenchService = class TradeComplianceWorkbenchService {
1701
1746
  }
1702
1747
  return batchRepo.save(batch);
1703
1748
  }
1749
+ async appendUnresolvedCatalogReviewIssues(manager, scope, task, blocks) {
1750
+ if (blocks.length === 0 || !task.resultEntityId)
1751
+ return null;
1752
+ const controlled = task.documentType === 'CONTROLLED_CATALOG';
1753
+ const batchRepo = controlled
1754
+ ? manager.getRepository(ControlledCatalogBatch)
1755
+ : manager.getRepository(SanctionCatalogBatch);
1756
+ const issueRepo = controlled
1757
+ ? manager.getRepository(ControlledCatalogImportIssue)
1758
+ : manager.getRepository(SanctionCatalogImportIssue);
1759
+ const batch = await required(batchRepo.findOne({ where: {
1760
+ ...activeScope(scope), id: task.resultEntityId
1761
+ } }), controlled ? '管控目录批次不存在' : '制裁目录批次不存在');
1762
+ for (const block of blocks) {
1763
+ const parsedPayload = {
1764
+ reviewBlockId: block.id,
1765
+ reviewDecision: 'UNRESOLVED_AUTO_SKIP',
1766
+ payload: block.payload,
1767
+ reasons: block.reasons
1768
+ };
1769
+ const existing = await issueRepo.findOne({ where: {
1770
+ ...activeScope(scope), batchId: batch.id, issueType: 'INVALID', parsedPayload
1771
+ } });
1772
+ if (existing)
1773
+ continue;
1774
+ batch.totalCount += 1;
1775
+ batch.invalidCount += 1;
1776
+ batch.skippedCount += 1;
1777
+ await issueRepo.save(issueRepo.create({
1778
+ ...createdScope(scope), batchId: batch.id, issueType: 'INVALID', sourceSequence: batch.totalCount,
1779
+ sourceLocation: block.sourceLocation, sourceContent: block.sourceContent,
1780
+ parsedPayload, message: '复核未完成,来源行已跳过'
1781
+ }));
1782
+ }
1783
+ return batchRepo.save(batch);
1784
+ }
1704
1785
  async appendStalledCatalogReviewIssues(manager, scope, task, batch, blocks) {
1705
1786
  const issueRepo = (task.documentType === 'CONTROLLED_CATALOG'
1706
1787
  ? manager.getRepository(ControlledCatalogImportIssue)