Commit b1a0a64a by 汪志阳

fix:bug修复

parent c8d2e6be
......@@ -123,4 +123,11 @@ public class PlatSpaceController {
return ApiResponseUtils.success(data);
}
@ApiOperation("修复空间层级数据")
@GetMapping("fixPlacePath")
public ApiResponseEntity<String> fixPlacePath(@RequestParam String spaceId) {
spaceService.fixPlacePath(spaceId);
return ApiResponseUtils.success();
}
}
......@@ -96,4 +96,6 @@ public interface PlatSpaceService extends IService<PlatSpace> {
List<PlatSpace> listChildAndOrgIds(List<String> spaceIds, List<String> orgIds);
void fixPlacePath(String spaceId);
}
......@@ -70,7 +70,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
private void check(PlatSpaceAddDTO dto) {
if (StrUtil.isNotBlank(dto.getParentPath())
&& dto.getParentPath().split(",").length >= 4) {
&& dto.getParentPath().split(",").length > 4) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
}
......@@ -224,8 +224,8 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
private void checkAndUpdateSonSpace(PlatSpace space) {
String parentPath = space.getParentPath();
int level = StrUtil.isBlank(parentPath) ? 0 : parentPath.split(",").length;
if (level > 3) {
int level = StrUtil.isBlank(parentPath) ? 1 : parentPath.split(",").length + 1;
if (level > 4) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
}
String spaceId = space.getId();
......@@ -238,16 +238,14 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
if (StrUtil.isBlank(s.getParentPath())) {
return;
}
List<String> parentSpaceIds = Lists.newArrayList(s.getParentPath().split(","));
parentSpaceIds.remove(space.getId());
if (parentSpaceIds.size() > maxLength.get()) {
maxLength.set(parentSpaceIds.size());
int maxSpacePath = getMaxSpacePath(s.getParentPath(), spaceId);
if (maxSpacePath > maxLength.get()) {
maxLength.set(maxSpacePath);
}
maxLength.set(parentSpaceIds.size());
});
sonLevel = maxLength.get();
}
if (level + sonLevel > 3) {
if (level + sonLevel > 4) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
}
// 更新下级空间的parentPath
......@@ -268,6 +266,12 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
private Integer getMaxSpacePath(String path, String splitSpace) {
List<String> pathList = Arrays.asList(path.split(","));
return pathList.size() - pathList.indexOf(splitSpace);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void del(String id) {
......@@ -1093,7 +1097,48 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
return data;
}
@Override
public void fixPlacePath(String spaceId) {
PlatSpace space = getById(spaceId);
if (space == null || StrUtil.isNotBlank(space.getParentId())) {
return;
}
List<PlatSpace> allList = new ArrayList<>();
recursionSetParentPath(spaceId, space.getParentPath(), allList);
if (CollUtil.isNotEmpty(allList)) {
updateBatchById(allList);
}
// fixAllSpacePath();
}
private void fixAllSpacePath() {
List<PlatSpace> allData = list();
List<PlatSpace> firstSpaceList = allData.stream().filter(f -> StrUtil.isBlank(f.getParentId())
&& StrUtil.isBlank(f.getParentPath())).collect(Collectors.toList());
if (CollUtil.isEmpty(firstSpaceList)) {
return;
}
firstSpaceList.forEach(f -> {
List<PlatSpace> allList = new ArrayList<>();
recursionSetParentPath(f.getId(), f.getParentPath(), allList);
if (CollUtil.isNotEmpty(allList)) {
updateBatchById(allList);
}
});
}
private void recursionSetParentPath(String spaceId, String parentPath, List<PlatSpace> allList) {
List<PlatSpace> firstSonList = list(Wrappers.<PlatSpace>lambdaQuery().eq(PlatSpace::getParentId, spaceId));
if (CollUtil.isEmpty(firstSonList)) {
return;
}
firstSonList.forEach(s -> {
s.setParentPath(StrUtil.isNotBlank(parentPath) ? parentPath + "," + s.getParentId() : spaceId);
allList.add(s);
recursionSetParentPath(s.getId(), s.getParentPath(), allList);
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment