-- 派单统计表
CREATE TABLE `dispatch_statistics` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `order_id` bigint(20) DEFAULT NULL COMMENT '订单ID',
  `worker_id` bigint(20) DEFAULT NULL COMMENT '师傅ID',
  `worker_name` varchar(100) DEFAULT NULL COMMENT '师傅姓名',
  `service_id` bigint(20) DEFAULT NULL COMMENT '服务ID',
  `service_name` varchar(200) DEFAULT NULL COMMENT '服务名称',
  `address_id` bigint(20) DEFAULT NULL COMMENT '用户地址ID',
  `address` varchar(500) DEFAULT NULL COMMENT '用户地址',
  `city_code` varchar(50) DEFAULT NULL COMMENT '城市编码',
  `city_name` varchar(100) DEFAULT NULL COMMENT '城市名称',
  `dispatch_type` int(11) DEFAULT NULL COMMENT '派单类型 1:自动派单 2:手动派单',
  `dispatch_result` int(11) DEFAULT NULL COMMENT '派单结果 1:成功 0:失败',
  `dispatch_time` bigint(20) DEFAULT NULL COMMENT '派单耗时（毫秒）',
  `distance_score` decimal(5,2) DEFAULT NULL COMMENT '距离评分',
  `skill_match_score` decimal(5,2) DEFAULT NULL COMMENT '技能匹配评分',
  `experience_score` decimal(5,2) DEFAULT NULL COMMENT '经验评分',
  `rating_score` decimal(5,2) DEFAULT NULL COMMENT '评分',
  `availability_score` decimal(5,2) DEFAULT NULL COMMENT '可用性评分',
  `new_worker_bonus_score` decimal(5,2) DEFAULT NULL COMMENT '新师傅奖励评分',
  `total_score` decimal(5,2) DEFAULT NULL COMMENT '综合评分',
  `candidate_count` int(11) DEFAULT NULL COMMENT '候选师傅数量',
  `retry_count` int(11) DEFAULT NULL COMMENT '重试次数',
  `failure_reason` varchar(500) DEFAULT NULL COMMENT '失败原因',
  `dispatch_date` datetime DEFAULT NULL COMMENT '派单时间',
  `created_at` datetime DEFAULT NULL COMMENT '创建时间',
  `updated_at` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_order_id` (`order_id`),
  KEY `idx_worker_id` (`worker_id`),
  KEY `idx_service_id` (`service_id`),
  KEY `idx_city_code` (`city_code`),
  KEY `idx_dispatch_date` (`dispatch_date`),
  KEY `idx_dispatch_result` (`dispatch_result`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='派单统计表';

-- 插入示例数据
INSERT INTO `dispatch_statistics` (`order_id`, `worker_id`, `worker_name`, `service_id`, `service_name`, `address_id`, `address`, `city_code`, `city_name`, `dispatch_type`, `dispatch_result`, `dispatch_time`, `distance_score`, `skill_match_score`, `experience_score`, `rating_score`, `availability_score`, `new_worker_bonus_score`, `total_score`, `candidate_count`, `retry_count`, `failure_reason`, `dispatch_date`, `created_at`, `updated_at`) VALUES
(1001, 201, '张师傅', 301, '空调维修', 401, '北京市朝阳区建国路88号', '110105', '朝阳区', 1, 1, 1500, 0.85, 0.90, 0.80, 0.88, 0.92, 0.00, 0.87, 5, 0, NULL, '2025-01-15 10:30:00', '2025-01-15 10:30:00', '2025-01-15 10:30:00'),
(1002, 202, '李师傅', 302, '水管维修', 402, '北京市海淀区中关村大街1号', '110108', '海淀区', 1, 1, 1200, 0.90, 0.95, 0.85, 0.92, 0.88, 0.00, 0.90, 4, 0, NULL, '2025-01-15 11:15:00', '2025-01-15 11:15:00', '2025-01-15 11:15:00'),
(1003, 203, '王师傅', 303, '电路维修', 403, '北京市西城区西单北大街120号', '110102', '西城区', 1, 0, 3000, 0.70, 0.60, 0.40, 0.75, 0.65, 1.00, 0.68, 3, 1, '技能不匹配', '2025-01-15 14:20:00', '2025-01-15 14:20:00', '2025-01-15 14:20:00'),
(1004, 204, '赵师傅', 304, '门窗安装', 404, '北京市东城区王府井大街255号', '110101', '东城区', 2, 1, 800, 0.95, 0.88, 0.90, 0.85, 0.95, 0.00, 0.91, 6, 0, NULL, '2025-01-15 16:45:00', '2025-01-15 16:45:00', '2025-01-15 16:45:00'),
(1005, 205, '刘师傅', 305, '家具安装', 405, '北京市丰台区丰台路168号', '110106', '丰台区', 1, 1, 1800, 0.80, 0.85, 0.75, 0.80, 0.85, 0.00, 0.81, 4, 0, NULL, '2025-01-15 18:30:00', '2025-01-15 18:30:00', '2025-01-15 18:30:00'); 