CREATE TABLE IF NOT EXISTS "mes_bom"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "code"        varchar  NOT NULL,
    "version"     varchar  NOT NULL,
    "product_id"  bigint   NOT NULL,
    "unit_id"     bigint   NOT NULL,
    "yield_rate"  varchar,
    "remark"      varchar,
    "is_enable"   bit      NOT NULL,
    "creator"     varchar           DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"     bit      NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint,
    PRIMARY KEY ("id")
) COMMENT '产品BOM表';

CREATE TABLE IF NOT EXISTS "mes_bom_detail"
(
    "id"           bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "product_id"   bigint   NOT NULL,
    "unit_id"      bigint   NOT NULL,
    "bom_id"       bigint   NOT NULL,
    "usage_number" varchar  NOT NULL,
    "yield_rate"   varchar,
    "remark"       varchar,
    "is_enable"    bit,
    "creator"      varchar           DEFAULT '',
    "create_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"      varchar           DEFAULT '',
    "update_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"      bit      NOT NULL DEFAULT FALSE,
    "tenant_id"    bigint,
    PRIMARY KEY ("id")
) COMMENT '产品BOM明细表';

CREATE TABLE IF NOT EXISTS "mes_organization"
(
    "id"             bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"           varchar  NOT NULL,
    "parent_id"      bigint   NOT NULL,
    "sort"           int      NOT NULL,
    "worker_user_id" bigint,
    "machine_id"     bigint,
    "phone"          varchar,
    "email"          varchar,
    "is_enable"      bit      NOT NULL,
    "status"         varchar,
    "org_class"      varchar,
    "org_type"       varchar,
    "creator"        varchar           DEFAULT '',
    "create_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"        varchar           DEFAULT '',
    "update_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"        bit      NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint,
    PRIMARY KEY ("id")
) COMMENT '工厂组织表';
CREATE TABLE IF NOT EXISTS "mes_task"
(
    "id"                  bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "code"                varchar  NOT NULL,
    "order_date"          varchar,
    "delivery_date"       varchar  NOT NULL,
    "status"              int      NOT NULL,
    "process_instance_id" varchar,
    "remark"              varchar,
    "is_enable"           bit      NOT NULL,
    "creator"             varchar           DEFAULT '',
    "create_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"             varchar           DEFAULT '',
    "update_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"             bit      NOT NULL DEFAULT FALSE,
    "tenant_id"           bigint,
    PRIMARY KEY ("id")
) COMMENT '生产任务单';
CREATE TABLE IF NOT EXISTS "mes_task_detail"
(
    "id"                bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "product_id"        bigint   NOT NULL,
    "unit_id"           bigint   NOT NULL,
    "task_id"           bigint   NOT NULL,
    "number"            bigint   NOT NULL,
    "package_size"      bigint   NOT NULL,
    "project_name"      varchar,
    "tech_requirements" varchar,
    "remark"            varchar,
    "is_enable"         bit,
    "creator"           varchar           DEFAULT '',
    "create_time"       datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"           varchar           DEFAULT '',
    "update_time"       datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"           bit      NOT NULL DEFAULT FALSE,
    "tenant_id"         bigint,
    PRIMARY KEY ("id")
) COMMENT '生产任务单明细';
CREATE TABLE IF NOT EXISTS "mes_plan"
(
    "id"                    bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "code"                  varchar,
    "product_id"            bigint   NOT NULL,
    "task_detail_id"        bigint   NOT NULL,
    "task_id"               bigint   NOT NULL,
    "plan_number"           bigint   NOT NULL,
    "finish_number"         bigint,
    "status"                int      NOT NULL,
    "plan_start_time"       varchar  NOT NULL,
    "plan_end_time"         varchar  NOT NULL,
    "start_time"            varchar  NOT NULL,
    "end_time"              varchar  NOT NULL,
    "production_manager_id" bigint,
    "remark"                varchar,
    "is_enable"             bit,
    "creator"               varchar           DEFAULT '',
    "create_time"           datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"               varchar           DEFAULT '',
    "update_time"           datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"               bit      NOT NULL DEFAULT FALSE,
    "tenant_id"             bigint,
    PRIMARY KEY ("id")
) COMMENT '生产计划';
CREATE TABLE IF NOT EXISTS "mes_item_requisition_detail"
(
    "id"                  bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "product_id"          bigint   NOT NULL,
    "unit_id"             bigint   NOT NULL,
    "item_requisition_id" bigint   NOT NULL,
    "number"              varchar,
    "remark"              varchar,
    "is_enable"           bit,
    "creator"             varchar           DEFAULT '',
    "create_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"             varchar           DEFAULT '',
    "update_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"             bit      NOT NULL DEFAULT FALSE,
    "tenant_id"           bigint,
    PRIMARY KEY ("id")
) COMMENT '领料明细';

