UPDATE afc_application SET CODE='QUALITY' WHERE ID='dqms-66';

DELETE FROM afc_res_group WHERE ID = 'quality-11';
DELETE FROM afc_res_group WHERE ID = 'quality-12';

INSERT INTO afc_res_group (ID, NAME, CODE, TYPES, RES_TYPE, DESCRIPTION, APP_ID, BUSINESS_OBJ_ID, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, SORT_NO, IS_FIXED)VALUES ('quality-11', '主数据平台变量', 'mdm_platform_vars', 'platform', 'systemVariable', null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, null, null, 1, null);
INSERT INTO afc_res_group (ID, NAME, CODE, TYPES, RES_TYPE, DESCRIPTION, APP_ID, BUSINESS_OBJ_ID, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, SORT_NO, IS_FIXED)VALUES ('quality-12', 'AFC变量', 'afc_platform_vars', 'platform', 'systemVariable', null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, null, null, 1, null);

DELETE FROM afc_system_variable WHERE RES_GROUP_ID = 'quality-11';
DELETE FROM afc_system_variable WHERE RES_GROUP_ID = 'quality-12';


INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES ('quality-11', 'mdm.server.url', 'mdm_server_url', 'http://10.15.15.130:29898', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-12', 'mdm.server.token', 'mdm_server_token', '501143620fac471bb1ec2840e09f091d', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-13', 'mdm.frequency.name', 'mdm_frequency_name', 'mdm_frequency', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-14', 'mdm.index.id', 'mdm_index_id', '775617973328220160', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-15', 'mdm.datasource.id', 'mdm_datasource_id', '775620198016421888', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-16', 'mdm.output.datasource.id', 'mdm_output_datasource_id', '775874119687409664', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-17', 'mdm.output.datasource.databaseName', 'mdm_output_datasource_databaseName', 'dqms_result_store', 'quality-11', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-18', 'afc.server.url', 'afc_server_url', 'http://10.15.15.136:28085', 'quality-12', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);
INSERT INTO afc_system_variable (ID, CODE, NAME, VALUE, RES_GROUP_ID, IS_ENCRYPT, DESCRIPTION, SOURCE, CREATE_USER, UPDATE_USER, TENANT_ID, CREATE_TIME, UPDATE_TIME, TYPES, APP_ID)VALUES('quality-19', 'afc.server.token', 'afc_server_token', 'fe98f2cbf76444169ef209d2f59a9967', 'quality-12', '0', null, null, null, null, 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'platform', null);


-- afc_res_group
DELETE FROM afc_res_group WHERE ID = 'dqms-457';
INSERT INTO afc_res_group (ID, NAME, CODE, TYPES, RES_TYPE, DESCRIPTION, APP_ID, BUSINESS_OBJ_ID, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, SORT_NO, IS_FIXED) VALUES ('dqms-457', '安全审计', 'securityAudit', null, null, null, 'dqms-66', null, 'sys_tenant', '2022-12-20 14:05:49', null, 'admin', null, 9, null);

-- afc_resource
DELETE FROM afc_res_group WHERE ID IN ('dqms-221', 'dqms-222');
INSERT INTO afc_resource (ID, NAME, CODE, TYPES, APP_ID, RES_GROUP_ID, SUB_TYPE, DESCRIPTION, BUSINESS_OBJ_ID, CONTENT, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, IS_FIXED) VALUES ('dqms-221', '操作日志', 'logger', 'url', 'dqms-66', 'dqms-457', null, null, null, '{"openType":"microApp","mark":"securityAudit/logger","url":null,"params":null,"microUrl":null,"microMark":"quality","isLowOrHigh":"high","resourceCode":null,"formStatus":null,"resourceType":null,"viewType":null,"appCode":"quality","query":null,"processDefName":null,"biId":null,"biType":null,"bicode":null}', 'sys_tenant', '2022-12-20 14:09:21','2022-12-20 14:15:46', 'admin','admin', null);
INSERT INTO afc_resource (ID, NAME, CODE, TYPES, APP_ID, RES_GROUP_ID, SUB_TYPE, DESCRIPTION, BUSINESS_OBJ_ID, CONTENT, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, IS_FIXED) VALUES ('dqms-222', '质量评分', 'checkDataScore', 'url', 'dqms-66', 'dqms-455', null, null, null, '{"openType":"microApp","mark":"dqAnalysis/checkDataScore","url":null,"params":null,"microUrl":null,"microMark":"quality","isLowOrHigh":"high","resourceCode":null,"formStatus":null,"resourceType":null,"viewType":null,"appCode":"quality","query":null,"processDefName":null,"biId":null,"biType":null,"bicode":null}', 'sys_tenant', '2022-12-28 15:40:38', '2022-12-28 16:54:59', 'admin', 'admin', null);


-- afc_menu
DELETE FROM afc_menu WHERE ID IN ('dqms-43', 'dqms-44', 'dqms-81');
INSERT INTO afc_menu (ID, NAME, CODE, RES_ID, DESCRIPTION, SORT_NO, IS_LEAF, TREE_LEVEL, SEQ, PARENT_ID, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, IS_FIXED, OPEN_TYPE, MENU_ICON, MENU_TYPE, BUSINESS_OBJ_ID, IS_NEW_WINDOW_OPEN) VALUES ('dqms-43', '操作日志', 'logger', 'dqms-221', null, 3, '1', null, null, 'dqms-81', 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'admin', null, null, null, 'jiandu', null, null, null);
INSERT INTO afc_menu (ID, NAME, CODE, RES_ID, DESCRIPTION, SORT_NO, IS_LEAF, TREE_LEVEL, SEQ, PARENT_ID, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, IS_FIXED, OPEN_TYPE, MENU_ICON, MENU_TYPE, BUSINESS_OBJ_ID, IS_NEW_WINDOW_OPEN) VALUES ('dqms-44', '质量评分', 'checkDataScore', 'dqms-222', null, 4, '1', null, null, 'dqms-369', 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'admin', null, null, null, null, null, null, null);
INSERT INTO afc_menu (ID, NAME, CODE, RES_ID, DESCRIPTION, SORT_NO, IS_LEAF, TREE_LEVEL, SEQ, PARENT_ID, TENANT_ID, CREATE_TIME, UPDATE_TIME, CREATE_USER, UPDATE_USER, IS_FIXED, OPEN_TYPE, MENU_ICON, MENU_TYPE, BUSINESS_OBJ_ID, IS_NEW_WINDOW_OPEN) VALUES ('dqms-81', '安全审计', 'securityAudit', null, null, 10, '0', null, null, 'dqms-442', 'sys_tenant', to_date('2022-12-30 12:00:00','yyyy-mm-dd hh24:mi:ss'), null, 'admin', null, null, null, 'jiandu', null, null, null);


-- afc_r_res_role
DELETE FROM afc_r_res_role WHERE ID IN ('dqms-424', 'dqms-423');
INSERT INTO afc_r_res_role (ID, RES_ID, RES_TYPE, ROLE_ID, ROLE_TYPE, BUSINESS_OBJ_ID, BUSINESS_OBJ_INST_ID, TENANT_ID, IS_FIXED) VALUES ('dqms-424', 'dqms-221', 'url', 'dqms-92', 'platform', null, null, 'sys_tenant', null);
INSERT INTO afc_r_res_role (ID, RES_ID, RES_TYPE, ROLE_ID, ROLE_TYPE, BUSINESS_OBJ_ID, BUSINESS_OBJ_INST_ID, TENANT_ID, IS_FIXED) VALUES ('dqms-423', 'dqms-222', 'url', 'dqms-92', 'platform', null, null, 'sys_tenant', null);

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 '检核结果上传路径';

