-- sql提交须知：
-- 1. 请按如下分类提交sql！！！
-- 2. 表名前不可有库名！！！
-- 3. 表结构部分，新添加的表，不可先创建后修改！！！
--
-- Version V3.5.51.0145
-- uat 2026-01-21
-- prod 2026-01-22

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

ALTER TABLE `zh_contract`
ADD COLUMN `supplement_price` decimal(30, 8) NULL DEFAULT 0 COMMENT '补充合同金额' AFTER `total_price`,
ADD COLUMN `need_shenpi` tinyint(1) NULL DEFAULT 0 COMMENT '是否需要审批' AFTER `name`,
ADD COLUMN `status` tinyint(2) NULL DEFAULT 1 COMMENT '审批状态' AFTER `need_shenpi`,
ADD COLUMN `times` tinyint(3) NULL DEFAULT 1 COMMENT '审批次数' AFTER `status`,
ADD COLUMN `sp_group` int(11) NULL DEFAULT 0 COMMENT '固定审批组id' AFTER `times`,
ADD COLUMN `final_auditor_str` varchar(50) NOT NULL DEFAULT '' COMMENT '终审人相关（cache）' AFTER `sp_group`,
ADD COLUMN `type` varchar(255) NULL DEFAULT '' COMMENT '合同类型（筛选的字段）' AFTER `final_auditor_str`,
ADD COLUMN `remark1` varchar(1000) NULL DEFAULT '' COMMENT '备注1' AFTER `remark`,
ADD COLUMN `tax` tinyint(3) NULL COMMENT '税率' AFTER `calc2`,
ADD COLUMN `attribute_json` mediumtext NULL COMMENT '附加属性json' AFTER `tax`,
ADD COLUMN `exist_supplement` tinyint(1) NULL DEFAULT 0 COMMENT '是否存在补充合同' AFTER `exist_pay`;

ALTER TABLE `zh_contract_pay`
ADD COLUMN `need_shenpi` tinyint(1) NULL COMMENT '是否需要审批' AFTER `fpcid`,
ADD COLUMN `status` tinyint(2) NULL DEFAULT 1 COMMENT '审批状态' AFTER `need_shenpi`,
ADD COLUMN `times` tinyint(3) NULL DEFAULT 1 COMMENT '审批次数' AFTER `status`,
ADD COLUMN `sp_group` int(11) NULL DEFAULT 0 COMMENT '固定审批组id' AFTER `times`,
ADD COLUMN `used` varchar(255) NULL DEFAULT '合同' COMMENT '资金用途' AFTER `pay_time`,
ADD COLUMN `final_auditor_str` varchar(50) NOT NULL DEFAULT '' COMMENT '终审人相关（cache）' AFTER `sp_group`;

ALTER TABLE `zh_contract_tree`
ADD COLUMN `remark1` varchar(1000) NULL DEFAULT '' COMMENT '备注1' AFTER `remark`;

