diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/mapper/InpatientDrugMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/mapper/InpatientDrugMapper.java
index 5edebc398..3ba1d6c60 100644
--- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/mapper/InpatientDrugMapper.java
+++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/mapper/InpatientDrugMapper.java
@@ -53,31 +53,35 @@ public interface InpatientDrugMapper {
@Param("operator") String operator);
/**
- * 汇总单 UPSERT:累计正负数量
+ * 汇总单 UPSERT:如果不存在则 INSERT;如果已存在则累计 quantity。
*
* @param orderId 医嘱ID
* @param drugId 药品ID
- * @param quantity 本次操作数量(正数为发药,负数为退药)
+ * @param quantity 本次发药/退药数量(正负均可)
+ * @param operator 操作人
*/
- @Insert("INSERT INTO inpatient_drug_dispense_summary " +
- "(order_id, drug_id, total_quantity, last_update) " +
- "VALUES (#{orderId}, #{drugId}, #{quantity}, NOW()) " +
- "ON DUPLICATE KEY UPDATE " +
- "total_quantity = total_quantity + #{quantity}, " +
- "last_update = NOW()")
+ @Insert({
+ ""
+ })
int upsertDrugDispenseSummary(@Param("orderId") Long orderId,
@Param("drugId") Long drugId,
- @Param("quantity") Integer quantity);
+ @Param("quantity") Integer quantity,
+ @Param("operator") String operator);
/**
- * 查询医嘱是否已完成发药(即汇总单中正向数量大于 0 且无未退药的负向数量)。
+ * 查询医嘱是否已经发药(汇总表中 total_quantity > 0)。
*
* @param orderId 医嘱ID
* @return true 已发药,false 未发药
*/
- @Select("SELECT EXISTS(" +
- "SELECT 1 FROM inpatient_drug_dispense_summary " +
- "WHERE order_id = #{orderId} AND total_quantity > 0" +
- ")")
+ @Select("SELECT IFNULL(total_quantity,0) > 0 FROM inpatient_drug_dispense_summary WHERE order_id = #{orderId}")
boolean selectDispensedFlag(@Param("orderId") Long orderId);
}
diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/InpatientDrugServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/InpatientDrugServiceImpl.java
index 274215347..3972162e6 100644
--- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/InpatientDrugServiceImpl.java
+++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/impl/InpatientDrugServiceImpl.java
@@ -49,63 +49,64 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
@Override
@Transactional(rollbackFor = Exception.class)
public void dispenseDrugs(Long orderId, List