@@ -18,6 +18,10 @@ import com.openhis.common.constant.CommonConstants;
import com.openhis.common.enums.* ;
import com.openhis.common.utils.EnumUtils ;
import com.openhis.common.utils.HisQueryUtils ;
import com.openhis.appointmentmanage.domain.ScheduleSlot ;
import com.openhis.appointmentmanage.mapper.ScheduleSlotMapper ;
import com.openhis.clinical.domain.Order ;
import com.openhis.clinical.service.IOrderService ;
import com.openhis.triageandqueuemanage.domain.DivLog ;
import com.openhis.triageandqueuemanage.domain.TriageQueueItem ;
import com.openhis.triageandqueuemanage.service.DivLogService ;
@@ -78,6 +82,12 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
@Resource
private DivLogService divLogService ;
@Resource
private IOrderService iOrderService ;
@Resource
private ScheduleSlotMapper scheduleSlotMapper ;
/**
* 查询就诊患者信息
*
@@ -264,8 +274,27 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
return R . fail ( " 非就诊中患者不能完诊 " ) ;
}
// 2. 查找队列项(限定当天,避免复诊患者匹配到历史队列记录)
// 2. 获取 pool_id 和 slot_id: 从 encounter → order_main → adm_schedule_slot 链路获取
// 确保 div_log 中的值与排班主表一致,不依赖 triage_queue_item( 队列项可能不存在或值错误)
Integer tenantId = SecurityUtils . getLoginUser ( ) . getTenantId ( ) ;
Long divPoolId = null ;
Long divSlotId = null ;
if ( encounter . getOrderId ( ) ! = null ) {
try {
Order order = iOrderService . getById ( encounter . getOrderId ( ) ) ;
if ( order ! = null & & order . getSlotId ( ) ! = null ) {
divSlotId = order . getSlotId ( ) ;
ScheduleSlot slot = scheduleSlotMapper . selectById ( divSlotId ) ;
if ( slot ! = null ) {
divPoolId = slot . getPoolId ( ) ;
}
}
} catch ( Exception e ) {
log . warn ( " 获取完诊div_log的pool_id/slot_id失败, encounterId={} " , encounterId , e ) ;
}
}
// 3. 查找队列项(限定当天,避免复诊患者匹配到历史队列记录)
TriageQueueItem queueItem = triageQueueItemService . getOne (
new LambdaQueryWrapper < TriageQueueItem > ( )
. eq ( TriageQueueItem : : getTenantId , tenantId )
@@ -278,31 +307,29 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
// 使用排除法而非白名单:只要不是"已完成"就可以完诊,覆盖跳过、等待等非标准流转状态
if ( queueItem ! = null & &
! TriageQueueStatus . COMPLETED . getValue ( ) . equals ( queueItem . getStatus ( ) ) ) {
// 更新队列状态为已完成
java . time . LocalDateTime nowLocal = java . time . LocalDateTime . now ( ) . truncatedTo ( ChronoUnit . SECONDS ) ;
queueItem . setStatus ( TriageQueueStatus . COMPLETED . getValue ( ) ) ;
queueItem . setUpdateTime ( nowLocal ) ;
triageQueueItemService . updateById ( queueItem ) ;
// 写入 div_log 审计日志(使用实体+Service替代原生JDBC SQL, 避免SQL注入风险, 便于维护)
try {
LoginUser loginUser = SecurityUtils . getLoginUser ( ) ;
DivLog divLog = new DivLog ( )
. setPoolId ( queueItem . getPoolId ( ) )
. setSlotId ( queueItem . getSlotId ( ) )
. setOpUserId ( loginUser ! = null ? loginUser . getUserId ( ) : null )
. setAction ( " COMPLETE " )
. setCreateTime ( LocalDateTime . now ( ) )
. setUpdateAt ( LocalDateTime . now ( ) )
. setCreatedAt ( LocalDateTime . now ( ) ) ;
divLogService . save ( divLog ) ;
} catch ( Exception e ) {
log . error ( " 写入div_log审计日志失败 " , e ) ;
// 审计日志失败不影响主流程
}
}
// 3. 更新状态、完成时间以及初复诊标识
// 写入 div_log 审计日志(独立于队列项,确保每次完诊都生成记录)
try {
LoginUser loginUser = SecurityUtils . getLoginUser ( ) ;
DivLog divLog = new DivLog ( )
. setPoolId ( divPoolId )
. setSlotId ( divSlotId )
. setOpUserId ( loginUser ! = null ? loginUser . getUserId ( ) : null )
. setAction ( " COMPLETE " )
. setCreateTime ( LocalDateTime . now ( ) )
. setUpdateAt ( LocalDateTime . now ( ) )
. setCreatedAt ( LocalDateTime . now ( ) ) ;
divLogService . save ( divLog ) ;
} catch ( Exception e ) {
log . error ( " 写入div_log审计日志失败 " , e ) ;
}
// 4. 更新状态、完成时间以及初复诊标识
Date now = new Date ( ) ;
int update = encounterMapper . update ( null ,
new LambdaUpdateWrapper < Encounter > ( )
@@ -315,7 +342,7 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
if ( update < = 0 ) return R . fail ( " 完诊失败 " ) ;
// 4 . 审计日志( sys_oper_log)
// 5 . 审计日志( sys_oper_log)
try {
String username = SecurityUtils . getUsernameSafe ( ) ;
String sql = " INSERT INTO sys_oper_log "