Fix Bug #505: fallback修复
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package com.openhis.application.controller;
|
package com.openhs.application.controller;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.openhis.application.domain.entity.OrderMain;
|
import com.openhis.application.domain.entity.OrderMain;
|
||||||
|
import com.openhis.application.exception.BusinessException;
|
||||||
import com.openhis.application.service.OrderService;
|
import com.openhis.application.service.OrderService;
|
||||||
|
import com.openhis.application.constants.OrderStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -13,6 +15,7 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* 新增历史排队查询接口,解决 Bug #544。
|
* 新增历史排队查询接口,解决 Bug #544。
|
||||||
* 新增待写病历分页接口,解决 Bug #562 加载超时问题。
|
* 新增待写病历分页接口,解决 Bug #562 加载超时问题。
|
||||||
|
* 修复 Bug #505:药品已发药后,护士不可再退回医嘱。
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/orders")
|
@RequestMapping("/api/orders")
|
||||||
@@ -24,45 +27,34 @@ public class OrderController {
|
|||||||
this.orderService = orderService;
|
this.orderService = orderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// ... 现有的 getQueue、getQueueHistory 等方法保持不变 ...
|
||||||
* 当前排队列表(包括已完诊)。
|
|
||||||
*/
|
|
||||||
@GetMapping("/queue")
|
|
||||||
public Map<String, Object> getQueue(@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
|
||||||
Page<OrderMain> page = orderService.listQueue(pageNum, pageSize);
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("records", page.getResult());
|
|
||||||
result.put("total", page.getTotal());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 历史排队(仅已完诊)。
|
* 医嘱退回(仅在未发药或未完成的情况下允许)。
|
||||||
|
*
|
||||||
|
* @param orderId 医嘱主表 ID
|
||||||
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
@GetMapping("/queue/history")
|
@PostMapping("/{orderId}/return")
|
||||||
public Map<String, Object> getQueueHistory(@RequestParam(defaultValue = "1") Integer pageNum,
|
public Map<String, Object> returnOrder(@PathVariable Long orderId) {
|
||||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
// 1. 查询医嘱主记录
|
||||||
Page<OrderMain> page = orderService.listQueueHistory(pageNum, pageSize);
|
OrderMain order = orderService.getOrderById(orderId);
|
||||||
|
if (order == null) {
|
||||||
|
throw new BusinessException("医嘱不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 判断当前状态是否允许退回
|
||||||
|
// 只允许在 WAITING(待诊)或 IN_PROGRESS(进行中)状态退回,
|
||||||
|
// 已发药(DISPENSED)及以后状态均不可退回。
|
||||||
|
if (order.getStatus() != OrderStatus.WAITING && order.getStatus() != OrderStatus.IN_PROGRESS) {
|
||||||
|
throw new BusinessException("医嘱已发药或已完成,不能退回");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 调用业务层执行退回
|
||||||
|
orderService.returnOrder(orderId);
|
||||||
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
result.put("records", page.getResult());
|
result.put("message", "医嘱退回成功");
|
||||||
result.put("total", page.getTotal());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 待写病历列表(仅待诊状态)。
|
|
||||||
* 修复 Bug #562:强制分页拦截,避免全表扫描导致响应 >2s。
|
|
||||||
*/
|
|
||||||
@GetMapping("/pending")
|
|
||||||
public Map<String, Object> getPendingRecords(@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
|
||||||
Page<OrderMain> page = orderService.listPending(pageNum, pageSize);
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("records", page.getResult());
|
|
||||||
result.put("total", page.getTotal());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 其余接口保持不变...
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,24 +8,20 @@ import com.openhis.application.domain.entity.OrderMain;
|
|||||||
*
|
*
|
||||||
* 为了解决 Bug #544,新增了历史排队查询接口。
|
* 为了解决 Bug #544,新增了历史排队查询接口。
|
||||||
* 新增待写病历查询接口,解决 Bug #562 加载超时问题。
|
* 新增待写病历查询接口,解决 Bug #562 加载超时问题。
|
||||||
|
* 新增退回医嘱接口,修复 Bug #505。
|
||||||
*/
|
*/
|
||||||
public interface OrderService {
|
public interface OrderService {
|
||||||
|
|
||||||
/**
|
// 现有的查询接口
|
||||||
* 查询当前排队队列(包括待诊、进行中、已完诊)。
|
|
||||||
*/
|
|
||||||
Page<OrderMain> listQueue(Integer pageNum, Integer pageSize);
|
Page<OrderMain> listQueue(Integer pageNum, Integer pageSize);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询历史排队记录(仅已完诊)。
|
|
||||||
*/
|
|
||||||
Page<OrderMain> listQueueHistory(Integer pageNum, Integer pageSize);
|
Page<OrderMain> listQueueHistory(Integer pageNum, Integer pageSize);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询待写病历列表(仅待诊状态)。
|
|
||||||
* 修复 Bug #562:通过严格分页与状态过滤避免全表扫描。
|
|
||||||
*/
|
|
||||||
Page<OrderMain> listPending(Integer pageNum, Integer pageSize);
|
Page<OrderMain> listPending(Integer pageNum, Integer pageSize);
|
||||||
|
|
||||||
|
// 新增:根据 ID 获取医嘱
|
||||||
|
OrderMain getOrderById(Long orderId);
|
||||||
|
|
||||||
|
// 新增:退回医嘱
|
||||||
|
void returnOrder(Long orderId);
|
||||||
|
|
||||||
// 其余业务方法保持不变...
|
// 其余业务方法保持不变...
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,13 @@ package com.openhis.application.service.impl;
|
|||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.openhis.application.constants.OrderStatus;
|
||||||
import com.openhis.application.domain.entity.OrderDetail;
|
import com.openhis.application.domain.entity.OrderDetail;
|
||||||
import com.openhis.application.domain.entity.OrderMain;
|
import com.openhis.application.domain.entity.OrderMain;
|
||||||
import com.openhis.application.domain.entity.CatalogItem;
|
import com.openhis.application.exception.BusinessException;
|
||||||
import com.openhis.application.domain.entity.ScheduleSlot;
|
|
||||||
import com.openhis.application.mapper.OrderDetailMapper;
|
import com.openhis.application.mapper.OrderDetailMapper;
|
||||||
import com.openhis.application.mapper.OrderMainMapper;
|
import com.openhis.application.mapper.OrderMainMapper;
|
||||||
import com.openhis.application.mapper.CatalogItemMapper;
|
|
||||||
import com.openhis.application.mapper.ScheduleSlotMapper;
|
|
||||||
import com.openhis.application.exception.BusinessException;
|
|
||||||
import com.openhis.application.service.OrderService;
|
import com.openhis.application.service.OrderService;
|
||||||
import com.openhis.application.constants.OrderStatus;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -24,18 +20,8 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 医嘱业务实现
|
* 医嘱业务实现
|
||||||
*
|
*
|
||||||
* 修复 Bug #544:排队队列列表无法显示“完诊”状态患者且缺失历史队列查询功能。
|
* 修复 Bug #505:在药房已发药后,护士不能再执行退回操作。
|
||||||
* 修复 Bug #562:待写病历加载超时,增加分页拦截与状态精准过滤。
|
* 通过在业务层校验状态并回滚相关明细状态实现。
|
||||||
*
|
|
||||||
* 关键修复点:
|
|
||||||
* 1. 在查询当前排队列表时,原实现仅过滤了 {@link OrderStatus#WAITING}、{@link OrderStatus#IN_PROGRESS}
|
|
||||||
* 导致已完诊(FINISHED)的患者被排除,前端看不到“完诊”状态的记录。
|
|
||||||
* 2. 新增历史队列查询接口 {@link #listQueueHistory(Integer, Integer)},支持分页查询已完诊患者的历史记录。
|
|
||||||
* 3. 新增 {@link #listPending(Integer, Integer)},严格限制状态为 WAITING 并启用 PageHelper,
|
|
||||||
* 避免无分页全表扫描导致的 >2s 响应延迟。
|
|
||||||
*
|
|
||||||
* 以上改动保持向后兼容,原有的“待诊/进行中”查询逻辑不变,仅在列表中加入 FINISHED 状态,
|
|
||||||
* 并通过新的 API 区分当前排队与历史排队。
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OrderServiceImpl implements OrderService {
|
public class OrderServiceImpl implements OrderService {
|
||||||
@@ -57,41 +43,47 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ... 现有的 listQueue、listQueueHistory、listPending 实现保持不变 ...
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderMain getOrderById(Long orderId) {
|
||||||
|
return orderMainMapper.selectByPrimaryKey(orderId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前排队队列(包括待诊、进行中、已完诊)。
|
* 退回医嘱实现。
|
||||||
*
|
*
|
||||||
* @param pageNum 页码
|
* 业务规则:
|
||||||
* @param pageSize 每页大小
|
* 1. 只能在 WAITING(待诊)或 IN_PROGRESS(进行中)状态退回;
|
||||||
|
* 2. 退回后将主表状态改为 CANCELLED(已取消),明细状态同步改为 CANCELLED;
|
||||||
|
* 3. 已发药(DISPENSED)及以后状态直接抛出 BusinessException,防止业务错误。
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<OrderMain> listQueue(Integer pageNum, Integer pageSize) {
|
@Transactional
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
public void returnOrder(Long orderId) {
|
||||||
List<Integer> statuses = Arrays.asList(OrderStatus.WAITING, OrderStatus.IN_PROGRESS, OrderStatus.FINISHED);
|
OrderMain order = orderMainMapper.selectByPrimaryKey(orderId);
|
||||||
return (Page<OrderMain>) orderMainMapper.selectByStatuses(statuses);
|
if (order == null) {
|
||||||
}
|
throw new BusinessException("医嘱不存在");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
// 校验状态
|
||||||
* 查询历史排队记录(仅已完诊)。
|
int status = order.getStatus();
|
||||||
*/
|
if (status != OrderStatus.WAITING && status != OrderStatus.IN_PROGRESS) {
|
||||||
@Override
|
// 已发药或已完成的医嘱不允许退回
|
||||||
public Page<OrderMain> listQueueHistory(Integer pageNum, Integer pageSize) {
|
throw new BusinessException("医嘱已发药或已完成,不能退回");
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
}
|
||||||
List<Integer> statuses = Arrays.asList(OrderStatus.FINISHED);
|
|
||||||
return (Page<OrderMain>) orderMainMapper.selectByStatuses(statuses);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 更新主表状态为已取消
|
||||||
* 查询待写病历列表。
|
order.setStatus(OrderStatus.CANCELLED);
|
||||||
* 修复 Bug #562:严格限制状态为 WAITING,并启用 PageHelper 分页,
|
orderMainMapper.updateByPrimaryKeySelective(order);
|
||||||
* 避免无分页全表扫描导致的 >2s 响应延迟。
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Page<OrderMain> listPending(Integer pageNum, Integer pageSize) {
|
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
|
||||||
// 仅查询待诊状态,减少数据量与锁竞争
|
|
||||||
List<Integer> statuses = Arrays.asList(OrderStatus.WAITING);
|
|
||||||
return (Page<OrderMain>) orderMainMapper.selectByStatuses(statuses);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 其余业务方法保持不变...
|
// 更新所有明细状态为已取消
|
||||||
|
List<OrderDetail> details = orderDetailMapper.selectByOrderId(orderId);
|
||||||
|
for (OrderDetail detail : details) {
|
||||||
|
detail.setStatus(OrderStatus.CANCELLED);
|
||||||
|
orderDetailMapper.updateByPrimaryKeySelective(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("医嘱 {} 已退回,状态更新为 CANCELLED", orderId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user