CREATE TABLE IF NOT EXISTS "mes_item_requisition"
(
    "id"                  bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "code"                varchar  NOT NULL,
    "requisition_date"    varchar,
    "delivery_date"       varchar,
    "status"              int,
    "process_instance_id" varchar,
    "plan_id"             bigint   NOT NULL,
    "remark"              varchar,
    "is_enable"           bit      NOT NULL,
    "creator"             varchar           DEFAULT '',
    "create_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"             varchar           DEFAULT '',
    "update_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"             bit      NOT NULL DEFAULT FALSE,
    "tenant_id"           bigint,
    PRIMARY KEY ("id")
) COMMENT '生产领料';
CREATE TABLE IF NOT EXISTS "mes_record_template"
(
    "id"                             bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"                           varchar  NOT NULL,
    "organization_id"                bigint   NOT NULL,
    "machine_id"                     bigint,
    "work_team_id"                   bigint,
    "start_time"                     varchar  NOT NULL,
    "end_time"                       varchar  NOT NULL,
    "group_manager_approve_id1"      bigint,
    "group_manager_approve_id2"      bigint,
    "production_manager_approve_id1" bigint,
    "production_manager_approve_id2" bigint,
    "process_instance_id"            varchar,
    "status"                         int      NOT NULL,
    "record_type"                    varchar  NOT NULL,
    "remark"                         varchar,
    "is_enable"                      bit,
    "creator"                        varchar           DEFAULT '',
    "create_time"                    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"                        varchar           DEFAULT '',
    "update_time"                    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"                        bit      NOT NULL DEFAULT FALSE,
    "tenant_id"                      bigint,
    PRIMARY KEY ("id")
) COMMENT '记录表模板';
CREATE TABLE IF NOT EXISTS "mes_record_chengxing"
(
    "id"             bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "record_id"      bigint   NOT NULL,
    "start_time"     varchar,
    "end_time"       varchar,
    "xijiang"        int      NOT NULL,
    "tuoshui"        int      NOT NULL,
    "ximu"           int      NOT NULL,
    "product_id"     bigint   NOT NULL,
    "appearance"     varchar  NOT NULL,
    "product_weight" varchar  NOT NULL,
    "remark"         varchar,
    "is_enable"      bit,
    "creator"        varchar           DEFAULT '',
    "create_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"        varchar           DEFAULT '',
    "update_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"        bit      NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint,
    PRIMARY KEY ("id")
) COMMENT '成型记录表';
CREATE TABLE IF NOT EXISTS "mes_record_suijiang"
(
    "id"                 bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "record_id"          bigint   NOT NULL,
    "start_time"         varchar  NOT NULL,
    "end_time"           varchar  NOT NULL,
    "suijiang_time"      varchar  NOT NULL,
    "suijiang_cost_time" varchar,
    "ratio_id"           bigint,
    "ratio"              varchar,
    "water_usage"        varchar,
    "density_out"        varchar,
    "add_item_usage"     varchar,
    "slag_yield"         varchar,
    "density"            varchar,
    "remark"             varchar,
    "is_enable"          bit      NOT NULL,
    "creator"            varchar           DEFAULT '',
    "create_time"        datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"            varchar           DEFAULT '',
    "update_time"        datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"            bit      NOT NULL DEFAULT FALSE,
    "tenant_id"          bigint,
    PRIMARY KEY ("id")
) COMMENT '碎浆记录表';

CREATE TABLE IF NOT EXISTS "mes_work_team"
(
    "id"             bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "team_name"      varchar,
    "team_leader_id" bigint   NOT NULL,
    "team_type"      varchar,
    "remark"         varchar,
    "is_enable"      bit      NOT NULL,
    "creator"        varchar           DEFAULT '',
    "create_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"        varchar           DEFAULT '',
    "update_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"        bit      NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint,
    PRIMARY KEY ("id")
) COMMENT '生产班组';
CREATE TABLE IF NOT EXISTS "mes_work_team_detail"
(
    "id"           bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "work_team_id" bigint,
    "user_id"      bigint   NOT NULL,
    "user_role"    int      NOT NULL,
    "remark"       varchar,
    "creator"      varchar           DEFAULT '',
    "create_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"      varchar           DEFAULT '',
    "update_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"      bit      NOT NULL DEFAULT FALSE,
    "tenant_id"    bigint,
    PRIMARY KEY ("id")
) COMMENT '班组成员';
CREATE TABLE IF NOT EXISTS "mes_produce_report"
(
    "id"                  bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "process_instance_id" varchar,
    "report_code"         varchar,
    "user_id"             bigint   NOT NULL,
    "org_id"              bigint   NOT NULL,
    "org_type"            varchar,
    "report_time"         varchar,
    "total_time"          varchar,
    "report_status"       int,
    "remark"              varchar,
    "creator"             varchar           DEFAULT '',
    "create_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"             varchar           DEFAULT '',
    "update_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"             bit      NOT NULL DEFAULT FALSE,
    "tenant_id"           bigint,
    "group_type"          int,
    "report_type"         varchar,
    "report_date"         varchar,
    PRIMARY KEY ("id")
) COMMENT '生产报工单';


