--报表设计主表
create table RPT_SET_MAIN
(
  id             numeric(19,0) default 0 not null,
  usercode       varchar(6) not null,
  title          varchar(100) not null,
  datasourcetype varchar(1) not null,
  datasourcename varchar(40) not null,
  userid         numeric(19,0) default 0 not null,
  updtime        DATE,
  remark         varchar(200),
  published      numeric(1,0) default 0 not null,
  dictobjid      numeric(19,0) default 0 not null,
  dictuiid       numeric(19,0) default 0 not null,
  menuid         numeric(19,0) default 0 not null,
  description    text
);
alter table RPT_SET_MAIN
  add constraint PK_RPT_SET_MAIN primary key (ID,usercode);

--入参表
create table RPT_SET_PARA
(
  id           numeric(19,0) default 0 not null,
  rptid        numeric(19,0) default 0 not null,
  serialno     numeric(19,0) default 0 not null,
  fieldname    varchar(40) not null,
  propname     varchar(40) not null,
  proptype     varchar(1) default 0 not null,
  iotype       varchar(1) default 0 not null,
  reftype      varchar(1) default 0 not null,
  refdataobj   varchar(40),
  reffield     varchar(40),
  refnamefield varchar(40),
  refcondition varchar(500),
  defaultvalue varchar(100)
);
create unique index IDX_RPT_SET_PARA on RPT_SET_PARA (RPTID, SERIALNO);

--数据集字段表
create table RPT_SET_COLUMN
(
  id         numeric(19,0) default 0 not null,
  rptid      numeric(19,0) default 0 not null,
  serialno   numeric(19,0) default 0 not null,
  fieldname  varchar(40) not null,
  fieldlabel varchar(40) not null,
  fieldtype  varchar(1) default 0 not null,
  fieldwidth numeric(4,0) not null,
  stattype   numeric(11,0) default 0 not null
);
create unique index IDX_RPT_SET_COLUMN on RPT_SET_COLUMN (RPTID, SERIALNO);

--枚举主表
create table RPT_SET_ENUM
(
  id           numeric(20,0) not null,
  gmt_create   DATE not null,
  gmt_modified DATE not null,
  code         Nvarchar(100) not null,
  name         Nvarchar(200) not null,
  remark       Nvarchar(500)
);
create unique index IDX_RPTSETENUM on RPT_SET_ENUM (CODE);

--枚举明细表
create table RPT_SET_ENUM_ITEM
(
  id           numeric(20,0) not null,
  gmt_create   DATE not null,
  gmt_modified DATE not null,
  p_id         numeric(20,0) not null,
  code         Nvarchar(100) not null,
  name         Nvarchar(200) not null,
  remark       Nvarchar(500)
);
create unique index IDX_RPTSETENUMITEM on RPT_SET_ENUM_ITEM (P_ID, CODE);

--图表设置表
create table DICT_CHART
(
  id          numeric(20,0) not null,
  dict_id     numeric(20,0) not null,
  serialno    numeric(10,0) default 0 not null,
  charttype   varchar(2) not null,
  chartoption text
);
alter table DICT_CHART
  add constraint PK_DICT_CHART primary key (ID);