From ae5f1c795b3d30130f63204bcca5e004618aa220 Mon Sep 17 00:00:00 2001 From: startcode <169514906@qq.com> Date: Mon, 22 Dec 2025 11:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E9=AA=8C=E9=A1=B9=E7=9B=AE=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E6=A3=80=E9=AA=8C=E7=B1=BB=E5=9E=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/InspectionTypeController.java | 49 +++++++------------ .../views/maintainSystem/Inspection/index.vue | 4 +- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/lab/controller/InspectionTypeController.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/lab/controller/InspectionTypeController.java index bbf36538..a2afa1e1 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/lab/controller/InspectionTypeController.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/lab/controller/InspectionTypeController.java @@ -24,14 +24,6 @@ import java.util.List; @AllArgsConstructor public class InspectionTypeController extends BaseController { - // 辅助方法:将字节数组转换为十六进制字符串 - private static String bytesToHex(byte[] bytes) { - StringBuilder sb = new StringBuilder(); - for (byte b : bytes) { - sb.append(String.format("%02X ", b)); - } - return sb.toString().trim(); - } private final IInspectionTypeService inspectionTypeService; private final TransactionTemplate transactionTemplate; @@ -43,7 +35,14 @@ public class InspectionTypeController extends BaseController { public AjaxResult list(InspectionType inspectionType) { // 使用Wrapper构建查询条件,确保order字段被正确处理 QueryWrapper queryWrapper = new QueryWrapper<>(inspectionType); + + // 默认只查询有效记录(前端也有过滤逻辑,这里是为了减少数据传输量) + if (inspectionType.getValidFlag() == null) { + queryWrapper.eq("valid_flag", 1); + } + List list = inspectionTypeService.list(queryWrapper); + log.debug("查询检验类型列表:条件={}, 返回记录数={}", inspectionType, list.size()); return AjaxResult.success(list); } @@ -72,23 +71,15 @@ public class InspectionTypeController extends BaseController { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("code", inspectionType.getCode()); - // 输出调试信息 - System.out.println("检查编码唯一性:code=" + inspectionType.getCode() + ", 长度=" + inspectionType.getCode().length()); - System.out.println("code的十六进制表示:" + bytesToHex(inspectionType.getCode().getBytes())); - - // 直接查询具体记录,而不仅仅是计数 + // 查询是否存在相同编码的记录 List existingRecords = inspectionTypeService.list(queryWrapper); - System.out.println("数据库中存在的记录数:" + existingRecords.size()); - for (InspectionType record : existingRecords) { - System.out.println("已存在记录:id=" + record.getId() + ", code=" + record.getCode() + ", code长度=" + record.getCode().length() + ", code十六进制=" + bytesToHex(record.getCode().getBytes())); - } + log.debug("检查编码唯一性:code={}, 数据库中存在记录数={}", inspectionType.getCode(), existingRecords.size()); if (!existingRecords.isEmpty()) { return AjaxResult.error("检验类型编码已存在"); } // 保存前再次验证 - System.out.println("准备保存数据:" + inspectionType); try { // 使用事务确保一致性 @@ -102,11 +93,11 @@ public class InspectionTypeController extends BaseController { } boolean result = inspectionTypeService.save(inspectionType); - System.out.println("保存结果:" + result); + log.info("新增检验类型成功:code={}, name={}", inspectionType.getCode(), inspectionType.getName()); return toAjax(result); }); } catch (Exception e) { - System.out.println("保存失败,错误信息:" + e.getMessage()); + log.error("新增检验类型失败:code={}, 错误信息:{}", inspectionType.getCode(), e.getMessage(), e); // 捕获唯一性约束冲突异常 if (e.getMessage().contains("uk_inspection_type_code") || @@ -139,15 +130,20 @@ public class InspectionTypeController extends BaseController { try { boolean result = inspectionTypeService.updateById(inspectionType); + if (result) { + log.info("修改检验类型成功:id={}, code={}, name={}", inspectionType.getId(), inspectionType.getCode(), inspectionType.getName()); + } return toAjax(result); } catch (Exception e) { + log.error("修改检验类型失败:id={}, code={}, 错误信息:{}", inspectionType.getId(), inspectionType.getCode(), e.getMessage(), e); + // 捕获唯一性约束冲突异常 - if (e.getMessage().contains("uk_inspection_type_code") || - e.getMessage().contains("duplicate key value") || + if (e.getMessage().contains("uk_inspection_type_code") || + e.getMessage().contains("duplicate key value") || e.getMessage().contains("检验类型编码已存在")) { return AjaxResult.error("检验类型编码已存在"); } - + return AjaxResult.error("更新失败:" + e.getMessage()); } } @@ -180,11 +176,4 @@ public class InspectionTypeController extends BaseController { return AjaxResult.error("删除失败: " + e.getMessage()); } } - - // 测试删除接口,直接返回成功 - @DeleteMapping("/test-delete/{id}") - public AjaxResult testDelete(@PathVariable Long id) { - log.info("测试删除接口,ID: {}", id); - return AjaxResult.success("测试删除成功"); - } } \ No newline at end of file diff --git a/openhis-ui-vue3/src/views/maintainSystem/Inspection/index.vue b/openhis-ui-vue3/src/views/maintainSystem/Inspection/index.vue index 695f6878..d3544386 100644 --- a/openhis-ui-vue3/src/views/maintainSystem/Inspection/index.vue +++ b/openhis-ui-vue3/src/views/maintainSystem/Inspection/index.vue @@ -796,10 +796,10 @@ const getInspectionTypeList = () => { // 确保数据结构与前端使用的一致,处理后端返回的AjaxResult格式 // 后端返回的数据格式: {code: 200, msg: "查询成功", data: [检验类型列表]} const inspectionTypeList = data.data || []; + // 后端实体字段名本身就是 sortOrder,这里不再从不存在的 item.order 做映射 const formattedData = inspectionTypeList.map(item => ({ ...item, - // 将后端返回的order字段映射到前端使用的sortOrder字段 - sortOrder: item.order + sortOrder: item.sortOrder })); // 过滤掉已逻辑删除的记录(validFlag为0) tableData.value = formattedData.filter(item => item.validFlag === 1);