/** 资方管理信息表 **/
DROP TABLE IF EXISTS `financial_institution_info`;
CREATE TABLE `financial_institution_info` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
 `institution_id` varchar(50) DEFAULT NULL COMMENT '资方id',
 `institution_name` varchar(50) DEFAULT NULL COMMENT '资方名称',
 `customer_manager` varchar(50) 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 `financial_relation_customer`;
CREATE TABLE `financial_relation_customer` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `financial_institution_info_id` bigint(20) NOT NULL  COMMENT '关联资方管理表Id',
  `credit_subject_name` varchar(200) DEFAULT NULL COMMENT '授信主体',
  `project_manager` varchar(50) 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 `financial_relation_customer_disburse`;
CREATE TABLE `financial_relation_customer_disburse` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `financial_relation_customer_id` bigint(20) NOT NULL  COMMENT '关联客户信息表Id',
    `business_no` varchar(50) DEFAULT '' COMMENT '业务编号',
    `contract_no` varchar(50) DEFAULT '' COMMENT '保理合同编号',
    `quota_disburse_batch` int(11) DEFAULT '0' COMMENT '批次号',
    `expire_date` datetime 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 `financial_customer_info`;
CREATE TABLE `financial_customer_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `financial_relation_customer_id` bigint(20) DEFAULT NULL COMMENT '关联客户信息表ID',
  `customer_status` bigint(20) 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 `financial_customer_his_info`;
CREATE TABLE `financial_customer_his_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `financial_customer_info_id` bigint(20) DEFAULT NULL COMMENT '资方管理主表ID',
  `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 `financial_basic_file_info`;
CREATE TABLE `financial_basic_file_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `financial_customer_info_id` bigint(20) DEFAULT NULL COMMENT '客户信息表ID',
  `financial_basic_file_dic_info_id` bigint(20) DEFAULT NULL COMMENT '基础资料清单字典表ID',
  `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 `financial_basic_file_his_info`;
CREATE TABLE `financial_basic_file_his_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `financial_customer_his_info_id` bigint(20) DEFAULT NULL COMMENT '客户信息历史表ID',
  `financial_basic_file_dic_info_id` bigint(20) DEFAULT NULL COMMENT '基础资料清单字典表ID',
  `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 `financial_basic_file_dic_info`;
CREATE TABLE `financial_basic_file_dic_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `gradation` int(10) DEFAULT NULL COMMENT '显示顺序',
  `profile_name` varchar(50) DEFAULT NULL COMMENT '资料名称',
  `remark` varchar(255) DEFAULT NULL COMMENT '说明',
  `delete_status` int(1) DEFAULT '0' 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 `financial_customer_approval_info`;
