DROP TABLE IF EXISTS `zs_tjfx_shop_customer`;
CREATE TABLE `zs_tjfx_shop_customer`  (
                                          `id` bigint(20) NOT NULL AUTO_INCREMENT,
                                          `shop_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '店铺名称',
                                          `customer_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户名称',
                                          `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                          PRIMARY KEY (`id`) USING BTREE,
                                          UNIQUE INDEX `uk_shop_customer`(`shop_name`, `customer_name`) USING BTREE,
                                          INDEX `idx_zs_tjfx_shop_customer_shop_name`(`shop_name`) USING BTREE,
                                          INDEX `idx_zs_tjfx_shop_customer_customer_name`(`customer_name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 98 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '店铺客户关联表' ROW_FORMAT = Dynamic;



DROP TABLE IF EXISTS `zs_tjfx_categories`;
CREATE TABLE `zs_tjfx_categories`  (
                                       `id` bigint(20) NOT NULL AUTO_INCREMENT,
                                       `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '分类名称',
                                       `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '分类描述',
                                       `field_config` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '字段配置JSON',
                                       `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                       `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                       PRIMARY KEY (`id`) USING BTREE,
                                       UNIQUE INDEX `name`(`name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 21 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '分类表' ROW_FORMAT = Dynamic;



DROP TABLE IF EXISTS `zs_tjfx_base_data`;
CREATE TABLE `zs_tjfx_base_data`  (
                                      `id` bigint(20) NOT NULL AUTO_INCREMENT,
                                      `product_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品编号',
                                      `product_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品名称',
                                      `brand` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '品牌',
                                      `category_id` bigint(20) NULL DEFAULT NULL COMMENT '分类ID',
                                      `category_specs` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '分类规格JSON',
                                      `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                      `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                      PRIMARY KEY (`id`) USING BTREE,
                                      UNIQUE INDEX `product_code`(`product_code`) USING BTREE,
                                      INDEX `idx_zs_tjfx_base_data_category_id`(`category_id`) USING BTREE,
                                      INDEX `idx_zs_tjfx_base_data_product_code`(`product_code`) USING BTREE,
                                      INDEX `idx_zs_tjfx_base_data_brand`(`brand`) USING BTREE,
                                      CONSTRAINT `zs_tjfx_base_data_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `zs_tjfx_categories` (`id`) ON DELETE SET NULL ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1277 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '基准数据表' ROW_FORMAT = Dynamic;


DROP TABLE IF EXISTS `zs_tjfx_analysis_data`;
CREATE TABLE `zs_tjfx_analysis_data`  (
                                          `id` bigint(20) NOT NULL AUTO_INCREMENT,
                                          `date` date NOT NULL COMMENT '日期',
                                          `shop_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '店铺名称',
                                          `product_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品编号',
                                          `product_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品名称',
                                          `customer_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '客户名称',
                                          `category` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '分类',
                                          `category_specs` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '分类规格JSON',
                                          `quantity` int(11) NULL DEFAULT NULL COMMENT '数量',
                                          `total_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '合计金额',
                                          `source` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '数据来源',
                                          `status` int(11) NULL DEFAULT 1 COMMENT '状态：1-正常，2-客户名称未匹配，3-分类规格未匹配',
                                          `delivery_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '出库类型',
                                          `destination` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '目的地',
                                          `remarks` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '备注',
                                          `order_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '订单编号',
                                          `row_number` int(11) NULL DEFAULT NULL COMMENT '行号',
                                          `brand` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '品牌',
                                          `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                          PRIMARY KEY (`id`) USING BTREE,
                                          INDEX `idx_date`(`date`) USING BTREE,
                                          INDEX `idx_shop_name`(`shop_name`) USING BTREE,
                                          INDEX `idx_product_code`(`product_code`) USING BTREE,
                                          INDEX `idx_customer_name`(`customer_name`) USING BTREE,
                                          INDEX `idx_status`(`status`) USING BTREE,
                                          INDEX `idx_delivery_type`(`delivery_type`) USING BTREE,
                                          INDEX `idx_created_at`(`created_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9582 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '分析数据表' ROW_FORMAT = Dynamic;
