Преглед изворни кода

修复检查项目创建、删除失败的问题

gengjunfang пре 1 недеља
родитељ
комит
e95e69edc9

+ 2 - 1
src/main/java/com/zskk/qcns/modules/exam/entity/ExamItem.java

@@ -1,6 +1,7 @@
 package com.zskk.qcns.modules.exam.entity;
 
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Getter;
@@ -25,7 +26,7 @@ public class ExamItem implements Serializable {
     /**
      * 主键ID
      */
-    @TableId(value = "id")
+    @TableId(value = "id", type = IdType.AUTO)
     private Long id;
 
     /**

+ 1 - 1
src/main/java/com/zskk/qcns/modules/exam/request/ExamItemUpdateVO.java

@@ -18,7 +18,7 @@ public class ExamItemUpdateVO {
 
     @NotNull(message = "ID不能为空")
     @Schema(description = "项目ID", example = "1")
-    private Long id;
+    private String id;
 
     @NotBlank(message = "项目名称不能为空")
     @Schema(description = "项目名称", example = "DX 胸部正位片")

+ 1 - 1
src/main/java/com/zskk/qcns/modules/exam/request/ExamItemVO.java

@@ -16,7 +16,7 @@ import java.time.LocalDateTime;
 public class ExamItemVO {
 
     @Schema(description = "项目ID", example = "1")
-    private Long id;
+    private String id;
 
     @Schema(description = "项目名称", example = "DX 胸部正位片")
     private String itemName;

+ 11 - 16
src/main/java/com/zskk/qcns/modules/exam/service/impl/ExamItemServiceImpl.java

@@ -86,8 +86,10 @@ public class ExamItemServiceImpl extends ServiceImpl<ExamItemMapper, ExamItem> i
     @Transactional(rollbackFor = Exception.class)
     public boolean updateExamItem(ExamItemUpdateVO updateVO) {
         // 检查项目是否存在
-        ExamItem existing = this.getById(updateVO.getId());
-        if (existing == null || existing.getStatus() == 0) {
+        ExamItem existing = this.getOne(new LambdaQueryWrapper<ExamItem>()
+                .eq(ExamItem::getId, updateVO.getId())
+                .eq(ExamItem::getStatus, 1));
+        if (existing == null) {
             throw new RuntimeException("检查项目不存在");
         }
 
@@ -118,18 +120,14 @@ public class ExamItemServiceImpl extends ServiceImpl<ExamItemMapper, ExamItem> i
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean deleteExamItem(Long id) {
-        // 检查项目是否存在
-        ExamItem existing = this.getById(id);
-        if (existing == null) {
-            throw new RuntimeException("检查项目不存在");
-        }
-
         // 逻辑删除
-        existing.setStatus(0);
-        boolean result = this.updateById(existing);
+        ExamItem examItem = new ExamItem();
+        examItem.setId(id);
+        examItem.setStatus(0);
+        boolean result = this.updateById(examItem);
 
         if (result) {
-            log.info("删除检查项目成功: id={}, itemName={}", existing.getId(), existing.getItemName());
+            log.info("删除检查项目成功: id={}", id);
         }
 
         return result;
@@ -138,11 +136,8 @@ public class ExamItemServiceImpl extends ServiceImpl<ExamItemMapper, ExamItem> i
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean updateEnabled(Long id, Integer enabled) {
-        ExamItem examItem = this.getById(id);
-        if (examItem == null) {
-            throw new RuntimeException("检查项目不存在");
-        }
-
+        ExamItem examItem = new ExamItem();
+        examItem.setId(id);
         examItem.setEnabled(enabled);
         boolean result = this.updateById(examItem);