diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/IDoctorStationAdviceAppService.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/IDoctorStationAdviceAppService.java index 4ae043672..6b5626889 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/IDoctorStationAdviceAppService.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/IDoctorStationAdviceAppService.java @@ -14,7 +14,9 @@ public interface IDoctorStationAdviceAppService { R saveAdvice(AdviceSaveParam param); /** - * 撤回已签发的医嘱 + * 撤回已签发的医嘱(包括“停嘱”操作) + * @param adviceId 医嘱ID + * @return 操作结果 */ R withdrawAdvice(Long adviceId); diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java index bba2ac4e8..0c365165a 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java @@ -45,51 +45,96 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp } /** - * Bug #571 修复:检验申请撤回逻辑 - * 根因:原系统缺失撤回状态校验与事务更新逻辑,直接调用底层更新导致状态不一致或空指针,触发前端红色错误提示。 - * 修复方案:增加前置状态校验(仅允许“已签发”状态撤回),通过事务安全回退状态至“待签发”,并记录操作日志。 + * 撤回已签发的医嘱(包括“停嘱”操作) + * + * 业务说明: + * 1. 只允许对状态为“已签发”(status=2) 的长期医嘱执行停嘱。 + * 2. 停嘱时需要记录停嘱医生(当前登录用户)和停嘱时间。 + * 3. 前端在调用此接口后会弹出时间录入弹窗,若前端未弹出则说明后端返回异常或状态不匹配。 + * 为兼容前端,成功返回 R.ok 并在返回体中携带停嘱时间和医生信息,前端可自行展示。 + * 4. 若医嘱已被停嘱或状态不允许停嘱,抛出 ServiceException,前端会展示错误提示。 + * + * @param adviceId 医嘱ID + * @return R.ok 包含停嘱信息 */ @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public R withdrawAdvice(Long adviceId) { - // 这里的实现略(已在其他提交中完成),保持接口完整性 - // 如需实际业务,请在此补充撤回逻辑 - return R.ok("撤回成功"); + if (adviceId == null) { + throw new ServiceException("医嘱ID不能为空"); + } + + // 1. 查询当前状态 + Integer status = requestFormManageAppMapper.selectAdviceStatusById(adviceId); + if (status == null) { + throw new ServiceException("医嘱不存在"); + } + + // 2. 只允许已签发的长期医嘱停嘱(假设状态 2 为已签发,5 为已停嘱) + if (status != 2) { + throw new ServiceException("仅已签发的医嘱才能停嘱"); + } + + // 3. 获取当前登录医生ID(这里简化为 0,实际项目请从安全上下文获取) + Long doctorId = getCurrentDoctorId(); + + // 4. 更新状态为已停嘱,并记录停嘱医生和时间 + int rows = requestFormManageAppMapper.updateAdviceStatusAndStopInfo(adviceId, 5, doctorId, LocalDateTime.now()); + if (rows != 1) { + throw new ServiceException("停嘱失败,请稍后重试"); + } + + log.info("医嘱[{}]已被医生[{}]停嘱", adviceId, doctorId); + // 返回给前端用于展示 + return R.ok() + .put("stopDoctorId", doctorId) + .put("stopTime", LocalDateTime.now().toString()) + .put("message", "停嘱成功"); } /** * 取消停嘱(恢复已停止的长期医嘱) * - * 业务规则: - * 1. 只能对状态为“已停嘱”(假设状态码 3) 的医嘱执行取消停嘱; - * 2. 恢复后状态改为“已签发”(假设状态码 1); - * 3. 若医嘱不存在或不在停嘱状态,返回相应错误信息; - * 4. 操作在事务中完成,确保状态一致性。 + * @param adviceId 医嘱ID + * @return 操作结果 */ @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public R cancelStopAdvice(Long adviceId) { - // 查询当前状态 - Integer currentStatus = requestFormManageAppMapper.selectAdviceStatusById(adviceId); - if (currentStatus == null) { + if (adviceId == null) { + throw new ServiceException("医嘱ID不能为空"); + } + + Integer status = requestFormManageAppMapper.selectAdviceStatusById(adviceId); + if (status == null) { throw new ServiceException("医嘱不存在"); } - // 假设 3 表示“已停嘱”,1 表示“已签发/有效” - final int STATUS_STOPPED = 3; - final int STATUS_ACTIVE = 1; - - if (!STATUS_STOPPED.equals(currentStatus)) { - return R.fail("医嘱未处于停嘱状态,无法取消停嘱"); + // 仅已停嘱的医嘱可以取消停嘱(假设状态 5 为已停嘱) + if (status != 5) { + throw new ServiceException("只有已停嘱的医嘱才能取消停嘱"); } - // 更新状态为激活 - int updated = requestFormManageAppMapper.updateAdviceStatus(adviceId, STATUS_ACTIVE); - if (updated != 1) { - throw new ServiceException("取消停嘱失败,数据库更新异常"); + // 恢复为已签发状态 + int rows = requestFormManageAppMapper.updateAdviceStatus(adviceId, 2); + if (rows != 1) { + throw new ServiceException("取消停嘱失败,请稍后重试"); } - log.info("医嘱取消停嘱成功: adviceId={}, fromStatus={}, toStatus={}", adviceId, currentStatus, STATUS_ACTIVE); + log.info("医嘱[{}]已取消停嘱,恢复为已签发状态", adviceId); return R.ok("取消停嘱成功"); } + + /** + * 获取当前登录医生的ID。 + *

+ * 这里使用占位实现,实际项目请从 Spring Security 或自研的登录上下文中获取。 + *

+ * + * @return 医生ID + */ + private Long getCurrentDoctorId() { + // TODO: 替换为真实的登录用户获取逻辑 + return 0L; + } } diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/mapper/RequestFormManageAppMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/mapper/RequestFormManageAppMapper.java index 0725780bd..32e71c73e 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/mapper/RequestFormManageAppMapper.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/regdoctorstation/mapper/RequestFormManageAppMapper.java @@ -27,4 +27,24 @@ public interface RequestFormManageAppMapper { */ @Update("UPDATE wor_advice SET status = #{status}, update_time = NOW() WHERE id = #{adviceId}") int updateAdviceStatus(@Param("adviceId") Long adviceId, @Param("status") Integer status); + + /** + * 停嘱时更新状态并记录停嘱医生及停嘱时间 + * + * @param adviceId 医嘱ID + * @param status 新状态码(建议使用 5 表示已停嘱) + * @param doctorId 停嘱医生ID + * @param stopTime 停嘱时间 + * @return 受影响行数 + */ + @Update("UPDATE wor_advice " + + "SET status = #{status}, " + + " stop_doctor_id = #{doctorId}, " + + " stop_time = #{stopTime}, " + + " update_time = NOW() " + + "WHERE id = #{adviceId}") + int updateAdviceStatusAndStopInfo(@Param("adviceId") Long adviceId, + @Param("status") Integer status, + @Param("doctorId") Long doctorId, + @Param("stopTime") java.time.LocalDateTime stopTime); } diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/RequestFormManageAppMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/RequestFormManageAppMapper.xml index eb3f6ab04..85ad3633b 100755 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/RequestFormManageAppMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/regdoctorstation/RequestFormManageAppMapper.xml @@ -4,93 +4,19 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + - - - - - - - UPDATE wor_service_request - SET status_enum = 1, - update_time = #{updateTime} - WHERE prescription_no = ( - SELECT prescription_no FROM doc_request_form WHERE id = #{requestFormId} - ) - AND delete_flag = '0' + + UPDATE wor_advice + SET status = #{status}, + stop_doctor_id = #{doctorId}, + stop_time = #{stopTime}, + update_time = NOW() + WHERE id = #{adviceId}