-- 请按如下分类提交sql！！！
-- Version todo
-- uat 2025-1-16
-- prod todo

------------------------------------
-- 表结构
------------------------------------

ALTER TABLE `zh_tender`
ADD COLUMN `c_mode` tinyint(1) NULL DEFAULT 0 COMMENT '变更清单模式' AFTER `c_rule_first`;

ALTER TABLE `zh_change_ledger`
ADD COLUMN `features` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT '' COMMENT '项目特征' AFTER `memo`;

ALTER TABLE `zh_sub_project`
ADD COLUMN `lock_file` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '资料归集，是否锁定' AFTER `filing_template_name`;

ALTER TABLE `zh_filing_template_list`
ADD COLUMN `is_share` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否分享' AFTER `memo`;

CREATE TABLE `zh_phase_pay`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid',
  `tid` int(11) NOT NULL COMMENT '标段id',
  `phase_order` int(11) UNSIGNED NOT NULL DEFAULT 1 COMMENT '期序号',
  `phase_date` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '支付年月',
  `create_user_id` int(11) NOT NULL COMMENT '创建人id',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(10) UNSIGNED NOT NULL COMMENT '最后修改人id',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
  `rela_stage` json NOT NULL COMMENT '关联期信息(json)--[{sid: int, sorder: int}]',
  `calc_base` json NOT NULL COMMENT '计算基数',
  `calc_base_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '计算基数缓存时间',
  `memo` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `audit_times` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '审批轮次',
  `audit_status` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '审批状态',
  `audit_max_sort` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最大审批排序',
  `audit_begin_time` timestamp NULL DEFAULT NULL COMMENT '审批开始时间',
  `audit_end_time` timestamp NULL DEFAULT NULL COMMENT '审批结束时间',
  `final_auditor_str` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '终审缓存信息',
  `calc_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期计量=工程计量款',
  `pay_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期付款=工程计量款+其他付款项',
  `cut_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期扣款=其他扣款项',
  `yf_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期应付',
  `sf_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期实付',
  `pre_calc_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期计量',
  `pre_pay_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期付款',
  `pre_cut_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期扣款',
  `pre_yf_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期应付',
  `pre_sf_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期实付',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

CREATE TABLE `zh_phase_pay_audit`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id',
  `phase_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '合同支付期id',
  `audit_id` int(11) UNSIGNED NOT NULL COMMENT '流程参与人id(含原报)',
  `name` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '参与人-姓名',
  `company` varchar(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '参与人-单位',
  `role` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '参与人-角色',
  `mobile` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '参与人-电话',
  `audit_times` int(11) UNSIGNED NOT NULL DEFAULT 1 COMMENT '审批次数',
  `audit_order` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '预定流程顺序',
  `audit_type` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '流程类型',
  `active_order` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '实际流程顺序',
  `audit_status` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '流程状态',
  `audit_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '流程结束时间',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `opinion` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '意见',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

CREATE TABLE `zh_phase_pay_detail`  (
  `id` int(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `uuid` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid',
  `tid` int(11) NOT NULL COMMENT '标段id',
  `phase_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '合同支付期id',
  `create_phase_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '创建期id',
  `create_phase_order` int(11) UNSIGNED NOT NULL DEFAULT 1 COMMENT '创建期序号',
  `master_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '拼接phase_id-audit_times-audit_sort',
  `tree_id` int(11) UNSIGNED NOT NULL COMMENT '树结构-id',
  `tree_pid` int(11) NOT NULL COMMENT '树结构-父id',
  `tree_order` int(11) UNSIGNED NOT NULL COMMENT '树结构-排序',
  `tree_level` int(4) UNSIGNED NOT NULL COMMENT '树结构-层级',
  `tree_is_leaf` tinyint(4) UNSIGNED NOT NULL COMMENT '树结构-是否子项',
  `tree_full_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '树结构-完整路径',
  `audit_times` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '审批轮次',
  `audit_sort` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '审批流程',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
  `create_user_id` int(11) UNSIGNED NOT NULL COMMENT '创建人id',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(11) UNSIGNED NOT NULL COMMENT '最后修改人id',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
  `is_minus` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否扣款',
  `is_fixed` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否固定项',
  `is_deleted` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否删除',
  `is_pause` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否暂停计量',
  `is_gather` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否汇总计算',
  `pay_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '支付类型',
  `start_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '起扣金额',
  `start_expr` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '起扣金额-计算式',
  `range_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '扣款限额',
  `range_expr` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '扣款限额-计算式',
  `expr` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期金额-计算式',
  `tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期金额',
  `pre_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期金额',
  `pre_used` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '上期是否已计量',
  `pre_finished` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '上期是否已计完',
  `end_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止本期金额',
  `postil` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期批注',
  `dl_value` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '计提期限-限制',
  `dl_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '计提期限-类型',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

CREATE TABLE `zh_phase_pay_file`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid',
  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id',
  `phase_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '合同支付期phase_id(zh_phase_pay.id)',
  `type` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '类型(pay/...)',
  `rela_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid(zh_phase_pay_detail.uuid/...)',
  `filename` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件名',
  `fileext` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
  `filesize` int(11) NOT NULL COMMENT '文件大小',
  `filepath` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
  `user_id` int(11) UNSIGNED NOT NULL COMMENT '用户id(zh_project_account.id)',
  `user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '用户名(缓存)',
  `user_company` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '公司(缓存)',
  `user_role` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '角色(缓存)',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `is_deleted` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

CREATE TABLE `zh_file_reference_list`  (
  `id` int(8) NOT NULL AUTO_INCREMENT COMMENT '自增id',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '名称',
  `create_time` int(10) NOT NULL COMMENT '创建时间',
  `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '标准清单列表' ROW_FORMAT = Dynamic;

CREATE TABLE `zh_file_reference`  (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增id',
  `list_id` int(8) NOT NULL COMMENT '列表id',
  `template_id` int(8) NOT NULL,
  `pid` int(10) NOT NULL COMMENT '父id',
  `order` tinyint(4) NOT NULL COMMENT '同级排序',
  `level` tinyint(2) NOT NULL COMMENT '层级',
  `full_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '层级定位辅助字段parent.full_path.ledger_id',
  `is_leaf` tinyint(1) NOT NULL COMMENT '是否叶子节点，界面显示辅助字段',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '名称',
  `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注',
  `node_type` int(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '节点类别',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '标段项目节点模板数据表' ROW_FORMAT = Dynamic;

------------------------------------
-- 表数据
------------------------------------

INSERT INTO `zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES (74, '关联项目', 'enterprise', 'conn', 48, 'add', NULL, 1);
INSERT INTO `zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES (75, '停用提示设置', 'project', 'stopmsg', 38, 'stopmsg', NULL, 1);
INSERT INTO `zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES (76, '参考文件', 'fileReference', 'all', 44, '', 6, 1);

UPDATE `zh_permission` SET `create_time` = 5 WHERE `id` = 57;



