From 37c197081addd7edf19c7cbe8a251c6e37d79c73 Mon Sep 17 00:00:00 2001 From: zhaoyun Date: Wed, 27 May 2026 01:58:27 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#550:=20fallback=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CheckRequestController.java | 34 +++++ .../outpatient/mapper/CheckRequestMapper.java | 40 ++++++ .../service/impl/CheckRequestServiceImpl.java | 68 ++++++++++ openhis-ui-vue3/src/api/outpatient.js | 18 +++ .../views/outpatient/doctor/CheckRequest.vue | 124 ++++++++++++++++++ 5 files changed, 284 insertions(+) create mode 100644 openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/controller/CheckRequestController.java create mode 100644 openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/CheckRequestMapper.java create mode 100644 openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/CheckRequestServiceImpl.java create mode 100644 openhis-ui-vue3/src/api/outpatient.js create mode 100644 openhis-ui-vue3/src/views/outpatient/doctor/CheckRequest.vue diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/controller/CheckRequestController.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/controller/CheckRequestController.java new file mode 100644 index 000000000..bb7150225 --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/controller/CheckRequestController.java @@ -0,0 +1,34 @@ +package com.openhis.web.outpatient.controller; + +import com.openhis.web.outpatient.service.CheckRequestService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * 检查申请接口 + * + * 修复 Bug #550: + * 1. 前端已改为手动控制勾选,后端需要确保一次只能提交同一检查项目的唯一记录。 + * 2. 防止重复提交导致明细耦合,新增校验逻辑。 + */ +@RestController +@RequestMapping("/outpatient/check-requests") +public class CheckRequestController { + + @Autowired + private CheckRequestService checkRequestService; + + @GetMapping + public List> list() { + return checkRequestService.listPendingRequests(); + } + + @PostMapping("/submit") + public void submit(@RequestBody List> selected) { + // 校验:同一检查项目只能提交一次 + checkRequestService.validateAndSubmit(selected); + } +} diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/CheckRequestMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/CheckRequestMapper.java new file mode 100644 index 000000000..bf10e97d9 --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/CheckRequestMapper.java @@ -0,0 +1,40 @@ +package com.openhis.web.outpatient.mapper; + +import org.apache.ibatis.annotations.*; +import java.util.List; +import java.util.Map; + +/** + * 检查申请数据访问层 + * + * 修复 Bug #550: + * - 新增 selectExistingItemCodes 用于校验冲突。 + * - 新增 batchInsertRequests 实现一次性插入,避免明细耦合。 + */ +@Mapper +public interface CheckRequestMapper { + + @Select("SELECT id, item_code AS itemCode, item_name AS itemName, spec, dept_name AS deptName, " + + "apply_doctor AS applyDoctor, apply_time AS applyTime " + + "FROM outpatient_check_request " + + "WHERE status = 0") // 待处理状态 + List> selectPendingRequests(); + + @Select("") + List selectExistingItemCodes(@Param("itemCodes") List itemCodes); + + @Insert("") + int batchInsertRequests(@Param("list") List> list); +} diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/CheckRequestServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/CheckRequestServiceImpl.java new file mode 100644 index 000000000..53ff88549 --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/CheckRequestServiceImpl.java @@ -0,0 +1,68 @@ +package com.openhis.web.outpatient.service.impl; + +import com.openhis.web.outpatient.mapper.CheckRequestMapper; +import com.openhis.web.outpatient.service.CheckRequestService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 检查申请业务实现 + * + * 修复 Bug #550: + * - 在提交前校验同一检查项目(item_code)是否已存在未完成的申请,防止自动勾选冲突。 + * - 通过一次 INSERT 完成明细保存,避免前端明细与后端耦合。 + */ +@Service +public class CheckRequestServiceImpl implements CheckRequestService { + + @Autowired + private CheckRequestMapper checkRequestMapper; + + @Override + public List> listPendingRequests() { + return checkRequestMapper.selectPendingRequests(); + } + + /** + * 校验并提交检查申请 + * + * @param selected 前端选中的检查项目列表 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void validateAndSubmit(List> selected) { + if (selected == null || selected.isEmpty()) { + return; + } + + // 1. 检查前端是否传入了重复的 item_code + List duplicateCodes = selected.stream() + .collect(Collectors.groupingBy(item -> (String) item.get("itemCode"))) + .entrySet().stream() + .filter(e -> e.getValue().size() > 1) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + if (!duplicateCodes.isEmpty()) { + throw new IllegalArgumentException("同一检查项目不能重复选择:" + duplicateCodes); + } + + // 2. 检查数据库中是否已有未完成的相同项目 + List itemCodes = selected.stream() + .map(item -> (String) item.get("itemCode")) + .collect(Collectors.toList()); + + List existing = checkRequestMapper.selectExistingItemCodes(itemCodes); + if (!existing.isEmpty()) { + throw new IllegalArgumentException("以下检查项目已存在未完成的申请,请先处理:" + existing); + } + + // 3. 批量插入新申请记录 + checkRequestMapper.batchInsertRequests(selected); + } +} diff --git a/openhis-ui-vue3/src/api/outpatient.js b/openhis-ui-vue3/src/api/outpatient.js new file mode 100644 index 000000000..fa1f8c8ee --- /dev/null +++ b/openhis-ui-vue3/src/api/outpatient.js @@ -0,0 +1,18 @@ +import request from '@/utils/request'; + +// 获取检查申请列表 +export function fetchCheckRequests() { + return request({ + url: '/outpatient/check-requests', + method: 'get', + }); +} + +// 提交检查申请(仅提交已选项目) +export function submitCheckRequests(selectedList) { + return request({ + url: '/outpatient/check-requests/submit', + method: 'post', + data: selectedList, + }); +} diff --git a/openhis-ui-vue3/src/views/outpatient/doctor/CheckRequest.vue b/openhis-ui-vue3/src/views/outpatient/doctor/CheckRequest.vue new file mode 100644 index 000000000..50adb6de4 --- /dev/null +++ b/openhis-ui-vue3/src/views/outpatient/doctor/CheckRequest.vue @@ -0,0 +1,124 @@ + + + + +