-- liutao
-- 业务管理基本信息表
DROP TABLE IF EXISTS `business_basic_info`;
CREATE TABLE `business_basic_info` (
                                       `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                       `business_number` varchar(50) NOT NULL COMMENT '业务编号',
                                       `business_name` varchar(50) DEFAULT NULL COMMENT '业务名称',
                                       `purchaser_id` bigint(20) DEFAULT NULL COMMENT '买方名称',  -- 从企业管理中获取
                                       `trading_platform_id` bigint(20) DEFAULT NULL COMMENT '贸易平台 ',  -- 从平台管理中获取
                                       `contents` varchar(500) DEFAULT '' COMMENT '项目内容',
                                       `unliquidated_goods_days` int(10) DEFAULT NULL COMMENT '最长货物未结算天数',
                                       `purchaser_retention_money` decimal(17,2) DEFAULT '0.00' COMMENT '买方质保金',
                                       `manager_id` bigint(20) NOT NULL COMMENT '业务经理Id',
                                       `check_operator` varchar(32) DEFAULT NULL COMMENT '验收经办人',
                                       `settlement_operator` varchar(32) DEFAULT NULL COMMENT '结算经办人',
                                       `status` bigint(20) DEFAULT NULL COMMENT '状态，已创建、贸易中、已结清、已完成',
                                       `user_create` varchar(32) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                       `user_modified` varchar(32) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                       `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                       `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                       PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='业务管理基本信息表';

-- 业务管理-供应商信息表
DROP TABLE IF EXISTS `business_supplier_info`;
CREATE TABLE `business_supplier_info` (
                                          `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                          `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                          `supplier_name` varchar(50) DEFAULT NULL COMMENT '供应商名称',
                                          `retention_money` decimal(17,2) DEFAULT '0.00' COMMENT '质保金',
                                          `fund_possession_cost` decimal(17,2) DEFAULT '0.00' COMMENT '资金占用费',
                                          `business_basic_info_id` bigint(20) NOT NULL COMMENT '业务基本信息表Id',

                                          `user_create` varchar(32) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                          `user_modified` varchar(32) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                          `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='业务管理供应商信息表';

-- 业务管理-招投标文件中间表
DROP TABLE IF EXISTS `business_bidding_file_ref`;
CREATE TABLE `business_bidding_file_ref` (
                                             `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                             `business_basic_info_id` bigint(20) NOT NULL COMMENT '业务基本信息表Id',
                                             `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                             `file_type` varchar(50) DEFAULT '' COMMENT '业务附件类型',
                                             PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='业务管理-招投标文件中间表';

-- 文件存放表
DROP TABLE IF EXISTS ` `;
CREATE TABLE `t_file_storage` (
                                  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
                                  `belongId` varchar(50) DEFAULT NULL COMMENT '文件附属对象id',
                                  `belongType` varchar(50) DEFAULT NULL COMMENT '文件附属对象类型',
                                  `fileType` varchar(50) DEFAULT NULL COMMENT '文件类型',
                                  `name` varchar(50) DEFAULT NULL COMMENT '文件名称',
                                  `originalName` varchar(128) DEFAULT NULL COMMENT '原名称',
                                  `path` varchar(256) DEFAULT NULL COMMENT '路径',
                                  `absolutePath` varchar(256) DEFAULT NULL COMMENT '绝对路径',
                                  `size` int(10) DEFAULT NULL COMMENT '大小',
                                  `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
                                  `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
                                  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文件存放表';

-- 企业客户信息表
DROP TABLE IF EXISTS `enterprise_customer_info`;
CREATE TABLE `enterprise_customer_info` (
                                            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',

                                            `enterprise_name` varchar(50) DEFAULT NULL COMMENT '企业名称',
                                            `socialCreditCode` varchar(18) DEFAULT NULL COMMENT '统一社会信用代码',
                                            `address` varchar(50) DEFAULT NULL COMMENT '注册地址',
                                            `phoneNumber` varchar(50) DEFAULT NULL COMMENT '注册电话',
                                            `auth_status` tinyint(50) DEFAULT '0' COMMENT '二网认证状态 0：未认证 1：已认证',
                                            `auth_url` varchar(1024) DEFAULT NULL COMMENT '二网认证链接',
                                            `fdd_customer_id` varchar(50) DEFAULT NULL COMMENT '二网在法大大上的客户编号',
                                            `synchronize_time` timestamp   NULL COMMENT '同步时间',
                                            `supplier` tinyint(50) NOT NULL COMMENT '核心企业或供应商 0：核心企业 1：供应商',

                                            `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
                                            `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
                                            `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                            `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                            PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='企业客户信息表';

-- 贸易平台
DROP TABLE IF EXISTS `trading_platform`;
CREATE TABLE `trading_platform` (
                                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                    `platform_name` varchar(250) DEFAULT NULL COMMENT '平台名称',
                                    `socialCreditCode` varchar(18) DEFAULT NULL COMMENT '统一社会信用代码',
                                    `address` varchar(50) DEFAULT NULL COMMENT '注册地址',
                                    `phoneNumber` varchar(50) DEFAULT NULL COMMENT '注册电话',
                                    `interest_bearing` int(10) DEFAULT NULL  COMMENT'是否计息',
                                    `auth_status` tinyint(50) DEFAULT '0' COMMENT '二网认证状态 0：未认证 1：已认证',
                                    `auto_sign_status` tinyint(50) DEFAULT '0' COMMENT '二网授权自动签署状态 0：未认证 1：已认证',
                                    `auth_url` varchar(1024) DEFAULT NULL COMMENT '二网认证链接',
                                    `auto_sign_url` varchar(1024) DEFAULT NULL COMMENT '自动签署链接',
                                    `fdd_customer_id` varchar(50) DEFAULT NULL COMMENT '二网在法大大上的客户编号',
                                    `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                    `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                    `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                    `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='贸易平台';

ALTER TABLE sys_user add enterprise_customer_id bigint(20) DEFAULT null COMMENT '企业客户信息表ID';

-- 验收单管理   修改数据库
DROP TABLE IF EXISTS `acceptance_sheet`;
CREATE TABLE `acceptance_sheet` (
                                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                    `acceptance_number` varchar(250) DEFAULT NULL COMMENT '验收单号',
                                    `business_number` varchar(250) DEFAULT NULL COMMENT '业务编号',
                                    `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                    `receiving_unit` varchar(250) DEFAULT NULL COMMENT '收货单位',
                                    `manager_name` varchar(250) DEFAULT NULL COMMENT '经办人姓名',
                                    `acceptance_date` datetime  NULL COMMENT '验收日期',
                                    `expected_settlement_date` datetime  NULL COMMENT '预计结算日期 ',
                                    `acceptance_status` bigint(20) DEFAULT NULL COMMENT '状态: 已录入 已退回 已驳回 已审核',
                                    `mortgage` tinyint(50) DEFAULT NULL COMMENT '是否底层 0：不做  1：可做  ' ,
                                    `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                    `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                    `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                    `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理';

-- 验收单管理历史数据   修改数据库
DROP TABLE IF EXISTS `acceptance_sheet_history`;
CREATE TABLE `acceptance_sheet_history` (
                                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                    `acceptance_number` varchar(250) DEFAULT NULL COMMENT '验收单号',
                                    `business_number` varchar(250) DEFAULT NULL COMMENT '业务编号',
                                    `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                    `receiving_unit` varchar(250) DEFAULT NULL COMMENT '收货单位',
                                    `manager_name` varchar(250) DEFAULT NULL COMMENT '经办人姓名',
                                    `acceptance_date` datetime  NULL COMMENT '验收日期',
                                    `expected_settlement_date` datetime  NULL COMMENT '预计结算日期 ',
                                    `acceptance_status` bigint(20) DEFAULT NULL COMMENT '状态: 已录入 已退回 已驳回 已审核',
                                    `mortgage` tinyint(50) DEFAULT NULL COMMENT '是否底层 0：不做  1：可做  ' ,
                                    `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                    `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                    `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                    `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理历史数据';

-- 验收单管理-审核表
DROP TABLE IF EXISTS `acceptance_audit`;
CREATE TABLE `acceptance_audit` (
                                    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                    `acceptance_sheet_id` bigint(20) NOT NULL COMMENT '验收单表Id',
                                    `approval_comment` varchar(3000) COLLATE utf8_bin DEFAULT '' COMMENT '审批意见',
                                    `approval_conclusion` tinyint(50) COLLATE utf8_bin DEFAULT null COMMENT '审批结论 0:通过 1：通过不做底层 2：否决 3：退回',
                                    `auditor_id` bigint(20) unsigned DEFAULT '0' COMMENT '审核人Id',
                                    `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                    `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                    `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                    `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理-审核表';


-- 验收单管理货物
DROP TABLE IF EXISTS `acceptance_business_goods`;
CREATE TABLE `acceptance_business_goods` (
                                  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                  `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                  `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                  `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                  `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                  `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                  `acceptance_sheet_id` bigint(20) DEFAULT NULL COMMENT '验收单id',
                                  `mortgage` tinyint(50) DEFAULT NULL COMMENT '是否底层 0：不做  1：可做  ' ,
                                  `settlement` tinyint(50) DEFAULT 0 COMMENT '是否结算 0：未结算  1：结算  ' ,
                                  `mortgage_complete` tinyint(50) DEFAULT 0 COMMENT '是否已经做过底层 0：未做过  1：已做过  ' ,
                                  `purchase_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '采购质保金',
                                  `sales_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '销售质保金',
                                  `purch_contract_number` varchar(250) DEFAULT NULL COMMENT '采购合同编号',
                                  `sales_contract_goods_id` bigint(20)  DEFAULT NULL COMMENT '销售合同货物id',

                                  `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                  `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理货物';

-- 验收单管理货物历史
DROP TABLE IF EXISTS `acceptance_business_goods_history`;
CREATE TABLE `acceptance_business_goods_history` (
                                  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                  `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                  `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                  `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                  `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                  `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                  `acceptance_sheet_id` bigint(20) DEFAULT NULL COMMENT '验收单id',
                                  `mortgage` tinyint(50) DEFAULT NULL COMMENT '是否底层 0：不做  1：可做  ' ,
                                  `settlement` tinyint(50) DEFAULT 0 COMMENT '是否结算 0：未结算  1：结算  ' ,
                                  `mortgage_complete` tinyint(50) DEFAULT 0 COMMENT '是否已经做过底层 0：未做过  1：已做过  ' ,
                                  `purchase_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '采购质保金',
                                  `sales_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '销售质保金',

                                  `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                  `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理货物历史';



-- 验收单管理-验收单文件中间表
DROP TABLE IF EXISTS `acceptance_sheet_file_ref`;
CREATE TABLE `acceptance_sheet_file_ref` (
                                             `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                             `acceptance_sheet_id` bigint(20) NOT NULL COMMENT '验收单表Id',
                                             `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                             `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                             PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理-验收单文件中间表';

-- 验收单管理历史-验收单文件中间表
DROP TABLE IF EXISTS `acceptance_sheet_file_ref_history`;
CREATE TABLE `acceptance_sheet_file_ref_history` (
                                             `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                             `acceptance_sheet_id` bigint(20) NOT NULL COMMENT '验收单表Id',
                                             `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                             `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                             PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理历史-验收单文件中间表';

-- 验收单管理-补充说明文件中间表
DROP TABLE IF EXISTS `acceptance_sheet_supplement_file_ref`;
CREATE TABLE `acceptance_sheet_supplement_file_ref` (
                                                        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                                        `acceptance_sheet_id` bigint(20) NOT NULL COMMENT '验收单表Id',
                                                        `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                                        `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                                        `supplement` varchar(250) DEFAULT NULL COMMENT '补充说明',
                                                        PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理-补充说明文件中间表';

-- 验收单管理历史-补充说明文件中间表
DROP TABLE IF EXISTS `acceptance_sheet_supplement_file_ref_history`;
CREATE TABLE `acceptance_sheet_supplement_file_ref_history` (
                                                        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                                        `acceptance_sheet_id` bigint(20) NOT NULL COMMENT '验收单表Id',
                                                        `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                                        `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                                        `supplement` varchar(250) DEFAULT NULL COMMENT '补充说明',
                                                        PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='验收单管理历史-补充说明文件中间表';

-- 结算单基础信息
DROP TABLE IF EXISTS `bill_basic_information`;
CREATE TABLE `bill_basic_information` (
                                          `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                          `business_number` varchar(50) NOT NULL COMMENT '业务编号',
                                          `trading_platform_id` bigint(20) DEFAULT NULL COMMENT '单位名称 ',  -- 从平台管理中获取
                                          `manager_name` varchar(250) DEFAULT NULL COMMENT '经办人',
                                          `bill_information_number` varchar(250) DEFAULT NULL COMMENT '结算单号',
                                          `settlement_date` datetime  NULL COMMENT '结算时间',
                                          `settlement_amount` decimal(17,2) DEFAULT NULL COMMENT '结算金额',
                                          `settlement_date_begin` datetime  NULL COMMENT '对账开始时间',
                                          `settlement_date_end` datetime  NULL COMMENT '对账结束时间',
                                          `supplement` varchar(250) DEFAULT NULL COMMENT '补充说明',
                                          `bill_status` bigint(20) DEFAULT NULL COMMENT '状态: 已录入 已退回 已驳回 已审核 待补充 已补充 已变更',


                                          `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                          `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                          `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单基础信息';

-- 结算单基础信息历史
DROP TABLE IF EXISTS `bill_basic_information_history`;
CREATE TABLE `bill_basic_information_history` (
                                          `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                          `business_number` varchar(50) NOT NULL COMMENT '业务编号',
                                          `trading_platform_id` bigint(20) DEFAULT NULL COMMENT '单位名称 ',  -- 从平台管理中获取
                                          `manager_name` varchar(250) DEFAULT NULL COMMENT '经办人',
                                          `bill_information_number` varchar(250) DEFAULT NULL COMMENT '结算单号',
                                          `settlement_date` datetime  NULL COMMENT '结算时间',
                                          `settlement_amount` decimal(17,2) DEFAULT NULL COMMENT '结算金额',
                                          `settlement_date_begin` datetime  NULL COMMENT '对账开始时间',
                                          `settlement_date_end` datetime  NULL COMMENT '对账结束时间',
                                          `supplement` varchar(250) DEFAULT NULL COMMENT '补充说明',
                                          `bill_status` bigint(20) DEFAULT NULL COMMENT '状态: 已录入 已退回 已驳回 已审核 待补充 已补充 已变更',


                                          `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                          `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                          `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单基础信息历史';

-- 结算单货物管理
DROP TABLE IF EXISTS `bill_goods_information`;
CREATE TABLE `bill_goods_information` (
                                          `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                          `acceptance_date` datetime  NULL COMMENT '验收日期',
                                          `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                          `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                          `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                          `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                          `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                          `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                          `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',
                                          `sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售单价',
                                          `total_sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售总价',
                                          `sales_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '销售质保金',
                                          `purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购单价',
                                          `total_purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购总价',
                                          `purchase_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '采购质保金',
                                          `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',

                                          `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                          `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                          `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单管理货物';

-- 结算单货物管理历史
DROP TABLE IF EXISTS `bill_goods_information_history`;
CREATE TABLE `bill_goods_information_history` (
                                          `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                          `acceptance_date` datetime  NULL COMMENT '验收日期',
                                          `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                          `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                          `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                          `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                          `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                          `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                          `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',
                                          `sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售单价',
                                          `total_sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售总价',
                                          `sales_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '销售质保金',
                                          `purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购单价',
                                          `total_purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购总价',
                                          `purchase_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '采购质保金',
                                          `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',

                                          `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                          `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                          `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单货物管理历史';

-- 结算单资金占用费
DROP TABLE IF EXISTS `bill_capital_occupation_fee`;
CREATE TABLE `bill_capital_occupation_fee` (
                                               `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                               `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                               `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                               `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                               `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                               `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                               `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                               `capital_occupation_fee` decimal(17,2) DEFAULT NULL COMMENT '资金占用费',
                                               `acceptance_date` datetime  NULL COMMENT '验收日期',
                                               `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',
                                               `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',

                                               `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                               `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                               `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                               `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                               PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单资金占用费';

-- 结算单资金占用费历史
DROP TABLE IF EXISTS `bill_capital_occupation_fee_history`;
CREATE TABLE `bill_capital_occupation_fee_history` (
                                               `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                               `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                               `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                               `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                               `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                               `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                               `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                               `capital_occupation_fee` decimal(17,2) DEFAULT NULL COMMENT '资金占用费',
                                               `acceptance_date` datetime  NULL COMMENT '验收日期',
                                               `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',

                                               `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                               `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                               `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                               `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                               PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单资金占用费历史';

-- 结算单回款计划
DROP TABLE IF EXISTS `bill_repayment_plan`;
CREATE TABLE `bill_repayment_plan` (
                                       `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                       `repayment_amount` decimal(17,2) DEFAULT NULL COMMENT '回款金额',
                                       `repayment_date` datetime  NULL COMMENT '回款日期',
                                       `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',

                                       `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                       `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                       `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                       `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                       PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单回款计划';

-- 结算单回款计划历史
DROP TABLE IF EXISTS `bill_repayment_plan_history`;
CREATE TABLE `bill_repayment_plan_history` (
                                       `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                       `repayment_amount` decimal(17,2) DEFAULT NULL COMMENT '回款金额',
                                       `repayment_date` datetime  NULL COMMENT '回款日期',
                                       `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',

                                       `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                       `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                       `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                       `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                       PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单回款计划历史';

-- 结算清单-文件中间表
DROP TABLE IF EXISTS `bill_file_ref`;
CREATE TABLE `bill_file_ref` (
                                             `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                             `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',
                                             `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                             `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                             `file_class`bigint(20) DEFAULT NULL COMMENT  '附件类型 1:普通附件 2:补充复件 3:网价附件',
                                             PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算清单-文件中间表';

-- 结算清单-文件中间表历史
DROP TABLE IF EXISTS `bill_file_ref_history`;
CREATE TABLE `bill_file_ref_history` (
                                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                 `bill_basic_information_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',
                                 `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                 `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                 `file_class`bigint(20) DEFAULT NULL COMMENT  '附件类型 1:普通附件 2:补充复件 3:网价附件',
                                 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算清单-文件中间表历史';

-- 结算单管理-审核表
DROP TABLE IF EXISTS `bill_audit`;
CREATE TABLE `bill_audit` (
                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                              `bill_basic_information_id` bigint(20) NOT NULL COMMENT '结算单表Id',
                              `approval_comment` varchar(3000) COLLATE utf8_bin DEFAULT '' COMMENT '审批意见',
                              `approval_conclusion` tinyint(50) COLLATE utf8_bin DEFAULT NULL COMMENT '审批结论 0:通过 1：通过补充资料 2：否决 3：退回',
                              `auditor_id` bigint(20) unsigned DEFAULT '0' COMMENT '审核人Id',

                              `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                              `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                              PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='结算单管理-审核表';

-- 底层基础信息
DROP TABLE IF EXISTS `mortgage_basic_information`;
CREATE TABLE `mortgage_basic_information` (
                                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                              `business_number` varchar(50) NOT NULL COMMENT '业务编号',
                                              `mortgage_number` varchar(250) DEFAULT NULL COMMENT '底层编号',
                                              `contract_number` varchar(250) DEFAULT NULL COMMENT '采购合同编号',
                                              `contract_name` varchar(250) DEFAULT NULL COMMENT '采购合同名称',
                                              `contract_amount` decimal(17,2) DEFAULT NULL COMMENT '采购合同金额',
                                              `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                              `purchaser_id` bigint(20) DEFAULT NULL COMMENT '买方名称',
                                              `remark` varchar(500) DEFAULT NULL COMMENT '备注' ,
                                              `mortgage_status` bigint(20) DEFAULT NULL COMMENT '状态: 已录入 已退回 已驳回 已审核 已过期',

                                              `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                              `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                              PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层基础信息';

-- 底层基础信息历史
DROP TABLE IF EXISTS `mortgage_basic_information_history`;
CREATE TABLE `mortgage_basic_information_history` (
                                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                              `business_number` varchar(50) NOT NULL COMMENT '业务编号',
                                              `mortgage_number` varchar(250) DEFAULT NULL COMMENT '底层编号',
                                              `contract_number` varchar(250) DEFAULT NULL COMMENT '采购合同编号',
                                              `contract_name` varchar(250) DEFAULT NULL COMMENT '采购合同名称',
                                              `contract_amount` decimal(17,2) DEFAULT NULL COMMENT '采购合同金额',
                                              `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
                                              `purchaser_id` bigint(20) DEFAULT NULL COMMENT '买方名称',
                                              `remark` varchar(500) DEFAULT NULL COMMENT '备注' ,
                                              `mortgage_status` bigint(20) DEFAULT NULL COMMENT '状态: 已录入 已退回 已驳回 已审核 已过期',

                                              `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                              `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                              PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层基础信息历史';


-- 底层货物管理
DROP TABLE IF EXISTS `mortgage_goods_information`;
CREATE TABLE `mortgage_goods_information` (
                                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                              `acceptance_date` datetime  NULL COMMENT '验收日期',
                                              `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                              `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                              `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                              `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                              `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                              `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                              `sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售单价',
                                              `total_sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售总价',
                                              `sales_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '销售质保金',
                                              `purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购单价',
                                              `total_purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购总价',
                                              `purchase_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '采购质保金',
                                              `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',

                                              `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                              `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                              PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层货物管理';

-- 底层货物管理历史
DROP TABLE IF EXISTS `mortgage_goods_information_history`;
CREATE TABLE `mortgage_goods_information_history` (
                                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                              `acceptance_date` datetime  NULL COMMENT '验收日期',
                                              `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                              `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                              `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                              `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                              `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                              `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                              `sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售单价',
                                              `total_sale_price` decimal(17,2) DEFAULT NULL COMMENT '销售总价',
                                              `sales_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '销售质保金',
                                              `purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购单价',
                                              `total_purchase_price` decimal(17,2) DEFAULT NULL COMMENT '采购总价',
                                              `purchase_guarantee_money` decimal(17,2) DEFAULT NULL COMMENT '采购质保金',
                                              `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',

                                              `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                              `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                              PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层货物管理历史';

-- 底层-文件中间表
DROP TABLE IF EXISTS `mortgage_file_ref`;
CREATE TABLE `mortgage_file_ref` (
                                     `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                     `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                     `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                     `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                     PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层-文件中间表';

-- 底层-文件中间表历史
DROP TABLE IF EXISTS `mortgage_file_ref_history`;
CREATE TABLE `mortgage_file_ref_history` (
                                     `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                     `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                     `file_storage_id` bigint(20) unsigned DEFAULT '0' COMMENT '附件的ID',
                                     `file_type` varchar(50) DEFAULT '' COMMENT '附件类型',
                                     PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层-文件中间表历史';


-- 底层信息
DROP TABLE IF EXISTS `mortgage_information`;
CREATE TABLE `mortgage_information` (
                                        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                        `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                        `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                        `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                        `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                        `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                        `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                        `accounts_receivable` decimal(17,2) DEFAULT NULL COMMENT '应收账款金额',
                                        `net_accounts_receivable` decimal(17,2) DEFAULT NULL COMMENT '应收账款净额',
                                        `start_of_reconciliation` datetime  NULL COMMENT '对账开始时间',
                                        `end_of_reconciliation` datetime  NULL COMMENT '对账结束时间',
                                        `account_receivable_period` bigint(20) unsigned DEFAULT null COMMENT '应收账款期限',
                                        `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',
                                        `sop_accounts_receivable_id` bigint(20) DEFAULT NULL COMMENT '对应sop国内保理应收账款表的Id',
                                        `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                        `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                        `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                        `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                        PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层信息';

-- 底层信息历史
DROP TABLE IF EXISTS `mortgage_information_history`;
CREATE TABLE `mortgage_information_history` (
                                        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                        `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                        `goods_name` varchar(250) DEFAULT NULL COMMENT '货物名称',
                                        `goods_factory` varchar(250) DEFAULT NULL COMMENT '厂家',
                                        `goods_type` varchar(250) DEFAULT NULL COMMENT '型号',
                                        `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
                                        `goods_num` decimal(17,3) DEFAULT NULL COMMENT '数量',
                                        `accounts_receivable` decimal(17,2) DEFAULT NULL COMMENT '应收账款金额',
                                        `net_accounts_receivable` decimal(17,2) DEFAULT NULL COMMENT '应收账款净额',
                                        `start_of_reconciliation` datetime  NULL COMMENT '对账开始时间',
                                        `end_of_reconciliation` datetime  NULL COMMENT '对账结束时间',
                                        `account_receivable_period` bigint(20) unsigned DEFAULT null COMMENT '应收账款期限',
                                        `acceptance_business_goods_id` bigint(20) DEFAULT NULL COMMENT '验收单货物Id',

                                        `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                        `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                        `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                        `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                        PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层信息历史';

-- 底层管理-审核表
DROP TABLE IF EXISTS `mortgage_audit`;
CREATE TABLE `mortgage_audit` (
                                  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

                                  `mortgage_basic_information_id` bigint(20) DEFAULT NULL COMMENT '底层基础信息表ID',
                                  `approval_comment` varchar(3000) COLLATE utf8_bin DEFAULT '' COMMENT '审批意见',
                                  `approval_conclusion` tinyint(50) COLLATE utf8_bin DEFAULT NULL COMMENT '审批结论 0:通过 1：否决 2：退回',
                                  `auditor_id` bigint(20) unsigned DEFAULT '0' COMMENT '审核人Id',

                                  `user_create` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '创建人',
                                  `user_modified` varchar(50) COLLATE utf8_bin DEFAULT '' COMMENT '修改人',
                                  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='底层管理-审核表';


-- 验收单模块字典项

INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('验收单状态', null, 'acceptanceSheetStatus', null, '1',  NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已录入', (SELECT t.id from t_dictionary t where t.code = 'acceptanceSheetStatus'), 'acceptance_sheet_create', null, '0', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已驳回', (SELECT t.id from t_dictionary t where t.code = 'acceptanceSheetStatus'), 'acceptance_sheet_overrule', null, '1', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已审核', (SELECT t.id from t_dictionary t where t.code = 'acceptanceSheetStatus'), 'acceptance_sheet_approval', null, '2', NOW(), NOW());

-- 业务管理模块字典项
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('业务管理状态', null, 'businessManagementStatus', null, '1',  NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已创建', (SELECT t.id from t_dictionary t where t.code = 'businessManagementStatus'), 'business_management_create', null, '0', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('贸易中', (SELECT t.id from t_dictionary t where t.code = 'businessManagementStatus'), 'business_management_in_trade', null, '1', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已结清', (SELECT t.id from t_dictionary t where t.code = 'businessManagementStatus'), 'business_management_settle', null, '2', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已结束', (SELECT t.id from t_dictionary t where t.code = 'businessManagementStatus'), 'business_management_complete', null, '3', NOW(), NOW());

-- 结算单模块字典项
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('结算单状态', null, 'billStatus', null, '1',  NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已录入', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_create', null, '0', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已退回', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_back', null, '1', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已驳回', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_overrule', null, '2', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已审核', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_approval', null, '3', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('待补充', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_need_add', null, '4', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已补充', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_added', null, '5', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已变更', (SELECT t.id from t_dictionary t where t.code = 'billStatus'), 'bill_changed', null, '6', NOW(), NOW());

-- 底层模块字典项

INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('底层状态', null, 'mortgageStatus', null, '1',  NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已创建', (SELECT t.id from t_dictionary t where t.code = 'mortgageStatus'), 'mortgage_create', null, '0', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已退回', (SELECT t.id from t_dictionary t where t.code = 'mortgageStatus'), 'mortgage_back', null, '1', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已驳回', (SELECT t.id from t_dictionary t where t.code = 'mortgageStatus'), 'mortgage_overrule', null, '2', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已审核', (SELECT t.id from t_dictionary t where t.code = 'mortgageStatus'), 'mortgage_approval', null, '3', NOW(), NOW());
INSERT INTO `t_dictionary` (name, parentId, code, value, gradation, gmt_create, gmt_modified)
VALUES ('已过期', (SELECT t.id from t_dictionary t where t.code = 'mortgageStatus'), 'mortgage_expired', null, '4', NOW(), NOW());

-- 添加系统权限--

-- 企业信息管理权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '企业信息管理', 'enterpriseManage', '0', NULL, '', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'enterpriseManage'), '供应商', 'supplier', '0', '企业信息管理', '/customer/listPage', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'supplier'), '添加企业', 'addSupplier', '0', '供应商', '/customer/add', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'supplier'), '同步', 'syncSupplier', '1', '供应商', '/customer/flush', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'supplier'), '查看', 'viewSupplier', '2', '供应商', '/customer/findDetail', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'enterpriseManage'), '核心企业', 'enterprise', '1', '企业信息管理', '/customer/enterpriseList', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'enterprise'), '添加企业', 'addEnterprise', '0', '核心企业', '/customer/add', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'enterprise'), '同步', 'syncEnterprise', '1', '核心企业', '/customer/flush', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'enterpriseManage'), '平台管理', 'platformManage', '2', NULL, '', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'platformManage'), '添加平台', 'addPlatform', '0', '平台管理', '/platform/addPage', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'platformManage'), '修改', 'updatePlatform', '1', '平台管理', '/platform/update', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'platformManage'), '复制认证链接', 'copyAuthLink', '2', '平台管理', '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'platformManage'), '复制自动签署链接', 'copySignLink', '3', '平台管理', '', NULL, NULL, NULL, NOW(), NOW());

-- 业务管理权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '业务管理', 'businessManage', '1', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'businessManage'), '新建业务', 'addBusiness', '0', '业务管理', '/business/management/addPage', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'businessManage'), '修改', 'updateBusiness', '1', '业务管理', '/business/management/turnToUpdate', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'businessManage'), '查看', 'viewBusiness', '2', '业务管理', '/business/management/findDetail', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'businessManage'), '移交', 'transferBusiness', '5', '业务管理', '/business/management/transferBusiness', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'businessManage'), '数据可见-查看全员', 'viewAllBusiness', '4', '业务管理', '/business/management/viewAllBusiness', NULL, NULL, NULL, NOW(), NOW());

-- 销售合同管理权限
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '销售合同管理', 'salesContractManage', '2', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'salesContractManage'), '数据可见-查看全员', 'viewAllSalesContract', '0', '销售合同管理', '/salesContractManage/viewAll', NULL, NULL, NULL, NOW(), NOW());

-- 采购合同管理权限
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '采购合同管理', 'purchContractManage', '3', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'purchContractManage'), '数据可见-查看全员', 'viewAllPurchContract', '0', '采购合同管理', '/purchContractManage/viewAll', NULL, NULL, NULL, NOW(), NOW());


-- 验收单权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '验收单管理', 'acceptanceManage', '4', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'acceptanceManage'), '新建验收单', 'addAcceptance', '0', '验收单管理', '/acceptance/management/addPage', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'acceptanceManage'), '修改', 'updateAcceptance', '1', '验收单管理', '/acceptance/management/turnToUpdate', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'acceptanceManage'), '查看', 'viewAcceptance', '2', '验收单管理', '/acceptance/management/findDetail', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'acceptanceManage'), '数据可见-查看全员', 'viewAllAcceptanceBusiness', '3', '验收单管理', '/acceptance/management/viewAllAcceptanceBusiness', NULL, NULL, NULL, NOW(), NOW());


