SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- 财务档案 for electronic_finance
-- ----------------------------
DROP TABLE IF EXISTS `electronic_finance`;
CREATE TABLE `electronic_finance`
(
    `id`                  bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
    `create_by`           varchar(20) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '制单人',
    `company_id`          bigint                                                        DEFAULT NULL COMMENT '业务实体id',
    `company`             varchar(30) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '业务实体',
    `user_id`             bigint                                                        DEFAULT NULL COMMENT '用户id',
    `dept_id`             bigint                                                        DEFAULT NULL COMMENT '所属部门id',
    `dept_name`           varchar(30) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '所属部门',
    `account`             varchar(100) COLLATE utf8mb4_general_ci                       DEFAULT NULL COMMENT '支付账户',
    `project`             varchar(255) COLLATE utf8mb4_general_ci                       DEFAULT NULL COMMENT '项目',
    `Invoice_number`      varchar(20) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '收据/发票号码',
    `price`               decimal(20, 2)                                                DEFAULT NULL COMMENT '金额',
    `status`              varchar(2) COLLATE utf8mb4_general_ci                         DEFAULT NULL COMMENT '状态',
    `position`            varchar(255) COLLATE utf8mb4_general_ci                       DEFAULT NULL COMMENT '纸档位置',
    `cherks`              int                                                           DEFAULT NULL COMMENT '完整性',
    `record_id`           bigint                                                        DEFAULT NULL COMMENT '归档id',
    `trade_type`          varchar(64) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '交易类型',
    `pay_type`            varchar(64) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '支付方式',
    `file_status`         varchar(64) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '归档状态',
    `contract_attachment` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '附件',
    `remarks`             varchar(500) COLLATE utf8mb4_general_ci                       DEFAULT NULL COMMENT '备注',
    `creator`             varchar(20) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '创建者',
    `updater`             varchar(20) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '更新者',
    `create_time`         datetime                                                      DEFAULT NULL COMMENT '创建日期',
    `update_time`         datetime                                                      DEFAULT NULL COMMENT '更新日期',
    `trade_date`          datetime                                                      DEFAULT NULL COMMENT '交易日期',
    `record_time`         varchar(20) COLLATE utf8mb4_general_ci                        DEFAULT NULL COMMENT '归档日期',
    `tenant_id`           bigint NOT NULL COMMENT '租户编号',
    `deleted`             bit(1)                                                        DEFAULT b'0' COMMENT '是否删除',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `IX_electronic_finance_tenant_id` (`tenant_id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 1
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci
  ROW_FORMAT = DYNAMIC COMMENT ='财务档案';

-- 查询电子档案菜单id
SELECT `id`
INTO @menuId
FROM `system_menu`
WHERE `name` = '电子档案';

-- 菜单 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id,
                        path, icon, component, status, component_name)
VALUES ('财务档案', '', 2, 0, @menuId,
        'electronic-finance', 'clipboard', 'ea/electronicFinance/index', 0, 'ElectronicFinance');

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

-- 按钮 SQL
INSERT INTO system_menu(name, permission, type, sort, parent_id,
                        path, icon, component, status)
VALUES ('财务档案查询', 'electronic:finance:query', 3, 1, @parentId,
        '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id,
                        path, icon, component, status)
VALUES ('财务档案创建', 'electronic:finance:create', 3, 2, @parentId,
        '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id,
                        path, icon, component, status)
VALUES ('财务档案更新', 'electronic:finance:update', 3, 3, @parentId,
        '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id,
                        path, icon, component, status)
VALUES ('财务档案删除', 'electronic:finance:delete', 3, 4, @parentId,
        '', '', '', 0);
INSERT INTO system_menu(name, permission, type, sort, parent_id,
                        path, icon, component, status)
VALUES ('财务档案导出', 'electronic:finance:export', 3, 5, @parentId,
        '', '', '', 0);

--  档案管理-财务字典
INSERT INTO `lyr-one`.`system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`,
                                          `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`,
                                          `deleted`)
VALUES (null, '10', '财务档案', 'electronic_finance', 'archives_file_type', '0', 'default', '', NULL, '',
        '2023-11-08 15:13:50', '', '2023-11-08 15:14:08', b'0');

