Fix Bug #503: AI修复
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.openhis.web.pharmacy.mapper;
|
||||
|
||||
import com.openhis.web.pharmacy.entity.DispensingRecord;
|
||||
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.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 发药记录数据库操作 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface DispensingRecordMapper {
|
||||
|
||||
@Select("SELECT * FROM pharmacy_dispensing_record WHERE id = #{id}")
|
||||
DispensingRecord selectById(@Param("id") Long id);
|
||||
|
||||
@Update("UPDATE pharmacy_dispensing_record SET nurse_exec_status = #{nurseExecStatus}, " +
|
||||
"pharmacy_apply_status = #{pharmacyApplyStatus}, exec_time = #{execTime}, " +
|
||||
"update_time = #{updateTime} WHERE id = #{id}")
|
||||
int updateById(DispensingRecord record);
|
||||
|
||||
/**
|
||||
* Bug #503 Fix: 批量更新药房申请状态
|
||||
* 确保汇总申请提交后,明细单与汇总单数据源状态一致
|
||||
*/
|
||||
@Update("<script>" +
|
||||
"UPDATE pharmacy_dispensing_record SET pharmacy_apply_status = #{status}, " +
|
||||
"update_time = #{updateTime} WHERE id IN " +
|
||||
"<foreach item='id' collection='orderIds' open='(' separator=',' close=')'>" +
|
||||
"#{id}" +
|
||||
"</foreach>" +
|
||||
"</script>")
|
||||
int batchUpdateApplyStatus(@Param("orderIds") List<Long> orderIds,
|
||||
@Param("status") Integer status,
|
||||
@Param("updateTime") LocalDateTime updateTime);
|
||||
|
||||
/**
|
||||
* 药房查询发药明细单
|
||||
* Bug #503 Fix: 强制过滤 pharmacy_apply_status = 1,避免未申请记录提前暴露
|
||||
*/
|
||||
@Select("SELECT * FROM pharmacy_dispensing_record " +
|
||||
"WHERE pharmacy_apply_status = 1 AND nurse_exec_status = 'EXECUTED' " +
|
||||
"ORDER BY create_time DESC")
|
||||
List<DispensingRecord> selectPharmacyDetailList();
|
||||
|
||||
/**
|
||||
* 药房查询发药汇总单
|
||||
* Bug #503 Fix: 与明细单使用相同的状态过滤条件,保证触发时机一致
|
||||
*/
|
||||
@Select("SELECT drug_code, drug_name, SUM(quantity) AS total_quantity, COUNT(*) AS record_count " +
|
||||
"FROM pharmacy_dispensing_record " +
|
||||
"WHERE pharmacy_apply_status = 1 AND nurse_exec_status = 'EXECUTED' " +
|
||||
"GROUP BY drug_code, drug_name ORDER BY create_time DESC")
|
||||
List<DispensingRecord> selectPharmacySummaryList();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.openhis.web.pharmacy.service;
|
||||
|
||||
import com.openhis.web.pharmacy.entity.DispensingRecord;
|
||||
import com.openhis.web.pharmacy.mapper.DispensingRecordMapper;
|
||||
import com.openhis.web.system.service.DictService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 住院发退药服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DispensingServiceImpl implements DispensingService {
|
||||
|
||||
private final DispensingRecordMapper dispensingRecordMapper;
|
||||
private final DictService dictService;
|
||||
|
||||
public DispensingServiceImpl(DispensingRecordMapper dispensingRecordMapper, DictService dictService) {
|
||||
this.dispensingRecordMapper = dispensingRecordMapper;
|
||||
this.dictService = dictService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 护士执行医嘱
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void executeDrugOrder(Long orderId) {
|
||||
DispensingRecord record = dispensingRecordMapper.selectById(orderId);
|
||||
if (record == null) {
|
||||
throw new IllegalArgumentException("发药记录不存在");
|
||||
}
|
||||
|
||||
record.setNurseExecStatus("EXECUTED");
|
||||
record.setExecTime(LocalDateTime.now());
|
||||
|
||||
// Bug #503 Fix: 根据字典配置控制药房可见状态
|
||||
// 默认模式为 APPLY_REQUIRED (需申请模式),执行时不推送到药房队列
|
||||
String submitMode = dictService.getValue("ward_nurse_submit_mode", "APPLY_REQUIRED");
|
||||
if ("APPLY_REQUIRED".equals(submitMode)) {
|
||||
record.setPharmacyApplyStatus(0); // 0-未申请,药房不可见
|
||||
} else {
|
||||
record.setPharmacyApplyStatus(1); // 1-已申请,药房可见(自动模式)
|
||||
}
|
||||
|
||||
record.setUpdateTime(LocalDateTime.now());
|
||||
dispensingRecordMapper.updateById(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 护士提交汇总发药申请
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void submitSummaryApplication(List<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
throw new IllegalArgumentException("申请单号列表不能为空");
|
||||
}
|
||||
|
||||
// Bug #503 Fix: 汇总申请触发时,统一将状态流转为“已申请”,确保明细与汇总同步可见
|
||||
dispensingRecordMapper.batchUpdateApplyStatus(orderIds, 1, LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user