-- 结算单权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '结算单管理', 'billManage', '5', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'billManage'), '新建结算单', 'addBill', '0', '结算单管理', '/Bill/management/addPage', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'billManage'), '修改', 'updateBill', '1', '结算单管理', '/Bill/management/turnToUpdate', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'billManage'), '查看', 'viewBill', '2', '结算单管理', '/Bill/management/findDetail', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'billManage'), '变更', 'changeBill', '3', '结算单管理', '/Bill/management/change', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'billManage'), '数据可见-查看全员', 'viewAllBillBusiness', '4', '结算单管理', '/Bill/management/viewAllBillBusiness', NULL, NULL, NULL, NOW(), NOW());

-- 底层管理 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '底层管理', 'mortgageManage', '6', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'mortgageManage'), '新建底层', 'addMortgage', '0', '底层管理', '/mortgage/management/addPage', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'mortgageManage'), '修改', 'updateMortgage', '1', '底层管理', '/mortgage/management/turnToUpdate', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'mortgageManage'), '查看', 'viewMortgage', '2', '底层管理', '/mortgage/management/findDetail', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'mortgageManage'), '数据可见-查看全员', 'viewAllMortgageBusiness', '3', '底层管理', '/mortgage/management/viewAllMortgageBusiness', NULL, NULL, NULL, NOW(), NOW());

