--自定义报表
alter table UR_ARPT add UD_SEQ_NO            INTEGER    default 0;
alter table UR_DS_FIELD add UD_DATA_PROP         VARCHAR2(1) default '0';
update UR_DS_FIELD set UD_DATA_PROP='1' where DIM_CODE is not null or DIM_CODE <> '';
update UR_DS_FIELD set UD_DATA_PROP='2' where (DIM_CODE is null or DIM_CODE = '') and DATA_TYPE<>'N';

alter table UR_IANA_IDX add UD_DATA_PROP         VARCHAR2(1) default '0';
update UR_IANA_IDX set UD_DATA_PROP='1' where DATA_TYPE='1';
update UR_IANA_IDX set UD_DATA_PROP='2' where (DATA_TYPE<>'1') and DATA_TYPE<>'N';

create table UR_ARPT_DS_IDX_COL  (
   ARPT_ID              VARCHAR2(36)                     not null,
   ADATA_ID             VARCHAR2(36)                     not null,
   SEQ_NO               INTEGER                          not null,
   FACTOR_NAME          VARCHAR2(255),
   P_FACTOR_NAME        VARCHAR2(255),
   FULL_NAME            VARCHAR2(1000),
   IDX_CODE             VARCHAR2(36)                     not null,
   constraint PK_UR_ARPT_DS_IDX_COL primary key (ARPT_ID, ADATA_ID, SEQ_NO)
);

create table UR_ARPT_UD  (
   UD_ID                VARCHAR2(36)                     not null,
   UD_NAME              VARCHAR2(255),
   USER_ID              VARCHAR2(36),
   G_ARPT_ID            VARCHAR2(36)                     not null,
   ARPT_ID              VARCHAR2(36),
   ADATA_ID             VARCHAR2(36)                     not null,
   constraint PK_UR_ARPT_UD primary key (UD_ID)
);

create index IDX_UR_ARPT_UD_U on UR_ARPT_UD (
   USER_ID ASC
);


create table UR_ARPT_UD_DS_IDX  (
   UD_ID                VARCHAR2(36)                     not null,
   IDX_CODE             VARCHAR2(36)                     not null,
   constraint PK_UR_ARPT_UD_DS_IDX primary key (UD_ID, IDX_CODE)
);

create table UR_ARPT_UD_FIELD_CON  (
   UD_ID                VARCHAR2(36)                     not null,
   SEQ_NO               INTEGER                          not null,
   IDX_CODE             VARCHAR2(36)                     not null,
   COMPARE              VARCHAR2(60),
   VAL_SEQ_NO           INTEGER                        default 1,
   VAL_COUNT            INTEGER                        default 1,
   DISPLAY_VALUE        VARCHAR2(4000),
   REAL_VALUE           VARCHAR2(3800),
   AND_OR               VARCHAR2(1),
   constraint PK_UR_ARPT_UD_FIELD_CON primary key (UD_ID, SEQ_NO)
);

create table UR_ARPT_UD_GRP  (
   UD_ID                VARCHAR2(36)                     not null,
   SUB_DIM_ID           VARCHAR2(36)                     not null,
   GRP_NO               INTEGER,
   constraint PK_UR_ARPT_UD_GRP primary key (UD_ID, SUB_DIM_ID)
);


create table UR_ARPT_UD_PARAM_VAL  (
   UD_ID                VARCHAR2(36)                     not null,
   PARAM_CODE           VARCHAR2(30)                     not null,
   VAL_SEQ_NO           INTEGER                        default 1  not null,
   VAL_COUNT            INTEGER                        default 1,
   DISPLAY_VALUE        VARCHAR2(4000),
   REAL_VALUE           VARCHAR2(3800),
   constraint PK_UR_ARPT_UD_PARAM_VAL primary key (UD_ID, PARAM_CODE, VAL_SEQ_NO)
);

create table UR_SYS_DIM_SUB  (
   SUB_DIM_ID           VARCHAR2(36)                     not null,
   SEQ_NO               INTEGER,
   GRP_NAME             VARCHAR2(60),
   DIM_CODE             VARCHAR2(30),
   GRP_CODE_LVL         INTEGER,
   constraint PK_UR_SYS_DIM_SUB primary key (SUB_DIM_ID)
);

create table UR_SYS_DIM_SUB_GRP  (
   SUB_DIM_GRP_ID       VARCHAR2(36)                     not null,
   SUB_DIM_GRP_NAME     VARCHAR2(60),
   SEQ_NO               INTEGER,
   constraint PK_UR_SYS_DIM_SUB_GRP primary key (SUB_DIM_GRP_ID)
);

create table UR_SYS_DIM_SUB_GRP_D  (
   SUB_DIM_GRP_ID       VARCHAR2(36)                     not null,
   SUB_DIM_ID           VARCHAR2(36)                     not null,
   GRP_NO               INTEGER,
   constraint PK_UR_SYS_DIM_SUB_GRP_D primary key (SUB_DIM_GRP_ID, SUB_DIM_ID)
);

--自定义报表查询菜单
Insert into ur_sys_menu
   (mod_id, l_code, is_end, mod_code, mod_name, 
   mod_type, form_name, pack_name, param, mod_tag, user_id)
 Values
   ('SYS_UD_QUERY', '00200113', '1', 'SYS_UD_QUERY', '自定义报表查询', 
    'MOD_ANA', 'TfrmUDQuery', 'RptQuery.exe', NULL, 4, 
    '*');


--Insert into ur_sys_menu_reform
--   (menu_id, l_code, is_end, disp_name, mod_type, mod_id, seq_no)
-- Values
--   ('SYS_UD_QUERY', '00080113', '1', '自定义报表查询', 'MOD', 
--    'SYS_UD_QUERY', 16);


Insert into ur_sys_res
   (lang_type, mod_id, res_id, res_type, seq_no, org_name, disp_name, mark)
 Values
   ('chi', 'SYS_UD_QUERY', 'FUNC_SETUP', 'F', 2, 
    '设置', '设置', '设置');
Insert into ur_sys_res
   (lang_type, mod_id, res_id, res_type, seq_no, org_name, disp_name, mark)
 Values
   ('chi', 'SYS_UD_QUERY', 'MOD', 'R', 1, 
    '自定义报表查询', '自定义报表查询', '自定义报表查询');
Insert into ur_sys_res
   (lang_type, mod_id, res_id, res_type, seq_no, org_name, disp_name, mark)
 Values
   ('chi', 'SYS_UD_QUERY', 'FUNC_SEARCH', 'F', 1, 
    '查询', '查询', '查询');