CREATE TABLE IF NOT EXISTS "mes_produce_report_detail"
(
    "id"             bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "report_id"      bigint,
    "plan_id"        bigint   NOT NULL,
    "product_id"     bigint   NOT NULL,
    "user_id"        bigint   NOT NULL,
    "org_id"         bigint   NOT NULL,
    "quality_rate"   varchar,
    "waste_reason"   varchar,
    "total_time"     varchar,
    "package_number" varchar,
    "remark"         varchar,
    "is_enable"      bit      NOT NULL,
    "creator"        varchar           DEFAULT '',
    "create_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"        varchar           DEFAULT '',
    "update_time"    datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"        bit      NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint,
    "quality_number" varchar,
    "waste_number"   varchar,
    "total_number"   varchar,
    "report_date"    varchar,
    "report_time"    varchar,
    "report_status"  int,
    PRIMARY KEY ("id")
) COMMENT '生产报工明细';

CREATE TABLE IF NOT EXISTS "mes_machine_component"
(
    "id"              bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"            varchar  NOT NULL,
    "parent_id"       bigint   NOT NULL,
    "sort"            int      NOT NULL,
    "org_id"          bigint   NOT NULL,
    "serial_code"     varchar,
    "outgoing_time"   varchar,
    "outgoing_report" varchar,
    "position"        varchar,
    "standard"        varchar,
    "remark"          varchar,
    "creator"         varchar           DEFAULT '',
    "create_time"     datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"         varchar           DEFAULT '',
    "update_time"     datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"         bit      NOT NULL DEFAULT FALSE,
    "tenant_id"       bigint,
    "status"          int      NOT NULL,
    "component_type"  int      NOT NULL,
    "machine_type"    varchar,
    PRIMARY KEY ("id")
) COMMENT '机台组织表';

CREATE TABLE IF NOT EXISTS "mes_feeding_record"
(
    "id"                  bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "feeding_record_code" varchar,
    "product_id"          bigint,
    "plan_id"             bigint,
    "item_id"             bigint,
    "feeding_pipeline"    varchar,
    "feeding_type"        varchar,
    "weight"              varchar,
    "feeding_time"        varchar,
    "user_id"             bigint,
    "remark"              varchar,
    "record_status"       varchar,
    "creator"             varchar           DEFAULT '',
    "create_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"             varchar           DEFAULT '',
    "update_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"             bit      NOT NULL DEFAULT FALSE,
    "tenant_id"           bigint,
    PRIMARY KEY ("id")
) COMMENT '投料记录';
CREATE TABLE IF NOT EXISTS "mes_stock_workshop"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "item_id"     bigint   NOT NULL,
    "count"       varchar  NOT NULL,
    "category_id" bigint,
    "creator"     varchar           DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"     bit      NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint,
    PRIMARY KEY ("id")
) COMMENT '车间仓库存';
CREATE TABLE IF NOT EXISTS "mes_stock_workshop_detail"
(
    "id"                         bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "item_id"                    bigint   NOT NULL,
    "count"                      varchar  NOT NULL,
    "detail_type"                varchar,
    "item_requisition_code"      varchar,
    "item_requisition_detail_id" bigint,
    "feeding_record_code"        varchar,
    "feeding_record_id"          bigint,
    "user_id"                    bigint   NOT NULL,
    "operate_time"               varchar,
    "creator"                    varchar           DEFAULT '',
    "create_time"                datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"                    varchar           DEFAULT '',
    "update_time"                datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"                    bit      NOT NULL DEFAULT FALSE,
    "tenant_id"                  bigint,
    PRIMARY KEY ("id")
) COMMENT '车间仓出入库明细';