ALTER TABLE `zh_shenpi_audit`
ADD COLUMN `audit_group` varchar(20) NOT NULL DEFAULT '' COMMENT '审批分组' AFTER `audit_ledger_id`,
ADD COLUMN `audit_group_order` tinyint(4) NOT NULL DEFAULT 0 COMMENT '组内审批顺序' AFTER `audit_group`,
ADD COLUMN `audit_group_limit` tinyint(4) NOT NULL DEFAULT 0 COMMENT '组内是否受限' AFTER `audit_group_order`,
ADD COLUMN `audit_checkno_valid` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否允许审批退回' AFTER `audit_group_limit`,
ADD COLUMN `audit_group_need` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '组内最少审批人数' AFTER `audit_checkno_valid`,
ADD COLUMN `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间' AFTER `sp_group`;

ALTER TABLE `zh_stage_audit`
ADD COLUMN `audit_group` varchar(20) NOT NULL DEFAULT '' COMMENT '审批分组' AFTER `audit_ledger_id`,
ADD COLUMN `audit_group_order` tinyint(4) NOT NULL DEFAULT 0 COMMENT '组内顺序' AFTER `audit_group`,
ADD COLUMN `audit_group_limit` tinyint(4) NOT NULL DEFAULT 0 COMMENT '组内是否受限' AFTER `audit_group_order`,
ADD COLUMN `audit_checkno_valid` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否允许审批退回' AFTER `audit_group_limit`,
ADD COLUMN `audit_group_need` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '组内最少审批人数' AFTER `audit_checkno_valid`;

ALTER TABLE `zh_tender_permission`
ADD COLUMN `cost` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '成本管理权限(,分隔，具体见代码定义)' AFTER `schedule`;

ALTER TABLE `zh_bills_template_list`
ADD COLUMN `sub_type` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '二级分类' AFTER `remark`;

ALTER TABLE `zh_sub_project`
ADD COLUMN `cost_ledger_template` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成本台账模板id' AFTER `common_json`,
ADD COLUMN `cost_analysis_template` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '成本分析模板id' AFTER `cost_ledger_template`,
ADD COLUMN `cost_calc_template` varchar(36) NOT NULL DEFAULT '' COMMENT '成本分析，计算模板id' AFTER `cost_analysis_template`;

CREATE TABLE `zh_cost_stage`  (
  `id` varchar(36) NOT NULL COMMENT 'uuid',
  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id(zh_tender.id)',
  `stage_type` varchar(20) NULL COMMENT '期类型（台账ledger/账面book/分析analysis）',
  `stage_order` int(11) UNSIGNED NOT NULL COMMENT '期序号',
  `rela_stage` json NULL COMMENT '关联期信息(json)--[{sid: varchar, sorder: int}]',
  `create_user_id` int(11) 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 '最后修改时间',
  `stage_date` varchar(20) NOT NULL COMMENT '报审月份',
  `decimal` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '{"tp": 6}' COMMENT '小数位数',
  `audit_times` tinyint(4) NOT NULL COMMENT '审批轮次',
  `audit_status` tinyint(4) NOT NULL COMMENT '审批状态',
  `audit_max_sort` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最大审批排序',
  `audit_begin_time` timestamp NULL COMMENT '开始审批时间',
  `audit_end_time` timestamp NULL COMMENT '审批结束时间',
  `final_auditor_str` varchar(255) NOT NULL DEFAULT '' COMMENT '终审缓存信息',
  `stage_tp` json NOT NULL COMMENT '金额',
  `stage_pre_tp` json NOT NULL COMMENT '截止上期金额',
  `calc_template` varchar(36) NOT NULL DEFAULT '' COMMENT '计算模板',
  PRIMARY KEY (`id`),
  INDEX `idx_tid_type`(`tid`, `stage_type`) USING BTREE
);

CREATE TABLE `zh_cost_stage_audit`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期id',
  `stage_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '期类型',
  `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_cost_stage_file`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid',
  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '期stage_id(zh_cost_stage.id)',
  `stage_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '类型(ledger/book/analysis/...)',
  `rela_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid(zh_cost_stage_ledger.id/...)',
  `rela_sub_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid(zh_cost_stage_detail.id/...)',
  `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 '是否删除',
  `extra_upload` 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_cost_stage_ledger` (
  `id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid',
  `cost_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid（不同期保持统一）',
  `tender_id` int(11) unsigned NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期id',
  `tree_id` int(11) NOT NULL COMMENT '节点id',
  `tree_pid` int(11) NOT NULL COMMENT '父节点id',
  `tree_level` tinyint(4) NOT NULL COMMENT '层级',
  `tree_order` mediumint(4) NOT NULL COMMENT '同级排序',
  `tree_full_path` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '层级定位辅助字段parent.full_path-tree_id',
  `tree_is_leaf` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否叶子节点，界面显示辅助字段',
  `code` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '编号',
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
  `unit` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' 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 '截止上期-实付',
  `pre_yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期-应付不含税',
  `pre_sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期-实付不含税',
  `tax` decimal(24, 8) NOT NULL DEFAULT 0 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 '实付',
  `yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '应付不含税',
  `sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '实付不含税',
  `postil` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期批注',
  `memo` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `add_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建人',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最后编辑人',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后编辑时间',
  `read_pay_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '本期付款-只读',
  `read_cut_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '本期扣款-只读',
  `read_yf_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '本期应付-只读',
  `read_sf_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '本期实付-只读',
  `read_yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期应付不含税-只读',
  `read_sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期实付不含税-只读',
  `calc_his` json DEFAULT NULL COMMENT '本期历史',
  `is_used` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否已使用',
  `is_deal` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否为合同节点',
  `had_detail` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '往期是否有明细数据',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_cost_stage_detail`  (
  `id` varchar(36) NOT NULL COMMENT 'uuid',
  `tender_id` int(11) NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '期id',
  `stage_order` int(11) NOT NULL COMMENT '期序号',
  `ledger_id` varchar(36) NOT NULL COMMENT '所属台账id(zh_stage_ledger.id)',
  `cost_id` varchar(36) CHARACTER SET utf16le NOT NULL COMMENT '所属台账cost_id(不同期一致zh_stage_ledger.cost_id)',
  `source_cid` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '导入的合同id',
  `d_order` int(11) NOT NULL COMMENT '排序',
  `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '编号',
  `name` varchar(255) CHARACTER SET utf16 NOT NULL DEFAULT '' COMMENT '名称',
  `party_b` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '乙方',
  `pay_date` varchar(50) NOT NULL DEFAULT '' 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 '截止上期-实付',
  `pre_yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期-应付不含税',
  `pre_sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '截止上期-实付不含税',
  `tax` decimal(24, 8) NOT NULL DEFAULT 0 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 '实付',
  `yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '应付不含税',
  `sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '实付不含税',
  `postil` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期批注',
  `memo` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `add_user_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人',
  `add_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
  `update_user_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最后编辑人',
  `update_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '最后编辑时间',
  `read_pay_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期付款-只读',
  `read_cut_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期扣款-只读',
  `read_yf_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期应付-只读',
  `read_sf_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期实付-只读',
  `read_yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期应付不含税-只读',
  `read_sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '本期实付不含税-只读',
  `calc_his` json NULL COMMENT '本期历史',
  `is_used` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否已使用',
  `is_deal` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否为合同节点',
  PRIMARY KEY (`id`)
);

