文件
yjyf/db/schema_phase24_master_cert.sql

128 行
9.7 KiB
SQL

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

-- ============================================================================
-- 优匠优服 · Phase 24 师傅技能证书上传与审核体系
-- 1. 创建技能证书类型字典表 fa_cert_dict(覆盖特种作业、驾驶、护理等全品类)
-- 2. 创建师傅技能证书记录表 fa_master_cert
-- 3. 注册后台管理菜单与权限规则(师傅管理 -> 技能证书)
-- ============================================================================
SET NAMES utf8mb4;
-- 1. 技能证书字典表
CREATE TABLE IF NOT EXISTS `fa_cert_dict` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`cert_code` varchar(50) NOT NULL DEFAULT '' COMMENT '证书编码',
`cert_name` varchar(80) NOT NULL DEFAULT '' COMMENT '证书名称',
`sample_type` varchar(30) NOT NULL DEFAULT 'special_card' COMMENT '示例图类型:special_card=特种作业卡/资格证,driver=驾驶证,health=健康证,qualification=行业备案/资质证',
`need_expire` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否需要有效期:1=是,0=否',
`weigh` int(11) NOT NULL DEFAULT '0' COMMENT '排序权重(越大越靠前)',
`status` enum('normal','hidden') NOT NULL DEFAULT 'normal' COMMENT '状态',
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间',
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uniq_cert_code` (`cert_code`) USING BTREE,
KEY `idx_status_weigh` (`status`, `weigh`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='技能证书类型字典表';
-- 2. 师傅技能证书上传与审核表
CREATE TABLE IF NOT EXISTS `fa_master_cert` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`master_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '师傅ID(fa_master.id)',
`cert_dict_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '证书字典ID(fa_cert_dict.id)',
`cert_code` varchar(50) NOT NULL DEFAULT '' COMMENT '证书编码',
`cert_name` varchar(80) NOT NULL DEFAULT '' COMMENT '证书名称(标准名称或自定义名称)',
`is_custom` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否自定义(其他证书):0=标准字典,1=自定义证书',
`cert_image` varchar(255) NOT NULL DEFAULT '' COMMENT '证书照片URL',
`expire_date` date DEFAULT NULL COMMENT '证件有效期截止日期',
`is_long_term` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否长期有效:0=否,1=是',
`status` enum('pending','pass','reject') NOT NULL DEFAULT 'pending' COMMENT '审核状态:pending=审核中,pass=已通过,reject=已驳回',
`audit_msg` varchar(255) NOT NULL DEFAULT '' COMMENT '审核意见/驳回原因',
`audit_admin_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '审核管理员ID',
`audittime` bigint(16) DEFAULT NULL COMMENT '审核时间',
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间',
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_master_status` (`master_id`, `status`) USING BTREE,
KEY `idx_master_code` (`master_id`, `cert_code`) USING BTREE,
KEY `idx_status_time` (`status`, `updatetime`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='师傅技能证书表';
-- 3. 幂等初始化 27 项标准证书 + 1 项其他证书
INSERT INTO `fa_cert_dict` (`cert_code`, `cert_name`, `sample_type`, `need_expire`, `weigh`, `status`, `createtime`, `updatetime`) VALUES
('electrician', '电工证', 'special_card', 1, 280, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('driver_license', '驾驶证', 'driver', 1, 270, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('high_altitude', '高空作业证', 'special_card', 1, 260, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('special_operation', '特种作业操作证', 'special_card', 1, 250, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('welder', '焊工证', 'special_card', 1, 240, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('weak_current', '弱电证', 'special_card', 1, 230, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('health_cert', '健康证', 'health', 1, 220, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('refrigeration_ac', '制冷与空调作业证', 'special_card', 1, 210, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('locksmith_record', '开锁备案', 'qualification', 1, 200, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('gas_appliance', '燃气器具安装维修资质', 'qualification', 1, 190, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('forklift', '叉车证', 'special_card', 1, 180, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('special_equip_safety', '特种设备安全管理证', 'special_card', 1, 170, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('crane_operation', '起重机作业证', 'special_card', 1, 160, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('elevator_operation', '电梯作业证', 'special_card', 1, 150, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('elderly_care', '养老护理员证', 'qualification', 1, 140, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('hazardous_chemical', '危险化学品安全作业证', 'special_card', 1, 130, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('boiler_operation', '锅炉作业证', 'special_card', 1, 120, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('coal_mine_safety', '煤矿安全作业操作证', 'special_card', 1, 110, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('pressure_vessel', '压力容器作业证', 'special_card', 1, 100, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('plant_vehicle', '场(厂)内专用机动车辆作业证', 'special_card', 1, 90, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('oil_gas_safety', '石油天然气安全作业证', 'special_card', 1, 80, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('maternal_care', '母婴护理师证', 'qualification', 1, 70, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('fireworks_safety', '烟花爆竹安全作业证', 'special_card', 1, 60, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('metallurgy_safety', '冶金(有色)生产安全作业证', 'special_card', 1, 50, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('metal_mine_safety', '金属非金属矿山安全作业证', 'special_card', 1, 40, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('nurse_license', '护士证', 'qualification', 1, 30, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('gas_cylinder', '气瓶作业证', 'special_card', 1, 20, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('other', '其他证书', 'qualification', 1, 1, 'normal', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE
`cert_name` = VALUES(`cert_name`),
`sample_type` = VALUES(`sample_type`),
`need_expire` = VALUES(`need_expire`),
`weigh` = VALUES(`weigh`),
`status` = VALUES(`status`),
`updatetime` = VALUES(`updatetime`);
-- 4. 注册后台【技能证书审核 (master_cert)】菜单与权限规则
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert', '技能证书', 'fa fa-id-badge', '', '师傅技能证书上传审核管理', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 174, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_manage'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert');
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert/index', '查看', 'fa fa-circle-o', '', '', 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_cert'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert/index');
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert/detail', '详情', 'fa fa-circle-o', '', '', 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_cert'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert/detail');
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert/audit', '审核', 'fa fa-circle-o', '', '', 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_cert'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert/audit');
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert/edit', '编辑', 'fa fa-circle-o', '', '', 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_cert'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert/edit');
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert/del', '删除', 'fa fa-circle-o', '', '', 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_cert'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert/del');
INSERT INTO `fa_auth_rule` (`type`, `pid`, `name`, `title`, `icon`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`, `status`)
SELECT 'file', p.id, 'master_cert/multi', '批量更新', 'fa fa-circle-o', '', '', 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'
FROM `fa_auth_rule` p
WHERE p.name = 'master_cert'
AND NOT EXISTS (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'master_cert/multi');