feat(G1,P16A,P16B): 收口主数据核心与节假日日历增强

这个提交包含在:
2026-03-07 17:29:03 +08:00
父节点 32a3d3724d
当前提交 195f46a2e3
共修改 35 个文件,包含 4556 行新增和 27 行删除
@@ -0,0 +1,91 @@
-- CreateEnum
CREATE TYPE "DocumentCategoryEntityType" AS ENUM ('reimbursement', 'leave', 'purchase_request', 'asset_card', 'general');
-- CreateTable
CREATE TABLE "legal_entities" (
"id" UUID NOT NULL,
"code" TEXT NOT NULL,
"name" TEXT NOT NULL,
"short_name" TEXT,
"currency_code" VARCHAR(8) NOT NULL DEFAULT 'CNY',
"tax_no" TEXT,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"archived_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL,
"updated_by" UUID,
CONSTRAINT "legal_entities_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "cost_centers" (
"id" UUID NOT NULL,
"legal_entity_id" UUID NOT NULL,
"code" TEXT NOT NULL,
"name" TEXT NOT NULL,
"parent_id" UUID,
"owner_employee_id" UUID,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"archived_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL,
"updated_by" UUID,
CONSTRAINT "cost_centers_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "document_categories" (
"id" UUID NOT NULL,
"code" TEXT NOT NULL,
"name" TEXT NOT NULL,
"entity_type" "DocumentCategoryEntityType" NOT NULL,
"sequence_prefix" TEXT NOT NULL,
"number_length" INTEGER NOT NULL DEFAULT 4,
"reset_period" "DocumentResetPeriod" NOT NULL,
"default_workflow_key" TEXT,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"archived_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL,
"updated_by" UUID,
CONSTRAINT "document_categories_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "legal_entities_code_key" ON "legal_entities"("code");
-- CreateIndex
CREATE INDEX "idx_legal_entities_status" ON "legal_entities"("enabled", "archived_at");
-- CreateIndex
CREATE INDEX "idx_cost_centers_legal_entity_status" ON "cost_centers"("legal_entity_id", "enabled", "archived_at");
-- CreateIndex
CREATE INDEX "idx_cost_centers_parent" ON "cost_centers"("parent_id");
-- CreateIndex
CREATE INDEX "idx_cost_centers_owner" ON "cost_centers"("owner_employee_id");
-- CreateIndex
CREATE UNIQUE INDEX "legal_entity_cost_center_code_ux" ON "cost_centers"("legal_entity_id", "code");
-- CreateIndex
CREATE UNIQUE INDEX "document_categories_code_key" ON "document_categories"("code");
-- CreateIndex
CREATE INDEX "idx_document_categories_entity_status" ON "document_categories"("entity_type", "enabled", "archived_at");
-- AddForeignKey
ALTER TABLE "cost_centers" ADD CONSTRAINT "cost_centers_legal_entity_id_fkey" FOREIGN KEY ("legal_entity_id") REFERENCES "legal_entities"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "cost_centers" ADD CONSTRAINT "cost_centers_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "cost_centers"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "cost_centers" ADD CONSTRAINT "cost_centers_owner_employee_id_fkey" FOREIGN KEY ("owner_employee_id") REFERENCES "employees"("id") ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,71 @@
-- CreateEnum
CREATE TYPE "HolidayCalendarDayType" AS ENUM ('holiday', 'workday', 'adjusted_workday');
-- AlterTable
ALTER TABLE "employees" ADD COLUMN "legal_entity_id" UUID;
-- AlterTable
ALTER TABLE "legal_entities" ADD COLUMN "default_holiday_calendar_id" UUID;
-- CreateTable
CREATE TABLE "holiday_calendars" (
"id" UUID NOT NULL,
"code" TEXT NOT NULL,
"name" TEXT NOT NULL,
"timezone" VARCHAR(64) NOT NULL DEFAULT 'Asia/Shanghai',
"legal_entity_id" UUID,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"archived_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL,
"updated_by" UUID,
CONSTRAINT "holiday_calendars_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "holiday_calendar_days" (
"id" UUID NOT NULL,
"calendar_id" UUID NOT NULL,
"date" DATE NOT NULL,
"day_type" "HolidayCalendarDayType" NOT NULL,
"name" TEXT NOT NULL,
"note" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL,
"updated_by" UUID,
CONSTRAINT "holiday_calendar_days_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "holiday_calendars_code_key" ON "holiday_calendars"("code");
-- CreateIndex
CREATE INDEX "idx_holiday_calendars_legal_entity_status" ON "holiday_calendars"("legal_entity_id", "enabled", "archived_at");
-- CreateIndex
CREATE INDEX "idx_holiday_calendar_days_calendar_date" ON "holiday_calendar_days"("calendar_id", "date");
-- CreateIndex
CREATE UNIQUE INDEX "holiday_calendar_day_ux" ON "holiday_calendar_days"("calendar_id", "date");
-- CreateIndex
CREATE INDEX "idx_employees_legal_entity" ON "employees"("legal_entity_id");
-- CreateIndex
CREATE INDEX "idx_legal_entities_default_calendar" ON "legal_entities"("default_holiday_calendar_id");
-- AddForeignKey
ALTER TABLE "employees" ADD CONSTRAINT "employees_legal_entity_id_fkey" FOREIGN KEY ("legal_entity_id") REFERENCES "legal_entities"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "legal_entities" ADD CONSTRAINT "legal_entities_default_holiday_calendar_id_fkey" FOREIGN KEY ("default_holiday_calendar_id") REFERENCES "holiday_calendars"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "holiday_calendars" ADD CONSTRAINT "holiday_calendars_legal_entity_id_fkey" FOREIGN KEY ("legal_entity_id") REFERENCES "legal_entities"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "holiday_calendar_days" ADD CONSTRAINT "holiday_calendar_days_calendar_id_fkey" FOREIGN KEY ("calendar_id") REFERENCES "holiday_calendars"("id") ON DELETE CASCADE ON UPDATE CASCADE;