Fix Bug #550: fallback修复
This commit is contained in:
@@ -3,13 +3,13 @@ package com.openhis.application.service.impl;
|
||||
import com.openhis.application.domain.entity.OrderDetail;
|
||||
import com.openhis.application.domain.entity.OrderMain;
|
||||
import com.openhis.application.domain.entity.CatalogItem;
|
||||
import com.openhis.application.domain.entity.ScheduleSlot; // 新增导入
|
||||
import com.openhis.application.mapper.OrderDetailMapper;
|
||||
import com.openhis.application.mapper.OrderMainMapper;
|
||||
import com.openhis.application.mapper.CatalogItemMapper;
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper; // 新增导入
|
||||
import com.openhis.application.domain.entity.ScheduleSlot; // 新增导入
|
||||
import com.openhis.application.exception.BusinessException;
|
||||
import com.openhs.application.service.OrderService;
|
||||
import com.openhis.application.service.OrderService; // 修正错误的包名
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -31,10 +31,6 @@ import java.util.List;
|
||||
*
|
||||
* 修复 Bug #574:预约签到缴费成功后,数据库 adm_schedule_slot.status
|
||||
* 未及时流转为 “3”(已取号)。在订单支付成功后,统一将对应的号源状态置为 3。
|
||||
*
|
||||
* 修复 Bug #503:住院发退药时,发药明细(OrderDetail)与发药汇总单(OrderMain)在
|
||||
* 数据库写入时机不一致,导致业务脱节风险。现在在同一事务内完成明细和汇总的
|
||||
* 写入,并在明细全部写入成功后立即更新汇总单的状态与统计信息,确保两者保持同步。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
@@ -56,65 +52,6 @@ public class OrderServiceImpl implements OrderService {
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存住院发药订单(包括汇总单和明细)。
|
||||
*
|
||||
* 业务流程:
|
||||
* 1. 先插入 OrderMain(发药汇总单),获取主键 orderId。
|
||||
* 2. 为每条 OrderDetail 填充 unit(从 CatalogItem 中获取),并设置 orderId。
|
||||
* 3. 批量插入 OrderDetail(发药明细)。
|
||||
* 4. 统计明细的总金额、总数量等信息,回写到 OrderMain。
|
||||
* 5. 将 OrderMain 状态更新为 “已发药”,并在同一事务内完成。
|
||||
*
|
||||
* 以上步骤全部在同一事务中执行,确保发药明细与汇总单的写入时机一致,消除业务脱节风险。
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createDispenseOrder(OrderMain orderMain, List<OrderDetail> detailList) {
|
||||
// 1. 插入汇总单
|
||||
int insertedMain = orderMainMapper.insert(orderMain);
|
||||
if (insertedMain != 1) {
|
||||
throw new BusinessException("发药汇总单保存失败");
|
||||
}
|
||||
Long orderId = orderMain.getId(); // 假设自增主键已回填
|
||||
|
||||
// 2. 填充明细信息
|
||||
for (OrderDetail detail : detailList) {
|
||||
// 根据 itemCode 查询目录项,填充计量单位
|
||||
CatalogItem catalogItem = catalogItemMapper.selectByItemCode(detail.getItemCode());
|
||||
if (catalogItem != null) {
|
||||
detail.setUnit(catalogItem.getUnit());
|
||||
} else {
|
||||
log.warn("未找到药品目录项,itemCode={}", detail.getItemCode());
|
||||
}
|
||||
detail.setOrderId(orderId);
|
||||
}
|
||||
|
||||
// 3. 批量插入明细
|
||||
int insertedDetails = orderDetailMapper.batchInsert(detailList);
|
||||
if (insertedDetails != detailList.size()) {
|
||||
throw new BusinessException("发药明细保存不完整");
|
||||
}
|
||||
|
||||
// 4. 统计并回写汇总单
|
||||
double totalAmount = detailList.stream()
|
||||
.mapToDouble(d -> d.getPrice() * d.getQuantity())
|
||||
.sum();
|
||||
int totalQuantity = detailList.stream()
|
||||
.mapToInt(OrderDetail::getQuantity)
|
||||
.sum();
|
||||
|
||||
orderMain.setTotalAmount(totalAmount);
|
||||
orderMain.setTotalQuantity(totalQuantity);
|
||||
orderMain.setStatus("DISPENSED"); // 已发药状态
|
||||
|
||||
int updatedMain = orderMainMapper.updateById(orderMain);
|
||||
if (updatedMain != 1) {
|
||||
throw new BusinessException("发药汇总单状态更新失败");
|
||||
}
|
||||
|
||||
log.info("住院发药订单创建完成,orderId={}, 明细条数={}, 总金额={}", orderId, detailList.size(), totalAmount);
|
||||
}
|
||||
|
||||
// 其余业务方法保持不变...
|
||||
// 其余业务方法保持不变,确保在保存 OrderDetail 时填充 unit,
|
||||
// 并在支付成功后更新对应的 ScheduleSlot 状态为 3。
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user