Files
hzdyjs/docs/需求文档/奖惩补贴需求/奖学金管理基础数据-兼得关系增强.sql
T
2025-08-10 00:24:31 +08:00

134 lines
9.2 KiB
SQL

-- =====================================================
-- 奖学金管理模块 - 兼得关系增强数据升级脚本
-- 版本: v1.1
-- 创建时间: 2025-01-27
-- 说明: 增强兼得关系配置功能,新增自定义配置选项
-- =====================================================
-- 设置字符集
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- =====================================================
-- 1. 新增兼得关系类型字典数据
-- =====================================================
-- 1.1 在现有兼得关系类型基础上新增CUSTOM选项
INSERT INTO `sys_dict_data` (`dict_code`, `dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `create_by`, `create_time`, `remark`) VALUES
(2000000000000005004, 4, '自定义配置', 'CUSTOM', 'jcbt_compatibility_type', '', 'primary', 'N', 1, NOW(), '可自定义具体的兼得关系');
-- 1.2 新增关系类型字典 (用于关系表)
INSERT INTO `sys_dict_type` (`dict_id`, `dict_name`, `dict_type`, `create_by`, `create_time`, `remark`) VALUES
(2000000000000000010, '兼得关系细分类型', 'jcbt_relation_type', 1, NOW(), '奖学金兼得关系的具体类型');
INSERT INTO `sys_dict_data` (`dict_code`, `dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `create_by`, `create_time`, `remark`) VALUES
(2000000000000010001, 1, '兼容', 'COMPATIBLE', 'jcbt_relation_type', '', 'success', 'N', 1, NOW(), '可以同时获得'),
(2000000000000010002, 2, '互斥', 'EXCLUSIVE', 'jcbt_relation_type', '', 'danger', 'N', 1, NOW(), '不能同时获得'),
(2000000000000010003, 3, '优先级', 'PRIORITY', 'jcbt_relation_type', '', 'warning', 'N', 1, NOW(), '有优先级关系');
-- =====================================================
-- 2. 创建兼得关系表 (如果不存在)
-- =====================================================
CREATE TABLE IF NOT EXISTS `jcbt_scholarship_compatibility` (
`id` BIGINT(20) NOT NULL COMMENT '主键ID',
`type_id_1` BIGINT(20) NOT NULL COMMENT '奖学金类型1',
`type_id_2` BIGINT(20) NOT NULL COMMENT '奖学金类型2',
`relation_type` VARCHAR(20) NOT NULL COMMENT '关系类型:COMPATIBLE-兼容,EXCLUSIVE-互斥,PRIORITY-优先级关系',
`priority_level` INT DEFAULT 0 COMMENT '优先级(relation_type为PRIORITY时有效)',
`description` VARCHAR(500) DEFAULT NULL COMMENT '关系描述',
`tenant_id` BIGINT(20) NOT NULL COMMENT '租户ID',
`create_by` BIGINT(20) DEFAULT NULL COMMENT '创建者',
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` BIGINT(20) DEFAULT NULL COMMENT '更新者',
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` TINYINT(1) DEFAULT 0 COMMENT '删除标记:0-正常,1-删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_types_tenant` (`type_id_1`, `type_id_2`, `tenant_id`, `deleted`),
INDEX `idx_type1_relation` (`type_id_1`, `relation_type`),
INDEX `idx_type2_relation` (`type_id_2`, `relation_type`),
INDEX `idx_tenant` (`tenant_id`, `deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='奖学金兼得关系表';
-- =====================================================
-- 3. 更新现有奖学金类型的兼得类型为CUSTOM
-- =====================================================
-- 3.1 更新现有已设置兼得关系的奖学金类型
UPDATE `jcbt_scholarship_type`
SET `compatibility_type` = 'CUSTOM',
`update_time` = NOW(),
`update_by` = 1
WHERE `id` IN (1, 2, 3, 4, 5, 6, 7)
AND `deleted` = 0;
-- =====================================================
-- 4. 迁移现有兼得关系数据到关系表 (如果表中没有数据)
-- =====================================================
-- 4.1 检查关系表是否为空,如果为空则插入基础关系数据
INSERT INTO `jcbt_scholarship_compatibility` (`id`, `type_id_1`, `type_id_2`, `relation_type`, `priority_level`, `description`, `tenant_id`, `create_by`, `create_time`)
SELECT * FROM (
SELECT 1 as id, 1 as type_id_1, 2 as type_id_2, 'EXCLUSIVE' as relation_type, 0 as priority_level, '一等与二等学业奖学金互斥' as description, 1 as tenant_id, 1 as create_by, NOW() as create_time
UNION ALL
SELECT 2, 1, 3, 'EXCLUSIVE', 0, '一等与三等学业奖学金互斥', 1, 1, NOW()
UNION ALL
SELECT 3, 2, 3, 'EXCLUSIVE', 0, '二等与三等学业奖学金互斥', 1, 1, NOW()
UNION ALL
SELECT 4, 1, 4, 'COMPATIBLE', 0, '学业奖学金与创新奖学金可兼得', 1, 1, NOW()
UNION ALL
SELECT 5, 1, 6, 'COMPATIBLE', 0, '学业奖学金与社会工作奖学金可兼得', 1, 1, NOW()
UNION ALL
SELECT 6, 4, 6, 'COMPATIBLE', 0, '创新奖学金与社会工作奖学金可兼得', 1, 1, NOW()
UNION ALL
SELECT 7, 4, 5, 'PRIORITY', 1, '创新特等奖学金优先于一等奖学金', 1, 1, NOW()
) AS temp_data
WHERE NOT EXISTS (SELECT 1 FROM `jcbt_scholarship_compatibility` WHERE `deleted` = 0);
-- =====================================================
-- 5. 新增权限配置
-- =====================================================
-- 5.1 奖学金类型管理权限细化
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `remark`) VALUES
-- 奖学金类型管理按钮权限
(9000000000000001101, '奖学金类型查询', 9000000000000001001, 1, '', '', '', 1, 0, 'F', '0', '0', 'jcbt:scholarshipType:query', '#', 1, NOW(), ''),
(9000000000000001102, '奖学金类型新增', 9000000000000001001, 2, '', '', '', 1, 0, 'F', '0', '0', 'jcbt:scholarshipType:add', '#', 1, NOW(), ''),
(9000000000000001103, '奖学金类型修改', 9000000000000001001, 3, '', '', '', 1, 0, 'F', '0', '0', 'jcbt:scholarshipType:edit', '#', 1, NOW(), ''),
(9000000000000001104, '奖学金类型删除', 9000000000000001001, 4, '', '', '', 1, 0, 'F', '0', '0', 'jcbt:scholarshipType:remove', '#', 1, NOW(), ''),
(9000000000000001105, '奖学金类型导出', 9000000000000001001, 5, '', '', '', 1, 0, 'F', '0', '0', 'jcbt:scholarshipType:export', '#', 1, NOW(), ''),
(9000000000000001106, '兼得关系配置', 9000000000000001001, 6, '', '', '', 1, 0, 'F', '0', '0', 'jcbt:scholarshipType:compatibility', '#', 1, NOW(), '兼得关系配置权限');
-- =====================================================
-- 6. 示例数据:带自定义兼得关系的新奖学金类型
-- =====================================================
-- 6.1 新增一个示例专项奖学金
INSERT INTO `jcbt_scholarship_type` (`id`, `type_code`, `type_name`, `type_category`, `level_type`, `award_amount`, `description`, `application_guide`, `compatibility_type`, `status`, `sort_order`, `is_system`, `tenant_id`, `create_by`, `create_time`) VALUES
(8, 'ZX_EXCELLENT', '卓越学子奖学金', 'SPECIAL', 'SPECIAL', 8000.00, '表彰在学业、创新、社会工作等方面全面发展的优秀学生', '需同时满足学业、创新、社会工作等多项要求', 'CUSTOM', 1, 1, 0, 1, 1, NOW());
-- 6.2 配置卓越学子奖学金的兼得关系(与所有其他奖学金互斥)
INSERT INTO `jcbt_scholarship_compatibility` (`id`, `type_id_1`, `type_id_2`, `relation_type`, `priority_level`, `description`, `tenant_id`, `create_by`, `create_time`) VALUES
(8, 8, 1, 'EXCLUSIVE', 0, '卓越学子奖学金与一等学业奖学金互斥', 1, 1, NOW()),
(9, 8, 2, 'EXCLUSIVE', 0, '卓越学子奖学金与二等学业奖学金互斥', 1, 1, NOW()),
(10, 8, 3, 'EXCLUSIVE', 0, '卓越学子奖学金与三等学业奖学金互斥', 1, 1, NOW()),
(11, 8, 4, 'EXCLUSIVE', 0, '卓越学子奖学金与创新特等奖学金互斥', 1, 1, NOW()),
(12, 8, 5, 'EXCLUSIVE', 0, '卓越学子奖学金与创新一等奖学金互斥', 1, 1, NOW()),
(13, 8, 6, 'EXCLUSIVE', 0, '卓越学子奖学金与社会工作一等奖学金互斥', 1, 1, NOW()),
(14, 8, 7, 'EXCLUSIVE', 0, '卓越学子奖学金与社会工作二等奖学金互斥', 1, 1, NOW());
-- =====================================================
-- 7. 操作日志记录
-- =====================================================
INSERT INTO `sys_oper_log` (`oper_id`, `title`, `business_type`, `method`, `request_method`, `operator_type`, `oper_name`, `dept_name`, `oper_url`, `oper_ip`, `oper_location`, `oper_param`, `json_result`, `status`, `error_msg`, `oper_time`, `cost_time`) VALUES
(9000000000000002001, '奖学金兼得关系增强', 1, '数据升级', 'POST', 1, 'admin', '系统部门', '/jcbt/compatibility/upgrade', '127.0.0.1', '内网IP', '升级兼得关系配置功能', '{"code":200,"msg":"升级成功"}', 0, NULL, NOW(), 0);
-- =====================================================
-- 结束
-- =====================================================
SET FOREIGN_KEY_CHECKS = 1;
-- 兼得关系增强数据升级完成
SELECT '奖学金兼得关系增强功能升级完成!新增CUSTOM自定义配置选项' AS result;