create table DQMS_OPERATION_LOG
(
    ID                   VARCHAR(64) NOT NULL ,
    OPERATOR_ID          VARCHAR(64) ,
    OPERATOR_NAME        VARCHAR(64),
    OPERATE_TYPE         INT,
    OPERATE_DATE         DATE,
    TARGET_TYPE          VARCHAR(64),
    TARGET_MODEL_ID      VARCHAR(64),
    TARGET_MODEL_NAME    VARCHAR(64),
    MESSAGE              CLOB,
    TENANT_ID            VARCHAR(64),
    PRIMARY KEY (ID)
);

COMMENT ON TABLE DQMS_OPERATION_LOG IS '操作日志';
COMMENT ON COLUMN DQMS_OPERATION_LOG.ID IS '操作日志ID';
COMMENT ON COLUMN DQMS_OPERATION_LOG.OPERATOR_ID IS '操作者ID';
COMMENT ON COLUMN DQMS_OPERATION_LOG.OPERATOR_NAME IS '操作者名称';
COMMENT ON COLUMN DQMS_OPERATION_LOG.OPERATE_TYPE IS '操作类型';
COMMENT ON COLUMN DQMS_OPERATION_LOG.OPERATE_DATE IS '时间';
COMMENT ON COLUMN DQMS_OPERATION_LOG.TARGET_TYPE IS '目标类型';
COMMENT ON COLUMN DQMS_OPERATION_LOG.TARGET_MODEL_ID IS '目标ID';
COMMENT ON COLUMN DQMS_OPERATION_LOG.TARGET_MODEL_NAME IS '目标名称';
COMMENT ON COLUMN DQMS_OPERATION_LOG.MESSAGE IS '信息';
COMMENT ON COLUMN DQMS_OPERATION_LOG.TENANT_ID IS '租户ID';

COMMENT ON TABLE DQMS_OPERATION_LOG IS '操作日志';
CREATE INDEX DQMS_OPERATION_LOG_INDEX_OPERATOR ON DQMS_OPERATION_LOG(OPERATOR_NAME);
CREATE INDEX DQMS_OPERATION_LOG_INDEX_OPERATE_TYPE ON DQMS_OPERATION_LOG(OPERATE_TYPE);
CREATE INDEX DQMS_OPERATION_LOG_INDEX_TARGET ON DQMS_OPERATION_LOG(TARGET_TYPE, TARGET_MODEL_ID, TARGET_MODEL_NAME);


CREATE TABLE DQMS_OPERATION_LOG_DETAIL
(
    ID                   varchar(64) not null,
    OLD_DATA_JSON        CLOB,
    NEW_DATA_JSON        CLOB,
    primary key (ID)
);

COMMENT ON COLUMN DQMS_OPERATION_LOG_DETAIL.ID IS '日志详情ID';
COMMENT ON COLUMN DQMS_OPERATION_LOG_DETAIL.OLD_DATA_JSON IS '旧值';
COMMENT ON COLUMN DQMS_OPERATION_LOG_DETAIL.NEW_DATA_JSON IS '新值';

COMMENT ON TABLE DQMS_OPERATION_LOG_DETAIL IS '操作日志详情';

-----------------------------
-- 组织机构评分
-----------------------------
CREATE TABLE DQMS_RATING_RESULT(
                                   ID  NUMBER(20,0) PRIMARY KEY,
                                   ORG_ID VARCHAR(64),
                                   ORG_NAME VARCHAR(50),
                                   ORG_LEVEL VARCHAR(2),
                                   PARENT_ORG_ID VARCHAR(64),
                                   SCORE NUMBER(20,0),
                                   START_DATE TIMESTAMP,
                                   END_DATE TIMESTAMP,
                                   RATING_CYCLE VARCHAR(50),
                                   RATING_POINT VARCHAR(50),
                                   CREATE_TIME TIMESTAMP,
                                   CREATE_USER VARCHAR(25),
                                   LAST_MODIFIER_TIME TIMESTAMP,
                                   LAST_MODIFIER_USER VARCHAR(25)
);

COMMENT ON COLUMN DQMS_RATING_RESULT.ORG_ID IS '组织ID';
COMMENT ON COLUMN DQMS_RATING_RESULT.ORG_NAME IS '组织名';
COMMENT ON COLUMN DQMS_RATING_RESULT.ORG_LEVEL IS '组织等级';
COMMENT ON COLUMN DQMS_RATING_RESULT.PARENT_ORG_ID IS '父组织ID';
COMMENT ON COLUMN DQMS_RATING_RESULT.SCORE IS '得分';
COMMENT ON COLUMN DQMS_RATING_RESULT.START_DATE IS '评估开始日期';
COMMENT ON COLUMN DQMS_RATING_RESULT.END_DATE IS '评估截至日期';
COMMENT ON COLUMN DQMS_RATING_RESULT.RATING_CYCLE IS '评分周期 年（year）、季度（quarter）、月（month）、周（week），默认月';
COMMENT ON COLUMN DQMS_RATING_RESULT.RATING_POINT IS '评分点 例如：2023-01';


ALTER TABLE ck_method_config ADD (SINK_MODE VARCHAR(64));
ALTER TABLE ck_method_config ADD (DATA_FROM VARCHAR(64));

alter table CK_CHECK_RESULT add CHECK_RESULT CLOB;
comment on column CK_CHECK_RESULT.CHECK_RESULT is '检核结果上传路径';