This commit is contained in:
gr
2026-10-15 11:03:54 +08:00
parent 70ddc1a70a
commit bb28d93cec
64 changed files with 12747 additions and 420 deletions
@@ -0,0 +1,55 @@
-- 复诊到期快照:每诊单一行(当前周期 = 最新有效业务订单)。
-- 写入:php think tcm:revisit-due-scan --mode=full(每日)/ --mode=incremental(每 30 分钟)+ 业务钩子(订单/挂号/指派)即时刷新单条。
-- 诊次口径与复诊接诊率一致:有效业务订单(剔 4/9/10、未软删)序号 + tcm_diagnosis.revisit_slot_start_offset(RevisitVisitSlotService)。
-- 时间相关状态(到期/预警/超期/过号/已约)在读取时由本表事实列(due_date、appointment_state、appointment_date、promised_date、closed_state)与 CURDATE() 推导,不再 join 挂号表。
-- 缺开药天数(medication_days=0)的行保持 closed_state=0,由读取侧推导为「缺开药天数」;仅无医助/诊单删除或禁用/无有效订单时置 5。
-- 索引:uk_diagnosis 一诊单一行/幂等 upsert;idx_assistant_open 弹窗拉取与列表 chip 计数;idx_open_due cron 与主管视图;idx_source_order 订单变更钩子。
CREATE TABLE IF NOT EXISTS `zyt_tcm_diagnosis_revisit_due` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`diagnosis_id` int unsigned NOT NULL DEFAULT 0 COMMENT '诊单ID(zyt_tcm_diagnosis.id)',
`assistant_id` int unsigned NOT NULL DEFAULT 0 COMMENT '当前持有医助(随 tcm_diagnosis.assistant_id 同步,(int) 强转)',
`patient_name` varchar(64) NOT NULL DEFAULT '' COMMENT '患者姓名快照',
`source_order_id` int unsigned NOT NULL DEFAULT 0 COMMENT '本周期锚点业务订单 zyt_tcm_prescription_order.id(最新有效订单)',
`order_create_time` int unsigned NOT NULL DEFAULT 0 COMMENT '锚点订单下单时间',
`valid_order_count` smallint unsigned NOT NULL DEFAULT 0 COMMENT '有效订单数',
`anchor_ts` int unsigned NOT NULL DEFAULT 0 COMMENT '用药起算时间戳',
`anchor_src` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '起算来源:1=签收 2=发货 3=下单',
`medication_days` smallint unsigned NOT NULL DEFAULT 0 COMMENT '开药天数(订单 medication_days,缺省回落处方 usage_days;0=缺失)',
`days_src` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '天数来源:0=缺失 1=订单 2=处方',
`rule_days` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '天数档位:14/21/28/30,0=其它',
`total_medication_days` smallint unsigned NOT NULL DEFAULT 0 COMMENT '累计开药天数',
`current_slot` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '患者当前已完成诊次(有效订单数+偏移)',
`next_slot` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '待复诊诊次 = current_slot+1',
`first_touch_date` date NULL COMMENT '首次触达日(首笔有效订单/首条指派取早)',
`due_date` date NULL COMMENT '预计复诊日 = DATE(anchor_ts)+medication_days+grace;缺天数为 NULL',
`closed_state` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=进行中 2=已挂号(自动) 3=已面诊(自动) 4=人工关闭 5=失效(无医助/诊单删除或禁用/无有效订单)',
`booked_appointment_id` int unsigned NOT NULL DEFAULT 0 COMMENT '触发关闭或当前待面诊的挂号单 id',
`appointment_state` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '锚点订单之后最新有效挂号状态(事实列):0=无 1=已约 3=已面诊 4=过号',
`appointment_date` date NULL COMMENT '上述挂号的预约日期(事实列)',
`missed_count` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '本周期过号/已约未到次数',
`contact_count` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '本周期「已联系」次数(上限 2,之后按延迟计)',
`contacted_at` int unsigned NOT NULL DEFAULT 0 COMMENT '最近一次「已联系」时间',
`promised_date` date NULL COMMENT '患者承诺复诊日期',
`snooze_count` smallint unsigned NOT NULL DEFAULT 0 COMMENT '延迟处理次数(越点越上心的依据)',
`escalation_level` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '升级等级 0~3 = f(snooze_count)',
`next_remind_at` int unsigned NOT NULL DEFAULT 0 COMMENT '下次弹窗时刻;弹窗只取 next_remind_at<=now',
`first_shown_at` int unsigned NOT NULL DEFAULT 0 COMMENT '首次弹出时间(仅写一次)',
`last_shown_at` int unsigned NOT NULL DEFAULT 0 COMMENT '最近弹出时间(统计用,不做节流)',
`last_snoozed_at` int unsigned NOT NULL DEFAULT 0 COMMENT '最近延迟时间',
`last_snoozed_by` int unsigned NOT NULL DEFAULT 0 COMMENT '最近延迟人',
`handled_at` int unsigned NOT NULL DEFAULT 0 COMMENT '人工关闭时间',
`handled_by` int unsigned NOT NULL DEFAULT 0 COMMENT '人工关闭人',
`handle_reason` varchar(16) NOT NULL DEFAULT '' COMMENT '人工关闭原因 lost/other',
`handle_remark` varchar(200) NOT NULL DEFAULT '' COMMENT '人工关闭说明',
`wecom_self_at` int unsigned NOT NULL DEFAULT 0 COMMENT '最近一次企微推送本人(P2)',
`wecom_self_count_day` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '当日已推送本人次数(P2)',
`wecom_supervisor_at` int unsigned NOT NULL DEFAULT 0 COMMENT '最近一次企微抄送主管(P2)',
`computed_at` int unsigned NOT NULL DEFAULT 0 COMMENT '最近重算时间',
`create_time` int unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
`update_time` int unsigned NOT NULL DEFAULT 0 COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_diagnosis` (`diagnosis_id`),
KEY `idx_assistant_open` (`assistant_id`, `closed_state`, `appointment_state`, `due_date`, `next_remind_at`),
KEY `idx_open_due` (`closed_state`, `due_date`),
KEY `idx_source_order` (`source_order_id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '诊单复诊到期快照(每诊单一行,列表标红/弹窗/延迟升级共用)';