-- 合同签章位能力补丁
-- 执行前请先确认正式库对象名与本测试库一致。

ALTER TABLE SEAL_CONTRACT_LAUNCH_MAIN ADD (
    SEAL_POS_CONFIGURED CHAR(1),
    SEAL_PDF_IMAGE_LIST CLOB
);

COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_POS_CONFIGURED IS '签章位是否已配置(Y/N)';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_MAIN.SEAL_PDF_IMAGE_LIST IS '签章平台PDF转图片列表JSON';

CREATE TABLE SEAL_CONTRACT_LAUNCH_SEAL_POS (
    ID NUMBER(20) PRIMARY KEY,
    CONTRACT_ID NUMBER(20) NOT NULL,
    PARTY_ID NUMBER(20) NOT NULL,
    LABEL VARCHAR2(100) NOT NULL,
    REQUIRED CHAR(1) DEFAULT 'Y' NOT NULL,
    PAGE_NUM NUMBER(10) NOT NULL,
    X NUMBER(12,2) NOT NULL,
    Y NUMBER(12,2) NOT NULL,
    WIDTH NUMBER(12,2) NOT NULL,
    HEIGHT NUMBER(12,2) NOT NULL,
    SEAL_ID VARCHAR2(100),
    SEAL_NAME VARCHAR2(200),
    REQUEST_ID VARCHAR2(100),
    SIGNED_STATUS NUMBER(2) DEFAULT 0 NOT NULL,
    SIGNED_BY_NAME VARCHAR2(100),
    SIGNED_BY_ID VARCHAR2(100),
    SIGNED_TIME TIMESTAMP,
    CREATE_BY VARCHAR2(100),
    CREATE_TIME TIMESTAMP DEFAULT SYSTIMESTAMP,
    UPDATE_BY VARCHAR2(100),
    UPDATE_TIME TIMESTAMP DEFAULT SYSTIMESTAMP,
    IS_DELETED CHAR(1) DEFAULT 'N' NOT NULL,
    REMARK VARCHAR2(500)
);

COMMENT ON TABLE SEAL_CONTRACT_LAUNCH_SEAL_POS IS '合同签章位配置表';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_SEAL_POS.PARTY_ID IS '签署方子表ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_SEAL_POS.REQUIRED IS '是否必签(Y/N)';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_SEAL_POS.REQUEST_ID IS '最近一次预盖章二维码请求ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_SEAL_POS.SIGNED_STATUS IS '0空框 1已选章 2待回调 3已签 4失败';

CREATE INDEX IDX_SC_LAUNCH_SEAL_POS_CONTRACT ON SEAL_CONTRACT_LAUNCH_SEAL_POS(CONTRACT_ID, IS_DELETED);
CREATE INDEX IDX_SC_LAUNCH_SEAL_POS_REQUEST ON SEAL_CONTRACT_LAUNCH_SEAL_POS(REQUEST_ID, IS_DELETED);

CREATE SEQUENCE SEQ_SEAL_CONTRACT_LAUNCH_SEAL_POS
    START WITH 1
    INCREMENT BY 1
    NOCACHE;
