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

853 lines
60 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.
-- =========================================================================
-- 公寓人脸门禁系统(智能门锁)业务表 —— KingbaseES 初始化脚本
--
-- 库名:iotlocks 模式:iotlocks
-- 前置:先执行同目录 ry.sql(若依基础表)
-- 版本:v1.0
--
-- 规范(与 ry.sql 完全一致):
-- 1) 所有对象显式限定 iotlocks.<对象名>,不依赖 search_path,避免命中
-- KingbaseES 系统模式 sys_catalog 中的同名内置对象。
-- 2) 主键统一 bigserial;关联列统一 bigint(不建物理外键,由业务层保证)。
-- 3) 状态/标志位统一 char(1) 或 char(2),与若依 del_flag/status 风格一致;
-- 时间统一 timestamp(不带时区),默认值用 CURRENT_TIMESTAMP。
-- 4) 表与列注释统一使用 comment on;索引统一 idx_ / uk_ 前缀。
-- 5) 脚本可重复执行:建表前 drop table if exists,种子数据先 delete 再 insert。
-- 6) 显式指定主键的种子数据,末尾统一 setval 复位序列(沿用 ry.sql 写法)。
--
-- 表清单:
-- 1. lock_group 公寓分组表
-- 2. lock_gateway 门锁网关表
-- 3. lock_device 智能门锁表
-- 4. lock_face 人脸数据表
-- 5. lock_auth 授权数据表
-- 6. lock_access_log 门禁通行日志表
-- 7. lock_command 下行命令记录表
-- 8. lock_mqtt_log MQTT 报文留痕表
-- 9. lock_service_config 服务参数配置表
-- =========================================================================
set search_path to iotlocks, public, pg_catalog, sys_catalog;
create schema if not exists iotlocks;
-- =========================================================================
-- 1、公寓分组表
-- 业务含义:一个公寓对应一个分组;分组是 MQTT 分组级主题
-- (ydlink/{groupCode}/thing/...)的载体,也是批量授权/远程开锁的粒度。
-- =========================================================================
drop table if exists iotlocks.lock_group;
create table iotlocks.lock_group (
group_id bigserial not null,
group_code varchar(32) not null,
group_name varchar(64) not null,
dept_id bigint default null,
manager varchar(64) default null,
phone varchar(20) default null,
address varchar(255) default null,
config_id bigint default null,
status char(1) default '0',
order_num int default 0,
del_flag char(1) default '0',
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (group_id)
);
comment on table iotlocks.lock_group is '公寓分组表';
comment on column iotlocks.lock_group.group_id is '分组ID';
comment on column iotlocks.lock_group.group_code is '分组编号(MQTT主题第2段,全局唯一,一经占用不再复用)';
comment on column iotlocks.lock_group.group_name is '公寓/分组名称';
comment on column iotlocks.lock_group.dept_id is '所属部门ID(用于数据权限)';
comment on column iotlocks.lock_group.manager is '负责人';
comment on column iotlocks.lock_group.phone is '联系电话';
comment on column iotlocks.lock_group.address is '公寓地址';
comment on column iotlocks.lock_group.config_id is '关联MQTT服务器配置ID(lock_service_config.config_id,空表示用全局默认)';
comment on column iotlocks.lock_group.status is '状态(0正常 1停用)';
comment on column iotlocks.lock_group.order_num is '显示顺序';
comment on column iotlocks.lock_group.del_flag is '删除标志(0代表存在 2代表删除)';
comment on column iotlocks.lock_group.create_by is '创建者';
comment on column iotlocks.lock_group.create_time is '创建时间';
comment on column iotlocks.lock_group.update_by is '更新者';
comment on column iotlocks.lock_group.update_time is '更新时间';
comment on column iotlocks.lock_group.remark is '备注';
create unique index uk_lock_group_code on iotlocks.lock_group (group_code);
create index idx_lock_group_dept on iotlocks.lock_group (dept_id);
create index idx_lock_group_status on iotlocks.lock_group (status);
-- =========================================================================
-- 2、门锁网关表
-- 业务含义:门锁网关是 LoRa 汇聚节点,下挂多台门锁;一个网关属于一个分组。
-- 网关是 MQTT 网关级主题(ydlink/{gatewaySn}/thing/...)的载体。
-- =========================================================================
drop table if exists iotlocks.lock_gateway;
create table iotlocks.lock_gateway (
gateway_id bigserial not null,
gateway_sn varchar(32) not null,
gateway_name varchar(64) default null,
group_id bigint default null,
gateway_ip varchar(64) default null,
subnet_mask varchar(64) default null,
default_gateway varchar(64) default null,
gateway_password varchar(128) default null,
config_id bigint default null,
lora_config varchar(1024) default null,
mqtt_config varchar(1024) default null,
config_version int default 0,
sync_status char(1) default '0',
online_status char(1) default '1',
last_online_time timestamp,
last_sync_time timestamp,
device_count int default 0,
firmware_ver varchar(32) default null,
status char(1) default '0',
del_flag char(1) default '0',
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (gateway_id)
);
comment on table iotlocks.lock_gateway is '门锁网关表';
comment on column iotlocks.lock_gateway.gateway_id is '网关ID';
comment on column iotlocks.lock_gateway.gateway_sn is '网关SN(MQTT主题第2段,全局唯一)';
comment on column iotlocks.lock_gateway.gateway_name is '网关名称';
comment on column iotlocks.lock_gateway.group_id is '所属分组ID(lock_group.group_id)';
comment on column iotlocks.lock_gateway.gateway_ip is '网关IP';
comment on column iotlocks.lock_gateway.subnet_mask is '子网掩码';
comment on column iotlocks.lock_gateway.default_gateway is '默认网关';
comment on column iotlocks.lock_gateway.gateway_password is '网关密码(密文存储,AES加密)';
comment on column iotlocks.lock_gateway.config_id is '关联MQTT服务器配置ID';
comment on column iotlocks.lock_gateway.lora_config is 'LORA参数配置(JSON)';
comment on column iotlocks.lock_gateway.mqtt_config is '网关侧MQTT参数(JSON)';
comment on column iotlocks.lock_gateway.config_version is '配置版本号(每次下发+1,用于比对网关侧是否已同步)';
comment on column iotlocks.lock_gateway.sync_status is '配置同步状态(0未同步 1已同步 2同步失败)';
comment on column iotlocks.lock_gateway.online_status is '在线状态(0在线 1离线)';
comment on column iotlocks.lock_gateway.last_online_time is '最后在线时间';
comment on column iotlocks.lock_gateway.last_sync_time is '最后配置同步时间';
comment on column iotlocks.lock_gateway.device_count is '下挂门锁数量(冗余统计)';
comment on column iotlocks.lock_gateway.firmware_ver is '网关固件版本';
comment on column iotlocks.lock_gateway.status is '状态(0正常 1停用)';
comment on column iotlocks.lock_gateway.del_flag is '删除标志(0代表存在 2代表删除)';
comment on column iotlocks.lock_gateway.create_by is '创建者';
comment on column iotlocks.lock_gateway.create_time is '创建时间';
comment on column iotlocks.lock_gateway.update_by is '更新者';
comment on column iotlocks.lock_gateway.update_time is '更新时间';
comment on column iotlocks.lock_gateway.remark is '备注';
create unique index uk_lock_gateway_sn on iotlocks.lock_gateway (gateway_sn);
create index idx_lock_gateway_group on iotlocks.lock_gateway (group_id);
create index idx_lock_gateway_online on iotlocks.lock_gateway (online_status);
create index idx_lock_gateway_sync on iotlocks.lock_gateway (sync_status);
-- =========================================================================
-- 3、智能门锁表
-- 业务含义:门锁终端,通过 LoRa 挂在一个网关下;gateway_id 为空表示未绑定网关。
-- 协议字段映射:device_sn -> devId,device_password -> devPsw,
-- dev_type -> devType,dev_ver -> devVer。
-- =========================================================================
drop table if exists iotlocks.lock_device;
create table iotlocks.lock_device (
device_id bigserial not null,
device_sn varchar(32) not null,
device_name varchar(64) default null,
gateway_id bigint default null,
group_id bigint default null,
device_password varchar(128) default null,
dev_type varchar(8) default null,
dev_ver varchar(16) default null,
face_algo_version varchar(32) default null,
room_no varchar(64) default null,
bind_time timestamp,
last_sync_time timestamp,
signal_strength varchar(8) default null,
battery_level int default null,
last_status_time timestamp,
online_status char(1) default '1',
last_online_time timestamp,
status char(1) default '0',
del_flag char(1) default '0',
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (device_id)
);
comment on table iotlocks.lock_device is '智能门锁表';
comment on column iotlocks.lock_device.device_id is '门锁ID';
comment on column iotlocks.lock_device.device_sn is '门锁SN(对应协议devId,全局唯一)';
comment on column iotlocks.lock_device.device_name is '门锁名称';
comment on column iotlocks.lock_device.gateway_id is '所属网关ID(lock_gateway.gateway_id,为空表示未绑定)';
comment on column iotlocks.lock_device.group_id is '冗余分组ID(便于按分组批量下发,与网关分组保持一致)';
comment on column iotlocks.lock_device.device_password is '门锁密码(密文存储,对应协议devPsw)';
comment on column iotlocks.lock_device.dev_type is '设备类型(对应协议devType)';
comment on column iotlocks.lock_device.dev_ver is '设备固件版本(对应协议devVer)';
comment on column iotlocks.lock_device.face_algo_version is '人脸算法版本(特征提取服务的 algorithm_version 入参,由每把门锁各自维护,如 2.14.5_2.7.1_M3)';
comment on column iotlocks.lock_device.room_no is '分配房间号';
comment on column iotlocks.lock_device.bind_time is '绑定网关时间';
comment on column iotlocks.lock_device.last_sync_time is '最后时间同步时间';
comment on column iotlocks.lock_device.signal_strength is '信号强度RSSI(dBm,op=lockrssi 上报,如 -42)';
comment on column iotlocks.lock_device.battery_level is '剩余电量(百分比,op=lockrssi 上报)';
comment on column iotlocks.lock_device.last_status_time is '最后状态上报时间(信号/电量上报时间)';
comment on column iotlocks.lock_device.online_status is '在线状态(0在线 1离线 2未知)';
comment on column iotlocks.lock_device.last_online_time is '最后在线时间';
comment on column iotlocks.lock_device.status is '状态(0正常 1停用)';
comment on column iotlocks.lock_device.del_flag is '删除标志(0代表存在 2代表删除)';
comment on column iotlocks.lock_device.create_by is '创建者';
comment on column iotlocks.lock_device.create_time is '创建时间';
comment on column iotlocks.lock_device.update_by is '更新者';
comment on column iotlocks.lock_device.update_time is '更新时间';
comment on column iotlocks.lock_device.remark is '备注';
create unique index uk_lock_device_sn on iotlocks.lock_device (device_sn);
create index idx_lock_device_gateway on iotlocks.lock_device (gateway_id);
-- 已有环境增量升级(信号/电量):以下 add column 带 if not exists,重复执行不会报错
alter table iotlocks.lock_device add column if not exists signal_strength varchar(8) default null;
alter table iotlocks.lock_device add column if not exists battery_level int default null;
alter table iotlocks.lock_device add column if not exists last_status_time timestamp;
comment on column iotlocks.lock_device.signal_strength is '信号强度RSSI(dBm,op=lockrssi 上报,如 -42)';
comment on column iotlocks.lock_device.battery_level is '剩余电量(百分比,op=lockrssi 上报)';
comment on column iotlocks.lock_device.last_status_time is '最后状态上报时间(信号/电量上报时间)';
create index idx_lock_device_group on iotlocks.lock_device (group_id);
create index idx_lock_device_room on iotlocks.lock_device (room_no);
-- =========================================================================
-- 4、人脸数据表
-- 业务含义:以 person_no(人员/人脸编号,协议中的 AA000009 形态)为主键标识的人脸库。
-- 图片与特征分离存储:图片走对象存储/文件服务,特征以 base64 落 text 列。
-- =========================================================================
drop table if exists iotlocks.lock_face;
create table iotlocks.lock_face (
face_id bigserial not null,
person_no varchar(32) not null,
person_name varchar(64) default null,
person_type char(1) default '0',
phone varchar(20) default null,
photo_url varchar(512) default null,
photo_md5 varchar(32) default null,
feature_data text,
feature_md5 varchar(32) default null,
feature_algo_version varchar(32) default null,
feature_size int default 0,
extract_status char(1) default '0',
extract_time timestamp,
extract_msg varchar(512) default null,
status char(1) default '0',
del_flag char(1) default '0',
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (face_id)
);
comment on table iotlocks.lock_face is '人脸数据表';
comment on column iotlocks.lock_face.face_id is '人脸数据ID';
comment on column iotlocks.lock_face.person_no is '人脸编号/人员编号(业务唯一,协议授权帧中的人员标识)';
comment on column iotlocks.lock_face.person_name is '姓名';
comment on column iotlocks.lock_face.person_type is '人员类型(0住户 1员工 2访客 3其他)';
comment on column iotlocks.lock_face.phone is '联系电话';
comment on column iotlocks.lock_face.photo_url is '人脸图片URL';
comment on column iotlocks.lock_face.photo_md5 is '图片指纹(用于变更检测与去重)';
comment on column iotlocks.lock_face.feature_data is '人脸特征值(base64编码)';
comment on column iotlocks.lock_face.feature_md5 is '特征指纹(变更检测与幂等下发用)';
comment on column iotlocks.lock_face.feature_algo_version is '特征算法版本(提取时实际使用的 algorithm_version)';
comment on column iotlocks.lock_face.feature_size is '特征字节数';
comment on column iotlocks.lock_face.extract_status is '特征提取状态(0未提取 1成功 2失败)';
comment on column iotlocks.lock_face.extract_time is '特征提取时间';
comment on column iotlocks.lock_face.extract_msg is '特征提取失败原因';
comment on column iotlocks.lock_face.status is '状态(0正常 1停用)';
comment on column iotlocks.lock_face.del_flag is '删除标志(0代表存在 2代表删除)';
comment on column iotlocks.lock_face.create_by is '创建者';
comment on column iotlocks.lock_face.create_time is '创建时间';
comment on column iotlocks.lock_face.update_by is '更新者';
comment on column iotlocks.lock_face.update_time is '更新时间';
comment on column iotlocks.lock_face.remark is '备注';
create unique index uk_lock_face_person_no on iotlocks.lock_face (person_no);
create index idx_lock_face_name on iotlocks.lock_face (person_name);
create index idx_lock_face_extract on iotlocks.lock_face (extract_status);
-- =========================================================================
-- 5、授权数据表
-- 业务含义:把某个人员(person_no)在某个门锁(device_id)上的某类凭证
-- (人脸/密码/指纹/IC卡)授权关系落库,并跟踪下发到设备的同步状态。
-- 协议对应:ydlink/{groupCode}/thing/data/batch 的 params 数组(add/delete)。
-- =========================================================================
drop table if exists iotlocks.lock_auth;
create table iotlocks.lock_auth (
auth_id bigserial not null,
auth_no varchar(64) not null,
person_no varchar(32) not null,
person_name varchar(64) default null,
device_id bigint not null,
device_sn varchar(32) default null,
gateway_id bigint default null,
group_id bigint default null,
auth_type char(2) not null,
auth_value text,
auth_value_md5 varchar(32) default null,
begin_time timestamp,
end_time timestamp,
auth_time timestamp,
sync_status char(1) default '0',
sync_time timestamp,
sync_msg varchar(512) default null,
retry_count int default 0,
status char(1) default '0',
del_flag char(1) default '0',
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (auth_id)
);
comment on table iotlocks.lock_auth is '授权数据表';
comment on column iotlocks.lock_auth.auth_id is '授权ID';
comment on column iotlocks.lock_auth.auth_no is '授权编号(业务唯一,建议规则 AUTH+日期+序号)';
comment on column iotlocks.lock_auth.person_no is '人员编号(lock_face.person_no)';
comment on column iotlocks.lock_auth.person_name is '冗余人员姓名';
comment on column iotlocks.lock_auth.device_id is '授权锁ID(lock_device.device_id)';
comment on column iotlocks.lock_auth.device_sn is '冗余门锁SN(下发组包直接用)';
comment on column iotlocks.lock_auth.gateway_id is '冗余网关ID';
comment on column iotlocks.lock_auth.group_id is '冗余分组ID(决定下发主题)';
comment on column iotlocks.lock_auth.auth_type is '授权类型(01人脸 02密码 03指纹 04IC卡)';
comment on column iotlocks.lock_auth.auth_value is '授权内容(人脸特征base64/密码密文/指纹特征/IC卡号)';
comment on column iotlocks.lock_auth.auth_value_md5 is '授权内容指纹(变更检测与重复下发判断)';
comment on column iotlocks.lock_auth.begin_time is '生效开始时间';
comment on column iotlocks.lock_auth.end_time is '生效结束时间(空表示永久有效)';
comment on column iotlocks.lock_auth.auth_time is '授权操作时间';
comment on column iotlocks.lock_auth.sync_status is '下发同步状态(0待下发 1已下发 2下发成功 3下发失败 4已清除)';
comment on column iotlocks.lock_auth.sync_time is '最后下发/响应时间';
comment on column iotlocks.lock_auth.sync_msg is '下发结果说明';
comment on column iotlocks.lock_auth.retry_count is '下发重试次数';
comment on column iotlocks.lock_auth.status is '状态(0正常 1停用)';
comment on column iotlocks.lock_auth.del_flag is '删除标志(0代表存在 2代表删除)';
comment on column iotlocks.lock_auth.create_by is '创建者';
comment on column iotlocks.lock_auth.create_time is '创建时间';
comment on column iotlocks.lock_auth.update_by is '更新者';
comment on column iotlocks.lock_auth.update_time is '更新时间';
comment on column iotlocks.lock_auth.remark is '备注';
create unique index uk_lock_auth_no on iotlocks.lock_auth (auth_no);
create unique index uk_lock_auth_person_lock on iotlocks.lock_auth (person_no, device_id, auth_type);
create index idx_lock_auth_person on iotlocks.lock_auth (person_no);
create index idx_lock_auth_device on iotlocks.lock_auth (device_id);
create index idx_lock_auth_group on iotlocks.lock_auth (group_id);
create index idx_lock_auth_sync on iotlocks.lock_auth (sync_status);
-- =========================================================================
-- 6、门禁通行日志表
-- 业务含义:设备通过 ydlink/{groupCode}/thing/event/trigger(op=lockrecord)
-- 上报的开门记录。本表为高频只追加表,故不设 del_flag / update_*。
--
-- 【性能提示】单公寓千级住户、日均万级记录时,建议按 open_time 做月度
-- 范围分区(KingbaseES 支持声明式分区),或按 recv_time 定期归档。
-- =========================================================================
drop table if exists iotlocks.lock_access_log;
create table iotlocks.lock_access_log (
log_id bigserial not null,
device_id bigint default null,
device_sn varchar(32) not null,
gateway_id bigint default null,
gateway_sn varchar(32) default null,
group_id bigint default null,
person_no varchar(32) default null,
person_name varchar(64) default null,
card_no varchar(32) default null,
-- 以下三项均为设备原样上报的编码:open_type 实测为 "7",open_dir 实测为 "14"/"16",
-- 长度不固定,故统一用 varchar(8),不能用 char(n)
open_type varchar(8) default null,
open_result varchar(8) default null,
open_dir varchar(8) default null,
open_time timestamp,
recv_time timestamp,
seq varchar(32) default null,
raw_params text,
create_time timestamp,
remark varchar(500) default null,
primary key (log_id)
);
comment on table iotlocks.lock_access_log is '门禁通行日志表';
comment on column iotlocks.lock_access_log.log_id is '日志ID';
comment on column iotlocks.lock_access_log.device_id is '门锁ID(解析device_sn得到,未登记时为空)';
comment on column iotlocks.lock_access_log.device_sn is '门锁SN';
comment on column iotlocks.lock_access_log.gateway_id is '上报网关ID';
comment on column iotlocks.lock_access_log.gateway_sn is '上报网关SN';
comment on column iotlocks.lock_access_log.group_id is '所属分组ID';
comment on column iotlocks.lock_access_log.person_no is '人员编号';
comment on column iotlocks.lock_access_log.person_name is '冗余人员姓名';
comment on column iotlocks.lock_access_log.card_no is '卡号/凭证号';
comment on column iotlocks.lock_access_log.open_type is '开门方式(字典 lock_open_type)';
comment on column iotlocks.lock_access_log.open_result is '开门结果(0失败 1成功)';
comment on column iotlocks.lock_access_log.open_dir is '开门方向(0进门 1出门 空未知)';
comment on column iotlocks.lock_access_log.open_time is '开门时间(设备上报时间)';
comment on column iotlocks.lock_access_log.recv_time is '服务端接收时间';
comment on column iotlocks.lock_access_log.seq is '报文序号(用于幂等去重)';
comment on column iotlocks.lock_access_log.raw_params is '原始params数组(JSON,便于协议字段二次解析)';
comment on column iotlocks.lock_access_log.create_time is '创建时间';
comment on column iotlocks.lock_access_log.remark is '备注';
create index idx_lock_access_log_device on iotlocks.lock_access_log (device_sn);
create index idx_lock_access_log_person on iotlocks.lock_access_log (person_no);
create index idx_lock_access_log_time on iotlocks.lock_access_log (open_time);
create index idx_lock_access_log_seq on iotlocks.lock_access_log (device_sn, seq);
create index idx_lock_access_log_group on iotlocks.lock_access_log (group_id);
-- 已有环境增量升级:开门记录上报值长度不固定(open_type="7"、open_dir="14"/"16"),原 char(n) 装不下
alter table iotlocks.lock_access_log alter column open_type type varchar(8);
alter table iotlocks.lock_access_log alter column open_result type varchar(8);
alter table iotlocks.lock_access_log alter column open_dir type varchar(8);
-- 已有环境增量升级:补充设备实测开门方式编码(lockrecord params[2]:7 人脸开门、2 密码开锁)
delete from iotlocks.sys_dict_data where dict_type = 'lock_open_type' and dict_value in ('7', '2');
insert into iotlocks.sys_dict_data
(dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark)
values
(117, 7, '人脸', '7', 'lock_open_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, '设备实测编码,待完整协议对齐后统一'),
(118, 8, '密码开锁', '2', 'lock_open_type', '', 'success', 'N', '0', 'admin', CURRENT_TIMESTAMP, '密码开锁时人员编号位为开锁密码');
-- =========================================================================
-- 7、下行命令记录表
-- 业务含义:所有平台→设备的指令统一下发留痕,支撑响应匹配、失败重试、
-- 离线补发与操作审计。覆盖:绑定/解绑门锁、同步时间、远程开关锁、重启网关、
-- 修改网络/LORA/MQTT参数、保存配置、授权下发、清除授权、清除门锁。
-- =========================================================================
drop table if exists iotlocks.lock_command;
create table iotlocks.lock_command (
command_id bigserial not null,
command_no varchar(64) not null,
command_type char(4) not null,
target_type char(1) not null,
target_id bigint default null,
target_code varchar(32) default null,
biz_id bigint default null,
topic varchar(255) default null,
payload text,
req_time timestamp,
resp_topic varchar(255) default null,
resp_payload text,
resp_time timestamp,
command_status char(1) default '0',
retry_count int default 0,
max_retry int default 3,
next_retry_time timestamp,
gateway_ack char(1) default '0',
device_ack char(1) default '0',
device_result char(1) default null,
error_msg varchar(512) default null,
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (command_id)
);
comment on table iotlocks.lock_command is '下行命令记录表';
comment on column iotlocks.lock_command.command_id is '命令ID';
comment on column iotlocks.lock_command.command_no is '命令编号(对应协议seq,全局唯一)';
comment on column iotlocks.lock_command.command_type is '命令类型(字典 lock_command_type)';
comment on column iotlocks.lock_command.target_type is '目标类型(1网关 2门锁 3分组)';
comment on column iotlocks.lock_command.target_id is '目标对象ID';
comment on column iotlocks.lock_command.target_code is '目标编号(网关SN/门锁SN/分组编号,用于主题拼装)';
comment on column iotlocks.lock_command.biz_id is '关联业务ID(如授权下发时指向 lock_auth.auth_id)';
comment on column iotlocks.lock_command.topic is '下发主题';
comment on column iotlocks.lock_command.payload is '下发报文内容';
comment on column iotlocks.lock_command.req_time is '下发时间';
comment on column iotlocks.lock_command.resp_topic is '响应主题';
comment on column iotlocks.lock_command.resp_payload is '响应报文内容';
comment on column iotlocks.lock_command.resp_time is '响应时间';
comment on column iotlocks.lock_command.command_status is '命令状态(0待发送 1已发送 2成功 3失败 4超时 5已取消)';
comment on column iotlocks.lock_command.retry_count is '已重试次数';
comment on column iotlocks.lock_command.max_retry is '最大重试次数';
comment on column iotlocks.lock_command.next_retry_time is '下次重试时间(补偿任务扫描用)';
comment on column iotlocks.lock_command.gateway_ack is '是否已收到网关回执(0否 1是)';
comment on column iotlocks.lock_command.device_ack is '是否已收到门锁回执(0否 1是)';
comment on column iotlocks.lock_command.device_result is '门锁回执结果(0失败 1成功),双回执齐备才判定命令成功';
comment on column iotlocks.lock_command.error_msg is '失败原因';
comment on column iotlocks.lock_command.create_by is '创建者';
comment on column iotlocks.lock_command.create_time is '创建时间';
comment on column iotlocks.lock_command.update_by is '更新者';
comment on column iotlocks.lock_command.update_time is '更新时间';
comment on column iotlocks.lock_command.remark is '备注';
create unique index uk_lock_command_no on iotlocks.lock_command (command_no);
create index idx_lock_command_status on iotlocks.lock_command (command_status);
create index idx_lock_command_target on iotlocks.lock_command (target_code);
create index idx_lock_command_time on iotlocks.lock_command (req_time);
create index idx_lock_command_retry on iotlocks.lock_command (command_status, next_retry_time);
-- 已有环境增量升级(双回执):以下 add column 带 if not exists,重复执行不会报错
alter table iotlocks.lock_command add column if not exists gateway_ack char(1) default '0';
alter table iotlocks.lock_command add column if not exists device_ack char(1) default '0';
alter table iotlocks.lock_command add column if not exists device_result char(1) default null;
comment on column iotlocks.lock_command.gateway_ack is '是否已收到网关回执(0否 1是)';
comment on column iotlocks.lock_command.device_ack is '是否已收到门锁回执(0否 1是)';
comment on column iotlocks.lock_command.device_result is '门锁回执结果(0失败 1成功),双回执齐备才判定命令成功';
-- =========================================================================
-- 8、MQTT 报文留痕表
-- 业务含义:上下行原始报文的落库留痕,用于协议联调、问题回溯与审计。
-- 可通过配置开关(仅记录收发/记录全部)控制写入量。
-- =========================================================================
drop table if exists iotlocks.lock_mqtt_log;
create table iotlocks.lock_mqtt_log (
log_id bigserial not null,
direction char(1) not null,
topic varchar(255) not null,
group_code varchar(32) default null,
gateway_sn varchar(32) default null,
device_sn varchar(32) default null,
op varchar(32) default null,
mode varchar(8) default null,
ac varchar(8) default null,
seq varchar(32) default null,
qos smallint default 1,
retained char(1) default '0',
payload text,
chksum varchar(32) default null,
verify_status char(1) default '0',
handle_status char(1) default '0',
handle_msg varchar(512) default null,
cost_time int default 0,
recv_time timestamp,
create_time timestamp,
primary key (log_id)
);
comment on table iotlocks.lock_mqtt_log is 'MQTT报文留痕表';
comment on column iotlocks.lock_mqtt_log.log_id is '日志ID';
comment on column iotlocks.lock_mqtt_log.direction is '方向(1上行设备→平台 2下行平台→设备)';
comment on column iotlocks.lock_mqtt_log.topic is 'MQTT主题';
comment on column iotlocks.lock_mqtt_log.group_code is '解析出的分组编号';
comment on column iotlocks.lock_mqtt_log.gateway_sn is '解析出的网关SN';
comment on column iotlocks.lock_mqtt_log.device_sn is '解析出的设备SN(协议devId)';
comment on column iotlocks.lock_mqtt_log.op is '操作类型(协议op)';
comment on column iotlocks.lock_mqtt_log.mode is '方向标识(s2d服务端→设备 d2s设备→服务端)';
comment on column iotlocks.lock_mqtt_log.ac is '动作类型(协议ac)';
comment on column iotlocks.lock_mqtt_log.seq is '报文序号(协议seq)';
comment on column iotlocks.lock_mqtt_log.qos is '服务质量';
comment on column iotlocks.lock_mqtt_log.retained is '是否保留消息(0否 1是)';
comment on column iotlocks.lock_mqtt_log.payload is '报文原文';
comment on column iotlocks.lock_mqtt_log.chksum is '报文校验和';
comment on column iotlocks.lock_mqtt_log.verify_status is '校验结果(0未校验 1通过 2失败)';
comment on column iotlocks.lock_mqtt_log.handle_status is '处理状态(0待处理 1成功 2失败 3已忽略)';
comment on column iotlocks.lock_mqtt_log.handle_msg is '处理结果说明';
comment on column iotlocks.lock_mqtt_log.cost_time is '处理耗时(毫秒)';
comment on column iotlocks.lock_mqtt_log.recv_time is '接收/发送时间';
comment on column iotlocks.lock_mqtt_log.create_time is '创建时间';
create index idx_lock_mqtt_log_topic on iotlocks.lock_mqtt_log (topic);
create index idx_lock_mqtt_log_device on iotlocks.lock_mqtt_log (device_sn);
create index idx_lock_mqtt_log_time on iotlocks.lock_mqtt_log (recv_time);
create index idx_lock_mqtt_log_handle on iotlocks.lock_mqtt_log (handle_status);
create index idx_lock_mqtt_log_seq on iotlocks.lock_mqtt_log (seq);
create index idx_lock_mqtt_log_direct on iotlocks.lock_mqtt_log (direction);
-- =========================================================================
-- 9、服务参数配置表
-- 业务含义:承载“系统参数”中的 MQTT 服务器配置、人脸特征提取服务配置
-- 以及其它平台参数。采用 结构化分类字段 + JSON 值 的折中方案:
-- 新增配置项无需改表,前端按 config_type 渲染不同表单。
--
-- config_value JSON 约定:
-- config_type=01(MQTT服务器)
-- {"brokerUrl":"tcp://127.0.0.1:1883","clientId":"","username":"","password":"",
-- "defaultQos":1,"cleanSession":true,"keepAlive":60,"connectionTimeout":30}
-- config_type=02(人脸特征服务)
-- 协议:POST multipart/form-data,表单字段名 file,值为图片文件
-- 返回:{"functionSuccess":true,"resultSuccess":true,"resultData":"特征base64","msg":"处理成功..."}
-- {"endpoint":"http://192.168.1.202:8802/bdws_api/Third/Api/Easen/getFaceFeatureData","timeout":10000}
-- 未配置时使用代码内置默认地址(同上)
-- config_type=03(平台参数)
-- {"accessLogKeepDays":180,"mqttLogLevel":"error","commandTimeout":10,"maxRetry":3}
-- =========================================================================
drop table if exists iotlocks.lock_service_config;
create table iotlocks.lock_service_config (
config_id bigserial not null,
config_name varchar(100) not null,
config_type char(2) not null,
config_value text,
group_id bigint default null,
is_default char(1) default '1',
enabled char(1) default '0',
status char(1) default '0',
del_flag char(1) default '0',
create_by varchar(64) default '',
create_time timestamp,
update_by varchar(64) default '',
update_time timestamp,
remark varchar(500) default null,
primary key (config_id)
);
comment on table iotlocks.lock_service_config is '服务参数配置表';
comment on column iotlocks.lock_service_config.config_id is '配置ID';
comment on column iotlocks.lock_service_config.config_name is '配置名称';
comment on column iotlocks.lock_service_config.config_type is '配置类型(01MQTT服务器 02人脸特征服务 03平台参数,字典 lock_config_type)';
comment on column iotlocks.lock_service_config.config_value is '配置内容(JSON)';
comment on column iotlocks.lock_service_config.group_id is '归属分组ID(为空表示全局默认)';
comment on column iotlocks.lock_service_config.is_default is '是否默认(0是 1否)';
comment on column iotlocks.lock_service_config.enabled is '是否启用(0启用 1停用)';
comment on column iotlocks.lock_service_config.status is '状态(0正常 1停用)';
comment on column iotlocks.lock_service_config.del_flag is '删除标志(0代表存在 2代表删除)';
comment on column iotlocks.lock_service_config.create_by is '创建者';
comment on column iotlocks.lock_service_config.create_time is '创建时间';
comment on column iotlocks.lock_service_config.update_by is '更新者';
comment on column iotlocks.lock_service_config.update_time is '更新时间';
comment on column iotlocks.lock_service_config.remark is '备注';
create unique index uk_lock_service_config_name on iotlocks.lock_service_config (config_name, config_type);
create index idx_lock_service_config_type on iotlocks.lock_service_config (config_type);
-- =========================================================================
-- 10、字典数据初始化
-- 先按 dict_type 清理,保证脚本可重复执行。
-- =========================================================================
delete from iotlocks.sys_dict_data where dict_type in
('lock_online_status','lock_open_type','lock_open_result','lock_auth_type',
'lock_command_type','lock_command_status','lock_sync_status','lock_handle_status',
'lock_config_type','lock_extract_status','lock_person_type','lock_target_type');
delete from iotlocks.sys_dict_type where dict_type in
('lock_online_status','lock_open_type','lock_open_result','lock_auth_type',
'lock_command_type','lock_command_status','lock_sync_status','lock_handle_status',
'lock_config_type','lock_extract_status','lock_person_type','lock_target_type');
insert into iotlocks.sys_dict_type (dict_id, dict_name, dict_type, status, create_by, create_time, remark) values
(100, '门禁设备在线状态', 'lock_online_status', '0', 'admin', CURRENT_TIMESTAMP, '网关/门锁在线状态列表'),
(101, '门禁开门方式', 'lock_open_type', '0', 'admin', CURRENT_TIMESTAMP, '需与设备协议锁定值对齐'),
(102, '门禁开门结果', 'lock_open_result', '0', 'admin', CURRENT_TIMESTAMP, '开门结果列表'),
(103, '门禁授权类型', 'lock_auth_type', '0', 'admin', CURRENT_TIMESTAMP, '人脸/密码/指纹/IC卡'),
(104, '门禁命令类型', 'lock_command_type', '0', 'admin', CURRENT_TIMESTAMP, '下行命令类型列表'),
(105, '门禁命令状态', 'lock_command_status','0', 'admin', CURRENT_TIMESTAMP, '命令下发状态列表'),
(106, '门禁授权同步状态', 'lock_sync_status', '0', 'admin', CURRENT_TIMESTAMP, '授权下发同步状态列表'),
(107, '门禁报文处理状态', 'lock_handle_status', '0', 'admin', CURRENT_TIMESTAMP, 'MQTT报文处理状态列表'),
(108, '门禁服务配置类型', 'lock_config_type', '0', 'admin', CURRENT_TIMESTAMP, '服务参数配置类型列表'),
(109, '人脸特征提取状态', 'lock_extract_status','0', 'admin', CURRENT_TIMESTAMP, '人脸特征提取状态列表'),
(110, '门禁人员类型', 'lock_person_type', '0', 'admin', CURRENT_TIMESTAMP, '人员类型列表'),
(111, '门禁命令目标类型', 'lock_target_type', '0', 'admin', CURRENT_TIMESTAMP, '命令下发目标类型列表');
insert into iotlocks.sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark) values
-- 在线状态
(100, 1, '在线', '0', 'lock_online_status', '', 'success', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(101, 2, '离线', '1', 'lock_online_status', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(102, 3, '未知', '2', 'lock_online_status', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 开门方式(【待确认】以下为拟定编码,须与设备协议 lockrecord 帧字段逐值核对后修订)
(110, 1, '人脸', '01', 'lock_open_type', '', 'primary', 'Y', '0', 'admin', CURRENT_TIMESTAMP, '待与设备协议对齐'),
(111, 2, '密码', '02', 'lock_open_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, '待与设备协议对齐'),
(112, 3, '指纹', '03', 'lock_open_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, '待与设备协议对齐'),
(113, 4, 'IC卡', '04', 'lock_open_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, '待与设备协议对齐'),
(114, 5, '远程开锁','05','lock_open_type', '', 'warning', 'N', '0', 'admin', CURRENT_TIMESTAMP, '平台下发开锁'),
(115, 6, '机械钥匙','06','lock_open_type', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, '待与设备协议对齐'),
(116, 9, '其他', '99', 'lock_open_type', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 设备实际上报的开门方式编码(lockrecord params[2]:7 人脸开门、2 密码开锁)
(117, 7, '人脸', '7', 'lock_open_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, '设备实测编码,待完整协议对齐后统一'),
(118, 8, '密码开锁', '2', 'lock_open_type', '', 'success', 'N', '0', 'admin', CURRENT_TIMESTAMP, '设备实测编码,密码开锁时人员编号位为开锁密码'),
-- 开门结果
(120, 1, '失败', '0', 'lock_open_result', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(121, 2, '成功', '1', 'lock_open_result', '', 'success', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 授权类型
(130, 1, '人脸', '01', 'lock_auth_type', '', 'primary', 'Y', '0', 'admin', CURRENT_TIMESTAMP, 'op=facefeature'),
(131, 2, '密码', '02', 'lock_auth_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'op=password'),
(132, 3, '指纹', '03', 'lock_auth_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(133, 4, 'IC卡', '04', 'lock_auth_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'op=iccard'),
-- 命令类型
(140, 1, '绑定门锁', '0001', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(141, 2, '解绑门锁', '0002', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(142, 3, '同步门锁时间', '0003', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(143, 4, '远程开锁', '0004', 'lock_command_type', '', 'warning', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{grpId}/thing/action/execute'),
(144, 5, '远程关锁', '0005', 'lock_command_type', '', 'warning', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{grpId}/thing/action/execute'),
(145, 6, '重启网关', '0006', 'lock_command_type', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(146, 7, '修改网络参数', '0007', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(147, 8, '修改LORA参数', '0008', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(148, 9, '修改MQTT参数', '0009', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(149, 10, '保存配置', '0010', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
(150, 11, '授权下发', '0011', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{grpId}/thing/data/batch'),
(151, 12, '清除授权', '0012', 'lock_command_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{grpId}/thing/data/batch'),
(152, 13, '清除门锁', '0013', 'lock_command_type', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, 'ydlink/{gwId}/thing/property/set'),
-- 命令状态
(160, 1, '待发送', '0', 'lock_command_status', '', 'info', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(161, 2, '已发送', '1', 'lock_command_status', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(162, 3, '成功', '2', 'lock_command_status', '', 'success', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(163, 4, '失败', '3', 'lock_command_status', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(164, 5, '超时', '4', 'lock_command_status', '', 'warning', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(165, 6, '已取消', '5', 'lock_command_status', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 授权同步状态
(170, 1, '待下发', '0', 'lock_sync_status', '', 'info', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(171, 2, '已下发', '1', 'lock_sync_status', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(172, 3, '下发成功', '2', 'lock_sync_status', '', 'success', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(173, 4, '下发失败', '3', 'lock_sync_status', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(174, 5, '已清除', '4', 'lock_sync_status', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 报文处理状态
(180, 1, '待处理', '0', 'lock_handle_status', '', 'info', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(181, 2, '成功', '1', 'lock_handle_status', '', 'success', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(182, 3, '失败', '2', 'lock_handle_status', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(183, 4, '已忽略', '3', 'lock_handle_status', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 服务配置类型
(190, 1, 'MQTT服务器', '01', 'lock_config_type', '', 'primary', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(191, 2, '人脸特征服务', '02', 'lock_config_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(192, 3, '平台参数', '03', 'lock_config_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 特征提取状态
(200, 1, '未提取', '0', 'lock_extract_status', '', 'info', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(201, 2, '成功', '1', 'lock_extract_status', '', 'success', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(202, 3, '失败', '2', 'lock_extract_status', '', 'danger', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 人员类型
(210, 1, '住户', '0', 'lock_person_type', '', 'primary', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(211, 2, '员工', '1', 'lock_person_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(212, 3, '访客', '2', 'lock_person_type', '', 'warning', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(213, 4, '其他', '3', 'lock_person_type', '', 'info', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
-- 命令目标类型
(220, 1, '网关', '1', 'lock_target_type', '', 'primary', 'Y', '0', 'admin', CURRENT_TIMESTAMP, ''),
(221, 2, '门锁', '2', 'lock_target_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, ''),
(222, 3, '分组', '3', 'lock_target_type', '', 'primary', 'N', '0', 'admin', CURRENT_TIMESTAMP, '');
-- =========================================================================
-- 11、菜单初始化
-- 使用 2000+ 号段(ry.sql 的菜单 setval 下限为 1999,不冲突)。
-- 若依 admin 角色(role_key='admin')默认拥有全部菜单,无需写 sys_role_menu。
-- =========================================================================
delete from iotlocks.sys_menu where perms like 'lock:%';
delete from iotlocks.sys_menu where menu_name = '门禁管理' and parent_id = 0;
-- 一级目录
insert into iotlocks.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
(2000, '门禁管理', 0, 4, 'iot', null, '', '', 1, 0, 'M', '0', '0', '', 'lock', 'admin', CURRENT_TIMESTAMP, '公寓人脸门禁系统目录');
-- 二级菜单:页面
insert into iotlocks.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
(2010, '公寓分组', 2000, 1, 'group', 'iot/group/index', '', '', 1, 0, 'C', '0', '0', 'lock:group:list', 'tree', 'admin', CURRENT_TIMESTAMP, '公寓分组菜单'),
(2020, '门锁网关', 2000, 2, 'gateway', 'iot/gateway/index', '', '', 1, 0, 'C', '0', '0', 'lock:gateway:list', 'server', 'admin', CURRENT_TIMESTAMP, '门锁网关菜单'),
(2030, '智能门锁', 2000, 3, 'device', 'iot/device/index', '', '', 1, 0, 'C', '0', '0', 'lock:device:list', 'lock', 'admin', CURRENT_TIMESTAMP, '智能门锁菜单'),
(2040, '人脸数据', 2000, 4, 'face', 'iot/face/index', '', '', 1, 0, 'C', '0', '0', 'lock:face:list', 'peoples', 'admin', CURRENT_TIMESTAMP, '人脸数据菜单'),
(2050, '授权管理', 2000, 5, 'auth', 'iot/auth/index', '', '', 1, 0, 'C', '0', '0', 'lock:auth:list', 'lock', 'admin', CURRENT_TIMESTAMP, '授权管理菜单'),
(2060, '通行记录', 2000, 6, 'accesslog', 'iot/accesslog/index','', '', 1, 0, 'C', '0', '0', 'lock:accesslog:list','list', 'admin', CURRENT_TIMESTAMP, '通行记录菜单'),
(2070, '命令记录', 2000, 7, 'command', 'iot/command/index', '', '', 1, 0, 'C', '0', '0', 'lock:command:list', 'job', 'admin', CURRENT_TIMESTAMP, '命令记录菜单'),
(2080, '报文日志', 2000, 8, 'mqttlog', 'iot/mqttlog/index', '', '', 1, 0, 'C', '0', '0', 'lock:mqttlog:list', 'log', 'admin', CURRENT_TIMESTAMP, '报文日志菜单'),
(2090, '系统参数', 2000, 9, 'config', 'iot/config/index', '', '', 1, 0, 'C', '0', '0', 'lock:config:list', 'edit', 'admin', CURRENT_TIMESTAMP, '系统参数菜单');
-- 三级菜单:按钮权限
insert into iotlocks.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
-- 公寓分组
(2011, '分组查询', 2010, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:group:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2012, '分组新增', 2010, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:group:add', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2013, '分组修改', 2010, 3, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:group:edit', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2014, '分组删除', 2010, 4, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:group:remove', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2015, '分组导出', 2010, 5, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:group:export', '#', 'admin', CURRENT_TIMESTAMP, ''),
-- 门锁网关
(2021, '网关查询', 2020, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2022, '网关新增', 2020, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:add', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2023, '网关修改', 2020, 3, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:edit', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2024, '网关删除', 2020, 4, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:remove', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2025, '网关导出', 2020, 5, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:export', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2026, '网关配置下发',2020, 6, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:config', '#', 'admin', CURRENT_TIMESTAMP, '修改网络/LORA/MQTT参数与保存配置'),
(2027, '网关重启', 2020, 7, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:reboot', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2028, '网关绑定门锁',2020, 8, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:gateway:bind', '#', 'admin', CURRENT_TIMESTAMP, '绑定/清除门锁'),
-- 智能门锁
(2031, '门锁查询', 2030, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2032, '门锁新增', 2030, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:add', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2033, '门锁修改', 2030, 3, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:edit', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2034, '门锁删除', 2030, 4, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:remove', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2035, '门锁导出', 2030, 5, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:export', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2036, '绑定/解绑网关',2030, 6, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:bind', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2037, '时间同步', 2030, 7, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:sync', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2038, '远程开锁', 2030, 8, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:device:open', '#', 'admin', CURRENT_TIMESTAMP, ''),
-- 人脸数据
(2041, '人脸查询', 2040, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:face:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2042, '人脸新增', 2040, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:face:add', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2043, '人脸修改', 2040, 3, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:face:edit', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2044, '人脸删除', 2040, 4, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:face:remove', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2045, '人脸导出', 2040, 5, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:face:export', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2046, '特征提取', 2040, 6, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:face:extract', '#', 'admin', CURRENT_TIMESTAMP, '调用人脸特征提取服务'),
-- 授权管理
(2051, '授权查询', 2050, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2052, '授权新增', 2050, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:add', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2053, '授权修改', 2050, 3, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:edit', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2054, '授权删除', 2050, 4, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:remove', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2055, '授权导出', 2050, 5, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:export', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2056, '授权下发', 2050, 6, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:push', '#', 'admin', CURRENT_TIMESTAMP, '向设备下发授权'),
(2057, '清除授权', 2050, 7, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:auth:clear', '#', 'admin', CURRENT_TIMESTAMP, ''),
-- 通行记录
(2061, '记录查询', 2060, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:accesslog:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2062, '记录导出', 2060, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:accesslog:export', '#', 'admin', CURRENT_TIMESTAMP, ''),
-- 命令记录
(2071, '命令查询', 2070, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:command:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2072, '命令重发', 2070, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:command:retry', '#', 'admin', CURRENT_TIMESTAMP, ''),
-- 报文日志
(2081, '报文查询', 2080, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:mqttlog:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
-- 系统参数
(2091, '参数查询', 2090, 1, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:config:query', '#', 'admin', CURRENT_TIMESTAMP, ''),
(2092, '参数修改', 2090, 2, '', null, '', '', 1, 0, 'F', '0', '0', 'lock:config:edit', '#', 'admin', CURRENT_TIMESTAMP, '');
-- =========================================================================
-- 12、序列复位
-- 本脚本与 ry.sql 均以显式主键插入种子数据,bigserial 序列不会自动推进,
-- 必须复位,否则后续通过页面新增记录会报主键冲突(23505)。
-- =========================================================================
select case when exists (select 1 from iotlocks.lock_group)
then setval(pg_get_serial_sequence('iotlocks.lock_group', 'group_id'), greatest((select max(group_id) from iotlocks.lock_group), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_gateway)
then setval(pg_get_serial_sequence('iotlocks.lock_gateway', 'gateway_id'), greatest((select max(gateway_id) from iotlocks.lock_gateway), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_device)
then setval(pg_get_serial_sequence('iotlocks.lock_device', 'device_id'), greatest((select max(device_id) from iotlocks.lock_device), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_face)
then setval(pg_get_serial_sequence('iotlocks.lock_face', 'face_id'), greatest((select max(face_id) from iotlocks.lock_face), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_auth)
then setval(pg_get_serial_sequence('iotlocks.lock_auth', 'auth_id'), greatest((select max(auth_id) from iotlocks.lock_auth), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_access_log)
then setval(pg_get_serial_sequence('iotlocks.lock_access_log', 'log_id'), greatest((select max(log_id) from iotlocks.lock_access_log), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_command)
then setval(pg_get_serial_sequence('iotlocks.lock_command', 'command_id'), greatest((select max(command_id) from iotlocks.lock_command), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_mqtt_log)
then setval(pg_get_serial_sequence('iotlocks.lock_mqtt_log', 'log_id'), greatest((select max(log_id) from iotlocks.lock_mqtt_log), 0))
else 1 end;
select case when exists (select 1 from iotlocks.lock_service_config)
then setval(pg_get_serial_sequence('iotlocks.lock_service_config', 'config_id'), greatest((select max(config_id) from iotlocks.lock_service_config), 0))
else 1 end;
select case when exists (select 1 from iotlocks.sys_menu where menu_id >= 2000)
then setval(pg_get_serial_sequence('iotlocks.sys_menu', 'menu_id'), greatest((select max(menu_id) from iotlocks.sys_menu), 2999))
else 1 end;
select case when exists (select 1 from iotlocks.sys_dict_type)
then setval(pg_get_serial_sequence('iotlocks.sys_dict_type', 'dict_id'), greatest((select max(dict_id) from iotlocks.sys_dict_type), 199))
else 1 end;
select case when exists (select 1 from iotlocks.sys_dict_data)
then setval(pg_get_serial_sequence('iotlocks.sys_dict_data', 'dict_code'), greatest((select max(dict_code) from iotlocks.sys_dict_data), 299))
else 1 end;
-- =========================================================================
-- 脚本结束
-- =========================================================================