package com.ruoyi.datacollection.api; import com.ruoyi.datacollection.config.DataCollectionSwitch; import com.ruoyi.datacollection.service.IHisDataCollectionService; import com.ruoyi.datacollection.service.IInhospDeptRefreshService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * 数据采集模块对外门面(常驻 Bean)—— 其它模块触发 HIS 采集的唯一入口。 * *

为什么必须"常驻"

* 本门面永远是 Spring Bean,不随开关状态增删。调用方({@code RyTask})的 * {@code @Autowired} 因此不会在任何开关状态下启动失败 —— * 与 {@code TaskFacade} / {@code PhoneFacade} / {@code TemplateFacade} 是同一条设计约束 * (历史教训:用 {@code @ConditionalOnProperty} 摘 Bean 会让调用方启动即失败, * 且只在启动时求值一次,做不到"改完参数 10 秒生效")。 * *

⚠️ 关闭时:抛异常,而不是静默跳过

* 模块关闭({@code sys_config: datacollection.enabled=false})时, * {@link #dealHisData(String)} 先过 {@link #requireEnabled()},抛 * {@link DataCollectionModuleDisabledException}: * * *

⚠️ 例外:{@link #isEnabled()} 不受守卫

* 它本身就是查开关状态用的;如果它也抛异常,"开关是不是关着"就再也问不出来了。 */ @Slf4j @Component public class DataCollectionFacade implements DataCollectionApi { /** * 运行时开关({@code sys_config} 优先,yml 兜底) */ @Autowired private DataCollectionSwitch dataCollectionSwitch; /** * 模块内实现(唯一实现 {@code HisDataCollectionServiceImpl}) */ @Autowired private IHisDataCollectionService hisDataCollectionService; /** * 模块内实现(唯一实现 {@code InhospDeptRefreshServiceImpl}): * 在院患者的科室/病区/床位每日刷新 */ @Autowired private IInhospDeptRefreshService inhospDeptRefreshService; /** * 模块是否启用({@code sys_config: datacollection.enabled},运行时热读) *

* ⚠️ 刻意不受守卫:见类注释。 */ @Override public boolean isEnabled() { return dataCollectionSwitch.isEnabled(); } @Override public void dealHisData(String todayZeroStr) { requireEnabled(); hisDataCollectionService.dealHisData(todayZeroStr); } @Override public int refreshInhospDeptInfo() { requireEnabled(); return inhospDeptRefreshService.refreshInhospDeptInfo(); } /** * 门面数据方法的统一入口守卫:模块关闭时抛 * {@link DataCollectionModuleDisabledException},由调用方决定如何降级。 */ private void requireEnabled() { if (!dataCollectionSwitch.isEnabled()) { log.warn("【数据采集】模块已关闭(参数配置 {} = false),拒绝门面访问", DataCollectionSwitch.CONFIG_KEY); throw new DataCollectionModuleDisabledException( DataCollectionModuleDisabledException.DISABLED_MESSAGE); } } }