liusheng
2026-11-09 279d50c151d14d04cb6680b10c82bf32b72968cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- ============================================================================
-- 在院患者"科室 / 病区 / 床位"每日刷新 —— 定时任务登记(可重复执行)
--
-- 背景:在院患者会转科、转病区、换床,而 pat_med_inhosp 的位置字段只在"入院采集"时
--       写过一次,之后不会自己更新,转科/换床患者会一直显示旧科室/旧病区/旧床位。
--       本任务每天按患者查一遍 HIS 里该患者"当前的在院信息"
--       (dtcQueryHealthcareRecordList —— 与入院采集同一个接口,按 healthcareRecordNo 单查、
--        statusList=["FH0109.24"] 只取在院记录),与库内比对后只写变化的字段。
--       已不在院(接口返回空)的患者只跳过计数:位置保持不动,inhospstate 仍由出院采集负责。
--
-- 实现:ruoyi-datacollection 的 InhospDeptRefreshServiceImpl
--       入口:ruoyi-quartz 的 com.ruoyi.quartz.task.RyTask#refreshInhospDeptInfo()
--       口径:仅 spring.profiles.active=nhfy(南华附一)执行;其他站点直接跳过
--
-- 参数选择理由:
--   cron_expression = '0 30 3 * * ?'  每天 03:30
--       —— 避开 01:00 的入院采集(dealHisData)与 02:00 的出院处理(dealOutHospInfo),
--          否则会与本任务抢"同一批患者的当前状态",读到半新半旧的数据。
--   concurrent      = '1'             禁止并发(一轮约 10 分钟:实测单次 137~460ms × 约 3000 人;
--                                     叠加执行没有意义,实现里另有 Redis 运行锁兜底手工触发)
--   misfire_policy  = '1'             立即执行:服务在 03:30 停机、之后才恢复时补跑一次。
--                                     本任务幂等(只写变化的字段),补跑无害;
--                                     若想"错过就算了",改成 '3' 即可。
--   status          = '0'             正常(登记后即启用)。要停用改成 '1',
--                                     或直接在「系统管理 → 定时任务」里暂停。
--
-- 注意:本任务受数据采集模块开关管辖(sys_config: datacollection.enabled)——
--       模块关闭时门面抛 DataCollectionModuleDisabledException,RyTask 只打一条 WARN 并跳过本轮。
--       见 sql/数据采集开关_sys_config.sql。
-- ============================================================================
 
insert into sys_job (job_name, job_group, invoke_target, cron_expression,
                     misfire_policy, concurrent, status, create_by, create_time, remark)
select '在院患者科室病区床位刷新(南华附一,每天)',
       'DEFAULT',
       'ryTask.refreshInhospDeptInfo()',
       '0 30 3 * * ?',
       '1',
       '1',
       '0',
       'admin',
       sysdate(),
       '每天 03:30 按患者刷新 pat_med_inhosp 的科室/病区/床位(数据采集模块)'
from dual
where not exists (
    select 1 from sys_job where invoke_target = 'ryTask.refreshInhospDeptInfo()'
);
 
-- ---------------------------------------------------------------------------
-- 登记后自检:应恰好一行,status='0'(正常)、concurrent='1'(禁止并发)
-- ---------------------------------------------------------------------------
-- select job_id, job_name, invoke_target, cron_expression, misfire_policy, concurrent, status
-- from sys_job where invoke_target = 'ryTask.refreshInhospDeptInfo()';
 
-- 只想先观察、不启用时:登记成暂停状态,验证过再启用
-- update sys_job set status = '0' where invoke_target = 'ryTask.refreshInhospDeptInfo()';
 
-- 回滚(撤销本任务登记)
-- delete from sys_job where invoke_target = 'ryTask.refreshInhospDeptInfo()';