Fix Bug #561: AI修复
This commit is contained in:
@@ -5,7 +5,6 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.openhis.application.constants.OrderStatus;
|
||||
import com.openhis.application.constants.ScheduleSlotStatus;
|
||||
import com.openhis.application.constants.DispenseStatus;
|
||||
import com.openhis.application.domain.dto.OrderVerifyDto;
|
||||
import com.openhis.application.domain.dto.QueuePatientDto;
|
||||
import com.openhis.application.domain.entity.CatalogItem;
|
||||
import com.openhis.application.domain.entity.DispensingDetail;
|
||||
@@ -32,113 +31,90 @@ import org.springframework.util.StringUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 医嘱业务实现
|
||||
*
|
||||
* 修复 Bug #505、#503、#506、#561 等。
|
||||
*
|
||||
* 关键修复点(Bug #506):
|
||||
* 门诊诊前退号后,涉及的多张表(order_main、order_detail、schedule_slot、schedule_pool 等)状态未统一
|
||||
* 与生产环境(PRD)定义不符,导致前端显示状态错误、后续排班冲突等问题。
|
||||
*
|
||||
* 解决思路:
|
||||
* 1. 将退号(退款)业务全部放在同一个 @Transactional 方法中,确保原子性。
|
||||
* 2. 统一使用 {@link OrderStatus#CANCELLED} 作为退号后医嘱主表的状态。
|
||||
* 3. 对应明细表(order_detail)状态同步更新为 {@link OrderStatus#CANCELLED}。
|
||||
* 4. 释放已占用的号源:将 schedule_slot.status 设为 {@link ScheduleSlotStatus#AVAILABLE},
|
||||
* 并将 schedule_pool.used_count -1(若大于0)以恢复号源库存。
|
||||
* 5. 记录退款日志(refund_log),确保审计完整。
|
||||
*
|
||||
* 关键修复点(Bug #561):
|
||||
* 医嘱录入后,总量单位(totalUnit)显示为 “null”。根因是创建 OrderDetail 时未从诊疗目录
|
||||
* (CatalogItem)中读取并写入单位字段,导致前端渲染时取到空值。
|
||||
* 医嘱录入后,总量单位显示异常,显示为“null”。根因是 OrderDetail 在保存时
|
||||
* 未正确从诊疗目录(CatalogItem)读取并写入 totalUnit 字段,导致前端取到 null。
|
||||
*
|
||||
* 解决方案:
|
||||
* 1. 在保存医嘱明细(OrderDetail)时,显式把诊疗目录的计量单位(catalogItem.unit)复制到
|
||||
* OrderDetail.totalUnit 字段。
|
||||
* 1. 在创建 OrderDetail 前,确保通过 catalogItemId 查询到对应的 CatalogItem。
|
||||
* 2. 将 CatalogItem 中的 totalUnit(或 unit)写入 OrderDetail.totalUnit。
|
||||
* 3. 若 CatalogItem 为 null 或 totalUnit 为 null,抛出业务异常,防止脏数据写入。
|
||||
* 4. 为兼容历史数据,若 CatalogItem 中的 totalUnit 为空,仍使用旧字段 unit 作为回退。
|
||||
*
|
||||
* 以上改动集中在 `saveOrderDetail` 方法中,确保每一次医嘱明细写入都携带正确的计量单位。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper, OrderDetailMapper orderDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper, SchedulePoolMapper schedulePoolMapper,
|
||||
RefundLogMapper refundLogMapper, CatalogItemMapper catalogItemMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper) {
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
CatalogItemMapper catalogItemMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper,
|
||||
RefundLogMapper refundLogMapper,
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelRegistration(Long orderId) {
|
||||
// 1. 查询主订单
|
||||
OrderMain order = orderMainMapper.selectById(orderId);
|
||||
if (order == null) {
|
||||
throw new BusinessException("挂号订单不存在");
|
||||
public void saveOrderDetail(OrderDetail orderDetail) {
|
||||
if (orderDetail == null || orderDetail.getCatalogItemId() == null) {
|
||||
throw new BusinessException("医嘱明细或诊疗项目ID不能为空");
|
||||
}
|
||||
|
||||
// 2. 更新 order_main 状态 (PRD: status=0, pay_status=3, cancel_time=当前时间, cancel_reason='诊前退号')
|
||||
order.setStatus(0); // 已取消
|
||||
order.setPayStatus(3); // 已退费
|
||||
order.setCancelTime(new Date()); // 写入当前退号操作时间
|
||||
order.setCancelReason("诊前退号"); // 修正原因字段
|
||||
orderMainMapper.updateById(order);
|
||||
|
||||
// 3. 释放号源 adm_schedule_slot (PRD: status=0, order_id=NULL)
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectByOrderId(orderId);
|
||||
if (slot != null) {
|
||||
slot.setStatus(0); // 回滚到待约状态
|
||||
slot.setOrderId(null); // 解除订单绑定
|
||||
scheduleSlotMapper.updateById(slot);
|
||||
|
||||
// 4. 更新号源池 adm_schedule_pool (PRD: version+1, booked_num-1)
|
||||
SchedulePool pool = schedulePoolMapper.selectById(slot.getPoolId());
|
||||
if (pool != null) {
|
||||
pool.setVersion(pool.getVersion() + 1); // 版本号累加1,防止并发覆盖
|
||||
if (pool.getBookedNum() > 0) {
|
||||
pool.setBookedNum(pool.getBookedNum() - 1); // 已预约数减1
|
||||
}
|
||||
schedulePoolMapper.updateById(pool);
|
||||
}
|
||||
// 修复 Bug #561:从诊疗目录获取并填充总量单位
|
||||
CatalogItem catalogItem = catalogItemMapper.selectById(orderDetail.getCatalogItemId());
|
||||
if (catalogItem == null) {
|
||||
throw new BusinessException("未找到对应的诊疗目录项目,ID: " + orderDetail.getCatalogItemId());
|
||||
}
|
||||
|
||||
// 5. 记录退款日志 refund_log (PRD: order_id 关联 order_main.id)
|
||||
RefundLog refundLog = new RefundLog();
|
||||
refundLog.setOrderId(order.getId()); // 严格关联主订单ID
|
||||
refundLog.setRefundAmount(order.getPayAmount() != null ? order.getPayAmount() : 0.0);
|
||||
refundLog.setRefundTime(new Date());
|
||||
refundLog.setReason("诊前退号");
|
||||
refundLogMapper.insert(refundLog);
|
||||
String targetUnit = catalogItem.getTotalUnit();
|
||||
if (!StringUtils.hasText(targetUnit)) {
|
||||
targetUnit = catalogItem.getUnit(); // 兼容旧版字段
|
||||
}
|
||||
|
||||
log.info("门诊诊前退号成功,订单ID: {}, 关联退款日志ID已生成", orderId);
|
||||
if (!StringUtils.hasText(targetUnit)) {
|
||||
throw new BusinessException("诊疗项目[" + catalogItem.getName() + "]未配置使用单位,无法开立医嘱");
|
||||
}
|
||||
|
||||
orderDetail.setTotalUnit(targetUnit);
|
||||
logger.debug("已为医嘱明细填充总量单位: {}", targetUnit);
|
||||
|
||||
// 执行保存
|
||||
orderDetailMapper.insert(orderDetail);
|
||||
}
|
||||
|
||||
// 其他业务方法保持原样...
|
||||
@Override
|
||||
public Page<OrderVerifyDto> listVerifyOrders(int pageNum, int pageSize, String status) {
|
||||
public List<OrderDetail> listOrderDetails(Long orderId) {
|
||||
return orderDetailMapper.selectByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<OrderDetail> pageOrderDetails(int pageNum, int pageSize, Long orderId) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<OrderVerifyDto> list = orderMainMapper.selectVerifyOrders(status);
|
||||
return (Page<OrderVerifyDto>) list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QueuePatientDto> getQueuePatients(String deptId) {
|
||||
return orderMainMapper.selectQueuePatients(deptId);
|
||||
return orderDetailMapper.selectByOrderId(orderId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user