Files
shanxia2.0/docs/sql/incremental_crm_contract_rewrite.sql
T
2026-06-01 08:21:21 +08:00

52 lines
3.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================================================
-- 合同管理模块重写 — 增量 DDL
-- 对比:docs/sql/sx.sql (CRM) vs docs/sql/shanxia2.0.sql (门户)
-- 说明:docs/crm-migration/plans/contract/03-ddl-diff.md
-- 日期:2026-05-31
-- 执行:在部署库手动执行;索引/唯一键若已存在会报错,可跳过对应语句
-- =============================================================================
-- -----------------------------------------------------------------------------
-- S1. 框架合同产品调价区间(门户原缺失整表)
-- -----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `crm_contract_product_price_tier` (
`id` varchar(64) NOT NULL COMMENT '主键ID(UUID)',
`contract_id` varchar(64) NOT NULL COMMENT '合同ID',
`contract_product_id` varchar(64) NOT NULL COMMENT '合同产品明细ID',
`start_date` date NOT NULL COMMENT '区间开始日期',
`end_date` date NOT NULL COMMENT '区间结束日期',
`price` decimal(15, 2) NOT NULL COMMENT '含税单价',
`letter_oss_ids` varchar(4000) DEFAULT NULL COMMENT '调价函OSS ID列表(JSON数组,如["id1","id2"])',
`letter_oss_id` varchar(64) DEFAULT NULL COMMENT '调价函单附件(废弃,请用 letter_oss_ids)',
`sort` int(11) DEFAULT '0' COMMENT '排序号',
`tenant_no` varchar(64) NOT NULL DEFAULT 'shanxia2.0' COMMENT '租户编号',
`order_num` int(11) DEFAULT NULL COMMENT '排序号(公共)',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建者',
`create_dept_id` varchar(64) NOT NULL DEFAULT '' COMMENT '创建部门',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` varchar(64) DEFAULT NULL COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`del_flag` smallint(6) NOT NULL DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_contract_id` (`contract_id`) USING BTREE,
KEY `idx_contract_product_id` (`contract_product_id`) USING BTREE,
KEY `idx_tenant_no` (`tenant_no`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='CRM-框架合同产品调价区间';
-- -----------------------------------------------------------------------------
-- S2. crm_contract 列表查询索引(sx 有、门户基线缺)
-- -----------------------------------------------------------------------------
ALTER TABLE `crm_contract` ADD INDEX `idx_status` (`status`);
ALTER TABLE `crm_contract` ADD INDEX `idx_owner_user_id` (`owner_user_id`);
ALTER TABLE `crm_contract` ADD INDEX `idx_sign_date` (`sign_date`);
ALTER TABLE `crm_contract` ADD INDEX `idx_end_date` (`end_date`);
ALTER TABLE `crm_contract` ADD INDEX `idx_create_time` (`create_time`);
-- -----------------------------------------------------------------------------
-- S3. 合同编号租户内唯一(软删维度与 CRM uk_contract_no_del_flag 对齐)
-- 若已存在同名或等价唯一索引,执行失败可忽略
-- -----------------------------------------------------------------------------
ALTER TABLE `crm_contract`
ADD UNIQUE KEY `uk_contract_tenant_no_del` (`contract_no`, `tenant_no`, `del_flag`);