znpt-backend/doc/auto_expiration_tables.sql

51 lines
3.4 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.

-- 自动到期检测配置表
CREATE TABLE `auto_expiration_config` (
`config_id` varchar(64) NOT NULL COMMENT '配置ID',
`table_name` varchar(100) NOT NULL COMMENT '表名',
`table_desc` varchar(200) DEFAULT NULL COMMENT '表描述',
`primary_key_field` varchar(100) NOT NULL COMMENT '主键字段',
`expire_date_field` varchar(100) NOT NULL COMMENT '到期时间字段',
`user_id_field` varchar(100) DEFAULT NULL COMMENT '关联用户字段',
`user_name_field` varchar(100) DEFAULT NULL COMMENT '用户姓名字段',
`business_name_field` varchar(100) DEFAULT NULL COMMENT '业务名称字段',
`remind_days` int(11) DEFAULT 30 COMMENT '提前提醒天数',
`enabled` varchar(1) DEFAULT '1' COMMENT '是否启用0-禁用1-启用)',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
`update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
`del_flag` varchar(1) DEFAULT '0' COMMENT '删除标志0代表存在1代表删除',
PRIMARY KEY (`config_id`),
UNIQUE KEY `uk_table_name` (`table_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='自动到期检测配置表';
-- 到期检测结果表
CREATE TABLE `expiration_result` (
`result_id` varchar(64) NOT NULL COMMENT '结果ID',
`config_id` varchar(64) DEFAULT NULL COMMENT '配置ID',
`table_name` varchar(100) NOT NULL COMMENT '表名',
`business_id` varchar(64) NOT NULL COMMENT '业务ID',
`business_name` varchar(200) DEFAULT NULL COMMENT '业务名称',
`user_id` varchar(64) DEFAULT NULL COMMENT '关联用户ID',
`user_name` varchar(100) DEFAULT NULL COMMENT '关联用户姓名',
`expire_date` date NOT NULL COMMENT '到期日期',
`remaining_days` int(11) DEFAULT NULL COMMENT '剩余天数',
`status` varchar(1) DEFAULT '0' COMMENT '状态0-正常1-即将到期2-已到期)',
`check_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '检测时间',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
`update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
`del_flag` varchar(1) DEFAULT '0' COMMENT '删除标志0代表存在1代表删除',
PRIMARY KEY (`result_id`),
KEY `idx_table_name` (`table_name`),
KEY `idx_status` (`status`),
KEY `idx_expire_date` (`expire_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='到期检测结果表';
-- 插入示例配置数据
INSERT INTO `auto_expiration_config` (`config_id`, `table_name`, `table_desc`, `primary_key_field`, `expire_date_field`, `user_id_field`, `user_name_field`, `business_name_field`, `remind_days`, `enabled`, `remark`) VALUES
('1', 'certification', '人员资质证书', 'certification_id', 'validity_date_end', 'user_id', NULL, 'certification_name', 30, '1', '人员资质证书到期检测'),
('2', 'insurance_info', '人员保险', 'insurance_info_id', 'expire_date', 'user_id', 'name', 'insurance_type_name', 30, '1', '人员保险到期检测'),
('3', 'regulation', '制度管理', 'regulation_id', 'expire_time', NULL, NULL, 'regulation_name', 30, '1', '制度到期检测');