-- 发票管理
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '发票管理', 'invoiceManage', '7', NULL, '', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'invoiceManage'), '销售发票', 'salesInvoice', '0', '发票管理', '/invoiceManage/salesInvoice', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'salesInvoice'), '添加发票', 'addSalesInvoice', '1', '待我处理', 'salesInvoice/salesInvoicePending/addSalesInvoice', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'salesInvoice'), '数据可见-查看全员', 'viewAllSalesInvoice', '2', '销售发票', 'salesInvoice/viewAllSalesInvoice', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'invoiceManage'), '采购发票', 'purchaseInvoice', '1', '发票管理', '/invoiceManage/purchaseInvoice', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'purchaseInvoice'), '添加发票', 'addPurchaseInvoice', '0', '待我处理', '/invoiceManage/purchaseInvoice/addPurchaseInvoice', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'purchaseInvoice'), '数据可见-查看全员', 'viewAllPurchaseInvoice', '0', '采购发票', '/invoiceManage/purchaseInvoice/viewAllPurchaseInvoice', NULL, NULL, NULL, NOW(), NOW());


-- 现金流管理
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '现金流管理', 'cashflowManage', '8', NULL, '', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'cashflowManage'), '现金流管理', 'recashflowManage', '0', '现金流管理', '/cashflowManage/recashflowManage', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'recashflowManage'), '新增', 'addCashflow', '0', '现金流管理', '/cashflowManage/recashflowManage/addCashflow', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'cashflowManage'), '银行信息设置', 'bankInformationSettings', '1', '现金流管理-现金流管理', '/cashflowManage/bankInformation', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'bankInformationSettings'), '新增', 'addBankInformation', '0', '银行信息设置', '/cashflowManage/bankInformation/addBankInformation', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'bankInformationSettings'), '查看', 'viewBankInformation', '1', '银行信息设置', '/cashflowManage/bankInformation/viewBankInformation', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'bankInformationSettings'), '修改', 'updateBankInformation', '2', '银行信息设置', '/cashflowManage/bankInformation/updateBankInformation', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'bankInformationSettings'), '删除', 'deleteBankInformation', '3', '银行信息设置', '/cashflowManage/bankInformation/deleteBankInformation', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'bankInformationSettings'), '禁用', 'disableBankInformation', '4', '银行信息设置', '/cashflowManage/bankInformation/disableBankInformation', NULL, NULL, NULL, NOW(), NOW());

