|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -30,21 +31,20 @@ import java.util.stream.Collectors;
|
|
|
public class LawyerLegalProblemScenarioServiceImpl extends ServiceImpl<LawyerLegalProblemScenarioMapper, LawyerLegalProblemScenario> implements LawyerLegalProblemScenarioService {
|
|
public class LawyerLegalProblemScenarioServiceImpl extends ServiceImpl<LawyerLegalProblemScenarioMapper, LawyerLegalProblemScenario> implements LawyerLegalProblemScenarioService {
|
|
|
|
|
|
|
|
@Override
|
|
@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) {
|
|
if (result) {
|
|
|
- return R.data(LawyerLegalProblemScenario);
|
|
|
|
|
|
|
+ return R.data(lawyerLegalProblemScenario);
|
|
|
}
|
|
}
|
|
|
return R.fail("新增失败");
|
|
return R.fail("新增失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@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) {
|
|
if (result) {
|
|
|
- return R.data(LawyerLegalProblemScenario);
|
|
|
|
|
|
|
+ return R.data(lawyerLegalProblemScenario);
|
|
|
}
|
|
}
|
|
|
return R.fail("修改失败");
|
|
return R.fail("修改失败");
|
|
|
}
|
|
}
|
|
@@ -52,12 +52,58 @@ public class LawyerLegalProblemScenarioServiceImpl extends ServiceImpl<LawyerLeg
|
|
|
@Override
|
|
@Override
|
|
|
public R<Boolean> deleteLawyerLegalProblemScenario(Integer id) {
|
|
public R<Boolean> deleteLawyerLegalProblemScenario(Integer id) {
|
|
|
log.info("LawyerLegalProblemScenarioServiceImpl.deleteLawyerLegalProblemScenario?id={}", 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) {
|
|
if (result) {
|
|
|
- return R.success("删除成功");
|
|
|
|
|
|
|
+ log.info("删除法律问题场景成功,共删除{}个场景", allIdsToDelete.size());
|
|
|
|
|
+ return R.success("删除成功,共删除" + allIdsToDelete.size() + "个场景");
|
|
|
}
|
|
}
|
|
|
return R.fail("删除失败");
|
|
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
|
|
@Override
|
|
|
public R<LawyerLegalProblemScenario> getCategoryTreeByFirstLevelId(Integer id) {
|
|
public R<LawyerLegalProblemScenario> getCategoryTreeByFirstLevelId(Integer id) {
|