CREATE TABLE `erp_autocode_rule`
(
    `id`            bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `rule_code`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '规则编码',
    `rule_name`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '规则名称',
    `rule_desc`     varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '描述',
    `max_length`    int                                                           DEFAULT NULL COMMENT '最大长度',
    `is_padded`     char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci     DEFAULT '' COMMENT '是否补齐',
    `padded_char`   varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '补齐字符',
    `padded_method` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci     DEFAULT 'L' COMMENT '补齐方式',
    `remark`        varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci DEFAULT '' COMMENT '备注',
    `is_enable`     bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time`   datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time`   datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`       bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`     bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='编码规则表';

CREATE TABLE `erp_autocode_part`
(
    `id`              bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `rule_id`         bigint   NOT NULL COMMENT '规则ID',
    `part_index`      int      NOT NULL COMMENT '分段序号',
    `part_type`       varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '分段类型，INPUTCHAR：输入字符，NOWDATE：当前日期时间，FIXCHAR：固定字符，SERIALNO：流水号',
    `part_code`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '分段编号',
    `part_name`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '分段名称',
    `part_length`     int      NOT NULL COMMENT '分段长度',
    `datetime_format` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '日期时间格式',
    `input_character` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '输入字符',
    `fix_character`   varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '固定字符',
    `seria_start_no`  int                                                           DEFAULT NULL COMMENT '流水号起始值',
    `seria_step`      int                                                           DEFAULT NULL COMMENT '流水号步长',
    `seria_now_no`    int                                                           DEFAULT NULL COMMENT '流水号当前值',
    `cycle_flag`      char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci      DEFAULT '' COMMENT '流水号是否循环',
    `cycle_method`    varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '循环方式，YEAR：按年，MONTH：按月，DAY：按天，HOUR：按小时，MINITE：按分钟，OTHER：按传入字符变',
    `remark`          varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci DEFAULT '' COMMENT '备注',
    `is_enable`       bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time`     datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time`     datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`         bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`       bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=71 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='编码规则组成表';

CREATE TABLE `erp_autocode_record`
(
    `id`              bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `rule_id`         bigint   NOT NULL COMMENT '规则ID',
    `gen_date`        varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '生成日期时间',
    `gen_index`       int                                                           DEFAULT NULL COMMENT '最后产生的序号',
    `last_result`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '最后产生的值',
    `last_serial_no`  int                                                           DEFAULT NULL COMMENT '最后产生的流水号',
    `last_input_char` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '最后传入的参数',
    `remark`          varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `is_enable`       bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time`     datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time`     datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`         bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`       bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='编码生成记录表';

CREATE TABLE `erp_mold_brand`
(
    `id`            bigint                                                        NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `code`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci  NOT NULL COMMENT '型号编码',
    `name`          varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT '型号名称',
    `mold_type`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT '规格',
    `product_id`    bigint                                                        NOT NULL COMMENT '产品ID',
    `use_time`      decimal(24, 6)                                                         DEFAULT NULL COMMENT '预期寿命(小时)',
    `maintain_type` tinyint                                                                DEFAULT '0' COMMENT '维保模式',
    `maintain_time` decimal(24, 6)                                                         DEFAULT NULL COMMENT '维保周期',
    `mold_size`     bigint                                                        NOT NULL COMMENT '模具系数',

    `remark`        varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '备注',
    `is_enable`     bit(1)                                                        NOT NULL DEFAULT b'1' COMMENT '是否启用',
    `creator`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci           DEFAULT '' COMMENT '创建者',
    `create_time`   datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci           DEFAULT '' COMMENT '更新者',
    `update_time`   datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`       bit(1)                                                        NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`     bigint                                                                 DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='模具型号表';

CREATE TABLE `erp_mold`
(
    `id`          bigint                                                        NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `code`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci  NOT NULL COMMENT '模具编码',
    `name`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT '模具名称',
    `unit_id`     bigint                                                        NOT NULL COMMENT '单位ID',
    `brand_id`     bigint                                                        NOT NULL COMMENT '型号ID',
    `machine_id`  bigint                                                        NOT NULL COMMENT '机台ID',
    `use_time`    decimal(24, 6)                                                DEFAULT NULL COMMENT '使用时间(小时)',
    `in_time`     datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入库时间',
    `status` tinyint                                                                DEFAULT '0' COMMENT '状态',
    `images`      varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT '模具图片',
    `remark`      varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '备注',
    `is_enable`   bit(1)                                                        NOT NULL DEFAULT b'1' COMMENT '是否启用',
    `creator`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci           DEFAULT '' COMMENT '创建者',
    `create_time` datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci           DEFAULT '' COMMENT '更新者',
    `update_time` datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`     bit(1)                                                        NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`   bigint                                                                 DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='模具表';



CREATE TABLE `mes_bom`
(
    `id`          bigint                                                        NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `code`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci  NOT NULL COMMENT 'BOM编码',
    `version`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT 'BOM版本',
    `product_id`  bigint                                                        NOT NULL COMMENT '产品ID',
    `unit_id`     bigint                                                        NOT NULL COMMENT '单位ID',
    `yield_rate`  decimal(24, 6)                                                         DEFAULT NULL COMMENT '成品率%',

    `remark`      varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '备注',
    `is_enable`   bit(1)                                                        NOT NULL DEFAULT b'1' COMMENT '是否启用',
    `creator`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci           DEFAULT '' COMMENT '创建者',
    `create_time` datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci           DEFAULT '' COMMENT '更新者',
    `update_time` datetime                                                      NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`     bit(1)                                                        NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`   bigint                                                                 DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='产品BOM表';

CREATE TABLE `mes_bom_detail`
(
    `id`          bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `product_id`  bigint   NOT NULL COMMENT '产品ID',
    `unit_id`     bigint   NOT NULL COMMENT '单位ID',
    `bom_id`      bigint   NOT NULL COMMENT 'BOM ID',
    `usage`       decimal(24, 6)                                                DEFAULT NULL COMMENT '用量',
    `yield_rate`  decimal(24, 6)                                                DEFAULT NULL COMMENT '损耗率%',

    `remark`      varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `is_enable`   bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time` datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time` datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`     bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`   bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='产品BOM明细表';


CREATE TABLE `mes_task`
(
    `id`                  bigint                                                       NOT NULL AUTO_INCREMENT COMMENT 'ID',

    `code`                varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT '编码',
    `order_date`          date COMMENT '创建时间',
    `delivery_date`       date COMMENT '创建时间',
    `status`              tinyint                                                               DEFAULT '0' COMMENT '状态',
    `process_instance_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT NULL COMMENT '流程实例的编号',

    `remark`              varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci         DEFAULT '' COMMENT '备注',
    `is_enable`           bit(1)                                                       NOT NULL DEFAULT b'1' COMMENT '是否启用',
    `creator`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '创建者',
    `create_time`         datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '更新者',
    `update_time`         datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`             bit(1)                                                       NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`           bigint                                                                DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='生产任务单';

CREATE TABLE `mes_task_detail`
(
    `id`                bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `product_id`        bigint   NOT NULL COMMENT '产品ID',
    `unit_id`           bigint   NOT NULL COMMENT '单位ID',
    `task_id`           bigint   NOT NULL COMMENT 'task ID',
    `number`            bigint   NOT NULL COMMENT '数量',
    `package_size`      bigint   NOT NULL COMMENT '打包要求(每包/个)',

    `project_name`      varchar(56) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '项目名称',
    `tech_requirements` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '技术要求',

    `remark`            varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `is_enable`         bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='生产任务单明细';

CREATE TABLE `mes_plan`
(
    `id`                bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `code`      varchar(56) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '计划编码',
    `product_id`        bigint   NOT NULL COMMENT '产品ID',
    `task_detail_id`    bigint   NOT NULL COMMENT '任务单明细ID',
    `task_id`           bigint   NOT NULL COMMENT '任务单ID',
    `plan_number`       bigint   NOT NULL COMMENT '数量',
    `finish_number`       bigint   NOT NULL COMMENT '成品数量',
    `status`            tinyint                                                               DEFAULT '0' COMMENT '状态',
    `plan_start_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '计划开始时间',
    `plan_end_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '计划结束时间',
    `start_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '实际开始时间',
    `end_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '实际结束时间',

    `production_manager_id` bigint NOT NULL COMMENT '生产主管ID',

    `remark`            varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `is_enable`         bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='生产计划';



CREATE TABLE `mes_item_requisition`
(
    `id`                  bigint                                                       NOT NULL AUTO_INCREMENT COMMENT 'ID',

    `code`                varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL COMMENT '编码',
    `requisition_date`          date COMMENT '下料时间',
    `delivery_date`       date COMMENT '创建时间',
    `status`              tinyint                                                               DEFAULT '0' COMMENT '状态',
    `process_instance_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT NULL COMMENT '流程实例的编号',
    `plan_id`     bigint   NOT NULL COMMENT '计划ID',

    `remark`              varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci         DEFAULT '' COMMENT '备注',
    `is_enable`           bit(1)                                                       NOT NULL DEFAULT b'1' COMMENT '是否启用',
    `creator`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '创建者',
    `create_time`         datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '更新者',
    `update_time`         datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`             bit(1)                                                       NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`           bigint                                                                DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='领料单';

CREATE TABLE `mes_item_requisition_detail`
(
    `id`                bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `product_id`  bigint   NOT NULL COMMENT '产品ID',
    `unit_id`     bigint   NOT NULL COMMENT '单位ID',
    `item_requisition_id`     bigint   NOT NULL COMMENT '领料单ID',
    `number`       decimal(24, 6)                                                DEFAULT NULL COMMENT '数量',

    `remark`            varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `is_enable`         bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',
    `creator`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '创建者',
    `create_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '更新者',
    `update_time`       datetime NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)   NOT NULL                                             DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint                                                        DEFAULT NULL COMMENT '租户id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='领料单明细';


CREATE TABLE `mes_organization`
(
    `id`             bigint                                                       NOT NULL AUTO_INCREMENT COMMENT '组织id',
    `name`           varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '组织名称',
    `parent_id`      bigint                                                       NOT NULL DEFAULT '0' COMMENT '父组织id',
    `sort`           int                                                          NOT NULL DEFAULT '0' COMMENT '显示顺序',
    `worker_user_id` bigint                                                                DEFAULT NULL COMMENT '负责人/工人',
    `machine_id` bigint                                                                DEFAULT NULL COMMENT '对应机台id',
    `phone`          varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT NULL COMMENT '联系电话',
    `email`          varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT NULL COMMENT '邮箱',

    `is_enable`         bit(1)   NOT NULL                                             DEFAULT b'1' COMMENT '是否启用',

    `status`         tinyint                                                      NOT NULL COMMENT '组织状态',
    `org_class`         tinyint                                                      NOT NULL COMMENT '组织等级',
    `org_type`         tinyint                                                      NOT NULL COMMENT '组织类型',
    `creator`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '创建者',
    `create_time`    datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci          DEFAULT '' COMMENT '更新者',
    `update_time`    datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`        bit(1)                                                       NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`      bigint                                                       NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='工厂组织表';
