ALTER TABLE `zh_budget`
ADD COLUMN `final_time`  timestamp NULL DEFAULT NULL COMMENT '生成动态决算时间' AFTER `decimal`,
ADD COLUMN `final_id`  int(11) UNSIGNED NOT NULL DEFAULT 0 AFTER `final_time`;

CREATE TABLE `zh_budget_final_list` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `bid` int(11) unsigned NOT NULL COMMENT '动态决算id',
  `uid` int(11) unsigned NOT NULL COMMENT '生成决算人id',
  `u_name` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '生成决算人-名字(缓存)',
  `u_role` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '生成决算人-角色(缓存)',
  `u_company` varchar(60) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '生成决算人-单位(缓存)',
  `u_mobile` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '生成决算人-电话',
  `u_login` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0' COMMENT '生成决算人-登录方式',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `tender` varchar(1000) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '关联标段id('',''分隔)',
  `tender_info` text COLLATE utf8_unicode_ci COMMENT '关联标段信息(json)',
  `status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '0: 取消, 1: 等待, 2: 进行中, 3: 完成',
  PRIMARY KEY (`id`),
  KEY `idx_bid` (`bid`,`create_time`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_budget_final` (
  `id` varchar(36) COLLATE utf8_unicode_ci NOT NULL,
  `bid` int(11) unsigned NOT NULL COMMENT '概算投资项目id',
  `final_id` bigint(11) unsigned NOT NULL COMMENT '决算id',
  `tree_id` int(11) unsigned NOT NULL COMMENT '树结构id',
  `tree_pid` int(11) NOT NULL COMMENT '树结构父id',
  `level` int(11) unsigned NOT NULL COMMENT '层级',
  `order` int(11) unsigned NOT NULL COMMENT '同级排序',
  `full_path` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '层级定位辅助字段parent.full_path.ledger_id',
  `is_leaf` tinyint(1) NOT NULL COMMENT '是否叶子节点，界面显示辅助字段',
  `code` varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '节点编号',
  `name` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '名称',
  `unit` varchar(15) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '单位',
  `gu_dgn_qty1` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '估算-设计数量1',
  `gu_dgn_qty2` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '估算-设计数量1',
  `gu_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '估算-金额',
  `gai_dgn_qty1` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '概算-设计数量1',
  `gai_dgn_qty2` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '概算-设计数量1',
  `gai_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '概算-金额',
  `yu_dgn_qty1` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '预算-设计数量1',
  `yu_dgn_qty2` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '预算-设计数量1',
  `yu_tp` decimal(24,8) NOT 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 '决算-台账-设计数量1',
  `total_price` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '决算-台账-经济指标',
  `dgn_price` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '决算-台账-经济指标',
  `dgn_qty` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '决算-台账-设计数量1/设计数量2',
  `final_dgn_qty1` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '决算-设计数量1',
  `final_dgn_qty2` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '决算-设计数量1',
  `final_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '决算-金额',
  `final_dgn_price` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '决算-经济指标',
  `final_dgn_qty` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '决算-设计数量1/设计数量2',
  `grow_dgn_qty1` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '增幅%-设计数量1',
  `grow_dgn_qty2` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '增幅%-设计数量1',
  `grow_tp` decimal(24,8) NOT NULL DEFAULT '0.00000000' COMMENT '增幅%-金额',
  `grow_dgn_qty` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '增幅%-设计数量1/设计数量2',
  PRIMARY KEY (`id`),
  KEY `idx_fid` (`final_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `zh_material_list_gcl` ADD `old_quantity` DECIMAL(30,8) NULL DEFAULT NULL COMMENT '数量，用于复原数据' AFTER `expr`,
ADD `old_expr` VARCHAR(255) NULL DEFAULT NULL COMMENT '公式，用于复原数据' AFTER `old_quantity`;

UPDATE `zh_material_list_gcl` SET `old_quantity`=`quantity`,`old_expr`=`expr`;

ALTER TABLE `zh_material` ADD `exponent_rate` TINYINT(3) NULL DEFAULT '0' COMMENT '材料税税率' AFTER `rate`;

UPDATE `zh_material` SET `exponent_rate`=`rate`;

ALTER TABLE `zh_material_list` ADD `is_self` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否为单独添加的工料清单关联' AFTER `is_join`;

UPDATE `zh_material_list` SET `mx_id`= null WHERE `mx_id` = '';

CREATE TABLE `zh_material_list_self`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tid` int(11) NOT NULL COMMENT '标段id',
  `mid` int(11) NOT NULL COMMENT '调差期id',
  `gcl_id` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '清单id',
  `xmj_id` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '项目节id',
  `mx_id` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '部位明细id',
  `in_time` datetime NOT NULL COMMENT '添加时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '单独调差的清单表';

ALTER TABLE `zh_advance_pay`
ADD COLUMN `selected`  tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '报表用，是否选择' AFTER `id`;