CREATE TABLE `zh_cost_stage_tag`  (
  `id` varchar(36) NOT NULL COMMENT 'uuid',
  `tender_id` int(11) NOT NULL COMMENT '标段id(zh_tender.id)',
  `stage_id` varchar(11) NOT NULL COMMENT '期id(zh_cost_stage.id)',
  `stage_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期类型(ledger/book/analysis/...)',
  `rela_id` varchar(36) NOT NULL COMMENT '关联id(zh_cost_stage_ledger.id/...)',
  `rela_sub_id` varchar(36) NOT NULL COMMENT '次关联id(zh_cost_stage_detail.id/...)',
  `create_user_id` int(11) NOT NULL COMMENT '创建人id(zh_project_accnount.id)',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(11) NOT NULL COMMENT '最后修改人id(zh_project_account.id)',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
  `share` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否共享给其他参与人',
  `color` varchar(7) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT '书签颜色',
  `comment` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '批注',
  PRIMARY KEY (`id`)
);

CREATE TABLE `zh_cost_stage_book` (
  `id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid(zh_cost_stage_ledger.id)',
  `tender_id` int(11) unsigned NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期id',
  `ledger_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '关联台账id(zh_stage_ledger.id)',
  `cost_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '关联台账cost_id(不同期一致zh_stage_ledger.cost_id)',
  `pre_in_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '截止上期-入账金额',
  `pre_in_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '截止上期-入账金额不含税',
  `in_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '入账金额',
  `in_excl_tax_tp` decimal(24, 8) NOT NULL COMMENT '入账金额不含税',
  `postil` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期批注',
  `memo` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `add_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建人',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最后编辑人',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后编辑时间',
  `read_in_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '本期入账-只读',
  `read_in_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '本期入账不含税-只读',
  `calc_his` json DEFAULT NULL COMMENT '本期历史',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_cost_stage_book_detail` (
  `id` varchar(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid(zh_cost_stage_ledger.id)',
  `tender_id` int(11) unsigned NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL COMMENT '期id',
  `stage_order` int(11) NOT NULL COMMENT '期序号',
  `ledger_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '关联台账id(zh_stage_detail.ledger_id)',
  `detail_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '关联明细id(zh_stage_detail.id)',
  `in_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '入账金额',
  `in_excl_tax_tp` decimal(24, 8) NOT NULL COMMENT '入账金额不含税',
  `postil` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期批注',
  `memo` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `add_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建人',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最后编辑人',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后编辑时间',
  `read_in_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '本期入账-只读',
  `read_in_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '本期入账不含税-只读',
  `calc_his` json DEFAULT NULL COMMENT '本期历史',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_cost_stage_analysis`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid',
  `cost_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid（不同期保持统一）',
  `tender_id` int(11) UNSIGNED NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期id',
  `tree_id` int(11) NOT NULL COMMENT '节点id',
  `tree_pid` int(11) NOT NULL COMMENT '父节点id',
  `tree_level` tinyint(4) NOT NULL COMMENT '层级',
  `tree_order` mediumint(4) NOT NULL COMMENT '同级排序',
  `tree_full_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '层级定位辅助字段parent.full_path-tree_id',
  `tree_is_leaf` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否叶子节点，界面显示辅助字段',
  `node_type` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '节点类型',
  `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '编号',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
  `unit` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '单位',
  `tax` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '税率（%）',
  `yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '应付金额-不含税',
  `in_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '入账金额-不含税',
  `sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '实付金额-不含税',
  `sf_percent` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '实付比例',
  `postil` varchar(1000) NOT NULL DEFAULT '' COMMENT '本期批注',
  `str1` varchar(255) NOT NULL DEFAULT '' COMMENT '文本',
  `str2` varchar(255) NOT NULL DEFAULT '' COMMENT '文本',
  `str3` varchar(255) NOT NULL DEFAULT '' COMMENT '文本',
  `str4` varchar(255) NOT NULL DEFAULT '' COMMENT '文本',
  `num_a` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_b` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_c` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_d` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_e` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_f` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_g` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_h` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_i` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_j` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_k` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_l` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_m` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_n` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_o` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `num_p` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值',
  `calc_read` json DEFAULT NULL COMMENT '本期计算-只读',
  `calc_his` json DEFAULT NULL COMMENT '本期历史',
  `add_user_id` int(11) NOT NULL COMMENT '新增人id',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
  `update_user_id` int(11) NOT NULL COMMENT '最后更新人id',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `calc_type` int(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '计算类型（收入1，支出2，其他0）',
  PRIMARY KEY (`id`)
);

CREATE TABLE `zh_cost_stage_analysis_detail`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid',
  `tender_id` int(11) NOT NULL COMMENT '标段id',
  `stage_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '期id',
  `ledger_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '所属台账id(zh_stage_ledger.id)',
  `cost_id` varchar(36) CHARACTER SET utf16le COLLATE utf16le_general_ci NOT NULL COMMENT '所属台账cost_id(不同期一致zh_stage_ledger.cost_id)',
  `source_id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '导入的合同id/明细id',
  `d_order` int(11) NOT NULL COMMENT '排序',
  `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '编号',
  `name` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NOT NULL DEFAULT '' COMMENT '名称',
  `party_b` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '乙方',
  `tax` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '税率（%）',
  `yf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '应付金额-不含税',
  `in_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '入账金额-不含税',
  `sf_excl_tax_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '实付金额-不含税',
  `sf_percent` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '实付比例',
  `postil` varchar(1000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '本期批注',
  `str1` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '文本',
  `str2` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '文本',
  `str3` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '文本',
  `str4` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '文本',
  `num_a` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_b` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_c` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_d` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_e` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_f` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_g` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_h` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_i` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_j` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_k` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_l` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_m` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_n` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_o` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `num_p` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值',
  `calc_read` json NULL COMMENT '本期计算-只读',
  `calc_his` json NULL COMMENT '本期计算-历史',
  `add_user_id` int(11) NOT NULL COMMENT '新增人id',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
  `update_user_id` int(11) NOT NULL COMMENT '最后更新人id',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `is_deal` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否为合同',
  PRIMARY KEY (`id`)
);

CREATE TABLE `zh_calc_tmpl_folder`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'uuid',
  `pid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '项目id(zh_project.id)',
  `type` varchar(20) NOT NULL COMMENT '模板类型(posCalc/...)',
  `master_id` varchar(36) NOT NULL COMMENT 'pid-type',
  `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
  `tree_id` int(11) NOT NULL COMMENT '节点id',
  `tree_pid` int(11) NOT NULL COMMENT '父节点id',
  `tree_level` tinyint(4) NOT NULL COMMENT '层级',
  `tree_order` mediumint(4) NOT NULL COMMENT '同级排序',
  `tree_full_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '层级定位辅助字段parent.full_path-tree_id',
  `tree_is_leaf` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否叶子节点，界面显示辅助字段',
  `add_user_id` int(11) NOT NULL COMMENT '新增人id',
  `add_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '新增时间',
  `update_user_id` int(11) NOT NULL COMMENT '最后更新人id',
  `update_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '最后更新时间',
  PRIMARY KEY (`id`)
);

