CREATE TABLE `mes_work_team`
(
    `id`             bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `team_name`      varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT '班组名称',
    `team_leader_id` bigint   NOT NULL COMMENT '组长ID',

    `team_type`      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_work_team_detail`
(
    `id`           bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `work_team_id` bigint                                                        DEFAULT NULL COMMENT '班组id',
    `user_id`      bigint   NOT NULL COMMENT '用户ID',

    `user_role`    tinyint  NOT NULL COMMENT '角色',
    `remark`       varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' 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_produce_report`
(
    `id`                  bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `process_instance_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT '流程实例编号',
    `report_code`         varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT '编号',
    `user_id`             bigint   NOT NULL COMMENT '用户ID',
    `org_id`              bigint   NOT NULL COMMENT '工序ID',
    `report_type`    varchar(255) COLLATE utf8mb4_unicode_ci                       DEFAULT NULL COMMENT '代报/自报',
    `group_type`     int                                                           DEFAULT NULL COMMENT '白班夜班',
    `org_type`            varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT NULL COMMENT '工序',
    `report_time`         varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '计件时段',
    `total_time`          decimal(24, 6)                                                DEFAULT NULL COMMENT '总时长',
    `report_date`    datetime                                                      DEFAULT NULL COMMENT '报工日期',
    `report_status`  tinyint                                                       DEFAULT NULL COMMENT '报工状态',
    `remark`              varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' 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_produce_report_detail`
(
    `id`             bigint   NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `report_id`      bigint                                                        DEFAULT NULL COMMENT '报工单id',
    `plan_id`        bigint                                                        DEFAULT NULL COMMENT '生产计划ID',
    `product_id`     bigint                                                        DEFAULT NULL COMMENT '产品ID',
    `user_id`        bigint                                                        DEFAULT NULL COMMENT '用户ID',
    `report_type`    varchar(255) COLLATE utf8mb4_unicode_ci                       DEFAULT NULL COMMENT '代报/自报',
    `group_type`     int                                                           DEFAULT NULL COMMENT '白班夜班',
    `org_type`       varchar(255) COLLATE utf8mb4_unicode_ci                       DEFAULT NULL COMMENT '工序类型',
    `org_id`         bigint                                                        DEFAULT NULL COMMENT '组织ID',
    `quality_number` decimal(24, 6)                                                DEFAULT NULL COMMENT '成品数量',
    `waste_number`   decimal(24, 6)                                                DEFAULT NULL COMMENT '废品数量',
    `total_number`   decimal(24, 6)                                                DEFAULT NULL COMMENT '总数量',
    `quality_rate`   decimal(24, 6)                                                DEFAULT NULL COMMENT '成品率',
    `waste_reason`   varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `report_time`    varchar(500) COLLATE utf8mb4_unicode_ci                       DEFAULT '' COMMENT '计件时间',
    `total_time`     decimal(24, 6)                                                DEFAULT NULL COMMENT '总时长',
    `package_number` decimal(24, 6)                                                DEFAULT NULL COMMENT '打包数量',
    `remark`         varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备注',
    `is_enable`      bit(1)                                                        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',
    `report_date`    datetime                                                      DEFAULT NULL COMMENT '报工日期',
    `report_status`  tinyint                                                       DEFAULT NULL COMMENT '报工状态',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 108
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='生产报工明细';


CREATE TABLE `mes_machine_component`
(
    `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 '显示顺序',
    `org_id`          bigint                                                       NOT NULL COMMENT '组织机台ID',
    `serial_code`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci         DEFAULT NULL COMMENT '装备SN号',
    `outgoing_time`   datetime                                                              DEFAULT NULL COMMENT '出厂日期',
    `outgoing_report` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '出厂报告',
    `position`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci         DEFAULT NULL COMMENT '位置',
    `standard`        varchar(255)                                                          DEFAULT NULL COMMENT '规格',
    `status`          tinyint                                                      NOT NULL COMMENT '状态',
    `component_type`  tinyint                                                      NOT NULL COMMENT '类型',

    `remark`          varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci         DEFAULT '' 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 ='机台组织表';


CREATE TABLE `mes_stock_workshop`
(
    `id`          bigint         NOT NULL AUTO_INCREMENT COMMENT 'id',
    `item_id`     bigint         NOT NULL COMMENT '原料编号',
    `count`       decimal(24, 6) NOT NULL COMMENT '库存数量',
    `category_id` bigint                                                       DEFAULT 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
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='车间仓库存';

CREATE TABLE `mes_stock_workshop_detail`
(
    `id`                         bigint         NOT NULL AUTO_INCREMENT COMMENT 'id',
    `item_id`                    bigint         NOT NULL COMMENT '原料id',
    `count`                      decimal(24, 6) NOT NULL COMMENT '数量',
    `detail_type`                varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '明细类别',
    `item_requisition_code`      varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '领料单',
    `item_requisition_detail_id` bigint         NOT NULL COMMENT '领料明细id',
    `feeding_record_code`        varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '投料单',
    `feeding_record_id`          bigint         NOT NULL COMMENT '投料id',
    `user_id`                    bigint         NOT NULL COMMENT '操作人员',
    `operate_time`               datetime                                                     DEFAULT CURRENT_TIMESTAMP 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
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='车间仓出入库明细';


CREATE TABLE `mes_feeding_record`
(
    `id`                  bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `feeding_record_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '单号',
    `plan_id`             bigint                                                        DEFAULT NULL COMMENT '计划id',
    `feeding_type`        varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '投料类型',
    `feeding_pipeline`    varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '制浆线',
    `feeding_time`        datetime                                                      DEFAULT CURRENT_TIMESTAMP COMMENT '投料时间',
    `record_status`       varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '状态',
    `product_id`          bigint                                                        DEFAULT NULL COMMENT '产品id',
    `item_id`             bigint                                                        DEFAULT NULL COMMENT '原料id',
    `weight`              decimal(24, 6)                                                DEFAULT NULL COMMENT '重量',
    `user_id`             bigint                                                        DEFAULT NULL COMMENT '记录人',
    `remark`              varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='投料记录';

CREATE TABLE `mes_feeding_record_detail`
(
    `id`           bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `record_id`    bigint                                                       DEFAULT NULL COMMENT '记录id',
    `item_id`      bigint                                                       DEFAULT NULL COMMENT '原料id',
    `weight`       decimal(24, 6)                                               DEFAULT NULL COMMENT '重量',
    `unit_id`      bigint                                                       DEFAULT NULL COMMENT '单位',
    `user_id`      bigint                                                       DEFAULT NULL COMMENT '记录人',
    `feeding_time` datetime                                                     DEFAULT CURRENT_TIMESTAMP 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='投料记录明细';

CREATE TABLE `mes_feeding_record_plan`
(
    `id`               bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `record_id`        bigint                                                       DEFAULT NULL COMMENT '记录id',
    `record_detail_id` bigint                                                       DEFAULT NULL COMMENT '记录明细id',
    `plan_id`          bigint                                                       DEFAULT NULL COMMENT '计划id',
    `item_id`          bigint                                                       DEFAULT NULL COMMENT '原料id',
    `weight`           decimal(24, 6)                                               DEFAULT NULL COMMENT '重量',
    `unit_id`          bigint                                                       DEFAULT NULL COMMENT '单位',
    `user_id`          bigint                                                       DEFAULT NULL COMMENT '记录人',
    `feeding_time`     datetime                                                     DEFAULT CURRENT_TIMESTAMP 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='投料记录分配计划';


CREATE TABLE `mes_error_record`
(
    `id`          bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `title`       varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '标题',
    `location`    varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  DEFAULT '' COMMENT '位置',
    `exception`   varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '异常',
    `pre_data`    varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '前数据',
    `post_data`   varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='错误记录';


CREATE TABLE `mes_stock_in_detail`
(
    `id`               bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `stock_in_id`      bigint                                                       DEFAULT NULL COMMENT '入库单id',
    `stock_in_no`      varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '入库单编号',
    `stock_in_item_id` bigint                                                       DEFAULT NULL COMMENT '入库单项id',
    `plan_id`          bigint                                                       DEFAULT NULL COMMENT '计划id',
    `product_id`       bigint                                                       DEFAULT NULL COMMENT '产品',
    `number`           decimal(24, 6)                                               DEFAULT 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='生产入库分配明细';


CREATE TABLE `mes_org_worker`
(
    `id`          bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `org_id`      bigint                                                       DEFAULT NULL COMMENT '工位id',
    `work_date`   datetime NOT NULL                                            DEFAULT NULL COMMENT '工作日期',
    `group_type`  int                                                          DEFAULT NULL COMMENT '1白班/2夜班',
    `worker_id`   bigint                                                       DEFAULT NULL COMMENT '工人id',
    `report_id`   bigint                                                       DEFAULT NULL COMMENT '报工单id',

    `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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='工位安排表';

CREATE TABLE `mes_work_report_plan`
(
    `id`                  bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `report_id`           bigint                                                       DEFAULT NULL COMMENT '报工单id',
    `plan_id`             bigint                                                       DEFAULT NULL COMMENT '计划id',
    `product_id`          bigint                                                       DEFAULT NULL COMMENT '产品ID',
    `quality_number_plan` decimal(24, 6)                                               DEFAULT NULL COMMENT '成品数量',
    `waste_number_plan`   decimal(24, 6)                                               DEFAULT NULL COMMENT '废品数量',
    `report_time_plan`    varchar(500) COLLATE utf8mb4_unicode_ci                      DEFAULT '' COMMENT '计件时间',
    `total_time_plan`     decimal(24, 6)                                               DEFAULT 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='报工分配计划';


CREATE TABLE `mes_produce_report_change_record`
(
    `id`            bigint   NOT NULL AUTO_INCREMENT COMMENT 'id',
    `report_id`     bigint                                                       DEFAULT NULL COMMENT '报工单id',
    `change_type`   varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '变更类型',
    `before_change` varchar(500) COLLATE utf8mb4_unicode_ci                      DEFAULT '' COMMENT '变更前数据',
    `after_change`  varchar(500) COLLATE utf8mb4_unicode_ci                      DEFAULT '' 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 = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci
  ROW_FORMAT = DYNAMIC COMMENT ='报工变更记录';

CREATE VIEW mes_view_report_plan_detail
AS
SELECT wp.*,
       pd.user_id,
       pd.report_type,
       pd.group_type,
       pd.org_type,
       pd.org_id,
       pd.quality_number,
       pd.waste_number,
       pd.report_date,
       pd.report_status,
       pd.creator as report_creator
FROM mes_work_report_plan wp
         JOIN mes_produce_report_detail pd ON wp.report_id = pd.id;
