-- 验收单人员变更审核表
drop table if exists acceptance_change_person_approval;
CREATE TABLE `acceptance_change_person_approval` (
                                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                              `acceptance_basic_info_id` bigint(20) unsigned DEFAULT '0' COMMENT '验收单-基础信息表ID',
                                              `approval_conclusion` varchar(50) DEFAULT '' COMMENT '通过pass/驳回back',
                                              `approval_comments` varchar(3000) DEFAULT '' COMMENT '审批意见',
                                              `user_create` varchar(32) DEFAULT '' COMMENT '创建人',
                                              `user_modified` varchar(32) DEFAULT '' COMMENT '修改人',
                                              `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                              `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                              PRIMARY KEY (`id`)
) COMMENT='--验收单人员变更审核表';

-- 验收单签署确认表
drop table if exists acceptance_sign_confirmation;
CREATE TABLE `acceptance_sign_confirmation` (
                                     `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                     `acceptance_basic_info_id` bigint(20) unsigned DEFAULT '0' COMMENT '验收单-基础信息表ID',
                                     `contract_link` varchar(2048) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同链接',
                                     `short_contract_link` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '客户合同链接短连接',
                                     `short_contract_link_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '短链接创建时间',
                                     `sign_conclusion` tinyint(1) DEFAULT NULL COMMENT '签署结论 1完成',
                                     `remark` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '说明',
                                     `user_create` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建人',
                                     `user_modified` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '修改人',
                                     `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                     `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                     PRIMARY KEY (`id`)
) COMMENT='--验收单签署确认表';

-- 验收单签署确认合同信息表
drop table if exists acceptance_sign_confirmation_electronic_info;
CREATE TABLE `acceptance_sign_confirmation_electronic_info` (
                                                     `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                                     `acceptance_sign_confirmation_id` bigint(20) NOT NULL COMMENT '验收单签署确认表Id',
                                                     `contract_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同名称',
                                                     `contract_id` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同id',
                                                     `file_id` bigint(20) DEFAULT NULL COMMENT '电子签文件',
                                                     `electronic_signature_personal_id` bigint(20) NOT NULL COMMENT '电子签个人信息表Id',
                                                     `transaction_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '客户合同交易id',
                                                     `sign_status` tinyint(1) DEFAULT NULL COMMENT '客户签署状态',
                                                     `back_file_id` bigint(20) DEFAULT NULL COMMENT '电子签回调文件',
                                                     `report_file_id` bigint(20) DEFAULT NULL COMMENT '出证电子签文件',
                                                     `user_create` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建人',
                                                     `user_modified` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '修改人',
                                                     `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                                     `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                                     PRIMARY KEY (`id`)
) COMMENT='--验收单签署确认合同信息表';

-- 验收单签署确认表
drop table if exists acceptance_sign_confirmation_history;
CREATE TABLE `acceptance_sign_confirmation_history` (
                                                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                                `acceptance_basic_info_id` bigint(20) unsigned DEFAULT '0' COMMENT '验收单-基础信息表ID',
                                                `contract_link` varchar(2048) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同链接',
                                                `short_contract_link` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '客户合同链接短连接',
                                                `short_contract_link_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '短链接创建时间',
                                                `sign_conclusion` tinyint(1) DEFAULT NULL COMMENT '签署结论 1完成',
                                                `remark` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '说明',
                                                `user_create` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建人',
                                                `user_modified` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '修改人',
                                                `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                                `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                                PRIMARY KEY (`id`)
) COMMENT='--验收单签署确认历史表';

-- 验收单签署确认合同信息表
drop table if exists acceptance_sign_confirmation_electronic_info_history;
CREATE TABLE `acceptance_sign_confirmation_electronic_info_history` (
                                                                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                                                `acceptance_sign_confirmation_id` bigint(20) NOT NULL COMMENT '验收单签署确认表Id',
                                                                `contract_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同名称',
                                                                `contract_id` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同id',
                                                                `file_id` bigint(20) DEFAULT NULL COMMENT '电子签文件',
                                                                `electronic_signature_personal_id` bigint(20) NOT NULL COMMENT '电子签个人信息表Id',
                                                                `transaction_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '客户合同交易id',
                                                                `sign_status` tinyint(1) DEFAULT NULL COMMENT '客户签署状态',
                                                                `back_file_id` bigint(20) DEFAULT NULL COMMENT '电子签回调文件',
                                                                `report_file_id` bigint(20) DEFAULT NULL COMMENT '出证电子签文件',
                                                                `user_create` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建人',
                                                                `user_modified` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '修改人',
                                                                `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                                                `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                                                PRIMARY KEY (`id`)
) COMMENT='--验收单签署确认合同信息历史表';