CREATE TABLE IF NOT EXISTS "mes_feeding_record_plan"
(
    "id"               bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "record_id"        bigint,
    "record_detail_id" bigint,
    "plan_id"          bigint,
    "item_id"          bigint,
    "weight"           varchar,
    "unit_id"          bigint,
    "user_id"          bigint,
    "feeding_time"     varchar,
    "creator"          varchar           DEFAULT '',
    "create_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"          varchar           DEFAULT '',
    "update_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"          bit      NOT NULL DEFAULT FALSE,
    "tenant_id"        bigint,
    PRIMARY KEY ("id")
) COMMENT '投料记录分配计划';

CREATE TABLE IF NOT EXISTS "mes_feeding_record_detail"
(
    "id"           bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "record_id"    bigint,
    "item_id"      bigint,
    "weight"       varchar,
    "unit_id"      bigint,
    "user_id"      bigint,
    "feeding_time" varchar,
    "creator"      varchar           DEFAULT '',
    "create_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"      varchar           DEFAULT '',
    "update_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"      bit      NOT NULL DEFAULT FALSE,
    "tenant_id"    bigint,
    PRIMARY KEY ("id")
) COMMENT '投料记录明细';

CREATE TABLE IF NOT EXISTS "mes_error_record"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "title"       varchar,
    "location"    varchar,
    "exception"   varchar,
    "pre_data"    varchar,
    "post_data"   varchar,
    "creator"     varchar           DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"     bit      NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint   NOT NULL,
    PRIMARY KEY ("id")
) COMMENT '错误记录';
CREATE TABLE IF NOT EXISTS "mes_stock_in_detail"
(
    "id"               bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "stock_in_id"      bigint,
    "stock_in_no"      varchar,
    "stock_in_item_id" bigint,
    "plan_id"          bigint,
    "product_id"       bigint,
    "number"           varchar,
    "creator"          varchar           DEFAULT '',
    "create_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"          varchar           DEFAULT '',
    "update_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"          bit      NOT NULL DEFAULT FALSE,
    "tenant_id"        bigint   NOT NULL,
    PRIMARY KEY ("id")
) COMMENT '生产入库分配明细';


CREATE TABLE IF NOT EXISTS "mes_org_worker"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "org_id"      bigint   NOT NULL,
    "work_date"   varchar  NOT NULL,
    "group_type"  int      NOT NULL,
    "worker_id"   bigint   NOT NULL,
    "report_id"   bigint,
    "creator"     varchar           DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"     bit      NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint   NULL,
    PRIMARY KEY ("id")
) COMMENT '工位安排表';

CREATE TABLE IF NOT EXISTS "mes_work_report_plan"
(
    "id"                  bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "report_id"           bigint,
    "plan_id"             bigint,
    "product_id"          bigint,
    "quality_number_plan" varchar,
    "waste_number_plan"   varchar,
    "report_time_plan"    varchar,
    "total_time_plan"     varchar,
    "creator"             varchar           DEFAULT '',
    "create_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"             varchar           DEFAULT '',
    "update_time"         datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"             bit      NOT NULL DEFAULT FALSE,
    "tenant_id"           bigint   NULL,
    PRIMARY KEY ("id")
) COMMENT '报工分配计划';
CREATE TABLE IF NOT EXISTS "mes_produce_report_change_record"
(
    "id"            bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "report_id"     bigint,
    "change_type"   varchar,
    "before_change" varchar,
    "after_change"  varchar,
    "creator"       varchar           DEFAULT '',
    "create_time"   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"       varchar           DEFAULT '',
    "update_time"   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"       bit      NOT NULL DEFAULT FALSE,
    "tenant_id"     bigint   NULL,
    PRIMARY KEY ("id")
) COMMENT '报工变更记录';


CREATE TABLE IF NOT EXISTS "mes_energy_device"
(
    "id"               bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"             varchar,
    "code"             varchar,
    "device_type"      varchar,
    "info"             varchar,
    "check_cron"       varchar,
    "last_check_time"  varchar,
    "last_check_value" varchar,
    "unit_name"        varchar,
    "is_enable"        bit      NOT NULL,
    "creator"          varchar           DEFAULT '',
    "create_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"          varchar           DEFAULT '',
    "update_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"          bit      NOT NULL DEFAULT FALSE,
    "tenant_id"        bigint,
    PRIMARY KEY ("id")
) COMMENT '能源设备';
CREATE TABLE IF NOT EXISTS "mes_energy_device_check_record"
(
    "id"               bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "device_id"        bigint   NOT NULL,
    "last_check_time"  varchar,
    "last_check_value" varchar,
    "check_value"      varchar  NOT NULL,
    "check_time"       varchar,
    "diff_value"       varchar,
    "unit_price"       varchar,
    "remark"           varchar,
    "creator"          varchar           DEFAULT '',
    "create_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"          varchar           DEFAULT '',
    "update_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"          bit      NOT NULL DEFAULT FALSE,
    "tenant_id"        bigint,
    PRIMARY KEY ("id")
) COMMENT '抄表记录';