ALTER TABLE `zh_pos_calc_detail`
ADD COLUMN `num_j` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值1' AFTER `num_i`,
ADD COLUMN `num_k` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值2' AFTER `num_j`,
ADD COLUMN `num_l` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值3' AFTER `num_k`,
ADD COLUMN `num_m` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值4' AFTER `num_l`,
ADD COLUMN `num_n` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值5' AFTER `num_m`,
ADD COLUMN `num_o` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值6' AFTER `num_n`,
ADD COLUMN `num_p` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值7' AFTER `num_o`,
ADD COLUMN `num_q` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值8' AFTER `num_p`,
ADD COLUMN `num_r` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值9' AFTER `num_q`,
ADD COLUMN `num_s` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值5' AFTER `num_r`,
ADD COLUMN `num_t` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值6' AFTER `num_s`,
ADD COLUMN `num_u` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值7' AFTER `num_t`;

ALTER TABLE `zh_calc_tmpl`
ADD COLUMN `folder_id` varchar(36) NOT NULL DEFAULT '' COMMENT '分类id(zh_calc_tmpl_folder.id)' AFTER `tid`;

ALTER TABLE `calculation`.`zh_project`
ADD COLUMN `calc_tmpl_set` json NULL COMMENT '计算模板配置' AFTER `common_json`;

