Kaynağa Gözat

删除了律师场景表实体类中多余的字段,更新新增和删除接口 添加条件

LuTong 4 hafta önce
ebeveyn
işleme
60065127a1

+ 2 - 10
alien-entity/src/main/java/shop/alien/entity/store/LawyerLegalProblemScenario.java

@@ -27,10 +27,6 @@ public class LawyerLegalProblemScenario extends Model<LawyerLegalProblemScenario
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
-    @ApiModelProperty(value = "编号")
-    @TableField("code")
-    private String code;
-
     @ApiModelProperty(value = "名称")
     @TableField("name")
     private String name;
@@ -43,13 +39,9 @@ public class LawyerLegalProblemScenario extends Model<LawyerLegalProblemScenario
     @TableField("parent_id")
     private Integer parentId;
 
-    @ApiModelProperty(value = "父类编号")
-    @TableField("parent_code")
-    private String parentCode;
-
     @ApiModelProperty(value = "父类名称")
-    @TableField("parentName")
-    private String parent_name;
+    @TableField("parent_name")
+    private String parentName;
 
     @ApiModelProperty(value = "排序字段, 数值越小越靠前")
     @TableField("sort_order")

+ 56 - 10
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerLegalProblemScenarioServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -30,21 +31,20 @@ import java.util.stream.Collectors;
 public class LawyerLegalProblemScenarioServiceImpl extends ServiceImpl<LawyerLegalProblemScenarioMapper, LawyerLegalProblemScenario> implements LawyerLegalProblemScenarioService {
 
     @Override
-    public R<LawyerLegalProblemScenario> addLawyerLegalProblemScenario(LawyerLegalProblemScenario LawyerLegalProblemScenario) {
-        log.info("LawyerLegalProblemScenarioServiceImpl.addLawyerLegalProblemScenario?LawyerLegalProblemScenario={}", LawyerLegalProblemScenario);
-        boolean result = this.save(LawyerLegalProblemScenario);
+    public R<LawyerLegalProblemScenario> addLawyerLegalProblemScenario(LawyerLegalProblemScenario lawyerLegalProblemScenario) {
+        boolean result = this.save(lawyerLegalProblemScenario);
         if (result) {
-            return R.data(LawyerLegalProblemScenario);
+            return R.data(lawyerLegalProblemScenario);
         }
         return R.fail("新增失败");
     }
 
     @Override
-    public R<LawyerLegalProblemScenario> editLawyerLegalProblemScenario(LawyerLegalProblemScenario LawyerLegalProblemScenario) {
-        log.info("LawyerLegalProblemScenarioServiceImpl.editLawyerLegalProblemScenario?LawyerLegalProblemScenario={}", LawyerLegalProblemScenario);
-        boolean result = this.updateById(LawyerLegalProblemScenario);
+    public R<LawyerLegalProblemScenario> editLawyerLegalProblemScenario(LawyerLegalProblemScenario lawyerLegalProblemScenario) {
+        log.info("LawyerLegalProblemScenarioServiceImpl.editLawyerLegalProblemScenario?LawyerLegalProblemScenario={}", lawyerLegalProblemScenario);
+        boolean result = this.updateById(lawyerLegalProblemScenario);
         if (result) {
-            return R.data(LawyerLegalProblemScenario);
+            return R.data(lawyerLegalProblemScenario);
         }
         return R.fail("修改失败");
     }
@@ -52,12 +52,58 @@ public class LawyerLegalProblemScenarioServiceImpl extends ServiceImpl<LawyerLeg
     @Override
     public R<Boolean> deleteLawyerLegalProblemScenario(Integer id) {
         log.info("LawyerLegalProblemScenarioServiceImpl.deleteLawyerLegalProblemScenario?id={}", id);
-        boolean result = this.removeById(id);
+        
+        // 参数校验
+        if (id == null) {
+            log.warn("删除法律问题场景失败:ID为空");
+            return R.fail("场景ID不能为空");
+        }
+        
+        // 查询要删除的场景
+        LawyerLegalProblemScenario scenario = this.getById(id);
+        if (scenario == null) {
+            log.warn("删除法律问题场景失败:场景不存在,id={}", id);
+            return R.fail("场景不存在");
+        }
+        
+        // 递归删除所有子场景
+        List<Integer> allIdsToDelete = new ArrayList<>();
+        allIdsToDelete.add(id);
+        collectChildIds(id, allIdsToDelete);
+        
+        log.info("准备删除场景及其子场景,共{}个,ids={}", allIdsToDelete.size(), allIdsToDelete);
+        
+        // 批量删除所有场景(包括当前场景和所有子场景)
+        boolean result = this.removeByIds(allIdsToDelete);
         if (result) {
-            return R.success("删除成功");
+            log.info("删除法律问题场景成功,共删除{}个场景", allIdsToDelete.size());
+            return R.success("删除成功,共删除" + allIdsToDelete.size() + "个场景");
         }
         return R.fail("删除失败");
     }
+    
+    /**
+     * 递归收集所有子场景的ID
+     *
+     * @param parentId 父场景ID
+     * @param idsList  用于收集所有子场景ID的列表
+     */
+    private void collectChildIds(Integer parentId, List<Integer> idsList) {
+        // 查询所有直接子场景(parentId = 当前场景ID)
+        QueryWrapper<LawyerLegalProblemScenario> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("parent_id", parentId)
+                .eq("delete_flag", 0);
+        List<LawyerLegalProblemScenario> children = this.list(queryWrapper);
+        
+        if (!CollectionUtils.isEmpty(children)) {
+            for (LawyerLegalProblemScenario child : children) {
+                Integer childId = child.getId();
+                idsList.add(childId);
+                // 递归查找子场景的子场景
+                collectChildIds(childId, idsList);
+            }
+        }
+    }
 
     @Override
     public R<LawyerLegalProblemScenario> getCategoryTreeByFirstLevelId(Integer id) {