CREATE TABLE IF NOT EXISTS "mes_mold_record"
(
    "id"            bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "flow_code"     varchar,
    "brand_id"      bigint   NOT NULL,
    "mold_id"       bigint   NOT NULL,
    "old_mold_id"   bigint,
    "machine_id"    bigint,
    "user_id"       bigint   NOT NULL,
    "record_type"   varchar  NOT NULL,
    "record_status" varchar  NOT NULL,
    "remark"        varchar  NOT NULL,
    "creator"       varchar           DEFAULT '',
    "create_time"   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"       varchar           DEFAULT '',
    "update_time"   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"       bit      NOT NULL DEFAULT FALSE,
    "tenant_id"     bigint,
    PRIMARY KEY ("id")
) COMMENT '模具维保';
CREATE TABLE IF NOT EXISTS "mes_mold_record_subject"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "subject"     varchar  NOT NULL,
    "expect"      varchar,
    "creator"     varchar           DEFAULT '',
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"     bit      NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint,
    PRIMARY KEY ("id")
) COMMENT '维保项目';
CREATE TABLE IF NOT EXISTS "mes_mold_record_subject_detail"
(
    "id"            bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "subject"       varchar,
    "expect"        varchar,
    "result"        varchar,
    "detail_status" varchar,
    "creator"       varchar           DEFAULT '',
    "create_time"   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"       varchar           DEFAULT '',
    "update_time"   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"       bit      NOT NULL DEFAULT FALSE,
    "tenant_id"     bigint,
    "record_id"     bigint,
    PRIMARY KEY ("id")
) COMMENT '模具维保明细';

CREATE TABLE IF NOT EXISTS "mes_dv_subject"
(
    "id"               bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "subject_code"     varchar  NOT NULL,
    "subject_name"     varchar  NOT NULL,
    "subject_type"     varchar,
    "subject_content"  varchar  NOT NULL,
    "subject_standard" varchar,
    "is_enable"        bit      NOT NULL,
    "creator"          varchar           DEFAULT '',
    "create_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"          varchar           DEFAULT '',
    "update_time"      datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"          bit      NOT NULL DEFAULT FALSE,
    "tenant_id"        bigint,
    PRIMARY KEY ("id")
) COMMENT '点检项目表';
CREATE TABLE IF NOT EXISTS "mes_dv_repair"
(
    "id"                bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "repair_code"       varchar  NOT NULL,
    "repair_name"       varchar,
    "machinery_id"      bigint   NOT NULL,
    "machinery_code"    varchar  NOT NULL,
    "machinery_name"    varchar  NOT NULL,
    "machinery_brand"   varchar,
    "machinery_spec"    varchar,
    "machinery_type_id" bigint   NOT NULL,
    "require_date"      varchar,
    "finish_date"       varchar,
    "confirm_date"      varchar,
    "repair_result"     varchar,
    "accepted_by"       varchar,
    "confirm_by"        varchar,
    "status"            varchar,
    "remark"            varchar,
    "creator"           varchar           DEFAULT '',
    "create_time"       datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"           varchar           DEFAULT '',
    "update_time"       datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"           bit      NOT NULL DEFAULT FALSE,
    "tenant_id"         bigint,
    PRIMARY KEY ("id")
) COMMENT '设备维修记录表';
CREATE TABLE IF NOT EXISTS "mes_dv_check"
(
    "id"           bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "plan_code"    varchar  NOT NULL,
    "plan_name"    varchar,
    "plan_type"    varchar  NOT NULL,
    "start_date"   varchar,
    "end_date"     varchar,
    "status"       varchar,
    "remark"       varchar,
    "is_enable"    bit      NOT NULL,
    "creator"      varchar           DEFAULT '',
    "create_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"      varchar           DEFAULT '',
    "update_time"  datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted"      bit      NOT NULL DEFAULT FALSE,
    "tenant_id"    bigint,
    "cycle_unit"   varchar,
    "cycle_count"  varchar,
    "plan_level"   varchar,
    "last_time"    varchar,
    "formula_code" varchar,
    PRIMARY KEY ("id")
) COMMENT '点检计划表';