CREATE TABLE `zh_budget_ctrl`  (
  `id` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '自增id',
  `bid` int(10) NOT NULL COMMENT '概算投资项目id',
  `tree_id` int(10) NOT NULL COMMENT '节点id',
  `tree_pid` int(10) NOT NULL COMMENT '父节点id',
  `level` tinyint(4) NOT NULL COMMENT '层级',
  `order` mediumint(4) NOT NULL DEFAULT 0 COMMENT '同级排序',
  `full_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '层级定位辅助字段parent.full_path.ledger_id',
  `is_leaf` tinyint(1) NOT NULL COMMENT '是否叶子节点，界面显示辅助字段',
  `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '节点编号',
  `b_code` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '名称',
  `unit` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '单位',
  `unit_price` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '单价',
  `quantity` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数量',
  `total_price` decimal(24, 8) NULL DEFAULT 0.00000000 COMMENT '金额',
  `dgn_qty1` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '设计数量1',
  `dgn_qty2` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '设计数量2',
  `drawing_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '图册号',
  `memo` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注',
  `node_type` int(4) UNSIGNED NULL DEFAULT 0 COMMENT '节点类别',
  `source` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '添加源',
  `remark` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_tender_id`(`bid`) USING BTREE,
  INDEX `idx_template_pid`(`tree_pid`) USING BTREE,
  INDEX `idx_level`(`level`) USING BTREE,
  INDEX `idx_full_path`(`bid`, `full_path`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '控制目标数据' ROW_FORMAT = Dynamic;

ALTER TABLE `zh_budget_final`
ADD COLUMN `ctrl_dgn_qty1` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '控制目标-设计数量1' AFTER `zb_tp`,
ADD COLUMN `ctrl_dgn_qty2` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '控制目标-设计数量1' AFTER `ctrl_dgn_qty1`,
ADD COLUMN `ctrl_dgn_qty` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '控制目标-设计数量1/设计数量2' AFTER `ctrl_dgn_qty2`,
ADD COLUMN `ctrl_dgn_price` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '控制目标-经济指标' AFTER `ctrl_dgn_qty`,
ADD COLUMN `ctrl_tp` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '控制目标-金额' AFTER `ctrl_dgn_price`;

ALTER TABLE `zh_budget_std`
ADD COLUMN `ctrl_chapter_id` varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT '控制目标-项目节-id列表(\',\'分隔)' AFTER `zb_bills_id`,
ADD COLUMN `ctrl_template_id` varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT '控制目标-新建模板-id列表(\',\'分隔)' AFTER `ctrl_chapter_id`,
ADD COLUMN `ctrl_bills_id` varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT '控制目标-工程量清单-id列表(\',\'分隔)' AFTER `ctrl_template_id`;

ALTER TABLE `zh_sub_project` ADD `shenpi` VARCHAR(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '审批流程设置' AFTER `payment_setting`;

ALTER TABLE `zh_shenpi_group`
ADD COLUMN `spid` varchar(255) NULL DEFAULT NULL COMMENT '项目id' AFTER `id`;

ALTER TABLE `zh_shenpi_audit`
ADD COLUMN `spid` varchar(255) NULL DEFAULT NULL COMMENT '项目id' AFTER `id`,
MODIFY COLUMN `tid` int(11) NULL DEFAULT NULL COMMENT '标段id' AFTER `spid`;

CREATE TABLE `zh_contract_sp_audit` (
  `id` int NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) NULL DEFAULT NULL COMMENT '项目id',
  `tid` int NULL DEFAULT NULL COMMENT '标段id',
  `cid` varchar(100) NULL DEFAULT NULL COMMENT '合同详情id',
  `cpid` int NULL DEFAULT NULL COMMENT '合同支付id',
  `aid` int NOT NULL COMMENT '审批人id',
  `order` int NOT NULL COMMENT '审批顺序',
  `times` int NOT NULL COMMENT '审批次数',
  `status` tinyint(1) NOT NULL COMMENT '审批状态',
  `begin_time` datetime NULL DEFAULT NULL COMMENT '开始审批时间',
  `end_time` datetime NULL DEFAULT NULL COMMENT '结束审批时间',
  `opinion` varchar(1000) NULL DEFAULT NULL COMMENT '审批意见',
  `audit_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '审批类型(1个人，2会签，3或签)',
  `audit_order` tinyint(4) NOT NULL DEFAULT 0 COMMENT '审批顺序',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT = '合同详情和合同支付，回款审批人表';

ALTER TABLE `zh_ancillary_gcl`
ADD COLUMN `pid` varchar(36) NOT NULL DEFAULT '' COMMENT '计量单元id' AFTER `lid`,
ADD COLUMN `calc_template` varchar(36) NOT NULL DEFAULT '' COMMENT '明细计算模板' AFTER `update_time`;

CREATE TABLE `zh_ancillary_gcl_detail`  (
  `id` varchar(36) NOT NULL COMMENT 'uuid',
  `tid` int(11) NOT NULL COMMENT '标段id(zh_tender.id)',
  `lid` varchar(36) NOT NULL COMMENT '台账id(zh_ledger.id)',
  `pid` varchar(36) NOT NULL COMMENT '计量单元id(zh_pos.id)',
  `ag_id` varchar(36) NOT NULL COMMENT '附属工程量id(zh_ancillary_gcl.id)',
  `agd_order` int(11) NOT NULL COMMENT '排序',
  `create_user_id` int(11) NOT NULL COMMENT '新增用户id(zh_project_account.id)',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
  `update_user_id` int(11) NOT NULL COMMENT '最后修改用户id(zh_project_account.id)',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
  `qty` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数量',
  `expr` varchar(255) NOT NULL DEFAULT '' COMMENT '数量计算式',
  `str1` varchar(255) NOT NULL DEFAULT '' COMMENT '文本1',
  `str2` varchar(255) NOT NULL DEFAULT '' COMMENT '文本2',
  `str3` varchar(255) NOT NULL DEFAULT '' COMMENT '文本3',
  `str4` varchar(255) NOT NULL DEFAULT '' COMMENT '文本4',
  `spec` varchar(50) NOT NULL DEFAULT '' COMMENT '规格',
  `num_a` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值a',
  `num_b` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值b',
  `num_c` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值c',
  `num_d` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值d',
  `num_e` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值e',
  `num_f` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值f',
  `num_g` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值g',
  `num_h` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值h',
  `num_i` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值i',
  `num_j` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值j',
  `num_k` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值k',
  `num_l` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值l',
  `num_m` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值m',
  `num_n` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值n',
  `num_o` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值o',
  `num_p` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值p',
  `num_q` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值q',
  `num_r` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值r',
  `num_s` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值s',
  `num_t` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值t',
  `num_u` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '数值u',
  PRIMARY KEY (`id`)
);

ALTER TABLE `zh_tender_cache`
MODIFY COLUMN `stage_flow_cur_info` varchar(5000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期-当前流程信息(json)' AFTER `stage_flow_cur_uid`,
MODIFY COLUMN `stage_flow_pre_info` varchar(5000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '期-上一流程信息(json)' AFTER `stage_flow_pre_uid`;


CREATE TABLE `zh_contract_supplement` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) NOT NULL COMMENT '合同类型(1是支出，2是收入)',
  `cid` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同详情id',
  `uid` int(11) DEFAULT NULL COMMENT '创建人id',
  `need_shenpi` tinyint(1) DEFAULT NULL COMMENT '是否需要审批',
  `status` tinyint(2) DEFAULT '1' COMMENT '审批状态',
  `times` tinyint(3) DEFAULT '1' COMMENT '审批次数',
  `sp_group` int(11) DEFAULT '0' COMMENT '固定审批组id',
  `final_auditor_str` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '终审人相关（cache）',
  `code` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '编号',
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '名称',
  `price` decimal(30,8) DEFAULT '0.00000000' COMMENT '金额',
  `party_a` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '甲方',
  `party_b` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '乙方',
  `sign_time` datetime DEFAULT NULL COMMENT '签订时间',
  `address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '签订地点',
  `content` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '补充原因及内容',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='合同补充表';

CREATE TABLE `zh_contract_supplement_attachment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) NOT NULL COMMENT '合同类型(1是支出，2是收入)',
  `cid` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '合同详情id',
  `csid` int(11) NOT NULL COMMENT '补充合同id',
  `uid` int(11) NOT NULL COMMENT '上传者id',
  `filename` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件名称',
  `fileext` varchar(5) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
  `filesize` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件大小',
  `filepath` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
  `upload_time` datetime NOT NULL COMMENT '上传时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_cid` (`csid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='合同补充附件表';
------------------------------------
-- 表数据
------------------------------------
