create table wash_customer
(
    id                         bigint auto_increment
        primary key,
    band                       varchar(255)  null,
    name                       varchar(255)  not null,
    code                       varchar(255)  not null,
    license_plate              varchar(255)  null,
    driver                     varchar(255)  null,
    default_factory_area_id    bigint        not null,
    customer_service_personnel varchar(255)  null,
    room_count                 int           null,
    bed_count                  int           null,
    province                   varchar(255)  null,
    city                       varchar(255)  null,
    district                   varchar(255)  null,
    address                    varchar(1000) null,
    lng                        double        null,
    lat                        double        null,
    create_time                datetime      not null,
    update_time                datetime      not null,
    status                     int default 0 not null,
    constraint code_unique_index
        unique (code)
);

create table wash_factory
(
    id          bigint auto_increment
        primary key,
    name        varchar(255)  not null,
    province    varchar(255)  null,
    city        varchar(255)  null,
    district    varchar(255)  null,
    address     varchar(1000) null,
    lng         double        null,
    lat         double        null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int default 0 not null
);

create table wash_factory_area
(
    id          bigint auto_increment
        primary key,
    factory_id  bigint        not null,
    name        varchar(255)  not null,
    province    varchar(255)  null,
    city        varchar(255)  null,
    district    varchar(255)  null,
    address     varchar(1000) null,
    lng         double        null,
    lat         double        null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int default 0 not null
);

create table wash_linen
(
    id      bigint auto_increment
        primary key,
    type_id bigint        not null,
    sort    int default 0 not null,
    name    varchar(255)  not null,
    remark  varchar(255)  null,
    status  int default 0 not null
);

create table wash_linen_type
(
    id     bigint auto_increment
        primary key,
    sort   int default 0 not null,
    name   varchar(255)  not null,
    remark varchar(255)  null,
    status int default 0 not null
);

create table wash_order
(
    id                      bigint auto_increment
        primary key,
    order_no                varchar(64)   not null,
    order_status            varchar(32)   not null,
    customer_id             bigint        not null,
    customer_name           varchar(255)  null,
    customer_code           varchar(255)  null,
    default_factory_area_id bigint        not null,
    factory_area_id         bigint        not null,
    factory_area_name       varchar(255)  null,
    create_user_id          bigint        not null,
    create_user_name        varchar(255)  null,
    execute_user_id         bigint        null,
    execute_user_name       varchar(255)  null,
    create_time             datetime      not null,
    update_time             datetime      not null,
    finish_time             datetime      null,
    finish_status           int default 0 not null,
    floor_count             int           null,
    order_data              json          not null,
    status                  int default 0 not null
);

create table wash_order_operation_enum
(
    id                bigint auto_increment
        primary key,
    name              varchar(255)  not null,
    order_operation   varchar(32)   not null,
    prev_order_status varchar(32)   null,
    next_order_status varchar(32)   null,
    remark            varchar(255)  null,
    status            int default 0 not null,
    constraint order_operation_unique_index
        unique (order_operation)
);

create table wash_order_operation_log
(
    id                bigint auto_increment
        primary key,
    order_no          varchar(64)  not null,
    order_operation   varchar(32)  not null,
    operate_user_id   bigint       not null,
    operate_user_name varchar(255) null,
    operate_time      datetime     not null
);

create table wash_order_status_enum
(
    id               bigint auto_increment
        primary key,
    order_status     varchar(32)             not null,
    order_operations varchar(255) default '' not null,
    name             varchar(255)            not null,
    remark           varchar(255)            null,
    status           int          default 0  not null,
    constraint order_status_unique_index
        unique (order_status)
);

create table wash_organization
(
    id          bigint auto_increment
        primary key,
    parent_id   bigint        null,
    name        varchar(255)  not null,
    remark      varchar(255)  null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int default 0 not null
);

create table wash_permission
(
    id          bigint auto_increment
        primary key,
    code        varchar(255)  not null,
    name        varchar(255)  not null,
    remark      varchar(255)  null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int default 0 not null
);

create table wash_role
(
    id          bigint auto_increment
        primary key,
    name        varchar(255)  not null,
    remark      varchar(255)  null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int default 0 not null
);

create table wash_role_ref_permission
(
    id            bigint auto_increment
        primary key,
    role_id       bigint not null,
    permission_id bigint not null
);

create index role_id_index
    on wash_role_ref_permission (role_id);

create table wash_user
(
    id              bigint auto_increment
        primary key,
    ssid            varchar(64)                                            null,
    package_name    varchar(128) default 'cn.com.devotiondigital.xiyuejia' not null,
    phone           varchar(32)                                            null,
    account         varchar(32)                                            null,
    nickname        varchar(255)                                           null,
    remark          varchar(255)                                           null,
    organization_id bigint                                                 null,
    create_time     datetime                                               not null,
    update_time     datetime                                               not null,
    status          int          default 0                                 not null
);

create table wash_user_ref_role
(
    id      bigint auto_increment
        primary key,
    user_id bigint not null,
    role_id bigint not null
);

create index role_id_index
    on wash_user_ref_role (role_id);

create index user_id_index
    on wash_user_ref_role (user_id);

