fix: 增加回单核对与付款登记门禁(09-08-reimbursement-payment-closeout)
ci-e2e / e2e (push) Canceled after 0s
ci-minimal / check-minimal (push) Canceled after 0s

这个提交包含在:
2026-09-15 07:21:55 +08:00
父节点 229867f5fd
当前提交 8d08d46d16
共修改 33 个文件,包含 3691 行新增和 11 行删除
@@ -0,0 +1,57 @@
ALTER TABLE "payment_batch_receipt_attachments" ADD COLUMN "receipt_ocr_version" INTEGER NOT NULL DEFAULT 0;
ALTER TABLE "payment_batch_receipt_attachments"
ADD COLUMN "receipt_ocr_state" VARCHAR(32) NOT NULL DEFAULT 'legacy',
ADD COLUMN "receipt_ocr_started_at" TIMESTAMP(3);
CREATE TABLE "payment_receipt_verifications" (
"id" UUID NOT NULL,
"attachment_id" UUID NOT NULL,
"source_sha256" VARCHAR(64) NOT NULL,
"source_version" INTEGER NOT NULL,
"status" VARCHAR(32) NOT NULL,
"pages_expected" INTEGER NOT NULL,
"pages_processed" INTEGER NOT NULL,
"normalized_encrypted" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "payment_receipt_verifications_pkey" PRIMARY KEY ("id"),
CONSTRAINT "payment_receipt_verifications_pages_check" CHECK (
pages_expected >= 0 AND pages_processed BETWEEN 0 AND pages_expected
),
CONSTRAINT "payment_receipt_verifications_attachment_id_fkey" FOREIGN KEY ("attachment_id")
REFERENCES "payment_batch_receipt_attachments"("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
CREATE INDEX "payment_receipt_verifications_attachment_id_created_at_idx"
ON "payment_receipt_verifications"("attachment_id", "created_at");
CREATE TABLE "payment_receipt_matches" (
"id" UUID NOT NULL,
"verification_id" UUID NOT NULL,
"item_id" UUID NOT NULL,
"page_number" INTEGER NOT NULL CHECK (page_number BETWEEN 1 AND 20),
"fingerprint" VARCHAR(64) NOT NULL,
"key_id" VARCHAR(64) NOT NULL,
CONSTRAINT "payment_receipt_matches_pkey" PRIMARY KEY ("id"),
CONSTRAINT "payment_receipt_matches_verification_id_fkey" FOREIGN KEY ("verification_id")
REFERENCES "payment_receipt_verifications"("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "payment_receipt_matches_item_id_fkey" FOREIGN KEY ("item_id")
REFERENCES "payment_batch_items"("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
CREATE UNIQUE INDEX "payment_receipt_matches_verification_id_page_number_key"
ON "payment_receipt_matches"("verification_id", "page_number");
CREATE UNIQUE INDEX "payment_receipt_matches_verification_id_item_id_key"
ON "payment_receipt_matches"("verification_id", "item_id");
CREATE INDEX "payment_receipt_matches_item_id_idx" ON "payment_receipt_matches"("item_id");
CREATE TABLE "payment_receipt_claims" (
"fingerprint" VARCHAR(64) NOT NULL,
"key_id" VARCHAR(64) NOT NULL,
"item_id" UUID NOT NULL,
"verification_id" UUID NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "payment_receipt_claims_pkey" PRIMARY KEY ("fingerprint"),
CONSTRAINT "payment_receipt_claims_item_id_fkey" FOREIGN KEY ("item_id")
REFERENCES "payment_batch_items"("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "payment_receipt_claims_verification_id_fkey" FOREIGN KEY ("verification_id")
REFERENCES "payment_receipt_verifications"("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
CREATE UNIQUE INDEX "payment_receipt_claims_item_id_key" ON "payment_receipt_claims"("item_id");
@@ -0,0 +1,21 @@
CREATE TABLE "payment_receipt_manual_proposals" (
"id" UUID NOT NULL PRIMARY KEY,
"attachment_id" UUID NOT NULL REFERENCES "payment_batch_receipt_attachments"("id") ON DELETE RESTRICT ON UPDATE CASCADE,
"original_verification_id" UUID NOT NULL REFERENCES "payment_receipt_verifications"("id") ON DELETE RESTRICT ON UPDATE CASCADE,
"source_sha256" VARCHAR(64) NOT NULL,
"source_version" INTEGER NOT NULL CHECK ("source_version" > 0),
"status" VARCHAR(32) NOT NULL CHECK ("status" IN ('pending_review', 'association_ready', 'approved', 'rejected')),
"proposed_by" UUID NOT NULL,
"reviewed_by" UUID,
"payload_encrypted" TEXT NOT NULL,
"review_note_encrypted" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"reviewed_at" TIMESTAMP(3),
CONSTRAINT "payment_receipt_manual_review_decision_check" CHECK (
("status" IN ('pending_review', 'association_ready') AND "reviewed_by" IS NULL AND "reviewed_at" IS NULL)
OR ("status" IN ('approved', 'rejected') AND "reviewed_by" IS NOT NULL AND "reviewed_at" IS NOT NULL
AND "reviewed_by" <> "proposed_by")
)
);
CREATE UNIQUE INDEX "payment_receipt_manual_proposals_attachment_id_source_version_key"
ON "payment_receipt_manual_proposals"("attachment_id", "source_version");
@@ -0,0 +1,13 @@
ALTER TABLE "payment_receipt_claims" ADD COLUMN "manual_proposal_id" UUID;
ALTER TABLE "payment_receipt_claims" ADD CONSTRAINT "payment_receipt_claims_manual_proposal_id_fkey"
FOREIGN KEY ("manual_proposal_id") REFERENCES "payment_receipt_manual_proposals"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
CREATE TABLE "payment_receipt_transaction_aliases" (
"fingerprint" VARCHAR(64) PRIMARY KEY,
"key_id" VARCHAR(64) NOT NULL,
"claim_fingerprint" VARCHAR(64) NOT NULL REFERENCES "payment_receipt_claims"("fingerprint") ON DELETE RESTRICT ON UPDATE CASCADE,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX "payment_receipt_transaction_aliases_claim_fingerprint_idx"
ON "payment_receipt_transaction_aliases"("claim_fingerprint");
INSERT INTO "payment_receipt_transaction_aliases" ("fingerprint", "key_id", "claim_fingerprint")
SELECT "fingerprint", "key_id", "fingerprint" FROM "payment_receipt_claims";