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

WHENEVER SQLERROR EXIT SQL.SQLCODE;

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

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

CREATE TABLE SEAL_CONTRACT_LAUNCH_MAIN (
    ID NUMBER(19) NOT NULL,
    CONTRACT_SYS_ID VARCHAR2(64 CHAR) NOT NULL,
    CONTRACT_CODE VARCHAR2(64 CHAR),
    LAW_CONTRACT_CODE VARCHAR2(64 CHAR),
    LAW_CONTRACT_ID VARCHAR2(64 CHAR),
    CONTRACT_NAME VARCHAR2(200 CHAR) NOT NULL,
    CONTRACT_TYPE VARCHAR2(64 CHAR) NOT NULL,
    CONTRACT_TYPE_CODE VARCHAR2(64 CHAR) NOT NULL,
    CONTRACT_SOURCE VARCHAR2(32 CHAR) DEFAULT 'ECP' NOT NULL,
    CREATION_MODE VARCHAR2(20 CHAR) NOT NULL,
    TEMPLATE_ID NUMBER(19),
    TEMPLATE_CODE VARCHAR2(64 CHAR),
    TEMPLATE_NAME VARCHAR2(200 CHAR),
    STATUS VARCHAR2(30 CHAR) NOT NULL,
    APPROVE_STATUS VARCHAR2(30 CHAR),
    APPROVE_MESSAGE VARCHAR2(500 CHAR),
    SEAL_CONTRACT_ID VARCHAR2(64 CHAR),
    SEAL_CONTRACT_STATUS NUMBER(10),
    CONTRACT_AMOUNT NUMBER(20, 2),
    CURRENCY_NAME VARCHAR2(20 CHAR),
    CONTRACT_PERIOD_TYPE VARCHAR2(10 CHAR),
    PERIOD_EXPLAIN VARCHAR2(500 CHAR),
    EFFECTIVE_START DATE,
    EFFECTIVE_END DATE,
    PAYMENT_METHOD VARCHAR2(500 CHAR),
    PRIMARY_CONTENT VARCHAR2(2000 CHAR),
    AMOUNT_EXPLAIN VARCHAR2(2000 CHAR),
    VALUATION_MODE VARCHAR2(10 CHAR),
    NEED_AMENDMENTS VARCHAR2(4 CHAR) DEFAULT '0',
    ESTIMATED_AMOUNT NUMBER(20, 2),
    SEAL_TYPE VARCHAR2(50 CHAR),
    TEXT_SOURCE VARCHAR2(50 CHAR),
    MANDATE_TYPE VARCHAR2(50 CHAR),
    CARGO_TYPE VARCHAR2(50 CHAR),
    ASSIST_DEPARTMENT_NAME VARCHAR2(200 CHAR),
    EXECUTOR_ACCOUNT VARCHAR2(64 CHAR),
    CREATOR_PHONE VARCHAR2(32 CHAR),
    SELF_CODE VARCHAR2(64 CHAR),
    MAIN_CONTRACT_CODE VARCHAR2(200 CHAR),
    SIGNING_SUBJECT_CODE VARCHAR2(500 CHAR),
    DATE_TYPE VARCHAR2(10 CHAR),
    IS_ADDIT INTEGER DEFAULT 2,
    IS_ELECTRON VARCHAR2(4 CHAR) DEFAULT '1',
    PAYMENT_DIRECTION VARCHAR2(10 CHAR),
    PUSH_URL VARCHAR2(500 CHAR),
    IS_MAJOR_CONTRACT INTEGER DEFAULT 0,
    IS_OPEN_BIDDING INTEGER DEFAULT 0,
    IS_YEAR_BUDGET INTEGER DEFAULT 0,
    IS_SHARE VARCHAR2(4 CHAR) DEFAULT '0',
    CONTRACT_NATURE VARCHAR2(4 CHAR) DEFAULT '0',
    IS_SGAT VARCHAR2(4 CHAR) DEFAULT '0',
    IS_NORMAL VARCHAR2(4 CHAR) DEFAULT '1',
    IS_TERMINATED VARCHAR2(4 CHAR) DEFAULT '0',
    IS_SINGLE_AGREEMENT VARCHAR2(4 CHAR) DEFAULT '0',
    BIDDING_NO VARCHAR2(100 CHAR),
    OPEN_BIDDING_REMARK VARCHAR2(500 CHAR),
    CONTRACT_GIST_REMARK VARCHAR2(1000 CHAR),
    EW_AMOUNT_TYPE VARCHAR2(100 CHAR),
    DJ_AMOUNT NUMBER(20, 2),
    YJ_AMOUNT NUMBER(20, 2),
    YFK_AMOUNT NUMBER(20, 2),
    BZJ_AMOUNT NUMBER(20, 2),
    BODY_SUMMARY VARCHAR2(2000 CHAR),
    TEMPLATE_FIELD_VALUES_JSON CLOB,
    CONTRACT_TEXT_FILE_NAME VARCHAR2(255 CHAR),
    CONTRACT_TEXT_FILE_PATH VARCHAR2(500 CHAR),
    CONTRACT_TEXT_FILE_TYPE VARCHAR2(50 CHAR),
    CONTRACT_TEXT_FILE_SIZE NUMBER(19),
    SIGNED_FILE_NAME VARCHAR2(255 CHAR),
    SIGNED_FILE_PATH VARCHAR2(500 CHAR),
    SIGNED_FILE_TYPE VARCHAR2(50 CHAR),
    SIGNED_FILE_SIZE NUMBER(19),
    SIGNED_FILE_URL VARCHAR2(1000 CHAR),
    SIGNED_OFFLINE_REASON VARCHAR2(1000 CHAR),
    SIGN_DATE DATE,
    SEAL_DATE DATE,
    SEAL_QUANTITY NUMBER(10) DEFAULT 1,
    ACTIVE_DATE DATE,
    ARCHIVE_DATE DATE,
    ARCHIVE_RECEIVE_DEPT VARCHAR2(100 CHAR),
    ARCHIVE_TRANSFEROR VARCHAR2(64 CHAR),
    ARCHIVE_KEEPER VARCHAR2(64 CHAR),
    ARCHIVE_KEEPER_UNIT VARCHAR2(200 CHAR),
    ARCHIVE_KEEPER_UNIT_CODE VARCHAR2(100 CHAR),
    INVOICE_DATE DATE,
    RECEIVE_DATE DATE,
    REMIND_DAYS NUMBER(10) DEFAULT 3,
    INITIATOR VARCHAR2(64 CHAR),
    INITIATOR_DEPT VARCHAR2(200 CHAR),
    COMPANY_NAME VARCHAR2(200 CHAR),
    ORG_ID VARCHAR2(64 CHAR),
    QUERY_SCOPE VARCHAR2(20 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_MAIN PRIMARY KEY (ID),
    CONSTRAINT UK_SEAL_CONTRACT_SYS_ID UNIQUE (CONTRACT_SYS_ID),
    SEAL_IS_SEAL VARCHAR2(4 CHAR) DEFAULT '1',
    SEAL_APPROVE_SAME VARCHAR2(4 CHAR) DEFAULT '1',
    COUNTERPARTY_CONFIRM_JSON VARCHAR2(2000 CHAR)
);

COMMENT ON TABLE SEAL_CONTRACT_LAUNCH_MAIN IS '合同发起主表';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ID IS '主键ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_SYS_ID IS '平台合同唯一编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_CODE IS '业务合同编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.LAW_CONTRACT_CODE IS '法务系统合同编号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.LAW_CONTRACT_ID IS '法务系统合同ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_NAME IS '合同名称';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_TYPE IS '合同类型中文名称';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_TYPE_CODE IS '合同类型编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_SOURCE IS '合同来源';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CREATION_MODE IS '创建方式：template/manual';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.TEMPLATE_ID IS '模板ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.TEMPLATE_CODE IS '模板编号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.TEMPLATE_NAME IS '模板名称';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.STATUS IS '合同当前状态';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.APPROVE_STATUS IS '审批状态';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.APPROVE_MESSAGE IS '审批说明';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_CONTRACT_ID IS '签章平台合同ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_CONTRACT_STATUS IS '签章平台合同状态';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_AMOUNT IS '合同金额';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CURRENCY_NAME IS '币种';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_PERIOD_TYPE IS '合同期限类型：0固定期限 1无固定期限';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.PERIOD_EXPLAIN IS '期限说明';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.EFFECTIVE_START IS '生效开始日期';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.EFFECTIVE_END IS '生效结束日期';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.PAYMENT_METHOD IS '付款方式';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.PRIMARY_CONTENT IS '合同主要内容';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.AMOUNT_EXPLAIN IS '金额说明';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.VALUATION_MODE IS '计价方式';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.NEED_AMENDMENTS IS '是否需修订条款：1是 0否';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ESTIMATED_AMOUNT IS '预估金额';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_QUANTITY IS '用印数量';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_TYPE IS '签订方式';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.TEXT_SOURCE IS '文本来源';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.MANDATE_TYPE IS '委托类型';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CARGO_TYPE IS '货种';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ASSIST_DEPARTMENT_NAME IS '协助部门';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.EXECUTOR_ACCOUNT IS '合同执行人账号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CREATOR_PHONE IS '创建人手机号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SELF_CODE IS '二级单位合同编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.MAIN_CONTRACT_CODE IS '主合同编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNING_SUBJECT_CODE IS '签约主体编码，多个用逗号分隔';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.DATE_TYPE IS '固定期间日期类型：0年 1月 2日';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_ADDIT IS '是否补录：1是 2否';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_ELECTRON IS '签署方式：0纸质 1电子';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.PAYMENT_DIRECTION IS '收支方向';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.PUSH_URL IS '法务审批回调地址';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_MAJOR_CONTRACT IS '是否重大合同';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_OPEN_BIDDING IS '是否公开招标';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_YEAR_BUDGET IS '是否列入当年预算';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_SHARE IS '是否共享';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_NATURE IS '签约主体是否涉外';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_SGAT IS '是否涉港澳台';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_NORMAL IS '是否正常';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_TERMINATED IS '是否终止';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_SINGLE_AGREEMENT IS '是否单方协议';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.BIDDING_NO IS '招标编号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.OPEN_BIDDING_REMARK IS '公开招标备注';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_GIST_REMARK IS '签订依据说明';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.EW_AMOUNT_TYPE IS '额外金额类型：DJ定金 YJ押金 YFK预付款 BZJ保证金';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.DJ_AMOUNT IS '定金金额';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.YJ_AMOUNT IS '押金金额';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.YFK_AMOUNT IS '预付款金额';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.BZJ_AMOUNT IS '保证金金额';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.BODY_SUMMARY IS '正文摘要';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.TEMPLATE_FIELD_VALUES_JSON IS '模板字段值JSON';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_TEXT_FILE_NAME IS '合同正文文件名';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_TEXT_FILE_PATH IS '合同正文文件路径';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_TEXT_FILE_TYPE IS '合同正文文件类型';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CONTRACT_TEXT_FILE_SIZE IS '合同正文文件大小';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNED_FILE_NAME IS '已签署文件名';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNED_FILE_PATH IS '已签署文件路径';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNED_FILE_TYPE IS '已签署文件类型';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNED_FILE_SIZE IS '已签署文件大小';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNED_OFFLINE_REASON IS '线下签署原因';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGNED_FILE_URL IS '已签署文件URL';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SIGN_DATE IS '签署日期';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_DATE IS '用印时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ACTIVE_DATE IS '合同生效日期';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ARCHIVE_DATE IS '归档时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ARCHIVE_RECEIVE_DEPT IS '合同归档接收部门编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ARCHIVE_TRANSFEROR IS '移交人账号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ARCHIVE_KEEPER IS '档案保管人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ARCHIVE_KEEPER_UNIT IS '档案保管单位';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ARCHIVE_KEEPER_UNIT_CODE IS '档案保管单位编码';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.INVOICE_DATE IS '开票时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.RECEIVE_DATE IS '收款时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.REMIND_DAYS IS '提醒提前天数';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.INITIATOR IS '发起人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.INITIATOR_DEPT IS '发起部门';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.COMPANY_NAME IS '发起公司';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.ORG_ID IS '组织ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.QUERY_SCOPE IS '查询范围';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CREATE_BY IS '创建人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.UPDATE_BY IS '更新人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.UPDATE_TIME IS '更新时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.IS_DELETED IS '逻辑删除标记';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.REMARK IS '备注';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_IS_SEAL IS '是否用印：1是 0否';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_APPROVE_SAME IS '审批是否一致：1是 0否';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.COUNTERPARTY_CONFIRM_JSON IS '相对方签署确认状态JSON';

CREATE INDEX IDX_CONTRACT_LAUNCH_STATUS ON SEAL_CONTRACT_LAUNCH_MAIN (STATUS);
CREATE INDEX IDX_CONTRACT_LAUNCH_CODE ON SEAL_CONTRACT_LAUNCH_MAIN (CONTRACT_CODE);
CREATE INDEX IDX_CONTRACT_LAUNCH_NAME ON SEAL_CONTRACT_LAUNCH_MAIN (CONTRACT_NAME);
CREATE INDEX IDX_SC_MAIN_CRTIME ON SEAL_CONTRACT_LAUNCH_MAIN (CREATE_TIME);

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

COMMIT;
