Fix Bug #584: AI修复
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.openhis.web.inpatient.mapper;
|
||||
|
||||
import com.openhis.web.inpatient.entity.SurgeryRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 手术申请数据库操作 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface SurgeryRequestMapper {
|
||||
|
||||
@Select("SELECT id, patient_id, status, sign_time, sign_doctor_id, nurse_verify_status, update_time FROM hisdev.surgery_request WHERE id = #{id}")
|
||||
SurgeryRequest selectById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 精确字段更新,避免全量覆盖导致脏数据
|
||||
*/
|
||||
@Update("UPDATE hisdev.surgery_request SET status = #{status}, sign_time = #{signTime}, sign_doctor_id = #{signDoctorId}, nurse_verify_status = #{nurseVerifyStatus}, update_time = #{updateTime} WHERE id = #{id}")
|
||||
int updateById(SurgeryRequest request);
|
||||
|
||||
/**
|
||||
* 级联更新关联手术医嘱状态
|
||||
*/
|
||||
@Update("UPDATE hisdev.surgery_order SET status = #{orderStatus}, update_time = NOW() WHERE surgery_request_id = #{requestId}")
|
||||
int updateOrderStatusByRequestId(@Param("requestId") Long requestId, @Param("orderStatus") String orderStatus);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.openhis.web.inpatient.service;
|
||||
|
||||
import com.openhis.web.inpatient.entity.SurgeryRequest;
|
||||
import com.openhis.web.inpatient.mapper.SurgeryRequestMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 手术申请服务实现
|
||||
*/
|
||||
@Service
|
||||
public class SurgeryRequestServiceImpl implements SurgeryRequestService {
|
||||
|
||||
private final SurgeryRequestMapper surgeryRequestMapper;
|
||||
|
||||
public SurgeryRequestServiceImpl(SurgeryRequestMapper surgeryRequestMapper) {
|
||||
this.surgeryRequestMapper = surgeryRequestMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除手术申请单(仅待签发状态)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteRequest(Long requestId) {
|
||||
if (requestId == null) {
|
||||
throw new IllegalArgumentException("申请单ID不能为空");
|
||||
}
|
||||
|
||||
SurgeryRequest request = surgeryRequestMapper.selectById(requestId);
|
||||
if (request == null) {
|
||||
throw new RuntimeException("手术申请单不存在");
|
||||
}
|
||||
|
||||
if (!"PENDING_SIGN".equals(request.getStatus())) {
|
||||
throw new RuntimeException("仅待签发状态的手术申请可删除");
|
||||
}
|
||||
|
||||
// 状态更新为已作废
|
||||
request.setStatus("CANCELLED");
|
||||
request.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
int updateResult = surgeryRequestMapper.updateById(request);
|
||||
if (updateResult <= 0) {
|
||||
throw new RuntimeException("删除失败,数据更新异常");
|
||||
}
|
||||
|
||||
// 级联作废对应的手术医嘱
|
||||
surgeryRequestMapper.updateOrderStatusByRequestId(requestId, "CANCELLED");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回手术申请单(仅已签发状态,防护士已校对冲突)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean revokeRequest(Long requestId) {
|
||||
if (requestId == null) {
|
||||
throw new IllegalArgumentException("申请单ID不能为空");
|
||||
}
|
||||
|
||||
SurgeryRequest request = surgeryRequestMapper.selectById(requestId);
|
||||
if (request == null) {
|
||||
throw new RuntimeException("手术申请单不存在");
|
||||
}
|
||||
|
||||
if (!"SIGNED".equals(request.getStatus())) {
|
||||
throw new RuntimeException("仅已签发状态的手术申请可撤回");
|
||||
}
|
||||
|
||||
// 防冲突实时校验:若病区护士已校对通过,拦截撤回
|
||||
if (Boolean.TRUE.equals(request.getNurseVerifyStatus())) {
|
||||
throw new RuntimeException("撤回失败!该手术申请已由病区护士已校对,请致电病区护士处理。");
|
||||
}
|
||||
|
||||
// 状态回滚:已签发 -> 待签发
|
||||
request.setStatus("PENDING_SIGN");
|
||||
request.setSignTime(null);
|
||||
request.setSignDoctorId(null);
|
||||
request.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
int updateResult = surgeryRequestMapper.updateById(request);
|
||||
if (updateResult <= 0) {
|
||||
throw new RuntimeException("撤回失败,数据更新异常");
|
||||
}
|
||||
|
||||
// 级联更新对应的手术医嘱状态为待签发
|
||||
surgeryRequestMapper.updateOrderStatusByRequestId(requestId, "PENDING_SIGN");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user