ALTER TABLE infra_file ADD hash VARCHAR(64);
COMMENT ON COLUMN infra_file.hash IS '文件哈希值（SHA-256）';
CREATE INDEX idx_infra_file_hash ON infra_file(hash);

-- 2. 附件信息表新增 AES 加密时存储的随机 IV 字段
ALTER TABLE infra_file ADD aes_iv VARCHAR(128);

COMMENT ON COLUMN infra_file.aes_iv IS 'AES加密时的随机IV（Base64编码）';

-- 3 业务附件统一管理
DROP TABLE IF EXISTS infra_bsn_file;
CREATE TABLE infra_bsn_file (
                                id bigint NOT NULL PRIMARY KEY,
                                bsn_id bigint  NOT NULL,
                                bsn_cd varchar(100) DEFAULT '' NULL,
                                file_id bigint  NOT NULL,
                                file_name varchar(500) DEFAULT '' NULL,
                                src varchar(100) DEFAULT '' NULL,
                                creator varchar(64) DEFAULT '' NULL,
                                create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
                                updater varchar(64) DEFAULT '' NULL,
                                update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
                                deleted smallint DEFAULT 0 NOT NULL,
                                tenant_id bigint DEFAULT 0 NOT NULL
);
COMMENT ON TABLE infra_bsn_file IS '业务附件关联表';
COMMENT ON COLUMN infra_bsn_file.id IS '主键ID';
COMMENT ON COLUMN infra_bsn_file.bsn_id IS '业务Id';
COMMENT ON COLUMN infra_bsn_file.bsn_cd IS '业务编码';
COMMENT ON COLUMN infra_bsn_file.file_id IS '附件fileId';
COMMENT ON COLUMN infra_bsn_file.file_name IS '附件名称';
COMMENT ON COLUMN infra_bsn_file.src IS '附件来源';
COMMENT ON COLUMN infra_bsn_file.creator IS '创建者';
COMMENT ON COLUMN infra_bsn_file.create_time IS '创建时间';
COMMENT ON COLUMN infra_bsn_file.updater IS '更新者';
COMMENT ON COLUMN infra_bsn_file.update_time IS '最后更新时间';
COMMENT ON COLUMN infra_bsn_file.deleted IS '是否删除';
COMMENT ON COLUMN infra_bsn_file.tenant_id IS '租户编号';

-- 业务菜单 sql
-- 菜单 SQL
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '1948328245618204673', '业务附件关联管理', '', 2, 0, 1243,
           'business-file', '', 'infra/businessfile/index', 0, 'BusinessFile'
       );

-- 按钮 SQL
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1951092724040097793', '业务附件关联查询', 'infra:business-file:query', 3, 1, 1948328245618204673,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1951092724040097794', '业务附件关联创建', 'infra:business-file:create', 3, 2, 1948328245618204673,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1951092724040097795', '业务附件关联更新', 'infra:business-file:update', 3, 3, 1948328245618204673,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1951092724040097796', '业务附件关联删除', 'infra:business-file:delete', 3, 4, 1948328245618204673,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1951092724040097797', '业务附件关联导出', 'infra:business-file:export', 3, 5, 1948328245618204673,
           '', '', '', 0
       );

-- 新增命名规范字典菜单
-- 菜单 SQL
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '1947909810016006146', '数据命名与简写标准管理', '', 2, 0, 2,
           'standard-name', '', 'infra/standardname/index', 0, 'StandardName'
       );

-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话，需要手动修改 @parentId 的部分的代码
-- SELECT @parentId := LAST_INSERT_ID();


-- 按钮 SQL
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953301310553645058', '数据命名与简写标准查询', 'infra:standard-name:query', 3, 1, 1947909810016006146,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953301310553645059', '数据命名与简写标准创建', 'infra:standard-name:create', 3, 2, 1947909810016006146,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953301310553645060', '数据命名与简写标准更新', 'infra:standard-name:update', 3, 3, 1947909810016006146,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953301310553645061', '数据命名与简写标准删除', 'infra:standard-name:delete', 3, 4, 1947909810016006146,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953301310553645062', '数据命名与简写标准导出', 'infra:standard-name:export', 3, 5, 1947909810016006146,
           '', '', '', 0
       );

-- 新增序列获取菜单
-- 菜单 SQL
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '1953701540574969857', '系统序列号管理', '', 2, 0, ${table.parentMenuId},
           'sequence', '', 'system/sequence/index', 0, 'Sequence'
       );

-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话，需要手动修改 @parentId 的部分的代码
-- SELECT @parentId := LAST_INSERT_ID();


-- 按钮 SQL
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953702581324398594', '系统序列号查询', 'system:sequence:query', 3, 1, 1953701540574969857,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953702581324398595', '系统序列号创建', 'system:sequence:create', 3, 2, 1953701540574969857,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953702581324398596', '系统序列号更新', 'system:sequence:update', 3, 3, 1953701540574969857,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953702581324398597', '系统序列号删除', 'system:sequence:delete', 3, 4, 1953701540574969857,
           '', '', '', 0
       );
INSERT INTO system_menu(
    id, name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '1953702581324398598', '系统序列号导出', 'system:sequence:export', 3, 5, 1953701540574969857,
           '', '', '', 0
       );