CREATE TABLE `financial_customer_approval_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `financial_customer_info_id` bigint(20) DEFAULT NULL COMMENT '客户信息表ID',
  `approval_conclusion` varchar(50) DEFAULT '' COMMENT '通过pass/退回back/拒绝veto',
  `approval_comments` varchar(3000) DEFAULT '' COMMENT '审批意见',
  `assignee_id` bigint(20) unsigned DEFAULT '0' 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 `financial_customer_expenditure_info`;
CREATE TABLE `financial_customer_expenditure_info` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `financial_relation_customer_disburse_id` bigint(20) DEFAULT NULL COMMENT '关联客户支用表ID',
    `disburse_status` bigint(20) 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 `financial_customer_expenditure_contract_info`;
CREATE TABLE `financial_customer_expenditure_contract_info` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `financial_customer_expenditure_info_id` bigint(20) DEFAULT NULL COMMENT '客户支用信息表ID',
    `upstream_contract_no` varchar(50) DEFAULT NULL COMMENT '上游合同编号',
    `upstream_contract_amount` decimal(17,2) DEFAULT NULL COMMENT '上游合同金额',
    `upstream_contract_payment_days` varchar(100) DEFAULT NULL COMMENT '上游合同账期',
    `upstream_accounts_receivable_amount` decimal(17,2) DEFAULT NULL COMMENT '上游应收账款金额',
    `downstream_contract_no` varchar(50) DEFAULT NULL COMMENT '下游合同编号',
    `downstream_contract_amount` decimal(17,2) DEFAULT NULL COMMENT '下游合同金额',
    `downstream_contract_payment_days` varchar(100) DEFAULT NULL COMMENT '下游合同账期',
    `downstream_accounts_receivable_amount` decimal(17,2) DEFAULT NULL COMMENT '下游应收账款金额',
    `currency_code` varchar(20) DEFAULT '' 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 `financial_customer_expenditure_approval_info`;
CREATE TABLE `financial_customer_expenditure_approval_info` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `financial_customer_expenditure_info_id` bigint(20) DEFAULT NULL COMMENT '客户支用信息表ID',
    `approval_conclusion` varchar(50) DEFAULT '' COMMENT '通过pass/退回back/拒绝veto',
    `approval_comments` varchar(3000) DEFAULT '' COMMENT '审批意见',
    `assignee_id` bigint(20) unsigned DEFAULT '0' 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 `financial_customer_expenditure_his_info`;
CREATE TABLE `financial_customer_expenditure_his_info` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `financial_customer_expenditure_info_id` bigint(20) DEFAULT NULL COMMENT '客户支用信息表Id',
    `customer_name` varchar(50) DEFAULT NULL COMMENT '客户名称',
    `loan_amount_total` decimal(17,2) DEFAULT NULL COMMENT '放款金额',
    `loan_date` varchar(50) DEFAULT NULL COMMENT '放款日期',
    `expire_date` varchar(50) 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 `financial_customer_expenditure_contract_his_info`;
CREATE TABLE `financial_customer_expenditure_contract_his_info` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `financial_customer_expenditure_his_info_id` bigint(20) DEFAULT NULL COMMENT '客户支用历史表Id',
    `upstream_contract_no` varchar(50) DEFAULT NULL COMMENT '上游合同编号',
    `upstream_contract_amount` decimal(17,2) DEFAULT NULL COMMENT '上游合同金额',
    `upstream_contract_payment_days` int(10) DEFAULT NULL COMMENT '上游合同账期',
    `upstream_accounts_receivable_amount` decimal(17,2) DEFAULT NULL COMMENT '上游应收账款金额',
    `downstream_contract_no` varchar(50) DEFAULT NULL COMMENT '下游合同编号',
    `downstream_contract_amount` decimal(17,2) DEFAULT NULL COMMENT '下游合同金额',
    `downstream_contract_payment_days` int(10) DEFAULT NULL COMMENT '下游合同账期',
    `downstream_accounts_receivable_amount` decimal(17,2) DEFAULT NULL COMMENT '下游应收账款金额',
    `currency_code` varchar(20) DEFAULT '' 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 '客户支用信息-合同历史信息表';

/** 客户信息-客户状态 **/
INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ('客户状态', NULL, 'financialCustomerStatus', NULL, 0);

INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (0,'企业法人营业执照（正副本）', '复印件加盖企业公章', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (1,'开户许可证或基本账户信息表', '复印件加盖企业公章', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (2,'企业章程及章程修正案等', '复印件加盖企业公章', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (3,'企业简介', '加盖企业公章', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (4,'企业征信（签署银行征信授权书）', '签署银行征信授权书一份，银行查后复印提供西投保', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (5,'法定代表人及（实际控制人）夫妻双方个人征信', '签署银行征信授权书一份，银行查后复印提供西投保', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (6,'近两年及最近一期增值税纳税申报表', '复印件加盖企业公章', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (7,'近三年度的财务报表及最近一期财务报表', '复印件加盖企业公章；多次申请的更新最新财务报表', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (8,'近一年主要交易银行流水', '复印件加盖企业公章：多次申请的更新最新数据', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (9,'法定代表人及（实际控制人）夫妻双方个人身份证', '复印件并加盖个人私章（方章）', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (10,'法定代表人及（实际控制人）夫妻双方个人户口本首页及个人页', '复印件并加盖个人私章（方章）', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (11,'法定代表人及（实际控制人）夫妻双方个人结婚证', '复印件并加盖个人私章（方章）', 0);
INSERT INTO`financial_basic_file_dic_info`(`gradation`, `profile_name`, `remark`, `delete_status`) VALUES (12,'其他', '', 0);


INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '待编辑', (SELECT t.id from t_dictionary t where code = 'financialCustomerStatus'), 'financial_customer_to_be_edit', NULL, 0);
INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '待审核', (SELECT t.id from t_dictionary t where code = 'financialCustomerStatus'), 'financial_customer_under_approval', NULL, 1);
INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '通过', (SELECT t.id from t_dictionary t where code = 'financialCustomerStatus'), 'financial_customer_pass', NULL, 2);
INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '拒绝', (SELECT t.id from t_dictionary t where code = 'financialCustomerStatus'), 'financial_customer_refuse', NULL, 3);

-- 资方信息历史数据导入（表名来自与sop）
SELECT DISTINCT
    t1.institution_name,
    t2.refinancing_management_id,
    t3.`name`
FROM
    refinancing_credit_info t1
        LEFT JOIN refinancing_customer_marketing_info t2 ON t1.refinancing_customer_marketing_info_id = t2.id LEFT JOIN sys_user t3 ON t2.belong = t3.id;


/**
资方管理权限
 */
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`) VALUES (NULL, '资方管理', 'financialInstitutionManagement', 0);
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'financialInstitutionManagement'),
'关联支用', 'relationDisburse', 0, '资方管理');
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'relationDisburse'),
'数据可见-查看全员', 'viewAllRelationDisburse', 0, '关联支用');
 INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'financialInstitutionManagement'),
