Browse Source

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

tags/v1.1.0^2
wanjing 1 year ago
parent
commit
a133c0bdf7
1 changed files with 53 additions and 34 deletions
  1. +53
    -34
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/update/UpdateDeptService.java

+ 53
- 34
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/update/UpdateDeptService.java View File

@@ -17,7 +17,6 @@ import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;
@@ -140,7 +139,7 @@ public class UpdateDeptService {
}

// 修改部门,公路和路段信息不能为空
if (CollectionUtils.isEmpty(newEditDeptRequest.getRoadSectionDtoList())) {
if (CollectionUtil.isEmpty(newEditDeptRequest.getRoadSectionDtoList())) {
return JsonResult.error(EditDeptCodeEnum.ROAD_IS_NULL.getCode(), EditDeptCodeEnum.ROAD_IS_NULL.getMsg());
}

@@ -148,7 +147,7 @@ public class UpdateDeptService {
List<RoadSectionDto> roadSectionDtoList = newEditDeptRequest.getRoadSectionDtoList();
for (RoadSectionDto roadSectionDto : roadSectionDtoList) {
sectionList = roadSectionDto.getSectionList();
if (CollectionUtils.isEmpty(sectionList)) {
if (CollectionUtil.isEmpty(sectionList)) {
return JsonResult.error(EditDeptCodeEnum.SECTION_IS_NULL.getCode(), EditDeptCodeEnum.SECTION_IS_NULL.getMsg());
}
}
@@ -192,37 +191,49 @@ public class UpdateDeptService {
*/
private void roadHandle(String tenantId, EditDeptRequest oldEditDeptRequest, EditDeptRequest newEditDeptRequest) {
List<RoadSectionDto> oldRoadSectionList = oldEditDeptRequest.getRoadSectionDtoList();
List<String> oldRoadIdList = oldRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());

List<String> oldRoadIdList = null;
if (CollectionUtil.isNotEmpty(oldRoadSectionList)) {
oldRoadIdList = oldRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());
}
List<RoadSectionDto> newRoadSectionList = newEditDeptRequest.getRoadSectionDtoList();
List<String> newRoadIdList = newRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());
List<String> newRoadIdList = null;
if (CollectionUtil.isNotEmpty(newRoadSectionList)) {
newRoadIdList = newRoadSectionList.stream().map(o -> o.getRoad().getId()).collect(Collectors.toList());
}

// 交集:存在公路, 不做处理
// Collection<String> union = org.apache.commons.collections4.CollectionUtils.union(oldRoadIdList, newRoadIdList);

// 差集:新增公路
Collection<String> addRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(newRoadIdList, oldRoadIdList);
if (!CollectionUtils.isEmpty(addRoadIdList)) {
Collection<String> addRoadIdList;
if (CollectionUtil.isNotEmpty(oldRoadIdList)) {
addRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(newRoadIdList, oldRoadIdList);
} else {
addRoadIdList = newRoadIdList;
}
if (CollectionUtil.isNotEmpty(addRoadIdList)) {
// 去重,防止前端提交了重复的数据
addRoadIdList= addRoadIdList.stream().distinct().collect(Collectors.toList());
this.addRoadToDept(tenantId, newEditDeptRequest.getId(), addRoadIdList);
}

// 差集:删除公路
Collection<String> subRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldRoadIdList, newRoadIdList);
Map<String, Long> oldRoadIdMap = oldRoadIdList.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
Map<String, Long> subRoadIdMap = subRoadIdList.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
if (!CollectionUtils.isEmpty(subRoadIdList)) {
List<String> deleteRoadIdList = new ArrayList<>();
for (String roadId : subRoadIdList) {
Long oldCount = oldRoadIdMap.get(roadId);
Long subCount = subRoadIdMap.get(roadId);
if (oldCount.equals(subCount)) {
deleteRoadIdList.add(roadId);
if (CollectionUtil.isNotEmpty(oldRoadIdList)) {
Collection<String> subRoadIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldRoadIdList, newRoadIdList);
Map<String, Long> oldRoadIdMap = oldRoadIdList.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
Map<String, Long> subRoadIdMap = subRoadIdList.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
if (CollectionUtil.isNotEmpty(subRoadIdList)) {
List<String> deleteRoadIdList = new ArrayList<>();
for (String roadId : subRoadIdList) {
Long oldCount = oldRoadIdMap.get(roadId);
Long subCount = subRoadIdMap.get(roadId);
if (oldCount.equals(subCount)) {
deleteRoadIdList.add(roadId);
}
}
if (CollectionUtil.isNotEmpty(deleteRoadIdList)) {
this.removeRoadToDept(tenantId, newEditDeptRequest.getId(), subRoadIdList);
}
}
if (CollectionUtil.isNotEmpty(deleteRoadIdList)) {
this.removeRoadToDept(tenantId, newEditDeptRequest.getId(), subRoadIdList);
}
}
}
@@ -257,7 +268,7 @@ public class UpdateDeptService {
}
list.add(roadDept);
}
if (!CollectionUtils.isEmpty(list)) {
if (CollectionUtil.isNotEmpty(list)) {
roadDeptMapper.insertBatch(list);
}
}
@@ -300,8 +311,10 @@ public class UpdateDeptService {
private void sectionhandle(String tenantId, EditDeptRequest oldEditDeptRequest, EditDeptRequest newEditDeptRequest) {
List<RoadSectionDto> oldRoadSectionList = oldEditDeptRequest.getRoadSectionDtoList();
List<Section> oldSectionList = new ArrayList<>();
for (RoadSectionDto roadSectionDto : oldRoadSectionList) {
oldSectionList.addAll(roadSectionDto.getSectionList());
if (CollectionUtil.isNotEmpty(oldRoadSectionList)) {
for (RoadSectionDto roadSectionDto : oldRoadSectionList) {
oldSectionList.addAll(roadSectionDto.getSectionList());
}
}

List<RoadSectionDto> newRoadSectionList = newEditDeptRequest.getRoadSectionDtoList();
@@ -309,14 +322,17 @@ public class UpdateDeptService {
for (RoadSectionDto roadSectionDto : newRoadSectionList) {
newSectionList.addAll(roadSectionDto.getSectionList());
}

List<String> oldSectionIdList = oldSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());
List<String> newSectionIdList = newSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());

// 差集:新增路段
Collection<String> addSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(newSectionIdList, oldSectionIdList);

if (!CollectionUtils.isEmpty(addSectionIdList)) {
Collection<String> addSectionIdList;
if (CollectionUtil.isNotEmpty(oldSectionList)) {
List<String> oldSectionIdList = oldSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());
addSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(newSectionIdList, oldSectionIdList);
} else {
addSectionIdList = newSectionIdList;
}
if (CollectionUtil.isNotEmpty(addSectionIdList)) {
// 去重,防止前端提交了重复的数据
addSectionIdList= addSectionIdList.stream().distinct().collect(Collectors.toList());
// 添加路段和部门数据
@@ -324,10 +340,13 @@ public class UpdateDeptService {
}

// 差集:删除路段
Collection<String> subSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldSectionIdList, newSectionIdList);
if (!CollectionUtils.isEmpty(subSectionIdList)) {
// 删除路段和部门数据
this.removeSectionToDept(tenantId, newEditDeptRequest.getId(), subSectionIdList);
if (CollectionUtil.isNotEmpty(oldSectionList)) {
List<String> oldSectionIdList = oldSectionList.stream().map(o -> o.getId()).collect(Collectors.toList());
Collection<String> subSectionIdList = org.apache.commons.collections4.CollectionUtils.subtract(oldSectionIdList, newSectionIdList);
if (CollectionUtil.isNotEmpty(subSectionIdList)) {
// 删除路段和部门数据
this.removeSectionToDept(tenantId, newEditDeptRequest.getId(), subSectionIdList);
}
}
}

@@ -362,7 +381,7 @@ public class UpdateDeptService {
list.add(sectionDept);
}

if (!CollectionUtils.isEmpty(list)) {
if (CollectionUtil.isNotEmpty(list)) {
sectionDeptMapper.insertBatch(list);
}
}

Loading…
Cancel
Save