Files
doorcontrol/base/RuoYi-Vue-master/sql/upgrade_d21_openapp.sql
T
zfjia 271e4ca77c chore: 导入门锁迭代开发工程基线
包含 RuoYi-Vue 后端(ruoyi-iot 门禁模块)、RuoYi-Vue2 前端、设计文档与升级脚本。
忽略构建产物(target/node_modules/dist)、IDE 配置、运行日志与数据库转储。
2026-11-01 19:44:40 +08:00

123 lines
7.8 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.
-- =========================================================================
-- 存量升级:D21 开放平台接入管理(v1 库)
--
-- 背景:D20 把外部应用(PMS/访客系统)的配置放在 application.yml 的
-- iot.openapi.apps[],改配置要重启,且无法在平台里查看用量。本脚本把
-- 应用配置落到 lock_open_app,由「开放管理 › 应用接入」维护。
--
-- 行为变化:
-- 1) 鉴权、回调和接口响应中的应用信息一律读表(带 30 秒缓存,改完即时生效);
-- 2) 服务首次启动时若表为空,会把 yml 的 apps[](或单 Key 模式的 api-key)
-- 原样导入本表,外部系统不用改 Key;导入后以表为准,yml 中 apps 可删除;
-- 3) 表不可用时(本脚本未执行)服务仍按 yml 运行,只打告警,不影响存量调用。
--
-- 幂等性:建表用 if not exists;菜单先按 perms 删除再插入;
-- 本脚本可重复执行。
--
-- 执行前置:备份 sys_menu;lock_open_app 为新表,无存量数据。
-- =========================================================================
set names utf8mb4;
-- =========================================================================
-- 1、外部应用接入配置表
-- app_code 是数据隔离键,写入 lock_stay.biz_system 与 lock_person_ref.app_code,
-- 创建后不可修改(改编码会让历史入住单失去归属)。
-- api_key / callback_secret 明文存储(与 D10 口径一致),页面只展示掩码,
-- 完整值仅在新增与重置时返回一次。
-- 不设 del_flag:app_code/api_key 唯一键需要覆盖全部行;删除仅允许在
-- 该应用没有任何入住单时执行(有数据只能停用)。
-- =========================================================================
create table if not exists lock_open_app (
app_id bigint(20) not null auto_increment comment '应用ID',
app_code varchar(32) not null comment '应用编码(数据隔离键,创建后不可改)',
app_name varchar(64) not null comment '应用名称',
api_key varchar(128) not null comment '接口密钥(X-API-Key,明文存储)',
callback_url varchar(255) default null comment '结果回调地址(为空表示不开通回调)',
callback_secret varchar(128) default null comment '回调签名密钥(为空表示不签名)',
status char(1) default '0' comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (app_id),
unique key uk_lock_open_app_code (app_code),
unique key uk_lock_open_app_key (api_key)
) engine=innodb comment = '外部应用接入配置';
-- =========================================================================
-- 2、菜单:开放管理(顶级目录)→ 应用接入
-- 2200 目录,2210 页面,2211–2216 按钮权限。
-- =========================================================================
delete from sys_menu where perms like 'lock:openapp:%';
delete from sys_menu where menu_id = 2200;
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, query, route_name, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark) values
(2200, '开放管理', 0, 5, 'openapi', null, '', '', 1, 0, 'M', '0', '0', '', 'link', 'admin', CURRENT_TIMESTAMP, '外部应用接入管理目录');
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, query, route_name, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark) values
(2210, '应用接入', 2200, 1, 'openapp', 'iot/openapp/index', '', '', 1, 0, 'C', '0', '0', 'lock:openapp:list', 'international', 'admin', CURRENT_TIMESTAMP, '外部应用配置与入住统计');
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, query, route_name, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark) values
(2211, '应用查询', 2210, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:openapp:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2212, '应用新增', 2210, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:openapp:add', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2213, '应用修改', 2210, 3, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:openapp:edit', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2214, '应用删除', 2210, 4, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:openapp:remove', '#', 'admin', CURRENT_TIMESTAMP, '有入住数据的应用不可删除'),
(2215, '重置密钥', 2210, 5, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:openapp:resetkey','#', 'admin', CURRENT_TIMESTAMP, '生成新的 X-API-Key'),
(2216, '启停应用', 2210, 6, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:openapp:status', '#', 'admin', CURRENT_TIMESTAMP, '');
-- =========================================================================
-- 3、存量配置迁移
-- yml 中还配着 iot.openapi.apps[](或单 Key 模式 api-key)时,服务首次启动
-- 若发现本表为空,会自动把这些应用原样写入本表(保留原 Key 与密钥),
-- 外部系统无需改 Key。导入完成后可在 yml 中删除 apps 段。
--
-- 若希望手工建档而不依赖自动导入,可参考下面的语句(示例,按实际值改):
-- insert into lock_open_app (app_code, app_name, api_key, callback_url, callback_secret, status, create_by, create_time, remark)
-- values ('PMS', '公寓 PMS', '<原Key>', 'https://pms.example.com/hook/lock', '<原密钥>', '0', 'admin', now(), '由 yml 迁入');
-- =========================================================================
-- =========================================================================
-- 4、执行后核对(只读)
-- =========================================================================
-- 4.1 表结构
-- show create table lock_open_app;
--
-- 4.2 应用清单与状态
-- select app_id, app_code, app_name, status,
-- case when callback_url is null or callback_url = '' then '未开通回调' else '已开通回调' end as callback,
-- create_time
-- from lock_open_app order by app_id;
--
-- 4.3 各应用入住统计(与页面口径一致:按 lock_stay.biz_system)
-- select a.app_code, a.app_name,
-- count(s.stay_id) as stay_total,
-- sum(case when s.stay_status = '1' then 1 else 0 end) as stay_active,
-- sum(case when date(s.checkin_time) = curdate() then 1 else 0 end) as stay_today,
-- max(s.checkin_time) as last_checkin_time
-- from lock_open_app a
-- left join lock_stay s on s.biz_system = a.app_code
-- group by a.app_id, a.app_code, a.app_name
-- order by a.app_id;
--
-- 4.4 菜单是否到位
-- select menu_id, menu_name, parent_id, menu_type, perms from sys_menu
-- where menu_id between 2200 and 2216 order by menu_id;
-- =========================================================================
-- 5、回滚(确认已切回 yml 配置后再执行)
-- =========================================================================
-- 5.1 菜单
-- delete from sys_menu where perms like 'lock:openapp:%';
-- delete from sys_menu where menu_id = 2200;
--
-- 5.2 表:确认 lock_stay.biz_system 的取值已同步回 yml 的 apps[].app-code 后再删
-- select distinct biz_system from lock_stay where biz_system is not null;
-- drop table if exists lock_open_app;