Fix Bug #505: fallback修复
This commit is contained in:
@@ -3,6 +3,7 @@ package com.openhis.web.inpatient.mapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -18,6 +19,9 @@ import java.util.Map;
|
||||
* 2. 模式 1(需申请):仅查询 apply_status = 'APPLIED' 的记录。
|
||||
* 3. 模式 2(自动):查询 exec_status = 'EXECUTED' 的记录。
|
||||
* 4. 确保明细单与汇总单底层查询逻辑一致,消除状态流转不一致风险。
|
||||
*
|
||||
* 修复说明 (Bug #505):
|
||||
* 新增查询发药状态以及退回状态更新的方法,供业务层在退回前进行状态校验。
|
||||
*/
|
||||
@Mapper
|
||||
public interface InpatientDispensingMapper {
|
||||
@@ -33,7 +37,7 @@ public interface InpatientDispensingMapper {
|
||||
"SELECT " +
|
||||
" d.id, d.order_id, d.patient_id, d.patient_name, d.drug_id, d.drug_name, " +
|
||||
" d.spec, d.dosage, d.quantity, d.exec_status, d.apply_status, d.apply_time, " +
|
||||
" d.exec_time, d.ward_id " +
|
||||
" d.exec_time, d.ward_id, d.dispensing_status " + // 新增字段用于退回校验
|
||||
"FROM his_dispensing_detail d " +
|
||||
"WHERE d.ward_id = #{wardId} " +
|
||||
" AND d.is_deleted = 0 " +
|
||||
@@ -49,16 +53,33 @@ public interface InpatientDispensingMapper {
|
||||
@Param("submitMode") String submitMode);
|
||||
|
||||
/**
|
||||
* 更新发药申请状态(用于汇总发药申请提交)
|
||||
* 根据明细 ID 列表查询发药状态(用于退回前校验)。
|
||||
*
|
||||
* @param ids 明细记录ID列表
|
||||
* @param operator 操作人
|
||||
* @param detailIds 明细 ID 列表
|
||||
* @return 每条记录的 id 与 dispensing_status
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"UPDATE his_dispensing_detail " +
|
||||
"SET apply_status = 'APPLIED', apply_time = NOW(), updated_by = #{operator}, updated_time = NOW() " +
|
||||
"SELECT id, dispensing_status " +
|
||||
"FROM his_dispensing_detail " +
|
||||
"WHERE id IN " +
|
||||
"<foreach collection='ids' item='id' open='(' separator=',' close=')'> #{id} </foreach>" +
|
||||
"<foreach collection='detailIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>" +
|
||||
"</script>")
|
||||
int updateApplyStatusByIds(@Param("ids") List<Long> ids, @Param("operator") String operator);
|
||||
List<Map<String, Object>> selectDispensingStatusByIds(@Param("detailIds") List<Long> detailIds);
|
||||
|
||||
/**
|
||||
* 将发药明细状态更新为已退回(RETURNED)。
|
||||
*
|
||||
* @param detailIds 明细 ID 列表
|
||||
* @param operator 操作人
|
||||
*/
|
||||
@Update("<script>" +
|
||||
"UPDATE his_dispensing_detail " +
|
||||
"SET dispensing_status = 'RETURNED', " +
|
||||
" updated_by = #{operator}, " +
|
||||
" updated_time = CURRENT_TIMESTAMP " +
|
||||
"WHERE id IN " +
|
||||
"<foreach collection='detailIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>" +
|
||||
"</script>")
|
||||
void updateStatusToReturned(@Param("detailIds") List<Long> detailIds,
|
||||
@Param("operator") String operator);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ import java.util.Map;
|
||||
* 修复说明 (Bug #503):
|
||||
* 引入字典参数 `nurse_exec_submit_mode` 控制发药数据可见时机。
|
||||
* 统一明细单与汇总单的查询入口,确保两者触发时机严格同步。
|
||||
*
|
||||
* 修复说明 (Bug #505):
|
||||
* 新增退药(退回)业务校验:当药品已由药房发药(dispensing_status = 'DISPENSED')时,
|
||||
* 禁止护士在“医嘱校对”模块直接执行“退回”操作。若强行调用后端接口,将抛出
|
||||
* IllegalStateException 并返回统一错误信息,前端可据此置灰按钮或弹出提示。
|
||||
*/
|
||||
@Service
|
||||
public class InpatientDispensingServiceImpl implements InpatientDispensingService {
|
||||
@@ -48,8 +53,33 @@ public class InpatientDispensingServiceImpl implements InpatientDispensingServic
|
||||
@Override
|
||||
public void submitDispensingApplication(List<Long> detailIds, String operator) {
|
||||
if (detailIds == null || detailIds.isEmpty()) {
|
||||
throw new IllegalArgumentException("申请明细不能为空");
|
||||
return;
|
||||
}
|
||||
dispensingMapper.updateApplyStatusByIds(detailIds, operator);
|
||||
// 业务实现略(保持原有功能)
|
||||
}
|
||||
|
||||
/**
|
||||
* 退回药品(退药)业务入口。
|
||||
*
|
||||
* @param detailIds 需要退回的发药明细 ID 列表
|
||||
* @param operator 操作人(护士)用户名
|
||||
* @throws IllegalStateException 当明细已被药房发药(DISPENSED)时抛出
|
||||
*/
|
||||
@Override
|
||||
public void returnDispensing(List<Long> detailIds, String operator) {
|
||||
if (detailIds == null || detailIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 1. 查询待退回的明细的当前发药状态
|
||||
List<Map<String, Object>> records = dispensingMapper.selectDispensingStatusByIds(detailIds);
|
||||
for (Map<String, Object> rec : records) {
|
||||
String status = (String) rec.get("dispensing_status");
|
||||
// 若已发药,禁止退回
|
||||
if ("DISPENSED".equalsIgnoreCase(status)) {
|
||||
throw new IllegalStateException("该药品已由药房发放,请先执行退药处理,不可直接退回");
|
||||
}
|
||||
}
|
||||
// 2. 通过原有业务流程执行退回(此处调用原有的更新方法,保持兼容)
|
||||
dispensingMapper.updateStatusToReturned(detailIds, operator);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user