javacodeadmin/sql/dispatch_score_record.sql

83 lines
4.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 派单评分记录表
-- 用于记录所有师傅的评分详情和各个影响因素的分值
-- 每天晚上12点定时任务更新
CREATE TABLE `dispatch_score_record` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`worker_id` bigint(20) NOT NULL COMMENT '师傅ID',
`worker_name` varchar(100) NOT NULL COMMENT '师傅姓名',
`worker_phone` varchar(20) DEFAULT NULL COMMENT '师傅电话',
`order_id` bigint(20) DEFAULT NULL COMMENT '订单ID如果是在派单过程中记录',
`service_id` bigint(20) DEFAULT NULL COMMENT '服务ID',
`user_address_id` bigint(20) DEFAULT NULL COMMENT '用户地址ID',
-- 各项评分
`distance_score` decimal(5,4) DEFAULT 0.0000 COMMENT '距离评分',
`skill_match_score` decimal(5,4) DEFAULT 0.0000 COMMENT '技能匹配评分',
`experience_score` decimal(5,4) DEFAULT 0.0000 COMMENT '经验评分',
`rating_score` decimal(5,4) DEFAULT 0.0000 COMMENT '评分权重',
`availability_score` decimal(5,4) DEFAULT 0.0000 COMMENT '可用性评分',
`new_worker_bonus_score` decimal(5,4) DEFAULT 0.0000 COMMENT '新师傅奖励评分',
`total_score` decimal(5,4) DEFAULT 0.0000 COMMENT '综合评分',
-- 各项权重
`weight_distance` decimal(5,4) DEFAULT 0.1500 COMMENT '距离权重',
`weight_skill_match` decimal(5,4) DEFAULT 0.2500 COMMENT '技能匹配权重',
`weight_experience` decimal(5,4) DEFAULT 0.1500 COMMENT '经验权重',
`weight_rating` decimal(5,4) DEFAULT 0.2000 COMMENT '评分权重',
`weight_availability` decimal(5,4) DEFAULT 0.1500 COMMENT '可用性权重',
`weight_new_worker_bonus` decimal(5,4) DEFAULT 0.1000 COMMENT '新师傅奖励权重',
-- 详细数据
`distance_km` decimal(10,2) DEFAULT NULL COMMENT '实际距离(公里)',
`skill_match_count` int(11) DEFAULT 0 COMMENT '匹配技能数量',
`total_skills_count` int(11) DEFAULT 0 COMMENT '总技能数量',
`completed_orders_count` int(11) DEFAULT 0 COMMENT '已完成订单数量',
`current_orders_count` int(11) DEFAULT 0 COMMENT '当前进行中订单数量',
`is_new_worker` tinyint(1) DEFAULT 0 COMMENT '是否新师傅1是0否',
`registration_days` int(11) DEFAULT 0 COMMENT '注册天数',
-- 位置信息
`worker_latitude` varchar(20) DEFAULT NULL COMMENT '师傅纬度',
`worker_longitude` varchar(20) DEFAULT NULL COMMENT '师傅经度',
`user_latitude` varchar(20) DEFAULT NULL COMMENT '用户纬度',
`user_longitude` varchar(20) DEFAULT NULL COMMENT '用户经度',
`city_code` varchar(20) DEFAULT NULL COMMENT '城市编码',
`district_code` varchar(20) DEFAULT NULL COMMENT '区县编码',
-- 状态信息
`worker_status` int(11) DEFAULT 1 COMMENT '师傅状态1启用0禁用',
`is_work` int(11) DEFAULT 1 COMMENT '是否工作1是0否',
`is_stop` int(11) DEFAULT 0 COMMENT '是否停止1是0否',
`has_unfinished_orders` tinyint(1) DEFAULT 0 COMMENT '是否有未完成订单1是0否',
`is_available` tinyint(1) DEFAULT 1 COMMENT '是否可用1是0否',
-- 排名信息
`rank_position` int(11) DEFAULT 0 COMMENT '排名位置',
`total_candidates` int(11) DEFAULT 0 COMMENT '总候选人数',
`is_selected` tinyint(1) DEFAULT 0 COMMENT '是否被选中1是0否',
`selection_reason` varchar(500) DEFAULT NULL COMMENT '选中原因',
-- 时间信息
`score_calculation_time` datetime DEFAULT NULL COMMENT '评分计算时间',
`last_update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-- 备注
`remark` varchar(1000) DEFAULT NULL COMMENT '备注信息',
PRIMARY KEY (`id`),
KEY `idx_worker_id` (`worker_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_total_score` (`total_score`),
KEY `idx_rank_position` (`rank_position`),
KEY `idx_is_selected` (`is_selected`),
KEY `idx_score_calculation_time` (`score_calculation_time`),
KEY `idx_worker_status` (`worker_status`),
KEY `idx_is_available` (`is_available`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='派单评分记录表';
-- 创建索引优化查询性能
CREATE INDEX `idx_worker_score_time` ON `dispatch_score_record` (`worker_id`, `score_calculation_time`);
CREATE INDEX `idx_score_rank` ON `dispatch_score_record` (`total_score` DESC, `rank_position`);
CREATE INDEX `idx_available_workers` ON `dispatch_score_record` (`is_available`, `total_score` DESC);