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

WHENEVER SQLERROR EXIT SQL.SQLCODE;

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

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

CREATE TABLE SEAL_CONTRACT_LAUNCH_PARTY (
    ID NUMBER(19) NOT NULL,
    CONTRACT_ID NUMBER(19) NOT NULL,
    ROLE_CODE VARCHAR2(10 CHAR) NOT NULL,
    ROLE_NAME VARCHAR2(20 CHAR) NOT NULL,
    SORT_ORDER NUMBER(10) DEFAULT 1,
    PARTNER_ID NUMBER(19),
    OPPOSITE_ID VARCHAR2(64 CHAR),
    COMPANY_NAME VARCHAR2(200 CHAR) NOT NULL,
    COMPANY_TYPE VARCHAR2(50 CHAR),
    OPPOSITE_CHARACTER VARCHAR2(20 CHAR),
    CONTACT_NAME VARCHAR2(100 CHAR),
    CONTACT_PHONE VARCHAR2(50 CHAR),
    CONTACT_EMAIL VARCHAR2(100 CHAR),
    CONTACT_ADDRESS VARCHAR2(500 CHAR),
    REGISTERED_ADDRESS VARCHAR2(500 CHAR),
    LEGAL_REPRESENTATIVE VARCHAR2(100 CHAR),
    CREDIT_CODE VARCHAR2(100 CHAR),
    BANK_NAME VARCHAR2(200 CHAR),
    BANK_ACCOUNT VARCHAR2(100 CHAR),
    NATURAL_PERSON_ID_TYPE VARCHAR2(20 CHAR),
    NATURAL_PERSON_ID_NUMBER VARCHAR2(100 CHAR),
    IS_GROUP_INTERNAL VARCHAR2(4 CHAR),
    IS_HONG_KONG_MACAO_TAIWAN VARCHAR2(4 CHAR),
    CREATE_BY VARCHAR2(64 CHAR),
    CREATE_TIME DATE DEFAULT SYSDATE,
    UPDATE_BY VARCHAR2(64 CHAR),
    UPDATE_TIME DATE DEFAULT SYSDATE,
    IS_DELETED VARCHAR2(2 CHAR) DEFAULT 'N',
    REMARK VARCHAR2(1000 CHAR),
    CONSTRAINT PK_SEAL_CONTRACT_LAUNCH_PARTY PRIMARY KEY (ID),
    SUBJECT_CODE VARCHAR2(100 CHAR)
);

COMMENT ON TABLE SEAL_CONTRACT_LAUNCH_PARTY IS '合同方信息表';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.ID IS '主键ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CONTRACT_ID IS '合同主表ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.ROLE_CODE IS '角色编码：A/B/C';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.ROLE_NAME IS '角色名称：甲方/乙方/丙方';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.SORT_ORDER IS '排序号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.PARTNER_ID IS '相对方管理表主键';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.OPPOSITE_ID IS '法务相对方ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.COMPANY_NAME IS '公司名称';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.COMPANY_TYPE IS '公司类型';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.OPPOSITE_CHARACTER IS '公司性质';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CONTACT_NAME IS '联系人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CONTACT_PHONE IS '联系电话';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CONTACT_EMAIL IS '联系邮箱';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CONTACT_ADDRESS IS '通讯地址';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.REGISTERED_ADDRESS IS '注册地址';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.LEGAL_REPRESENTATIVE IS '法定代表人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CREDIT_CODE IS '统一社会信用代码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.BANK_NAME IS '开户行';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.BANK_ACCOUNT IS '银行账号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.NATURAL_PERSON_ID_TYPE IS '自然人证件类型';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.NATURAL_PERSON_ID_NUMBER IS '自然人证件号码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.IS_GROUP_INTERNAL IS '是否集团内';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.IS_HONG_KONG_MACAO_TAIWAN IS '是否涉港澳台';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CREATE_BY IS '创建人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.UPDATE_BY IS '更新人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.UPDATE_TIME IS '更新时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.IS_DELETED IS '逻辑删除标记';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.REMARK IS '备注';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_PARTY.SUBJECT_CODE IS '主体编码（我方主体组织ID，相对方通常为空）';

CREATE INDEX IDX_SC_PARTY_CTID ON SEAL_CONTRACT_LAUNCH_PARTY (CONTRACT_ID);

CREATE SEQUENCE SEQ_SEAL_CONTRACT_LAUNCH_PARTY
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 9999999999999999999999999999
    NOCYCLE
    CACHE 20
    NOORDER;

COMMIT;
