-- 项目管理、临时额度管理、合同管理模块

DROP TABLE IF EXISTS `blade_project_apply`;
CREATE TABLE `blade_project_apply` (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
  `create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
  `create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_user` bigint(20) DEFAULT NULL COMMENT '修改人',
  `update_time` datetime DEFAULT NULL COMMENT '修改时间',
  `status` int(11) DEFAULT '1' COMMENT '状态',
  `is_deleted` int(11) DEFAULT '0' COMMENT '是否已删除',
  `apply_no` varchar(100) DEFAULT NULL COMMENT '立项申请单号',
  `project_code` varchar(100) DEFAULT NULL COMMENT '项目编号',
  `project_name` varchar(100) DEFAULT NULL COMMENT '项目名称',
  `project_short_name` varchar(50) DEFAULT NULL COMMENT '项目简称',
  `project_type` varchar(50) DEFAULT NULL COMMENT '项目类型',
  `business_dept_id` bigint(20) DEFAULT NULL COMMENT '业务部门ID',
  `business_dept_name` varchar(100) DEFAULT NULL COMMENT '业务部门',
  `undertake_dept_id` bigint(20) DEFAULT NULL COMMENT '承办部门ID',
  `undertake_dept_name` varchar(100) DEFAULT NULL COMMENT '承办部门',
  `project_source` varchar(50) DEFAULT NULL COMMENT '项目由来',
  `source_remark` varchar(500) DEFAULT NULL COMMENT '项目由来说明',
  `fund_limit` decimal(18,2) DEFAULT NULL COMMENT '项目资金使用额度(万元)',
  `receivable_limit` decimal(18,2) DEFAULT NULL COMMENT '项目应收账款额度(万元)',
  `receivable_days` int(11) DEFAULT NULL COMMENT '应收账款回款期限(天)',
  `payment_days` int(11) DEFAULT NULL COMMENT '回款账期(天)',
  `cargo_type` varchar(100) DEFAULT NULL COMMENT '货物类型',
  `cargo_quantity` varchar(100) DEFAULT NULL COMMENT '预估货物数量',
  `business_start_date` date DEFAULT NULL COMMENT '业务周期开始日期',
  `business_end_date` date DEFAULT NULL COMMENT '业务周期结束日期',
  `transport_route` varchar(200) DEFAULT NULL COMMENT '运输线路',
  `transport_type` varchar(100) DEFAULT NULL COMMENT '运输类型',
  `business_type` varchar(100) DEFAULT NULL COMMENT '业务类型',
  `project_scale` decimal(18,2) DEFAULT NULL COMMENT '项目规模(万元)',
  `estimated_profit` decimal(18,2) DEFAULT NULL COMMENT '预计利润(万元)',
  `fund_demand` decimal(18,2) DEFAULT NULL COMMENT '资金需求(万元)',
  `settlement_mode` varchar(100) DEFAULT NULL COMMENT '结算方式',
  `handler_user_id` bigint(20) DEFAULT NULL COMMENT '项目经办人ID',
  `handler_user_name` varchar(100) DEFAULT NULL COMMENT '项目经办人',
  `principal_user_id` bigint(20) DEFAULT NULL COMMENT '项目负责人ID',
  `principal_user_name` varchar(100) DEFAULT NULL COMMENT '项目负责人',
  `customer_names` varchar(500) DEFAULT NULL COMMENT '客户名称',
  `carrier_names` varchar(500) DEFAULT NULL COMMENT '下游承运商',
  `customer_json` text DEFAULT NULL COMMENT '客户信息JSON',
  `carrier_json` text DEFAULT NULL COMMENT '承运商信息JSON',
  `situation_remark` text DEFAULT NULL COMMENT '项目情况说明',
  `attachments_json` text DEFAULT NULL COMMENT '项目附件JSON',
  `approval_status` varchar(50) DEFAULT NULL COMMENT '审批状态',
  `current_node` varchar(100) DEFAULT NULL COMMENT '当前节点',
  `current_processor` varchar(100) DEFAULT NULL COMMENT '当前处理人',
  `effective_type` varchar(50) DEFAULT NULL COMMENT '生效类型',
  `approved_time` datetime DEFAULT NULL COMMENT '审核通过时间',
  `change_content` text DEFAULT NULL COMMENT '变更内容',
  `change_reason` varchar(500) DEFAULT NULL COMMENT '变更原因',
  `void_reason` varchar(500) DEFAULT NULL COMMENT '作废原因',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_project_apply_name` (`project_name`, `is_deleted`) USING BTREE,
  KEY `idx_project_apply_dept` (`undertake_dept_id`) USING BTREE,
  KEY `idx_project_apply_status` (`approval_status`) USING BTREE,
  KEY `idx_project_apply_create_time` (`create_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='项目立项';

DROP TABLE IF EXISTS `blade_temporary_credit_limit`;
CREATE TABLE `blade_temporary_credit_limit` (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
  `create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
  `create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_user` bigint(20) DEFAULT NULL COMMENT '修改人',
  `update_time` datetime DEFAULT NULL COMMENT '修改时间',
  `status` int(11) DEFAULT '1' COMMENT '状态',
  `is_deleted` int(11) DEFAULT '0' COMMENT '是否已删除',
  `application_no` varchar(100) DEFAULT NULL COMMENT '申请单号',
  `project_id` bigint(20) DEFAULT NULL COMMENT '项目ID',
  `project_code` varchar(100) DEFAULT NULL COMMENT '项目编号',
  `project_name` varchar(100) DEFAULT NULL COMMENT '项目名称',
  `undertake_dept_id` bigint(20) DEFAULT NULL COMMENT '承办部门ID',
  `undertake_dept_name` varchar(100) DEFAULT NULL COMMENT '承办部门',
  `project_fund_limit` decimal(18,2) DEFAULT NULL COMMENT '项目资金使用额度(万元)',
  `used_fund_limit` decimal(18,2) DEFAULT NULL COMMENT '已使用项目资金额度(万元)',
  `remaining_fund_limit` decimal(18,2) DEFAULT NULL COMMENT '剩余项目资金使用额度(万元)',
  `apply_limit` decimal(18,2) DEFAULT NULL COMMENT '申请临时额度(万元)',
  `valid_until` date DEFAULT NULL COMMENT '申请有效期至',
  `apply_dept_id` bigint(20) DEFAULT NULL COMMENT '申请部门ID',
  `apply_dept_name` varchar(100) DEFAULT NULL COMMENT '申请部门',
  `applicant_id` bigint(20) DEFAULT NULL COMMENT '申请人ID',
  `applicant_name` varchar(100) DEFAULT NULL COMMENT '申请人',
  `approval_status` varchar(50) DEFAULT NULL COMMENT '审批状态',
  `current_node` varchar(100) DEFAULT NULL COMMENT '当前节点',
  `current_processor` varchar(100) DEFAULT NULL COMMENT '当前处理人',
  `approved_time` datetime DEFAULT NULL COMMENT '审核通过时间',
  `attachments_json` text DEFAULT NULL COMMENT '附件JSON',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_temp_credit_project` (`project_id`) USING BTREE,
  KEY `idx_temp_credit_dept` (`apply_dept_id`) USING BTREE,
  KEY `idx_temp_credit_status` (`approval_status`) USING BTREE,
  KEY `idx_temp_credit_create_time` (`create_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='临时额度申请';

DROP TABLE IF EXISTS `blade_contract_manage`;
CREATE TABLE `blade_contract_manage` (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
  `create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
  `create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_user` bigint(20) DEFAULT NULL COMMENT '修改人',
  `update_time` datetime DEFAULT NULL COMMENT '修改时间',
  `status` int(11) DEFAULT '1' COMMENT '状态',
  `is_deleted` int(11) DEFAULT '0' COMMENT '是否已删除',
  `contract_no` varchar(100) DEFAULT NULL COMMENT '合同编号',
  `contract_name` varchar(100) DEFAULT NULL COMMENT '合同名称',
  `project_id` bigint(20) DEFAULT NULL COMMENT '所属项目ID',
  `project_name` varchar(100) DEFAULT NULL COMMENT '所属项目',
  `organization_id` bigint(20) DEFAULT NULL COMMENT '所属组织ID',
  `organization_name` varchar(100) DEFAULT NULL COMMENT '所属组织',
  `contract_category` varchar(50) DEFAULT NULL COMMENT '合同类别',
  `sign_type` varchar(50) DEFAULT NULL COMMENT '签约类型',
  `party_a` varchar(200) DEFAULT NULL COMMENT '甲方',
  `party_b` varchar(200) DEFAULT NULL COMMENT '乙方',
  `start_date` date DEFAULT NULL COMMENT '开始日期',
  `end_date` date DEFAULT NULL COMMENT '结束日期',
  `temporary_start_date` date DEFAULT NULL COMMENT '临时效力起',
  `temporary_end_date` date DEFAULT NULL COMMENT '临时效力止',
  `handler_user_id` bigint(20) DEFAULT NULL COMMENT '经办人ID',
  `handler_user_name` varchar(100) DEFAULT NULL COMMENT '经办人',
  `sign_date` date DEFAULT NULL COMMENT '签订日期',
  `settlement_mode` varchar(100) DEFAULT NULL COMMENT '结算方式',
  `contract_format` varchar(50) DEFAULT NULL COMMENT '合同格式',
  `legal_seal_flag` int(11) DEFAULT '0' COMMENT '是否需要加盖法人章',
  `copy_count` int(11) DEFAULT NULL COMMENT '一式份数',
  `payment_days` int(11) DEFAULT NULL COMMENT '回款账期(天)',
  `contract_stage` varchar(50) DEFAULT NULL COMMENT '合同阶段',
  `approval_status` varchar(50) DEFAULT NULL COMMENT '审核状态',
  `current_node` varchar(100) DEFAULT NULL COMMENT '当前节点',
  `current_processor` varchar(100) DEFAULT NULL COMMENT '当前处理人',
  `approved_time` datetime DEFAULT NULL COMMENT '审核通过时间',
  `billing_enabled` int(11) DEFAULT '0' COMMENT '计费信息开关',
  `contract_file_json` text DEFAULT NULL COMMENT '合同主文件JSON',
  `attachments_json` text DEFAULT NULL COMMENT '其它附件JSON',
  `billing_plan_json` text DEFAULT NULL COMMENT '计费方案JSON',
  `settlement_rule_json` text DEFAULT NULL COMMENT '结算生成规则JSON',
  `reconciliation_json` text DEFAULT NULL COMMENT '对账配置JSON',
  `change_record_json` text DEFAULT NULL COMMENT '变更记录JSON',
  `change_content` text DEFAULT NULL COMMENT '变更内容',
  `change_reason` varchar(500) DEFAULT NULL COMMENT '变更原因',
  `terminate_reason` varchar(500) DEFAULT NULL COMMENT '终止原因',
  `remark` varchar(2000) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_contract_project` (`project_id`) USING BTREE,
  KEY `idx_contract_org` (`organization_id`) USING BTREE,
  KEY `idx_contract_stage_status` (`contract_stage`, `approval_status`) USING BTREE,
  KEY `idx_contract_end_date` (`end_date`) USING BTREE,
  KEY `idx_contract_create_time` (`create_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='合同管理';

INSERT IGNORE INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES
(2100000000000000000, 0, 'project_manage', '项目管理', 'project_manage', '/project', 'iconfont icon-caidan', 41, 1, 0, 1, NULL, '', 0),
(2100000000000000100, 2100000000000000000, 'project_apply', '项目管理', 'project_apply', '/business/project-apply', 'iconfont icon-caidanguanli', 10, 1, 0, 1, NULL, '', 0),
(2100000000000000101, 2100000000000000100, 'project_apply_view', '查看', 'project_apply_view', '', '', 1, 2, 0, 1, NULL, '', 0),
(2100000000000000102, 2100000000000000100, 'project_apply_add', '新增', 'project_apply_add', '', '', 2, 2, 0, 1, NULL, '', 0),
(2100000000000000103, 2100000000000000100, 'project_apply_edit', '编辑', 'project_apply_edit', '', '', 3, 2, 0, 1, NULL, '', 0),
(2100000000000000104, 2100000000000000100, 'project_apply_delete', '删除', 'project_apply_delete', '', '', 4, 2, 0, 1, NULL, '', 0),
(2100000000000000105, 2100000000000000100, 'project_apply_export', '批量导出', 'project_apply_export', '', '', 5, 2, 0, 1, NULL, '', 0),
(2100000000000000106, 2100000000000000100, 'project_apply_submit', '提交审批', 'project_apply_submit', '', '', 6, 2, 0, 1, NULL, '', 0),
(2100000000000000107, 2100000000000000100, 'project_apply_withdraw', '撤回', 'project_apply_withdraw', '', '', 7, 2, 0, 1, NULL, '', 0),
(2100000000000000108, 2100000000000000100, 'project_apply_approve', '审批通过', 'project_apply_approve', '', '', 8, 2, 0, 1, NULL, '', 0),
(2100000000000000109, 2100000000000000100, 'project_apply_reject', '审批驳回', 'project_apply_reject', '', '', 9, 2, 0, 1, NULL, '', 0),
(2100000000000000110, 2100000000000000100, 'project_apply_change', '发起变更', 'project_apply_change', '', '', 10, 2, 0, 1, NULL, '', 0),
(2100000000000000111, 2100000000000000100, 'project_apply_void', '作废', 'project_apply_void', '', '', 11, 2, 0, 1, NULL, '', 0),
(2100000000000000200, 2100000000000000000, 'temporary_credit_limit', '临时额度管理', 'temporary_credit_limit', '/business/temporary-credit-limit', 'iconfont icon-caidanguanli', 20, 1, 0, 1, NULL, '', 0),
(2100000000000000201, 2100000000000000200, 'temporary_credit_limit_view', '查看', 'temporary_credit_limit_view', '', '', 1, 2, 0, 1, NULL, '', 0),
(2100000000000000202, 2100000000000000200, 'temporary_credit_limit_add', '新增', 'temporary_credit_limit_add', '', '', 2, 2, 0, 1, NULL, '', 0),
(2100000000000000203, 2100000000000000200, 'temporary_credit_limit_edit', '编辑', 'temporary_credit_limit_edit', '', '', 3, 2, 0, 1, NULL, '', 0),
(2100000000000000204, 2100000000000000200, 'temporary_credit_limit_delete', '删除', 'temporary_credit_limit_delete', '', '', 4, 2, 0, 1, NULL, '', 0),
(2100000000000000205, 2100000000000000200, 'temporary_credit_limit_export', '批量导出', 'temporary_credit_limit_export', '', '', 5, 2, 0, 1, NULL, '', 0),
(2100000000000000206, 2100000000000000200, 'temporary_credit_limit_submit', '提交审批', 'temporary_credit_limit_submit', '', '', 6, 2, 0, 1, NULL, '', 0),
(2100000000000000207, 2100000000000000200, 'temporary_credit_limit_withdraw', '撤回', 'temporary_credit_limit_withdraw', '', '', 7, 2, 0, 1, NULL, '', 0),
(2100000000000000208, 2100000000000000200, 'temporary_credit_limit_approve', '审批通过', 'temporary_credit_limit_approve', '', '', 8, 2, 0, 1, NULL, '', 0),
(2100000000000000209, 2100000000000000200, 'temporary_credit_limit_reject', '审批驳回', 'temporary_credit_limit_reject', '', '', 9, 2, 0, 1, NULL, '', 0),
(2110000000000000000, 0, 'contract_manage_root', '合同管理', 'contract_manage_root', '/contract', 'iconfont icon-caidan', 42, 1, 0, 1, NULL, '', 0),
(2110000000000000100, 2110000000000000000, 'contract_manage', '合同管理', 'contract_manage', '/business/contract-manage', 'iconfont icon-caidanguanli', 10, 1, 0, 1, NULL, '', 0),
(2110000000000000101, 2110000000000000100, 'contract_manage_view', '查看', 'contract_manage_view', '', '', 1, 2, 0, 1, NULL, '', 0),
(2110000000000000102, 2110000000000000100, 'contract_manage_add', '新增', 'contract_manage_add', '', '', 2, 2, 0, 1, NULL, '', 0),
(2110000000000000103, 2110000000000000100, 'contract_manage_edit', '编辑', 'contract_manage_edit', '', '', 3, 2, 0, 1, NULL, '', 0),
(2110000000000000104, 2110000000000000100, 'contract_manage_delete', '删除', 'contract_manage_delete', '', '', 4, 2, 0, 1, NULL, '', 0),
(2110000000000000105, 2110000000000000100, 'contract_manage_export', '批量导出', 'contract_manage_export', '', '', 5, 2, 0, 1, NULL, '', 0),
(2110000000000000106, 2110000000000000100, 'contract_manage_copy', '复制', 'contract_manage_copy', '', '', 6, 2, 0, 1, NULL, '', 0),
(2110000000000000107, 2110000000000000100, 'contract_manage_temp', '转临时合同', 'contract_manage_temp', '', '', 7, 2, 0, 1, NULL, '', 0),
(2110000000000000108, 2110000000000000100, 'contract_manage_formal', '转正式合同', 'contract_manage_formal', '', '', 8, 2, 0, 1, NULL, '', 0),
(2110000000000000109, 2110000000000000100, 'contract_manage_withdraw', '撤回', 'contract_manage_withdraw', '', '', 9, 2, 0, 1, NULL, '', 0),
(2110000000000000110, 2110000000000000100, 'contract_manage_approve', '审批通过', 'contract_manage_approve', '', '', 10, 2, 0, 1, NULL, '', 0),
(2110000000000000111, 2110000000000000100, 'contract_manage_reject', '审批驳回', 'contract_manage_reject', '', '', 11, 2, 0, 1, NULL, '', 0),
(2110000000000000112, 2110000000000000100, 'contract_manage_change', '发起变更', 'contract_manage_change', '', '', 12, 2, 0, 1, NULL, '', 0),
(2110000000000000113, 2110000000000000100, 'contract_manage_terminate', '终止合同', 'contract_manage_terminate', '', '', 13, 2, 0, 1, NULL, '', 0);
