-- ========================================
-- 用药管理模块 - 菜单权限配置
-- PostgreSQL 版本
-- ========================================

-- 用药计划菜单
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '用药计划', menu_id, 10, 'medicationPlan', 'health/medicationPlan/index', 1, 0, 'C', '0', '0', 'health:medicationPlan:list', 'calendar', 'admin', NOW(), '用药计划菜单'
FROM sys_menu WHERE menu_name = '健康管理' LIMIT 1;

-- 用药计划按钮权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '用药计划查询', m.menu_id, 1, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationPlan:query', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationPlan:list'
UNION ALL
SELECT '用药计划新增', m.menu_id, 2, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationPlan:add', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationPlan:list'
UNION ALL
SELECT '用药计划修改', m.menu_id, 3, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationPlan:edit', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationPlan:list'
UNION ALL
SELECT '用药计划删除', m.menu_id, 4, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationPlan:remove', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationPlan:list';

-- 用药任务菜单
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '用药任务', menu_id, 11, 'medicationTask', 'health/medicationTask/index', 1, 0, 'C', '0', '0', 'health:medicationTask:list', 'log', 'admin', NOW(), '用药任务菜单'
FROM sys_menu WHERE menu_name = '健康管理' LIMIT 1;

-- 用药任务按钮权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '用药任务查询', m.menu_id, 1, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationTask:query', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationTask:list'
UNION ALL
SELECT '用药任务修改', m.menu_id, 2, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationTask:edit', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationTask:list'
UNION ALL
SELECT '用药任务删除', m.menu_id, 3, '', NULL, 1, 0, 'F', '0', '0', 'health:medicationTask:remove', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:medicationTask:list';

-- 用药统计菜单
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '用药统计', menu_id, 12, 'medicationStatistic', 'health/medicationStatistic/index', 1, 0, 'C', '0', '0', 'health:medicationStatistic:query', 'chart', 'admin', NOW(), '用药统计菜单'
FROM sys_menu WHERE menu_name = '健康管理' LIMIT 1;

-- 慢性疾病档案菜单
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '慢性疾病档案', menu_id, 9, 'chronicDisease', 'health/chronicDisease/index', 1, 0, 'C', '0', '0', 'health:chronicDisease:list', 'folder', 'admin', NOW(), '慢性疾病档案菜单'
FROM sys_menu WHERE menu_name = '健康管理' LIMIT 1;

-- 慢性疾病档案按钮权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT '慢性疾病档案查询', m.menu_id, 1, '', NULL, 1, 0, 'F', '0', '0', 'health:chronicDisease:query', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:chronicDisease:list'
UNION ALL
SELECT '慢性疾病档案新增', m.menu_id, 2, '', NULL, 1, 0, 'F', '0', '0', 'health:chronicDisease:add', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:chronicDisease:list'
UNION ALL
SELECT '慢性疾病档案修改', m.menu_id, 3, '', NULL, 1, 0, 'F', '0', '0', 'health:chronicDisease:edit', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:chronicDisease:list'
UNION ALL
SELECT '慢性疾病档案删除', m.menu_id, 4, '', NULL, 1, 0, 'F', '0', '0', 'health:chronicDisease:remove', '#', 'admin', NOW(), ''
FROM sys_menu m WHERE m.perms = 'health:chronicDisease:list';

-- ========================================
-- 字典类型
-- ========================================
INSERT INTO sys_dict_type (dict_name, dict_type, status, create_by, create_time, remark)
VALUES
('用药频率类型', 'medication_frequency_type', '0', 'admin', NOW(), '用药频率类型字典'),
('用药计划状态', 'medication_plan_status', '0', 'admin', NOW(), '用药计划状态字典'),
('服药任务状态', 'medication_task_status', '0', 'admin', NOW(), '服药任务状态字典'),
('疾病状态', 'disease_status', '0', 'admin', NOW(), '疾病状态字典');

-- ========================================
-- 字典数据
-- ========================================
-- 用药频率类型
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time)
VALUES
(1, '每天', '1', 'medication_frequency_type', '', 'primary', 'Y', '0', 'admin', NOW()),
(2, '每周', '2', 'medication_frequency_type', '', 'success', 'N', '0', 'admin', NOW()),
(3, '隔天', '3', 'medication_frequency_type', '', 'info', 'N', '0', 'admin', NOW()),
(4, '自定义', '4', 'medication_frequency_type', '', 'warning', 'N', '0', 'admin', NOW());

-- 用药计划状态
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time)
VALUES
(1, '执行中', '1', 'medication_plan_status', '', 'primary', 'Y', '0', 'admin', NOW()),
(2, '已暂停', '2', 'medication_plan_status', '', 'warning', 'N', '0', 'admin', NOW()),
(3, '已结束', '3', 'medication_plan_status', '', 'info', 'N', '0', 'admin', NOW());

-- 服药任务状态
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time)
VALUES
(0, '待服药', '0', 'medication_task_status', '', 'warning', 'Y', '0', 'admin', NOW()),
(1, '已服药', '1', 'medication_task_status', '', 'success', 'N', '0', 'admin', NOW()),
(2, '漏服', '2', 'medication_task_status', '', 'danger', 'N', '0', 'admin', NOW()),
(3, '跳过', '3', 'medication_task_status', '', 'info', 'N', '0', 'admin', NOW());

-- 疾病状态
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time)
VALUES
(1, '稳定', '1', 'disease_status', '', 'success', 'Y', '0', 'admin', NOW()),
(2, '需关注', '2', 'disease_status', '', 'warning', 'N', '0', 'admin', NOW()),
(3, '急性期', '3', 'disease_status', '', 'danger', 'N', '0', 'admin', NOW());