# 盘点单码表
DROP TABLE IF EXISTS `inv_count_codes`;
CREATE TABLE `inv_count_codes`  (
                                    `id` int(0) NOT NULL AUTO_INCREMENT COMMENT 'id',
                                    `orderIdFk` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '盘点单ID',
                                    `productId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '产品ID',
                                    `code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '码',
                                    `status` tinyint(1) NULL DEFAULT NULL COMMENT '条码状态（多码或少码） 0：少    1：多',
                                    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '盘点单据码表' ROW_FORMAT = Dynamic;

# 盘点单据表
DROP TABLE IF EXISTS `inv_count_order`;
CREATE TABLE `inv_count_order`  (
                                    `id` int(0) NOT NULL AUTO_INCREMENT COMMENT 'id',
                                    `orderId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '盘点单号',
                                    `invStorageCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '仓库号',
                                    `invWarehouseCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '分库号',
                                    `invSpaceCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '货位号',
                                    `createUser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '盘点用户ID',
                                    `createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
                                    `updateTime` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
                                    `auditUser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '审核用户ID',
                                    `auditTime` datetime(0) NULL DEFAULT NULL COMMENT '审核时间',
                                    `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态',
                                    `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注字段',
                                    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '盘点单据表' ROW_FORMAT = Dynamic;

# 盘点单据详情表
DROP TABLE IF EXISTS `inv_count_order_detail`;
CREATE TABLE `inv_count_order_detail`  (
                                           `id` int(0) NOT NULL AUTO_INCREMENT COMMENT 'id',
                                           `orderIdFk` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '盘点单号',
                                           `productId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '产品ID',
                                           `batchNo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '批次号',
                                           `produceDate` datetime(0) NULL DEFAULT NULL COMMENT '生产日期',
                                           `expireDate` datetime(0) NULL DEFAULT NULL COMMENT '失效日期',
                                           `serialNo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '序列号',
                                           `countNum` int(0) NULL DEFAULT NULL COMMENT '盘点数量',
                                           `invNum` int(0) NULL DEFAULT NULL COMMENT '账面数量',
                                           `profitNum` int(0) NULL DEFAULT NULL COMMENT '盘盈数量',
                                           `lossNum` int(0) NULL DEFAULT NULL COMMENT '盘亏数量',
                                           `status` tinyint(1) NULL DEFAULT NULL COMMENT '盈亏状态  0：亏损 1：盈利',
                                           PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '盘点单详情' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

# 货位字典表
DROP TABLE IF EXISTS `inv_space`;
CREATE TABLE `inv_space`  (
                              `id` int(0) NOT NULL AUTO_INCREMENT COMMENT 'ID',
                              `code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '货位码',
                              `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '货位名称',
                              `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '货位分类',
                              `invStorageCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '所属仓库',
                              `invWarehouseCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '所属分库',
                              `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态',
                              `createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
                              `updateTime` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
                              `createUser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建人',
                              `updateUser` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '更新人',
                              `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
                              PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '货位字典表' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

# 库存详情表添加货位号字段
ALTER TABLE `udiwms`.`inv_product_detail`
    ADD COLUMN `invSpaceCode` varchar(255) NULL COMMENT '货位号' AFTER `invWarehouseCode`;
