-- =============================================
-- SEAL_PARTNER_CONTACT 建表脚本 (Oracle)
-- 自动整理生成，已合并历史patch字段
-- 执行方式: sqlplus developer/dev123@localhost/XEPDB1 @SEAL_PARTNER_CONTACT.sql
-- =============================================

WHENEVER SQLERROR EXIT SQL.SQLCODE;

BEGIN
    EXECUTE IMMEDIATE 'DROP SEQUENCE SEQ_SEAL_PARTNER_CONTACT';
EXCEPTION
    WHEN OTHERS THEN
        IF SQLCODE != -2289 THEN RAISE; END IF;
END;
/

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE SEAL_PARTNER_CONTACT CASCADE CONSTRAINTS';
EXCEPTION
    WHEN OTHERS THEN
        IF SQLCODE != -942 THEN RAISE; END IF;
END;
/

CREATE TABLE SEAL_PARTNER_CONTACT (
    ID NUMBER(19) NOT NULL,
    PARTNER_RECORD_ID NUMBER(19) NOT NULL,
    CONTACT_NAME VARCHAR2(50 CHAR) NOT NULL,
    CONTACT_PHONE VARCHAR2(20 CHAR) NOT NULL,
    POSTAL_ADDRESS VARCHAR2(100 CHAR) NOT NULL,
    EMAIL VARCHAR2(50 CHAR) NOT NULL,
    SORT_ORDER NUMBER(10) DEFAULT 1 NOT NULL,
    DEL_FLAG CHAR(1 CHAR) DEFAULT '0' NOT NULL,
    CREATE_BY VARCHAR2(64 CHAR),
    CREATE_TIME DATE DEFAULT SYSDATE,
    UPDATE_BY VARCHAR2(64 CHAR),
    UPDATE_TIME DATE DEFAULT SYSDATE,
    REMARK VARCHAR2(500 CHAR),
    CONSTRAINT PK_SEAL_PARTNER_CONTACT PRIMARY KEY (ID)
);

COMMENT ON TABLE SEAL_PARTNER_CONTACT IS '相对方联系人表';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.ID IS '主键ID';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.PARTNER_RECORD_ID IS '关联相对方主表 CUSTOMER_SYSID';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.CONTACT_NAME IS '联系人姓名';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.CONTACT_PHONE IS '联系电话';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.POSTAL_ADDRESS IS '通讯地址';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.EMAIL IS '电子邮箱';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.SORT_ORDER IS '排序号';
COMMENT ON COLUMN SEAL_PARTNER_CONTACT.DEL_FLAG IS '删除标记：0存在 2删除';

CREATE INDEX IDX_PARTNER_RECORD_ID ON SEAL_PARTNER_CONTACT (PARTNER_RECORD_ID);

CREATE SEQUENCE SEQ_SEAL_PARTNER_CONTACT
    START WITH 4
    INCREMENT BY 1
    NOCACHE
    NOCYCLE;

INSERT INTO SEAL_PARTNER_CONTACT
(ID, PARTNER_RECORD_ID, CONTACT_NAME, CONTACT_PHONE, POSTAL_ADDRESS, EMAIL,
 SORT_ORDER, DEL_FLAG, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, REMARK)
VALUES
(1, 1, '周经理', '15757460062', '宁波市北仑区明州西路188号A座', 'zhoujingli@example.com',
 1, '0', 'local_test', TO_DATE('2026-05-20 09:12:33', 'YYYY-MM-DD HH24:MI:SS'),
 'local_test', TO_DATE('2026-05-20 09:12:33', 'YYYY-MM-DD HH24:MI:SS'), '主联系人');
INSERT INTO SEAL_PARTNER_CONTACT
(ID, PARTNER_RECORD_ID, CONTACT_NAME, CONTACT_PHONE, POSTAL_ADDRESS, EMAIL,
 SORT_ORDER, DEL_FLAG, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, REMARK)
VALUES
(2, 3, 'Alice Brown', '+44-20-8899-0001', '88 Harbour Street, London', 'alice.brown@ocean-energy.com',
 1, '0', 'local_test', TO_DATE('2026-05-18 11:08:22', 'YYYY-MM-DD HH24:MI:SS'),
 'local_test', TO_DATE('2026-05-18 11:08:22', 'YYYY-MM-DD HH24:MI:SS'), '海外主联系人');
INSERT INTO SEAL_PARTNER_CONTACT
(ID, PARTNER_RECORD_ID, CONTACT_NAME, CONTACT_PHONE, POSTAL_ADDRESS, EMAIL,
 SORT_ORDER, DEL_FLAG, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, REMARK)
VALUES
(3, 3, 'Tom Lee', '+44-20-8899-0002', '88 Harbour Street, London', 'tom.lee@ocean-energy.com',
 2, '0', 'local_test', TO_DATE('2026-05-18 11:08:22', 'YYYY-MM-DD HH24:MI:SS'),
 'local_test', TO_DATE('2026-05-18 11:08:22', 'YYYY-MM-DD HH24:MI:SS'), '备用联系人');

COMMIT;