'合作概况', 'overviewCooperation', 1, '资方管理');
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename='overviewCooperation'),
'数据可见-查看全员', 'viewAllOverviewCooperation', 0, '合作概况');
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'financialInstitutionManagement'),
'客户信息', 'financialCustomerManagement', 2, '资方管理');
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename ='financialCustomerManagement'),
'数据可见-查看全员', 'viewAllFinancialCustomer', 0, '客户信息');
  INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'financialInstitutionManagement'),
'客户支用', 'customerDisburse', 3, '资方管理');
INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename='customerDisburse'),
'数据可见-查看全员', 'viewAllFinancialInstitution', 0, '客户支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'relationDisburse'),
'添加资方账号', 'addAccount', 1, '关联支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'relationDisburse'),
'关联企业', 'addEnterprise', 2, '关联支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'relationDisburse'),
'关联支用', 'addEnterpriseDisburse', 3, '关联支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'relationDisburse'),
'详情', 'getDetailList', 4, '关联支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'relationDisburse'),
'删除', 'deleteEnterprise', 5, '关联支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'financialCustomerManagement'),
'查看', 'viewFinancialCustomer', 1, '客户信息');


INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'financialCustomerManagement'),
'资料下载', 'downloadCustomerFile', 2, '客户信息');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'customerDisburse'),
'查看', 'viewCustomerDisburse', 1, '客户支用');

INSERT INTO `t_permission`(`parentId`, `cname`, `ename`, `gradation`, `moduleName`) VALUES ((SELECT t.id from t_permission t where ename = 'customerDisburse'),
'资料下载', 'downloadCustomerDisburseFile', 2, '客户支用');




INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ('客户信息管理', (select t.id from t_dictionary t where code = 'systemBusinessModel'),
'financialCustomerManagement', NULL, 13);
INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ('客户支用信息管理', (select t.id from t_dictionary t where code = 'systemBusinessModel'),
'financialCustomerExpenditureManagement', NULL, 14);

/**
添加资方机构
 */
 INSERT INTO `sys_org`( `name`, `dept_no`, `internal_code`, `sub_count_max`, `sub_count`, `gradation`, `simple_pinyin`, `full_pinyin`,   `org_type`) VALUES
 ('资方机构', 'financialBacker', '.888.', 11, 11, 0, 'zfjg', 'zifangjigou', 0);

/**
修改用户表name字段的长度
 */
ALTER TABLE `sys_user` MODIFY COLUMN `name` varchar(200) DEFAULT NULL COMMENT '用户名';

/**
附件表和附件关系表增加索引
 */
ALTER TABLE t_file_storage ADD INDEX idx_path ( path );
ALTER TABLE sys_attachment_ref ADD INDEX idx_file_storage_id ( file_storage_id );