-- 添加是否签署确认
alter table acceptance_basic_info add `sign_confirm` tinyint(3) DEFAULT null COMMENT '是否签署确认 0否 1是';

alter table acceptance_his_info add `sign_confirm` tinyint(3) DEFAULT null COMMENT '是否签署确认 0否 1是';

-- 添加文件签署人
alter table acceptance_basic_info add `signer` bigint(20) DEFAULT NULL COMMENT '验收单签署人Id';

alter table acceptance_his_info add `signer` bigint(20) DEFAULT NULL COMMENT '验收单签署人Id';

drop table if exists acceptance_sign_confirmation_goods_info;
CREATE TABLE `acceptance_sign_confirmation_goods_info` (
                                             `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
                                             `acceptance_sign_confirmation_id` bigint(20) DEFAULT NULL COMMENT '验收单历史信息表id',
                                             `goods_name` varchar(500) DEFAULT NULL COMMENT '货物名称',
                                             `goods_material` varchar(500) DEFAULT NULL COMMENT '货物材质',
                                             `goods_type` varchar(500) DEFAULT NULL COMMENT '型号',
                                             `goods_factory` varchar(500) DEFAULT NULL COMMENT '厂家',
                                             `goods_unit` varchar(50) DEFAULT NULL COMMENT '单位',
                                             `goods_quantity` decimal(17,4) DEFAULT NULL COMMENT '数量',
                                             `acceptance_date` datetime NOT NULL COMMENT '验收日期',
                                             `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
                                             `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
                                             `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                             `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                             `sales_price` decimal(17,4) DEFAULT NULL COMMENT '销售单价',
                                             PRIMARY KEY (`id`) USING BTREE
) COMMENT='下游验收单-签署确认历史货物信息表';

alter table invoice_customer_info add remark varchar(500) DEFAULT NULL COMMENT '备注信息';

-- 刷新验收单状态
update acceptance_basic_info set acceptance_status = 234 where acceptance_status!= 918;
update acceptance_basic_info set acceptance_status = 235 where acceptance_status!= 234;

update purch_contract_supplement_info set approval = 1 where approval is null;

alter table acceptance_basic_info modify `change_person` tinyint(3) DEFAULT null COMMENT '核心企业经办人是否变更 0否 1是';

INSERT INTO `t_permission`( `parentId`, `cname`, `ename`, `gradation`, `moduleName`, `url`, `icon`, `user_create`, `user_modified`, `gmt_create`, `gmt_modified`)
VALUES ( (select t.id from t_permission t where t.ename = 'electronicSignaturePersonal'), '删除', 'electronicSignaturePersonalDelete', 3, '企业信息管理', '', NULL, NULL, NULL, now(), now());


INSERT INTO `t_permission`( `parentId`, `cname`, `ename`, `gradation`, `moduleName`, `url`, `icon`, `user_create`, `user_modified`, `gmt_create`, `gmt_modified`)
VALUES ( (select t.id from t_permission t where t.ename = 'electronicSignaturePersonal'), '刷新认证链接', 'electronicSignaturePersonalFlushUrl', 4, '企业信息管理', '', NULL, NULL, NULL, now(), now());

-- 分账管理添加处理权限
INSERT INTO t_permission (parentId, cname, ename, gradation, moduleName, url, icon, user_create, user_modified, gmt_create, gmt_modified)
VALUES ((SELECT t.id FROM t_permission t WHERE t.ename = 'ledgerManagement'), '处理', 'ledgerHandle', '1', '分账管理', '/ledgerManage/handle', NULL, NULL, NULL, NOW(), NOW());
