ALTER TABLE `zh_project`
ADD COLUMN `common_json` json NULL COMMENT '通用json，没有sql查询值必要的可放这' AFTER `notice_setting`;
ALTER TABLE `zh_ledger_tag`
ADD COLUMN `pos_id` varchar(36) NOT NULL DEFAULT '' COMMENT '关联计量单元id(zh_pos表中的id)' AFTER `id`;

ALTER TABLE `zh_change`
ADD COLUMN `valuation_tp` decimal(30, 8) NULL DEFAULT 0 COMMENT '计价金额(审批完成后统计)' AFTER `negative_tp`,
ADD COLUMN `unvaluation_tp` decimal(30, 8) NULL DEFAULT 0 COMMENT '不计价金额(审批完成后统计)' AFTER `valuation_tp`;

ALTER TABLE `zh_change`
MODIFY COLUMN `positive_tp` decimal(30, 8) NOT NULL DEFAULT 0.00000000 COMMENT '正变更金额' AFTER `order_by`,
MODIFY COLUMN `negative_tp` decimal(30, 8) NOT NULL DEFAULT 0.00000000 COMMENT '负变更金额' AFTER `positive_tp`;

ALTER TABLE `zh_change_audit_list`
ADD COLUMN `oamount2` decimal(30, 8) NULL DEFAULT NULL COMMENT '原数量（可编辑）' AFTER `oamount`;

ALTER TABLE `zh_ledger_attachment`
MODIFY COLUMN `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id' AFTER `id`,
ADD COLUMN `revise_id` varchar(36) NOT NULL COMMENT '修订id' AFTER `tid`,
ADD COLUMN `revising` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '修订中' AFTER `revise_id`,
MODIFY COLUMN `uid` int(11) UNSIGNED NOT NULL COMMENT '上传者id' AFTER `lid`,
ADD COLUMN `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间' AFTER `in_time`;

ALTER TABLE `zh_ledger_attachment`
ADD INDEX `idx_tid`(`tid`),
ADD INDEX `idx_tid_sid`(`tid`, `settle_id`),
ADD INDEX `idx_tid_rid`(`tid`, `revise_id`),
ADD INDEX `idx_tid_revising`(`tid`, `revising`);

CREATE TABLE `zh_ancillary_gcl`  (
  `id` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'uuid',
  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id',
  `lid` varchar(36) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '台账id（zh_ledger.id）',
  `g_order` int(11) UNSIGNED NOT NULL DEFAULT 1 COMMENT '排序',
  `is_aux` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '辅材',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
  `unit` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '单位',
  `quantity` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '设计量',
  `expr` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '设计量公式',
  `drawing_code` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '图册号',
  `memo` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `add_user_id` int(11) UNSIGNED NOT NULL COMMENT '创建人',
  `add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_user_id` int(11) UNSIGNED NOT NULL COMMENT '最后修改人',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_tid`(`tid`) USING BTREE,
  INDEX `idex_tid_lid`(`tid`, `lid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '台账-附属工程量' ROW_FORMAT = Dynamic;

--修复转换值问题，并且需要再运行一次db_script/check_bills更新checked_price方法
UPDATE `zh_change_audit_list` SET `checked_amount` = CONVERT(`samount`, DECIMAL(30, 8)) WHERE `samount` != '';

UPDATE `zh_change_audit_list` SET `oamount2` = `oamount`;
