
CREATE TABLE PARTY_STRUCT(
        STRUCT_TYPE_ID BIGINT NOT NULL,
        PARENT_ENTITY_ID BIGINT NOT NULL,
        CHILD_ENTITY_ID BIGINT NOT NULL,
	PRIORITY INTEGER,
	STATUS INTEGER,
	DIM_ID BIGINT,
	SCOPE_ID VARCHAR(50),
        CONSTRAINT PK_PARTY_STRUCT PRIMARY KEY(STRUCT_TYPE_ID,PARENT_ENTITY_ID,CHILD_ENTITY_ID),
        CONSTRAINT FK_PARTY_STRUCT_TYPE FOREIGN KEY(STRUCT_TYPE_ID) REFERENCES PARTY_STRUCT_TYPE(ID),
        CONSTRAINT FK_PARTY_STRUCT_PARENT FOREIGN KEY(PARENT_ENTITY_ID) REFERENCES PARTY_ENTITY(ID),
        CONSTRAINT FK_PARTY_STRUCT_CHILD FOREIGN KEY(CHILD_ENTITY_ID) REFERENCES PARTY_ENTITY(ID),
        CONSTRAINT FK_PARTY_STRUCT_DIM FOREIGN KEY(DIM_ID) REFERENCES PARTY_DIM(ID)
);

COMMENT ON TABLE PARTY_STRUCT IS '组织关系';
COMMENT ON COLUMN PARTY_STRUCT.STRUCT_TYPE_ID IS '外键，组织关系类型';
COMMENT ON COLUMN PARTY_STRUCT.PARENT_ENTITY_ID IS '外键，上级实体';
COMMENT ON COLUMN PARTY_STRUCT.CHILD_ENTITY_ID IS '外键，下级实体';
COMMENT ON COLUMN PARTY_STRUCT.PRIORITY IS '排序';
COMMENT ON COLUMN PARTY_STRUCT.STATUS IS '状态';
COMMENT ON COLUMN PARTY_STRUCT.SCOPE_ID IS '租户';
