-- 销售合同历史表
DROP TABLE IF EXISTS `sales_contract_basic_info_history`;
CREATE TABLE sales_contract_basic_info_history like sales_contract_basic_info;

INSERT INTO sales_contract_basic_info_history select * FROM sales_contract_basic_info;

-- 销售合同付款条件历史表
DROP TABLE IF EXISTS `ssales_contract_payment_condition_history`;
CREATE TABLE sales_contract_payment_condition_history like sales_contract_payment_condition;

INSERT INTO sales_contract_payment_condition_history select * FROM sales_contract_payment_condition;

-- 销售合同结算信息历史表
DROP TABLE IF EXISTS `sales_contract_settle_info_history`;
CREATE TABLE sales_contract_settle_info_history like sales_contract_settle_info;

INSERT INTO sales_contract_settle_info_history select * FROM sales_contract_settle_info;

-- 销售合同质保金历史表
DROP TABLE IF EXISTS `sales_contract_retention_info_history`;
CREATE TABLE sales_contract_retention_info_history like sales_contract_retention_info;

INSERT INTO sales_contract_retention_info_history select * FROM sales_contract_retention_info;

-- 销售合同货物历史表
DROP TABLE IF EXISTS `sales_contract_goods_info_history`;
CREATE TABLE sales_contract_goods_info_history like sales_contract_goods_info;

INSERT INTO sales_contract_goods_info_history select * FROM sales_contract_goods_info;

-- 将销售合同历史文件信息刷新为历史节点
UPDATE sys_attachment_ref set entity_name = "salesContractHistoryFile" where entity_id  in (38,34,32,24,18,12) and  entity_name = "salesContractFile";

-- 销售合同补充信息历史表
DROP TABLE IF EXISTS `sales_contract_supplement_info_history`;
CREATE TABLE sales_contract_supplement_info_history like sales_contract_supplement_info;

INSERT INTO sales_contract_supplement_info_history select * FROM sales_contract_supplement_info;

-- 销售合同补充货物信息历史表

DROP TABLE IF EXISTS `sales_contract_supplement_goods_info_history`;
CREATE TABLE sales_contract_supplement_goods_info_history like sales_contract_supplement_goods_info;

INSERT INTO sales_contract_supplement_goods_info_history select * FROM sales_contract_supplement_goods_info;

-- 采购合同基础信息历史表
DROP TABLE IF EXISTS `purch_contract_basic_info_history`;
CREATE TABLE purch_contract_basic_info_history like purch_contract_basic_info;

INSERT INTO purch_contract_basic_info_history select * FROM purch_contract_basic_info;

-- 采购合同放款条件历史表
DROP TABLE IF EXISTS `purch_contract_payment_condition_history`;
CREATE TABLE purch_contract_payment_condition_history like purch_contract_payment_condition;

INSERT INTO purch_contract_payment_condition_history select * FROM purch_contract_payment_condition;

-- 采购合同结算周期历史表
DROP TABLE IF EXISTS `purch_contract_settle_cycle_history`;
CREATE TABLE purch_contract_settle_cycle_history like purch_contract_settle_cycle;

INSERT INTO purch_contract_settle_cycle_history select * FROM purch_contract_settle_cycle;

-- 采购合同质保金历史表
DROP TABLE IF EXISTS `purch_contract_retention_info_history`;
CREATE TABLE purch_contract_retention_info_history like purch_contract_retention_info;

INSERT INTO purch_contract_retention_info_history select * FROM purch_contract_retention_info;

-- 采购合同价格计算规则历史表
DROP TABLE IF EXISTS `purch_contract_price_rule_history`;
CREATE TABLE purch_contract_price_rule_history like purch_contract_price_rule;

INSERT INTO purch_contract_price_rule_history select * FROM purch_contract_price_rule;

-- 采购合同货物历史表
DROP TABLE IF EXISTS `purch_contract_goods_info_history`;
CREATE TABLE purch_contract_goods_info_history like purch_contract_goods_info;

INSERT INTO purch_contract_goods_info_history select * FROM purch_contract_goods_info;

-- 采购合同增值税要求历史表
DROP TABLE IF EXISTS `purch_contract_vat_info_history`;
CREATE TABLE purch_contract_vat_info_history like purch_contract_vat_info;

INSERT INTO purch_contract_vat_info_history select * FROM purch_contract_vat_info;

-- 采购合同结算和付款历史表
DROP TABLE IF EXISTS `purch_contract_settle_payment_history`;
CREATE TABLE purch_contract_settle_payment_history like purch_contract_settle_payment;

INSERT INTO purch_contract_settle_payment_history select * FROM purch_contract_settle_payment;

-- 采购合同收货人和发货人历史表
DROP TABLE IF EXISTS `purch_contract_buyer_seller_history`;
CREATE TABLE purch_contract_buyer_seller_history like purch_contract_buyer_seller;

INSERT INTO purch_contract_buyer_seller_history select * FROM purch_contract_buyer_seller;

-- 采购合同补充信息历史表
DROP TABLE IF EXISTS `purch_contract_supplement_info_history`;
CREATE TABLE purch_contract_supplement_info_history like purch_contract_supplement_info;

INSERT INTO purch_contract_supplement_info_history select * FROM purch_contract_supplement_info;

-- 采购合同补充货物信息历史表
DROP TABLE IF EXISTS `purch_contract_supplement_goods_info_history`;
CREATE TABLE purch_contract_supplement_goods_info_history like purch_contract_supplement_goods_info;

INSERT INTO purch_contract_supplement_goods_info_history select * FROM purch_contract_supplement_goods_info;


UPDATE sys_attachment_ref SET entity_name = "salesContractSupplementHistoryFile" WHERE entity_id IN (1,2,3) AND entity_name = "salesContractSupplementFile";