-- 分账管理权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '分账管理', 'ledgerManage', '9', NULL, '', NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'ledgerManage'), '数据可见-查看全员', 'viewAllLedger', '0', '分账管理', '/ledgerManage/viewAll', NULL, NULL, NULL, NOW(), NOW());

-- 消息管理权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '消息管理', 'messageManage', '10', NULL, '', NULL, NULL, NULL, NOW(), NOW());

-- 系统管理权限 --
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES (NULL, '系统管理', 'systemManage', '11', NULL, '', NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'systemManage'), '组织机构管理', 'orgManage', 0, '系统管理', '/sys/org/list', 'fa fa-sitemap', NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '部门-添加子部门', 'addOrg', 1, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '部门-编辑部门', 'updateOrg', 2, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '部门-调整部门排序', 'orderOrg', 3, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-添加成员', 'addUser', 4, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-调整排序', 'orderUser', 5, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-批量禁用', 'batchUserDisabled', 6, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-批量启用', 'batchUserEnabled', 7, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-重置密码', 'resetUserPassword', 8, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-调整部门', 'switchOrg', 9, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-禁用', 'userDisabled', 10, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '成员-启用', 'userEnabled', 11, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '角色-新增角色组', 'addRoleGroup', 12, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '角色-新增角色', 'addRole', 13, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '角色-添加成员', 'addRoleUserRel', 14, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'orgManage'), '角色-批量移除', 'batchDeleteRoleUserRel', 15, '组织机构管理', NULL, NULL, NULL, NULL, NOW(), NOW());

INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'systemManage'), '登录日志', 'loginLogManage', 1, '系统管理', '/loginLog/list', 'fa fa-indent', NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'systemManage'), '在线用户', 'onLineUserManage', 2, '系统管理', '/authority/online_user_list', 'fa fa-indent', NULL, NULL, NOW(), NOW());
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id from t_permission t where t.ename = 'systemManage'), '流程管理', 'flowableManagement', 5, '系统管理', '', NULL, NULL, NULL, NOW(), NOW());
